} // Get full index $sla_index = snmp_translate('pingCtlRowStatus."' . $sla_owner . '"."' . $sla_name . '"', $mib); $sla_index = str_replace('.1.3.6.1.2.1.80.1.2.1.23.', '', $sla_index); $data = array('device_id' => $device['device_id'], 'sla_mib' => $mib, 'sla_index' => $sla_name, 'sla_owner' => $sla_owner, 'sla_tag' => $entry['pingCtlTargetAddress'], 'sla_status' => $entry['pingCtlRowStatus'], 'sla_graph' => 'jitter', 'deleted' => 0); if ($entry['pingCtlAdminStatus'] == 'disabled') { // If SLA administarively disabled, exclude from polling $data['deleted'] = 1; } // Type conversions // Standart types: pingIcmpEcho, pingUdpEcho, pingSnmpQuery, pingTcpConnectionAttempt // Juniper types: jnxPingIcmpTimeStamp, jnxPingHttpGet, jnxPingHttpGetMetadata, jnxPingDnsQuery, jnxPingNtpQuery, jnxPingUdpTimestamp // HH3C types: $data['rtt_type'] = str_replace(array('ping', 'jnxPing', 'hh3cNqa'), '', $entry['pingCtlType']); // Tag / Target if (isHexString($entry['pingCtlTargetAddress']) || stripos($data['rtt_type'], 'Echo') !== FALSE) { $data['sla_tag'] = hex2ip($data['sla_tag']); } // Limits $data['sla_limit_high'] = $entry['pingCtlTimeOut'] > 0 ? $entry['pingCtlTimeOut'] * 1000 : 5000; $data['sla_limit_high_warn'] = intval($data['sla_limit_high'] / 5); /* // Migrate old indexes if (isset($sla_db[$mib_lower][$sla_owner.'.'.$name])) { // Old (non numeric) indexes $sla_db[$mib_lower][$sla_index] = $sla_db[$mib_lower][$sla_owner.'.'.$name]; unset($sla_db[$mib_lower][$sla_owner.'.'.$name]); dbUpdate(array('sla_index' => $sla_index, 'sla_mib' => $mib), 'slas', "`sla_id` = ?", array($sla_db[$mib_lower][$sla_index]['sla_id'])); } */
function snmp_hexstring($str) { if (isHexString($str)) { return hex2str(str_replace(' ', '', str_replace(' 00', '', $str))); } else { return $str; } }
} //fix for ricoh devices returning garbage and devices returning percentage if ($os == 'ricoh') { if ($current == '-3') { $current = 50; } elseif ($current == '-100') { $current = 0; } else { $current = $current / $capacity * 100; } } else { //normal devices returning toner values $current = $current / $capacity * 100; } $type = 'jetdirect'; if (isHexString($descr)) { $descr = snmp_hexstring($descr); } discover_toner($valid_toner, $device, $toner_oid, $index, $type, $descr, $capacity_oid, $capacity, $current); } } } //end if } //end foreach } //end if // Delete removed toners d_echo("\n Checking ... \n"); d_echo($valid_toner); $sql = "SELECT * FROM toner WHERE device_id = '" . $device['device_id'] . "'";
<?php $hardware = trim(snmp_get($device, '1.3.6.1.4.1.18928.1.1.1.1.0', '-OQv', '', ''), '"'); if (!$hardware) { $hardware = trim(snmp_get($device, '1.3.6.1.4.1.18928.1.2.1.1.0', '-OQv', '', ''), '"'); } $version = trim(snmp_get($device, '1.3.6.1.4.1.18928.1.1.1.4.0', '-OQv', '', ''), '"'); if (!$version) { $version = trim(snmp_get($device, '1.3.6.1.4.1.18928.1.2.1.4.0', '-OQv', '', ''), '"'); } $serial = trim(snmp_get($device, '1.3.6.1.4.1.18928.1.1.1.3.0', '-OQv', '', ''), '"'); if (!$serial) { $serial = trim(snmp_get($device, '1.3.6.1.4.1.18928.1.2.1.3.0', '-OQv', '', ''), '"'); } if (isHexString($serial)) { // Sometimes firmware outputs serial as hex-string $serial = snmp_hexstring($serial); }
function hex2ip($ip_snmp) { $ip_snmp = trim(str_replace('"', '', $ip_snmp)); $ip = str_replace(':', ' ', $ip_snmp); if (!isHexString($ip)) { return $ip_snmp; } $ip_array = explode(' ', $ip); if (count($ip_array) == 4) { // IPv4 $ip = hexdec($ip_array[0]) . '.' . hexdec($ip_array[1]) . '.' . hexdec($ip_array[2]) . '.' . hexdec($ip_array[3]); } else { // IPv6 $ip = str_replace(' ', '', strtolower($ip)); $ip = substr(preg_replace('/([a-f\\d]{4})/', "\$1:", $ip), 0, -1); } return $ip; }
/** * Convert an SNMP hex string to regular string * * @param string $string * @return string */ function snmp_hexstring($string) { if (isHexString($string)) { return hex2str(str_replace(' 00', '', $string)); // 00 is EOL } else { return $string; } }