0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3 ); function nagios_diode($new_ecode, $new_status, $new_prefdata = NULL) { global $NAGIOS_API_ECODES, $nagios_ecode, $nagios_prefdata, $nagios_status, $nagios_separator; #print "DEBUG: $new_ecode - $new_prefdata - $new_status" ; if ( $NAGIOS_API_ECODES[$new_ecode] > $NAGIOS_API_ECODES[$nagios_ecode] ) { #print "DEBUG: transitioning from: " . $nagios_ecode . " -> " . $new_ecode . "\n"; $nagios_ecode = $new_ecode; } if (is_null($nagios_prefdata)) { $nagios_prefdata = $new_prefdata; } else { $nagios_prefdata = $nagios_prefdata . $nagios_separator . $new_prefdata; } if (is_null($nagios_status)) { $nagios_status = $new_status; } else if (!is_null($new_status)) { $nagios_status = $nagios_status . $nagios_separator . $new_status; } } function cane_one() { global $NAGIOS_API_ECODES, $nagios_ecode, $nagios_prefdata, $nagios_status; print "$nagios_status" . '|' . "$nagios_prefdata"; exit($NAGIOS_API_ECODES[$nagios_ecode]); } function wsstrip($str) { $str=ereg_replace("[\r\t\n]","",$str); return $str; } // Search an array for values using preg_match and return the corresponding key - useful for parsing cmd_output from exec() function array_psearch($needle, $haystack, $strict=false) { if (!is_array($haystack)) user_error('Third argument to array_usearch is expected to be an array, '.gettype($haystack).' given', E_USER_ERROR); foreach($haystack as $key=>$value) if (preg_match($needle, $value)) return $key; }; function snmptable($host, $community, $oid, $isNameOID) { // TODO: get original state and restore at bottom snmp_set_oid_numeric_print(FALSE); snmp_set_quick_print(TRUE); snmp_set_enum_print(TRUE); $retval = array(); // this is what we return // $reval[row][oid|value] // if the return is anything, SNMP tables count from 1 // they call this their "internal index", e.g., // carpIfTable has carpIfIndex $raw = snmprealwalk($host, $community, $oid); if (count($raw) == 0) return ($retval); // no data $prefix_length = 0; $largest = 0; foreach ($raw as $key => $value) { // if ($isNameOID) { $prefix_elements = count(explode('.', $key)); } else { // if we get to here, we're using strictly numeric OIDs // don't just use $oid's length since it may be non-numeric $prefix_elements = count(explode('.', $oid)); } #print "DEBUG: Prefix element count: " . $prefix_elements . "\n"; $tmp = '.' . strtok($key, '.'); while ($prefix_elements > 1) { $tmp .= '.' . strtok('.'); $prefix_elements--; } $tmp .= '.'; $prefix_length = strlen($tmp); $prefix_elements = count(explode('.', $key)); // ask for this object for retval index // uses the OID suffix -- god what // a fucking bad idea this was $prefix_oid_name = $prefix_elements - 2; // this is our retval colum name or "type" $prefix_oid_index = $prefix_elements - 1; // this is our retval colum name $index = explode('.', $key); $retval[$index[$prefix_oid_index]]["oid"] = $key; $retval[$index[$prefix_oid_index]]["$index[$prefix_oid_name]"] = $value; if ($largest < $index[0]) $largest = $index[0]; } if (count($retval) == 0) return ($retval); // no data // fill in holes and blanks the agent may "give" you foreach($retval as $k => $x) { for ($i = 1; $i <= $largest; $i++) { if (! isset($retval[$k][$i])) { $retval[$k][$i] = ''; } } ksort($retval[$k]); } return($retval); } ?>