Пример #1
0
 function __set($name, $value)
 {
     switch ($name) {
         case 'quick_print':
             snmp_set_quick_print($value);
             break;
         case 'oid_output_format':
             /* needs php >= 5.2.0 */
             snmp_set_oid_output_format($value);
             break;
         case 'enum_print':
             snmp_set_enum_print($value);
             break;
         case 'valueretrieval':
             snmp_set_valueretrieval($value);
             break;
         default:
             $trace = debug_backtrace();
             trigger_error('Undefined property via __set(): ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
             return null;
     }
 }
Пример #2
0
 /**
  * Sets the output format for SNMP queries.
  *
  * Should be one of the class OID_OUTPUT_* constants
  *
  * @param int $f The fomat to use
  * @return Cityware\Snmp\SNMP An instance of $this (for fluent interfaces)
  */
 public function setOidOutputFormat($f)
 {
     snmp_set_oid_output_format($f);
     return $this;
 }
Пример #3
0
 function get_snmp($details)
 {
     $CI =& get_instance();
     if (!isset($details->system_id) or $details->system_id == '') {
         $details->snmp_community = 'public';
         $details->snmp_version = '2c';
         $details->snmp_port = '161';
     } else {
         $encrypted_access_details = $CI->m_system->get_access_details($details->system_id);
         if ($encrypted_access_details == '') {
         }
         $decoded_access_details = $CI->encrypt->decode($encrypted_access_details);
         $decoded_access_details = json_decode($decoded_access_details);
         $details->snmp_community = @$decoded_access_details->snmp_community;
         $details->snmp_version = @$decoded_access_details->snmp_version;
         $details->snmp_port = @$decoded_access_details->snmp_port;
         $details->man_ip_address = @$decoded_access_details->ip_address;
     }
     if (!isset($details->snmp_community) or $details->snmp_community == '') {
         $details->snmp_community = 'public';
     }
     if (!isset($details->snmp_version) or $details->snmp_version == '') {
         $details->snmp_version = '';
     }
     if (!isset($details->snmp_port) or $details->snmp_port == '') {
         $details->snmp_port = '161';
     }
     # we may only have been given a system_id
     # but if the access_details were completed, that may be enough
     # if they weren't, we would at least need a hostname ot ip address
     if (!isset($details->man_ip_address) and !isset($details->hostname)) {
         return;
     }
     $module = new stdclass();
     if ((!isset($details->hostname) or $details->hostname == '') and (isset($details->man_ip_address) and $details->man_ip_address != '' and $details->man_ip_address != '000.000.000.000' and $details->man_ip_address != '0.0.0.0')) {
         $details->hostname = gethostbyaddr(ip_address_from_db($details->man_ip_address));
     }
     if ((!isset($details->man_ip_address) or $details->man_ip_address == '' or $details->man_ip_address == '0.0.0.0' or $details->man_ip_address == '000.000.000.000') and (isset($details->hostname) and $details->hostname != '')) {
         $details->man_ip_address = gethostbyname($details->hostname);
     }
     if (filter_var($details->hostname, FILTER_VALIDATE_IP)) {
         # we did not get a valid hostname back :-(
     } else {
         # we have a name of some sort
         if (strpos($details->hostname, ".") !== FALSE) {
             # fqdn - explode it
             if (!isset($details->fqdn) or $details->fqdn == '') {
                 $details->fqdn = $details->hostname;
             }
             $i = explode(".", $details->hostname);
             $details->hostname = $i[0];
             if (!isset($details->domain) or $details->domain == '') {
                 unset($i[0]);
                 $details->domain = implode(".", $i);
             }
         } else {
             # it's just a name
         }
     }
     $timeout = '300000';
     $retries = '2';
     if (!extension_loaded('snmp')) {
         return $details;
     }
     # test for SNMP version
     # to do - test for v3
     if ($details->snmp_version == '') {
         if ($test_v1 = @snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0", $timeout)) {
             # ok, we have v1
             $details->snmp_version = '1';
         }
         if ($test_v2 = @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0", $timeout)) {
             # ok, we have v2
             $details->snmp_version = '2c';
         }
     }
     if ($details->snmp_version == '2c') {
         snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
         // test for connectivity
         $test_connect = @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0", $timeout, $retries);
         if ($test_connect) {
             // printer duplex
             $details->printer_duplex = '';
             $i = @snmp2_walk($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.13.4.1.10.1");
             if (count($i) > 0) {
                 $details->printer_duplex = 'False';
                 for ($k = 0; $k < count($i); $k++) {
                     if (mb_strpos($i[$k], "Duplex") !== FALSE) {
                         $details->printer_duplex = 'True';
                     }
                 }
             }
             // sysObjectID
             #$i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0" ));
             $details->snmp_oid = str_replace("OID: .", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.2.0"));
             if (strtolower($details->snmp_oid) == 'no such object available on this agent at this oid') {
                 $details->snmp_oid = '';
             }
             if ($details->snmp_oid > '') {
                 $oid = get_oid($details->snmp_oid);
                 $details->manufacturer = $oid->manufacturer;
                 $details->man_manufacturer = $oid->manufacturer;
                 $details->model = $oid->model;
                 $details->man_model = $oid->model;
                 $details->type = $oid->type;
                 $details->device_type = $oid->type;
                 $details->man_type = $oid->type;
                 $details->os_group = $oid->os_group;
                 $details->man_os_group = $oid->os_group;
             }
             if ($details->snmp_oid == '1.3.6.1.4.1.8072.3.2.255') {
                 # a generic OID - take some guesses...
                 $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0"));
                 if (strpos($i, "Darwin Kernel Version 12") !== FALSE) {
                     # looks like an OSX device
                     $details->manufacturer = "Apple Inc";
                 }
             }
             if ($details->snmp_oid == '1.3.6.1.4.1.6876.4.1') {
                 # grab some specific details for VMware ESX
                 $model = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.6876.1.1.0"));
                 $version = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.6876.1.2.0"));
                 $details->model = $model . " (" . $version . ")";
                 $details->model = str_replace("\"", "", $details->model);
                 $details->man_model = $details->model;
                 $details->os_group = "VMware";
                 $details->man_os_group = "VMware";
                 $details->os_family = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.6876.1.1.0"));
                 $details->os_family = str_replace("\"", "", $details->os_family);
                 $details->man_os_family = $details->os_family;
                 $details->os_name = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0"));
                 $details->os_name = str_replace("\"", "", $details->os_name);
                 $details->man_os_name = $details->os_name;
                 $details->type = 'computer';
                 $details->man_type = 'computer';
                 $details->device_type = 'computer';
                 $details->man_class = 'hypervisor';
             }
             if (substr($details->snmp_oid, 0, 13) == '1.3.6.1.4.1.9') {
                 # grab some Cisco specific details
                 $i = explode("\$", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.9.9.25.1.1.1.2.5"));
                 $details->os_version = trim($i[1]);
                 $i = @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.9.9.25.1.1.1.2.7");
                 if (strpos($i, "IOS") !== FALSE) {
                     $details->os_group = 'Cisco';
                     $details->man_os_group = 'Cisco';
                     $details->os_family = 'Cisco IOS';
                     $details->man_os_family = 'Cisco IOS';
                     $details->os_name = "Cisco IOS version " . $details->os_version;
                     $details->man_os_name = "Cisco IOS version " . $details->os_version;
                 }
                 if (strpos($i, "Catalyst Operating") !== FALSE) {
                     $details->os_group = 'Cisco';
                     $details->man_os_group = 'Cisco';
                     $details->os_family = 'Cisco Catalyst OS';
                     $details->man_os_family = 'Cisco Catalyst OS';
                     $detail->os_name = "Cisco Catalyst OS version " . $details->os_version;
                     $detail->man_os_name = "Cisco Catalyst OS version " . $details->os_version;
                 }
             }
             // manufacturer
             if (!isset($details->manufacturer) or $details->manufacturer == '') {
                 $hex = @snmp2_walk($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.8.2.1.14.1");
                 if (count($hex) > 0) {
                     if (isset($hex[1])) {
                         if (mb_strpos($hex[1], "Hex-STRING: ") !== FALSE) {
                             $hex[1] = str_replace("Hex-STRING: ", "", $hex[1]);
                             for ($i = 0; $i < strlen($hex[1]); $i++) {
                                 $details->manufacturer .= chr(hexdec(substr($hex[1], $i, 2)));
                             }
                         } else {
                             $details->manufacturer = str_replace("STRING: ", "", $hex[1]);
                             $details->manufacturer = str_replace('"', '', $details->manufacturer);
                         }
                     }
                 }
                 if ($details->manufacturer == '' or $details->manufacturer == 'No Such Object available on this agent at this OID') {
                     $details->manufacturer = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.12.1")));
                 }
             }
             if ($details->manufacturer == 'No Such Instance currently exists at this OID') {
                 $details->manufacturer = '';
             }
             if ($details->manufacturer == 'No Such Object available on this agent at this OID') {
                 $details->manufacturer = '';
             }
             // serial
             if (!isset($details->serial) or $details->serial == '') {
                 # generic snmp
                 $details->serial = str_replace('"', '', str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.5.1.1.17.1")));
                 if ($details->serial == 'No Such Instance currently exists at this OID') {
                     $details->serial = '';
                 }
                 if ($details->serial == 'No Such Object available on this agent at this OID') {
                     $details->serial = '';
                 }
                 if ($details->serial == 'No Such Instance currently exists at this OID') {
                     $details->serial = '';
                 }
                 # Generic Cisco
                 if ($details->serial == '') {
                     $details->serial = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.11.1")));
                     if ($details->serial == 'No Such Instance currently exists at this OID') {
                         $details->serial = '';
                     }
                     if ($details->serial == 'No Such Object available on this agent at this OID') {
                         $details->serial = '';
                     }
                     if ($details->serial == 'No Such Instance currently exists at this OID') {
                         $details->serial = '';
                     }
                 }
                 # Cisco 37xx stack
                 if ($details->serial == '') {
                     $details->serial = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.9.5.1.2.19.0")));
                     if ($details->serial == 'No Such Instance currently exists at this OID') {
                         $details->serial = '';
                     }
                     if ($details->serial == 'No Such Object available on this agent at this OID') {
                         $details->serial = '';
                     }
                     if ($details->serial == 'No Such Instance currently exists at this OID') {
                         $details->serial = '';
                     }
                 }
                 # remove  false
                 if ($details->serial == 'No Such Instance currently exists at this OID') {
                     $details->serial = '';
                 }
                 if ($details->serial == 'No Such Object available on this agent at this OID') {
                     $details->serial = '';
                 }
                 if ($details->serial == 'No Such Instance currently exists at this OID') {
                     $details->serial = '';
                 }
             }
             $details->man_serial = $details->serial;
             // mac address
             if (!isset($details->mac_address) or $details->mac_address == '') {
                 $interface_number = @str_replace("INTEGER: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.2." . $details->man_ip_address));
                 $details->mac_address = @str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.2.2.1.6." . $interface_number));
                 $details->mac_address = @trim(str_replace("Hex-", "", $details->mac_address));
                 $details->mac_address = @str_replace(" ", ":", $details->mac_address);
                 # need to split and join because of the dropped 0's
                 $i = explode(":", $details->mac_address);
                 for ($k = 0; $k < count($i); $k++) {
                     if (strlen($i[$k]) == 1) {
                         $i[$k] = '0' . $i[$k];
                     }
                     if (strlen($i[$k]) == 0) {
                         $i[$k] = '00';
                     }
                 }
                 $details->mac_address = strtoupper(implode(":", $i));
                 if ($details->mac_address == '00') {
                     $details->mac_address = '';
                 }
             }
             // type
             if (!isset($details->type) or $details->type == '') {
                 $h = str_replace("OID: HOST-RESOURCES-TYPES::hrDevice", "", str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.25.3.2.1.2.1")));
                 if (strtolower($h) == 'no such object available on this agent at this oid' or $h == '') {
                     # If the device is a Switch, the OID 1.3.6.1.2.1.17.1.2.0 and OID 1.3.6.1.2.1.4.1.0 should have a value of 2
                     $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.17.1.2.0"));
                     $j = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.1.0"));
                     if ($i == '2' and $j == '2') {
                         $details->type = 'switch';
                     }
                     # If the device is a Router, the OID 1.3.6.1.2.1.4.1.0 should have a value of 1
                     if (!isset($details->type) or $details->type == '') {
                         $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.1.0"));
                         if ($i == '1') {
                             $device->type = 'router';
                         }
                     }
                     # If the device is a Printer, the OID 1.3.6.1.2.1.43.5.1.1.1.1 should have a value
                     if (!isset($details->type) or $details->type == '') {
                         $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.43.5.1.1.1.1"));
                         if ($i == '1') {
                             $device->type = 'printer';
                         }
                     }
                 }
             }
             if (isset($details->type) and $details->type != '' and (!isset($details->man_type) or $details->man_type == '')) {
                 $details->man_type = $details->type;
             }
             // model
             if (!isset($details->model) or $details->model == '') {
                 $details->model = str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.25.3.2.1.3.1"));
                 if ($details->model == '' or $details->model == 'No Such Object available on this agent at this OID') {
                     if (strpos(strtolower($details->manufacturer), 'cisco') !== FALSE) {
                         $details->model = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.13.1")));
                     }
                 }
             }
             if (strtolower($details->model) == 'no such object available on this agent at this oid') {
                 $details->model = '';
             }
             // name
             if (!isset($details->sysname) or $details->sysname == '') {
                 $details->sysname = strtolower(str_replace("\"", "", str_replace("STRING: ", "", @snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0"))));
             }
             if (strtolower($details->sysname) == 'no such object available on this agent at this oid') {
                 $details->sysname = '';
             }
             // description
             if (!isset($details->description) or $details->description == '') {
                 $details->description = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0")));
                 $details->description = str_replace("\r\n", " ", $details->description);
             }
             if (strtolower($details->description) == 'no such object available on this agent at this oid') {
                 $details->description = '';
             }
             // uptime
             if (!isset($details->uptime) or $details->uptime == '') {
                 $i = str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.3.0"));
                 if ($i > '' and strpos($i, ")") !== FALSE) {
                     $j = explode(")", $i);
                     $details->uptime = trim($j[1]);
                 } else {
                     $details->uptime = '';
                 }
             }
             // location
             if (!isset($details->location) or $details->location == '') {
                 $details->location = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.6.0")));
             }
             if ($details->location == 'Unknown (edit /etc/snmp/snmpd.conf)') {
                 $details->location = '';
             }
             if ($details->location == 'not set') {
                 $details->location = '';
             }
             if ($details->location == 'No Such Object available on this agent at this OID') {
                 $details->location = '';
             }
             if ($details->location > '') {
                 $details->description = "Location: " . $details->location . ". " . $details->description;
             }
             // contact
             if (!isset($details->contact) or $details->contact == '') {
                 $details->contact = str_replace("\"", "", str_replace("STRING: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.4.0")));
             }
             if ($details->contact == 'Root  (configure /etc/snmp/snmpd.conf)') {
                 $details->contact = '';
             }
             if ($details->contact == 'not set') {
                 $details->contact = '';
             }
             if ($details->contact > '') {
                 $details->description = "Contact: " . $details->contact . ". " . $details->description;
             }
             // subnet
             if (!isset($details->subnet) or $details->subnet == '') {
                 $details->subnet = @str_replace("IpAddress: ", "", snmp2_get($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.3." . $details->man_ip_address));
             }
             if ($details->subnet == 'No Such Instance currently exists at this OID') {
                 $details->subnet = '';
             }
             if ($details->subnet == 'No Such Object available on this agent at this OID') {
                 $details->subnet = '';
             }
             /*
             // installed modules with serial numbers
             $i = @snmp2_walk($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.47.1.1.1.1.11");
             if (count($i) > 0) {
             	if (($i[0] == 'No more variables left in this MIB View (It is past the end of the MIB tree)') or ($i[0] == '')){unset($i); $i = array();}
             	if (count($i) > 0) {
             		$count = 0;
             		for ($j=0; $j<count($i); $j++) {
             			if ((mb_strpos($i[$j], $details->serial) === FALSE) and ($i[$j] != "") and ($i[$j] != "\"\"")){
             				$k = $j + 1;
             				$k = "1.3.6.1.2.1.47.1.1.1.1.3." . $k;
             				$oid = snmp2_get($details->man_ip_address, $details->snmp_community, $k);
             				$oid = str_replace("OID: .", "", $oid);
             				$module->$count = get_oid($oid);
             				$module->$count->serial = str_replace("STRING: ", "", $i[$j]);
             				$module->$count->serial = str_replace('"', '', $module->$count->serial);
             				$count++;
             			}
             		}
             		$details->modules = $module;
             	}
             }
             */
         }
     }
     if ($details->snmp_version == '1') {
         $details->snmp_oid = '';
         $details->snmp_oid = str_replace("OID: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.2.0"));
         if (strtolower($details->snmp_oid) == 'no such object available on this agent at this oid') {
             $details->snmp_oid = '';
         }
         if ($details->snmp_oid > '') {
             $oid = get_oid($details->snmp_oid);
             $details->manufacturer = $oid->manufacturer;
             $details->man_manufacturer = $oid->manufacturer;
             $details->model = $oid->model;
             $details->man_model = $oid->model;
             $details->type = $oid->type;
             $details->device_type = $oid->type;
             $details->man_type = $oid->type;
             $details->os_group = $oid->os_group;
             $details->man_os_group = $oid->os_group;
         }
         if ($details->oid == '1.3.6.1.4.1.714.1.2.6') {
             # We have a Wyse thin client - some specifics.
             $details->serial = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.4.1.714.1.2.6.2.1.0"));
             $details->sysname = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0"));
             $details->description = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.1.0"));
             $details->contact = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.4.0"));
             if ($details->contact > '') {
                 $details->description = "Contact: " . $details->contact . ". " . $details->description;
             }
             $details->location = str_replace("String: .", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.6.0"));
             if ($details->location > '') {
                 $details->description = "Location: " . $details->location . ". " . $details->description;
             }
         }
         $interface_number = str_replace("INTEGER: ", "", @snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.2." . $details->man_ip_address));
         $i = "1.3.6.1.2.1.2.2.1.6." . $interface_number;
         $details->mac_address = snmpget($details->man_ip_address, $details->snmp_community, $i);
         $details->mac_address = trim(str_replace("Hex-STRING: ", "", $details->mac_address));
         $details->mac_address = str_replace(" ", ":", $details->mac_address);
         $details->subnet = str_replace("IpAddress: ", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.20.1.3." . $details->man_ip_address));
         $details->hostname = trim(str_replace("\"", "", str_replace("STRING: ", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.1.5.0"))));
         $details->next_hop = str_replace("IpAddress: ", "", snmpget($details->man_ip_address, $details->snmp_community, "1.3.6.1.2.1.4.21.1.7.0.0.0.0"));
     }
     // update the system
     #if ($details->snmp_version > '') {
     #$CI2->m_system->process_snmp($details);
     return $details;
     #}
 }
Пример #4
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_SNMPPINFO_ACCESS)) {
         case 'command':
             if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                     $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 } else {
                     $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 }
                 foreach ($printers as $printer) {
                     CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
                     if (strlen(trim($buffer)) > 0) {
                         $this->_filecontent[$printer] = $buffer;
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
                         if (strlen(trim($buffer2)) > 0) {
                             $this->_filecontent[$printer] = $this->_filecontent[$printer] . "\n" . $buffer2;
                         }
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.43.18.1.1", $buffer3, PSI_DEBUG);
                         if (strlen(trim($buffer3)) > 0) {
                             $this->_filecontent[$printer] = $this->_filecontent[$printer] . "\n" . $buffer3;
                         }
                     }
                 }
             }
             break;
         case 'php-snmp':
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                     $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 } else {
                     $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 }
                 foreach ($printers as $printer) {
                     if (!PSI_DEBUG) {
                         restore_error_handler();
                         /* default error handler */
                         $old_err_rep = error_reporting();
                         error_reporting(E_ERROR);
                         /* fatal errors only */
                     }
                     $bufferarr = snmprealwalk($printer, "public", ".1.3.6.1.2.1.1.5", 1000000, 1);
                     if (!PSI_DEBUG) {
                         error_reporting($old_err_rep);
                         /* restore error level */
                         set_error_handler('errorHandlerPsi');
                         /* restore error handler */
                     }
                     if (!empty($bufferarr)) {
                         $buffer = "";
                         foreach ($bufferarr as $id => $string) {
                             $buffer = $buffer . $id . " = " . $string . "\n";
                         }
                         if (!PSI_DEBUG) {
                             restore_error_handler();
                             /* default error handler */
                             $old_err_rep = error_reporting();
                             error_reporting(E_ERROR);
                             /* fatal errors only */
                         }
                         $bufferarr2 = snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.11.1.1", 1000000, 1);
                         if (!PSI_DEBUG) {
                             error_reporting($old_err_rep);
                             /* restore error level */
                             set_error_handler('errorHandlerPsi');
                             /* restore error handler */
                         }
                         if (!empty($bufferarr2)) {
                             foreach ($bufferarr2 as $id => $string) {
                                 $buffer = $buffer . $id . " = " . $string . "\n";
                             }
                         }
                         if (!PSI_DEBUG) {
                             restore_error_handler();
                             /* default error handler */
                             $old_err_rep = error_reporting();
                             error_reporting(E_ERROR);
                             /* fatal errors only */
                         }
                         $bufferarr3 = snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.18.1.1", 1000000, 1);
                         if (!PSI_DEBUG) {
                             error_reporting($old_err_rep);
                             /* restore error level */
                             set_error_handler('errorHandlerPsi');
                             /* restore error handler */
                         }
                         if (!empty($bufferarr3)) {
                             foreach ($bufferarr3 as $id => $string) {
                                 $buffer = $buffer . $id . " = " . $string . "\n";
                             }
                         }
                         if (strlen(trim($buffer)) > 0) {
                             $this->_filecontent[$printer] = $buffer;
                         }
                     }
                 }
             }
             break;
         case 'data':
             if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                     $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 } else {
                     $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 }
                 $pn = 0;
                 foreach ($printers as $printer) {
                     $buffer = "";
                     if (CommonFunctions::rfts(APP_ROOT . "/data/snmppinfo{$pn}.txt", $buffer) && !empty($buffer)) {
                         $this->_filecontent[$printer] = $buffer;
                     }
                     $pn++;
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_SNMPPINFO_ACCESS)", "Bad SNMPPInfo configuration in SNMPPInfo.config.php");
             break;
     }
 }
 private function changeSNMPSettings()
 {
     if (function_exists("snmp_get_quick_print")) {
         $this->snmpSavedQuickPrint = snmp_get_quick_print();
         snmp_set_quick_print(1);
     }
     if (function_exists("snmp_get_valueretrieval")) {
         $this->snmpSavedValueRetrieval = 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);
     }
 }
Пример #6
0
 function snmp_audit($ip, $credentials, $display)
 {
     error_reporting(E_ALL);
     $CI =& get_instance();
     $log = new stdClass();
     $log->file = 'system';
     $log->severity = 7;
     if ($display == 'y') {
         $log->display = 'y';
     } else {
         $log->display = 'n';
     }
     if (!extension_loaded('snmp')) {
         $log->message = 'SNMP PHP function not loaded hence not attempting to run snmp_helper::snmp_audit function';
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } else {
         $log->message = 'SNMP PHP function loaded and attempting to run snmp_helper::snmp_audit function';
         stdlog($log);
     }
     # we need an ip address
     if (empty($ip)) {
         $log->message = 'SNMP command received no ip address';
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } elseif (!filter_var($ip, FILTER_VALIDATE_IP)) {
         $log->message = 'SNMP command received invalid ip address';
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } else {
         $log->message = 'snmp_helper::snmp_audit function received ip ' . $ip;
         stdlog($log);
     }
     if (empty($credentials) or !is_object($credentials)) {
         $log->message = 'SNMP snmp_helper::snmp_audit received no credentials for ' . $ip;
         $log->severity = 5;
         stdlog($log);
         unset($log);
         return false;
     } else {
         $log->message = 'snmp_helper::snmp_audit function received credentials for ip ' . $ip;
         stdlog($log);
     }
     # new in 1.5 - remove the type from the returned SNMP query.
     # this affects the snmp_clean function in this file
     snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
     snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
     $details = new stdClass();
     $module = new stdclass();
     $return_ips = new stdClass();
     $return_ips->item = array();
     $details->ip = (string) $ip;
     $details->manufacturer = '';
     $details->serial = '';
     $details->model = '';
     $details->type = '';
     $details->sysDescr = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.1.0");
     $details->description = $details->sysDescr;
     $details->sysContact = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.4.0");
     $details->contact = $details->sysContact;
     $details->sysName = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.5.0");
     $details->hostname = $details->sysName;
     $details->name = $details->sysName;
     $details->sysLocation = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.6.0");
     $details->location = $details->sysLocation;
     // uptime
     $details->sysUpTime = intval(my_snmp_get($ip, $credentials, "1.3.6.1.6.3.10.2.1.3.0")) * 100;
     if (empty($details->sysUpTime)) {
         $details->sysUpTime = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.3.0");
     }
     if (empty($details->sysUpTime)) {
         $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.3.0");
         if ($i > '' and strpos($i, ")") !== false) {
             $j = explode(")", $i);
             $details->uptime = intval(trim($j[1]) * 24 * 60 * 60);
         } else {
             $details->uptime = '';
         }
     }
     // OID
     $details->sysObjectID = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.1.2.0");
     $details->snmp_oid = $details->sysObjectID;
     if ($details->snmp_oid > '') {
         $details->manufacturer = get_oid($details->snmp_oid);
         if ($details->manufacturer == 'net-snmp') {
             $details->manufacturer = (string) '';
         }
     }
     # sometimes we get an OID, but not enough to specify a manufacturer
     $explode = explode(".", $details->snmp_oid);
     if (!isset($explode[6])) {
         $vendor_oid = 0;
         if (strpos($details->sysDescr, "ZyXEL") !== false) {
             # we have a Zyxel device
             $vendor_oid = 890;
         }
     } else {
         $vendor_oid = intval($explode[6]);
     }
     if (file_exists(BASEPATH . '../application/helpers/snmp_' . $vendor_oid . '_helper.php')) {
         $log->message = 'snmp_helper::snmp_audit is loading the snmp helper for ' . $vendor_oid . ' when scanning ' . $ip;
         stdlog($log);
         unset($get_oid_details);
         include 'snmp_' . $vendor_oid . "_helper.php";
         $new_details = $get_oid_details($ip, $credentials, $details->snmp_oid);
         foreach ($new_details as $key => $value) {
             $details->{$key} = $value;
         }
         unset($new_details);
     } else {
         $log->message = 'snmp_helper::snmp_audit could not load the snmp helper for ' . $vendor_oid . ' when scanning ' . $ip;
         $log->severity = 6;
         stdlog($log);
         $log->severity = 7;
     }
     if (!empty($details->sysDescr) and stripos($details->sysDescr, 'dd-wrt') !== false) {
         $details->os_group = 'Linux';
         $details->os_name = 'DD-WRT';
         $details->type = 'router';
     }
     if (!empty($details->sysDescr) and stripos($details->sysDescr, "Darwin Kernel Version 12") !== false) {
         $details->manufacturer = "Apple Inc";
         $details->os_family = 'Apple OSX';
     }
     if (!empty($details->manufacturer) and (stripos($details->manufacturer, 'tplink') !== false or stripos($details->manufacturer, 'tp-link') !== false)) {
         $details->manufacturer = 'TP-Link Technology Co.,Ltd';
     }
     if (!empty($details->sysDescr) and stripos($details->sysDescr, 'buffalo terastation') !== false) {
         $details->manufacturer = 'Buffalo';
         $details->model = 'TeraStation';
         $details->type = 'nas';
     }
     if (!empty($details->sysDescr) and (stripos($details->sysDescr, 'synology') !== false or stripos($details->sysDescr, 'diskstation') !== false)) {
         $details->manufacturer = 'Synology';
         $temp = my_snmp_get($ip, $credentials, "1.3.6.1.4.1.6574.1.5.1.0");
         $details->model = trim('DiskStation ' . $temp);
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.4.1.6574.1.5.2.0");
         $details->type = 'nas';
         $details->os_group = 'Linux';
         $details->os_family = 'Synology DSM';
         $details->os_name = 'Synology ' . my_snmp_get($ip, $credentials, "1.3.6.1.4.1.6574.1.5.3.0");
     }
     // guess at manufacturer using entity mib
     if (empty($details->manufacturer)) {
         $details->manufacturer = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.12.1");
     }
     // guess at model using entity mib
     if (empty($details->model)) {
         $details->model = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.13");
     }
     // guess at model using host resources mib
     if (empty($details->model)) {
         $details->model = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.25.3.2.1.3.1");
     }
     // serial
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.11");
     }
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.11.1");
     }
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.11.1.0");
     }
     # generic snmp
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.5.1.1.17.1");
     }
     # below is another generic attempt - works for my NetGear Cable Modem
     if (empty($details->serial)) {
         $details->serial = my_snmp_get($ip, $credentials, "1.3.6.1.4.1.4491.2.4.1.1.1.3.0");
     }
     $log->message = 'snmp_helper::snmp_audit thinks ' . $ip . ' is a type:' . $details->type . ' model:' . $details->model . ' serial:' . $details->serial;
     stdlog($log);
     // subnet
     if (empty($details->subnet)) {
         $details->subnet = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.4.20.1.3." . $details->ip);
     }
     // mac address
     if (empty($details->mac_address)) {
         $interface_number = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.4.20.1.2." . $ip);
         snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
         $details->mac_address = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6." . $interface_number);
         snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
         $details->mac_address = format_mac($details->mac_address);
     }
     // last attempt at a MAC - just use whatever's in the first interface MAC
     if (empty($details->mac_address)) {
         snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
         $details->mac_address = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6.1");
         snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
         $details->mac_address = format_mac($details->mac_address);
     }
     $log->message = 'snmp_helper::snmp_audit MAC Address for ' . $ip . ' is ' . $details->mac_address;
     stdlog($log);
     // type
     if (empty($details->type) or $details->type == 'network printer') {
         $h = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.25.3.2.1.2.1");
         if ($h == '1.3.6.1.2.1.25.3.1.5') {
             # we have a printer
             $details->type = 'network printer';
             $i = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.13.4.1.10.1");
             if (count($i) > 0) {
                 $details->printer_duplex = 'n';
                 for ($k = 0; $k < count($i); $k++) {
                     if (mb_strpos($i[$k], "Duplex") !== false) {
                         $details->printer_duplex = 'y';
                     }
                 }
             }
             if (empty($details->manufacturer)) {
                 $hex = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.8.2.1.14.1");
                 if (count($hex) > 0) {
                     if (isset($hex[1])) {
                         if (mb_strpos($hex[1], "Hex-STRING: ") !== false) {
                             $hex[1] = str_replace("Hex-STRING: ", "", $hex[1]);
                             for ($i = 0; $i < strlen($hex[1]); $i++) {
                                 $details->manufacturer .= chr(hexdec(substr($hex[1], $i, 2)));
                             }
                         } else {
                             $details->manufacturer = str_replace("STRING: ", "", $hex[1]);
                             $details->manufacturer = str_replace('"', '', $details->manufacturer);
                         }
                     }
                 }
             }
             $details->printer_color = 'n';
             $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.11.1.1.6.1.2");
             if (strpos(strtolower($i), "cartridge") !== false) {
                 # it's likely this is a colour printer
                 $details->printer_color = 'y';
             }
         } else {
             # If the device is a Switch, the OID 1.3.6.1.2.1.17.1.2.0 is an integer and
             #                                OID 1.3.6.1.2.1.4.1.0    should have a value of 2
             $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.17.1.2.0");
             $j = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.4.1.0");
             if ($i == intval($i) and $j == '2') {
                 $details->type = 'switch';
             }
             # If the device is a Router, the OID 1.3.6.1.2.1.4.1.0 should have a value of 1 (already read above)
             if (empty($details->type)) {
                 if ($i == '1') {
                     $details->type = 'router';
                 }
             }
             # If the device is a Printer, the OID 1.3.6.1.2.1.43.5.1.1.1.1 should have a value
             #if (!isset($details->type) or $details->type == '') {
             $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.5.1.1.1.1");
             if (strpos(strtolower($i), "counter32") !== false) {
                 $details->type = 'network printer';
                 // printer duplex
                 $details->printer_duplex = '';
                 $i = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.13.4.1.10.1");
                 if (count($i) > 0) {
                     $details->printer_duplex = 'n';
                     for ($k = 0; $k < count($i); $k++) {
                         if (mb_strpos($i[$k], "Duplex") !== false) {
                             $details->printer_duplex = 'y';
                         }
                     }
                 }
                 if (empty($details->manufacturer)) {
                     $hex = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.43.8.2.1.14.1");
                     if (count($hex) > 0) {
                         if (isset($hex[1])) {
                             if (mb_strpos($hex[1], "Hex-STRING: ") !== false) {
                                 $hex[1] = str_replace("Hex-STRING: ", "", $hex[1]);
                                 for ($i = 0; $i < strlen($hex[1]); $i++) {
                                     $details->manufacturer .= chr(hexdec(substr($hex[1], $i, 2)));
                                 }
                             } else {
                                 $details->manufacturer = str_replace("STRING: ", "", $hex[1]);
                                 $details->manufacturer = str_replace('"', '', $details->manufacturer);
                             }
                         }
                     }
                 }
                 $details->printer_color = 'n';
                 $i = my_snmp_get($ip, $credentials, "1.3.6.1.2.1.43.11.1.1.6.1.2");
                 if (strpos(strtolower($i), "cartridge") !== false) {
                     # it's likely this is a colour printer
                     $details->printer_color = 'y';
                 }
             }
         }
     }
     // modules - NOTE, we call these 'entities' in the web interface
     $log->message = 'snmp_helper::snmp_audit module retrieval for ' . $ip . ' starting';
     stdlog($log);
     $modules = array();
     $modules_list = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.47.1.1.1.1.2");
     if (isset($modules_list) and is_array($modules_list) and count($modules_list) > 0) {
         $log->message = 'snmp_helper::snmp_audit module count for ' . $ip . ' is ' . count($modules_list);
         stdlog($log);
         $log->message = 'snmp_helper::snmp_audit object_id retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_object_id = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.3');
         $log->message = 'snmp_helper::snmp_audit contained_in retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_contained_in = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.4');
         $log->message = 'snmp_helper::snmp_audit class retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_class = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.5');
         $log->message = 'snmp_helper::snmp_audit hardware_revision retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_hardware_revision = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.8');
         $log->message = 'snmp_helper::snmp_audit firmware_revision retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_firmware_revision = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.9');
         $log->message = 'snmp_helper::snmp_audit software_revision retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_software_revision = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.10');
         $log->message = 'snmp_helper::snmp_audit serial_number retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_serial_number = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.11');
         $log->message = 'snmp_helper::snmp_audit asset_id retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_asset_id = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.15');
         $log->message = 'snmp_helper::snmp_audit is_fru retrieval for ' . $ip . ' starting';
         stdlog($log);
         $temp_is_fru = my_snmp_real_walk($ip, $credentials, '1.3.6.1.2.1.47.1.1.1.1.16');
         foreach ($modules_list as $key => $value) {
             $log->message = 'snmp_helper::snmp_audit processing module ' . $value . ' for ' . $ip . ' starting';
             stdlog($log);
             $module = new stdClass();
             $module->description = $value;
             $module->module_index = str_replace('.1.3.6.1.2.1.47.1.1.1.1.2.', '', $key);
             $module->object_ident = $temp_object_id['.1.3.6.1.2.1.47.1.1.1.1.3.' . $module->module_index];
             $module->contained_in = $temp_contained_in['.1.3.6.1.2.1.47.1.1.1.1.4.' . $module->module_index];
             $module->class = $temp_class['.1.3.6.1.2.1.47.1.1.1.1.5.' . $module->module_index];
             $module->hardware_revision = $temp_hardware_revision['.1.3.6.1.2.1.47.1.1.1.1.8.' . $module->module_index];
             $module->firmware_revision = $temp_firmware_revision['.1.3.6.1.2.1.47.1.1.1.1.9.' . $module->module_index];
             $module->software_revision = $temp_software_revision['.1.3.6.1.2.1.47.1.1.1.1.10.' . $module->module_index];
             $module->serial = $temp_serial_number['.1.3.6.1.2.1.47.1.1.1.1.11.' . $module->module_index];
             $module->asset_ident = $temp_asset_id['.1.3.6.1.2.1.47.1.1.1.1.15.' . $module->module_index];
             $module->is_fru = $temp_is_fru['.1.3.6.1.2.1.47.1.1.1.1.16.' . $module->module_index];
             if ((string) $module->is_fru == '1') {
                 $module->is_fru = 'y';
             } else {
                 $module->is_fru = 'n';
             }
             $module->class_text = 'unknown';
             if ($module->class == '1') {
                 $module->class_text = 'other';
             }
             if ($module->class == '2') {
                 $module->class_text = 'unknown';
             }
             if ($module->class == '3') {
                 $module->class_text = 'chassis';
             }
             if ($module->class == '4') {
                 $module->class_text = 'backplane';
             }
             if ($module->class == '5') {
                 $module->class_text = 'container';
             }
             if ($module->class == '6') {
                 $module->class_text = 'powerSupply';
             }
             if ($module->class == '7') {
                 $module->class_text = 'fan';
             }
             if ($module->class == '8') {
                 $module->class_text = 'sensor';
             }
             if ($module->class == '9') {
                 $module->class_text = 'module';
             }
             if ($module->class == '10') {
                 $module->class_text = 'port';
             }
             if ($module->class == '11') {
                 $module->class_text = 'stack';
             }
             if ($module->class == '12') {
                 $module->class_text = 'cpu';
             }
             $modules[] = $module;
         }
     }
     $log->message = 'snmp_helper::snmp_audit module retrieval for ' . $ip . ' complete';
     stdlog($log);
     // network intereface details
     $interfaces = array();
     $interfaces_filtered = array();
     $interfaces = my_snmp_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.1");
     $log->message = 'snmp_helper::snmp_audit interface count for ' . $ip . ' is ' . count($interfaces);
     stdlog($log);
     if (is_array($interfaces) and count($interfaces) > 0) {
         $log->message = 'snmp_helper::snmp_audit models retrieval for ' . $ip . ' starting';
         stdlog($log);
         $models = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.2");
         $log->message = 'snmp_helper::snmp_audit types retrieval for ' . $ip . ' starting';
         stdlog($log);
         $types = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.3");
         $log->message = 'snmp_helper::snmp_audit speeds retrieval for ' . $ip . ' starting';
         stdlog($log);
         $speeds = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.5");
         $log->message = 'snmp_helper::snmp_audit mac_addresses retrieval for ' . $ip . ' starting';
         stdlog($log);
         $mac_addresses = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.6");
         $log->message = 'snmp_helper::snmp_audit ip_enableds retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ip_enableds = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.8");
         $log->message = 'snmp_helper::snmp_audit ip_addresses retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ip_addresses = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.4.20.1.2");
         $log->message = 'snmp_helper::snmp_audit ifAdminStatus retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ifAdminStatus = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.7");
         $log->message = 'snmp_helper::snmp_audit ifLastChange retrieval for ' . $ip . ' starting';
         stdlog($log);
         $ifLastChange = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.2.2.1.9");
         if (isset($details->os_group) and $details->os_group == "VMware") {
             $log->message = 'snmp_helper::snmp_audit ip_addresses_2 retrieval for ' . $ip . ' starting';
             stdlog($log);
             $ip_addresses_2 = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.4.34.1.3.1.4");
         }
         $log->message = 'snmp_helper::snmp_audit subnets retrieval for ' . $ip . ' starting';
         stdlog($log);
         $subnets = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.4.20.1.3");
         $log->message = 'snmp_helper::snmp_audit connection_ids retrieval for ' . $ip . ' starting';
         stdlog($log);
         $connection_ids = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.31.1.1.1.1");
         $log->message = 'snmp_helper::snmp_audit aliases retrieval for ' . $ip . ' starting';
         stdlog($log);
         $aliases = my_snmp_real_walk($ip, $credentials, "1.3.6.1.2.1.31.1.1.1.18");
         foreach ($interfaces as $key => $value) {
             $log->message = 'snmp_helper::snmp_audit processing interface ' . $value . ' for ' . $ip . ' starting';
             stdlog($log);
             $interface = new stdclass();
             $interface->net_index = $value;
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             $interface->mac = format_mac(my_snmp_get($ip, $credentials, "1.3.6.1.2.1.2.2.1.6." . $interface->net_index));
             snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
             if (!isset($interface->mac)) {
                 $interface->mac = (string) '';
             }
             $interface->model = @$models[".1.3.6.1.2.1.2.2.1.2." . $interface->net_index];
             $interface->description = $interface->model;
             $interface->connection = @$connection_ids[".1.3.6.1.2.1.31.1.1.1.1." . $interface->net_index];
             $interface->alias = @$aliases[".1.3.6.1.2.1.31.1.1.1.18." . $interface->net_index];
             $interface->type = @interface_type(@$types[".1.3.6.1.2.1.2.2.1.3." . $interface->net_index]);
             $interface->ip_enabled = @ip_enabled($ip_enableds[".1.3.6.1.2.1.2.2.1.8." . $interface->net_index]);
             $interface->ifadminstatus = @if_admin_status($ifAdminStatus[".1.3.6.1.2.1.2.2.1.7." . $interface->net_index]);
             $interface->iflastchange = @$ifLastChange[".1.3.6.1.2.1.2.2.1.9." . $interface->net_index];
             $interface->speed = @$speeds[".1.3.6.1.2.1.2.2.1.5." . $interface->net_index];
             $interface->manufacturer = '';
             $interface->connection_status = '';
             $interface->dhcp_enabled = '';
             $interface->dhcp_server = '';
             $interface->dhcp_lease_obtained = '';
             $interface->dhcp_lease_expires = '';
             $interface->dns_host_name = '';
             $interface->dns_domain = '';
             $interface->dns_domain_reg_enabled = '';
             $interface->dns_server = '';
             if (is_array($ip_addresses) and count($ip_addresses > 0)) {
                 foreach ($ip_addresses as $each_key => $each_value) {
                     if ($each_value == $interface->net_index) {
                         $new_ip = new stdclass();
                         $new_ip->net_index = $interface->net_index;
                         $new_ip->ip = str_replace(".1.3.6.1.2.1.4.20.1.2.", "", $each_key);
                         $new_ip->mac = $interface->mac;
                         $new_ip->netmask = @$subnets[".1.3.6.1.2.1.4.20.1.3." . $new_ip->ip];
                         $new_ip->version = '4';
                         if ($new_ip->ip != '127.0.0.1' and $new_ip->ip != '127.0.1.1') {
                             $return_ips->item[] = $new_ip;
                         }
                         $new_ip = null;
                     }
                 }
             }
             if (isset($ip_addresses_2) and is_array($ip_addresses_2) and isset($details->os_group) and $details->os_group == "VMware") {
                 // likely we have a VMware ESX box - get what we can
                 foreach ($ip_addresses_2 as $each_key => $each_value) {
                     $new_ip = new stdClass();
                     $new_ip->net_index = $each_value;
                     $new_ip->ip = str_replace(".1.3.6.1.2.1.4.34.1.3.1.4.", "", $each_key);
                     $new_ip->netmask = '';
                     $new_ip->version = '4';
                     if ($new_ip->net_index == $interface->net_index) {
                         $new_ip->mac = $interface->mac;
                         if ($new_ip->ip != '127.0.0.1' and $new_ip->ip != '127.0.1.1') {
                             $return_ips->item[] = $new_ip;
                         }
                     }
                     $new_ip = null;
                 }
             }
             if (isset($details->os_group) and $details->os_group == 'Windows') {
                 if (isset($interface->ip_addresses) and count($interface->ip_addresses) > 0) {
                     if (strpos(strtolower($interface->type), 'loopback') === false) {
                         $interfaces_filtered[] = $interface;
                     }
                 }
             } else {
                 if (strtolower($interface->type != 'software loopback')) {
                     $interfaces_filtered[] = $interface;
                 }
             }
         }
     }
     // end of network interfaces
     // Virtual Guests
     $guests = array();
     if ($vendor_oid == 6876) {
         if (file_exists(BASEPATH . '../application/helpers/snmp_6876_2_helper.php')) {
             $log->message = 'snmp_helper::snmp_audit is loading the model helper for VMware virtual guests';
             stdlog($log);
             include 'snmp_6876_2_helper.php';
         }
     }
     $return_array = array('details' => $details, 'interfaces' => $interfaces_filtered, 'guests' => $guests, 'modules' => $modules, 'ip' => $return_ips);
     return $return_array;
 }
Пример #7
0
 /**
  * Executes php 5.4 SNMP class walk interface
  * 
  * @param string $ip
  * @param string $community
  * @param string $oid
  * @param bool   $cache
  * @param bool   $nowait
  * @return string
  */
 protected function snmpWalkClass($ip, $community, $oid, $cache = true)
 {
     $cachetime = time() - $this->cacheTime;
     $cachepath = self::CACHE_PATH;
     $cacheFile = $cachepath . $ip . '_' . $oid;
     $result = '';
     //cache handling
     if (file_exists($cacheFile)) {
         //cache not expired
         if (filemtime($cacheFile) > $cachetime and $cache == true) {
             $result = file_get_contents($cacheFile);
         } else {
             //cache expired - refresh data
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             $session = new SNMP(SNMP::VERSION_1, $ip, $community, $this->timeoutNative, $this->retriesNative);
             $raw = $session->walk($oid);
             $session->close();
             if (!empty($raw)) {
                 foreach ($raw as $oid => $value) {
                     $result .= $oid . ' = ' . $value . "\n";
                 }
             }
             file_put_contents($cacheFile, $result);
         }
     } else {
         //no cached file exists
         snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
         $session = new SNMP(SNMP::VERSION_1, $ip, $community, $this->timeoutNative, $this->retriesNative);
         $raw = $session->walk($oid);
         $session->close();
         if (!empty($raw)) {
             foreach ($raw as $oid => $value) {
                 $result .= $oid . ' = ' . $value . "\n";
             }
         }
         file_put_contents($cacheFile, $result);
     }
     return $result;
 }
Пример #8
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (PSI_PLUGIN_SNMPPINFO_ACCESS) {
         case 'command':
             $printers = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SNMPPINFO_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($printers as $printer) {
                 CommonFunctions::executeProgram("snmpwalk", "-On -c public -v 1 " . $printer . " 1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
                 if (strlen(trim($buffer)) > 0) {
                     $this->_filecontent[$printer] = $buffer;
                     CommonFunctions::executeProgram("snmpwalk", "-On -c public -v 1 " . $printer . " 1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
                     if (strlen(trim($buffer2)) > 0) {
                         $this->_filecontent[$printer] = $buffer . "\n" . $buffer2;
                     } else {
                         $this->_filecontent[$printer] = $buffer;
                     }
                 }
             }
             break;
         case 'php-snmp':
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             $printers = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SNMPPINFO_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($printers as $printer) {
                 if (!PSI_DEBUG) {
                     restore_error_handler();
                 }
                 $bufferarr = snmprealwalk($printer, "public", "1.3.6.1.2.1.1.5");
                 if (!PSI_DEBUG) {
                     set_error_handler('errorHandlerPsi');
                 }
                 if (!empty($bufferarr)) {
                     $buffer = "";
                     foreach ($bufferarr as $id => $string) {
                         $buffer = $buffer . $id . " = " . $string . "\n";
                     }
                     if (!PSI_DEBUG) {
                         restore_error_handler();
                     }
                     $bufferarr2 = snmprealwalk($printer, "public", "1.3.6.1.2.1.43.11.1.1");
                     if (!PSI_DEBUG) {
                         set_error_handler('errorHandlerPsi');
                     }
                     if (!empty($bufferarr2)) {
                         foreach ($bufferarr2 as $id => $string) {
                             $buffer = $buffer . $id . " = " . $string . "\n";
                         }
                     }
                     if (strlen(trim($buffer)) > 0) {
                         $this->_filecontent[$printer] = $buffer;
                     }
                 }
             }
             break;
         case 'data':
             $printers = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SNMPPINFO_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             $pn = 0;
             foreach ($printers as $printer) {
                 $buffer = "";
                 if (CommonFunctions::rfts(APP_ROOT . "/data/SNMPPInfo{$pn}.txt", $buffer) && !empty($buffer)) {
                     $this->_filecontent[$printer] = $buffer;
                 }
                 $pn++;
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_SNMPPINFO_ACCESS)", "Bad SNMPPInfo configuration in SNMPPInfo.config.php");
             break;
     }
 }
<?php

require_once dirname(__FILE__) . '/snmp_include.inc';
//EXPECTF format is quickprint OFF
snmp_set_enum_print(false);
snmp_set_quick_print(false);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL);
echo "SNMPv1\n";
$session = new SNMP(SNMP::VERSION_1, $hostname, $community, $timeout, $retries);
$session->valueretrieval = SNMP_VALUE_LIBRARY;
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
var_dump($session->get(array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.3.0')));
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
var_dump($session->close());
echo "SNMPv2\n";
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
var_dump($session->close());
echo "GET with preserving original OID names\n";
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
$orig = array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.2.1.1.5.0');
$result = $session->get($orig, TRUE);
foreach ($orig as $oid) {
    var_dump($result[$oid]);
}
var_dump($session->close());
echo "WALK multiple on single OID\n";
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
$z = $session->walk('.1.3.6.1.2.1.1');
 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"));
         debug("Timeout changed to " . $timeout . " microseconds.\n");
     }
     if ($map->get_hint("snmp_abort_count") != '') {
         $abort_count = intval($map->get_hint("snmp_abort_count"));
         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"));
         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) {
                     $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) {
                     // 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]++;
                 }
             }
             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 {
             warn("SNMP for {$host} has reached {$abort_count} failures. Skipping. [WMSNMP01]");
         }
     }
     debug("SNMP ReadData: Returning (" . ($data[IN] === NULL ? 'NULL' : $data[IN]) . "," . ($data[OUT] === NULL ? 'NULL' : $data[OUT]) . ",{$data_time})\n");
     return array($data[IN], $data[OUT], $data_time);
 }
Пример #11
0
 /**
  * Check weather user online
  * 
  * @param string $login
  * @param int $vlan
  * @return string
  */
 public function GetUserVlanOnline($login, $vlan)
 {
     snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
     if ($this->GetOnlineDetectOid($login, $vlan)) {
         @($data = snmp2_real_walk($this->allTerminators[$this->allVlanHosts[$login]['vlanpoolid']]['ip'], $this->AllSwitches[$this->allTerminators[$this->allVlanHosts[$login]['vlanpoolid']]['ip']]['snmp'], $this->GetOnlineDetectOid($login, $vlan)));
         if (empty($data)) {
             return "Offline" . " " . wf_img_sized('skins/icon_inactive.gif', '', '', '12');
         } else {
             return "Online" . " " . wf_img_sized('skins/icon_active.gif', '', '', '12');
         }
     } else {
         return 'empty';
     }
 }
Пример #12
0
 /**
  * Change SNMP value
  * The "type" parameter must be one of the following, depending on the type of variable to set on the SNMP host:
  * i    INTEGER
  * u    unsigned INTEGER
  * t    TIMETICKS
  * a    IPADDRESS
  * o    OBJID
  * s    STRING
  * x    HEX STRING
  * d    DECIMAL STRING
  * n    NULLOBJ
  * b    BITS 
  * @param Host $host
  * @param string $object_id
  * @param string $type
  * @param mixed $value
  * @return bool
  * @throws Exception
  */
 public static function set($host, $object_id, $type, $value)
 {
     snmp_set_oid_output_format(self::$oid_format);
     $snmp = $host->snmpTemplate;
     if (is_null($type)) {
         throw new Exception('type not set');
     }
     if ($snmp instanceof SnmpTemplate) {
         switch ($snmp->version) {
             case "1":
                 $result = snmpset($host->ip, $snmp->community, $object_id, $type, $value, $snmp->timeout, $snmp->retries);
                 break;
             case "2":
             case "2c":
                 $result = snmp2_set($host->ip, $snmp->community, $object_id, $type, $value, $snmp->timeout, $snmp->retries);
                 break;
             case "3":
                 $result = snmp3_set($host->ip, $snmp->security_name, $snmp->security_level, $snmp->auth_protocol, $snmp->auth_passphrase, $snmp->priv_protocol, $snmp->priv_passphrase, $object_id, $type, $value, $snmp->timeout, $snmp->retries);
                 break;
             default:
                 throw new Exception('SNMP Template not implemented yet');
         }
     }
     return $result;
 }
Пример #13
0
 /**
  * get all information from all configured ups in phpsysinfo.ini and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
         case 'command':
             if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
                 if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
                     $upss = eval(PSI_UPS_SNMPUPS_LIST);
                 } else {
                     $upss = array(PSI_UPS_SNMPUPS_LIST);
                 }
                 foreach ($upss as $ups) {
                     CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG);
                     if (strlen($buffer) > 0) {
                         $this->_output[$ups] = $buffer;
                         $buffer = "";
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG);
                         if (strlen($buffer) > 0) {
                             $this->_output[$ups] .= "\n" . $buffer;
                         }
                         $buffer = "";
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.3", $buffer, PSI_DEBUG);
                         if (strlen($buffer) > 0) {
                             $this->_output[$ups] .= "\n" . $buffer;
                         }
                         $buffer = "";
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.4", $buffer, PSI_DEBUG);
                         if (strlen($buffer) > 0) {
                             $this->_output[$ups] .= "\n" . $buffer;
                         }
                     }
                 }
             }
             break;
         case 'php-snmp':
             if (!extension_loaded("snmp")) {
                 $this->error->addError("Requirements error", "SNMPups plugin requires the snmp extension to php in order to work properly");
                 break;
             }
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
                 if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
                     $upss = eval(PSI_UPS_SNMPUPS_LIST);
                 } else {
                     $upss = array(PSI_UPS_SNMPUPS_LIST);
                 }
                 foreach ($upss as $ups) {
                     if (!PSI_DEBUG) {
                         restore_error_handler();
                         /* default error handler */
                         $old_err_rep = error_reporting();
                         error_reporting(E_ERROR);
                         /* fatal errors only */
                     }
                     $bufferarr = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.1", 1000000, 1);
                     if (!PSI_DEBUG) {
                         error_reporting($old_err_rep);
                         /* restore error level */
                         set_error_handler('errorHandlerPsi');
                         /* restore error handler */
                     }
                     if (!empty($bufferarr)) {
                         $buffer = "";
                         foreach ($bufferarr as $id => $string) {
                             $buffer .= $id . " = " . $string . "\n";
                         }
                         if (!PSI_DEBUG) {
                             restore_error_handler();
                             /* default error handler */
                             $old_err_rep = error_reporting();
                             error_reporting(E_ERROR);
                             /* fatal errors only */
                         }
                         $bufferarr2 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.2", 1000000, 1);
                         $bufferarr3 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.3", 1000000, 1);
                         $bufferarr4 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.4", 1000000, 1);
                         if (!PSI_DEBUG) {
                             error_reporting($old_err_rep);
                             /* restore error level */
                             set_error_handler('errorHandlerPsi');
                             /* restore error handler */
                         }
                         if (!empty($bufferarr2)) {
                             foreach ($bufferarr2 as $id => $string) {
                                 $buffer .= $id . " = " . $string . "\n";
                             }
                             if (!empty($bufferarr3)) {
                                 foreach ($bufferarr3 as $id => $string) {
                                     $buffer .= $id . " = " . $string . "\n";
                                 }
                             }
                         }
                         if (!empty($bufferarr4)) {
                             foreach ($bufferarr4 as $id => $string) {
                                 $buffer .= $id . " = " . $string . "\n";
                             }
                         }
                         if (strlen(trim($buffer)) > 0) {
                             $this->_output[$ups] = $buffer;
                         }
                     }
                 }
             }
             break;
         default:
             $this->error->addError("switch(PSI_UPS_SNMPUPS_ACCESS)", "Bad SNMPups configuration in phpsysinfo.ini");
             break;
     }
 }
Пример #14
0
 /**
  * Init the class
  */
 protected function init($config)
 {
     //--- Init the class:
     Basic::initClass($this, $config);
     //--- Reset:
     $this->agentStatus = null;
     $this->agentVersion = null;
     $this->agentReadCommunity = null;
     $this->setError();
     snmp_set_oid_output_format($this->oidOutputFormat);
 }
<?php

require_once dirname(__FILE__) . '/snmp_include.inc';
echo "Checking error handling\n";
var_dump(snmp_set_oid_output_format());
var_dump(snmp_set_oid_output_format(123));
echo "Checking working\n";
var_dump(snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL));
var_dump(snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC));