down_cache = array (); if (function_exists('snmpget')) { return (true); } wm_debug("SNMP DS: snmpget() not found. Do you have the PHP SNMP module?\n"); return (false); } function Recognise($targetstring) { if (preg_match("/^snmp:([^:]+):([^:]+):([^:]+):([^:]+)$/", $targetstring, $matches)) { return true; } else { return false; } } function ReadData($targetstring, &$map, &$item) { $data[IN] = null; $data[OUT] = null; $data_time = 0; $timeout = 1000000; $retries = 2; $abort_count = 0; $in_result = null; $out_result = null; if ($map->get_hint('snmp_timeout') != '') { $timeout = intval($map->get_hint('snmp_timeout')); wm_debug('Timeout changed to ' . $timeout . " microseconds.\n"); } if ($map->get_hint("snmp_abort_count") != '') { $abort_count = intval($map->get_hint("snmp_abort_count")); wm_debug("Will abort after $abort_count failures for a given host.\n"); } if ($map->get_hint("snmp_retries") != '') { $retries = intval($map->get_hint("snmp_retries")); wm_debug("Number of retries changed to " . $retries . ".\n"); } if (preg_match("/^snmp:([^:]+):([^:]+):([^:]+):([^:]+)$/", $targetstring, $matches)) { $community = $matches[1]; $host = $matches[2]; $in_oid = $matches[3]; $out_oid = $matches[4]; if (($abort_count == 0) || (($abort_count > 0) && (!isset($this->down_cache[$host]) || intval($this->down_cache[$host]) < $abort_count))) { if (function_exists("snmp_get_quick_print")) { $was = snmp_get_quick_print(); snmp_set_quick_print(1); } if (function_exists("snmp_get_valueretrieval")) { $was2 = snmp_get_valueretrieval(); } if (function_exists('snmp_set_oid_output_format')) { snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC); } if (function_exists('snmp_set_valueretrieval')) { snmp_set_valueretrieval(SNMP_VALUE_PLAIN); } if ($in_oid != '-') { $in_result = snmpget($host, $community, $in_oid, $timeout, $retries); if ($in_result !== FALSE) { $data[IN] = floatval($in_result); $item->add_hint("snmp_in_raw", $in_result); } else { $this->down_cache{$host}++; } } if ($out_oid != '-') { $out_result = snmpget($host, $community, $out_oid, $timeout, $retries); if ($out_result !== FALSE) { // use floatval() here to force the output to be *some* kind of number // just in case the stupid formatting stuff doesn't stop net-snmp returning 'down' instead of 2 $data[OUT] = floatval($out_result); $item->add_hint("snmp_out_raw", $out_result); } else { $this->down_cache{$host}++; } } wm_debug("SNMP ReadData: Got $in_result and $out_result\n"); $data_time = time(); if (function_exists("snmp_set_quick_print")) { snmp_set_quick_print($was); } } else { wm_warn( "SNMP for $host has reached $abort_count failures. Skipping. [WMSNMP01]"); } } wm_debug( sprintf("SNMP ReadData: Returning (%s, %s, %s)\n", string_or_null($data[IN]), string_or_null($data[OUT]), $data_time )); return (array ( $data[IN], $data[OUT], $data_time )); } } // vim:ts=4:sw=4: ?>