From 722e89f12e845bebbc2fed116a4836a4abb5c900 Mon Sep 17 00:00:00 2001 From: Tom Laermans Date: Sun, 11 Jul 2010 14:36:30 +0000 Subject: [PATCH] only discover toner if it actually exists - HP LJ 4100 has 4 indexes but only one toner; should fix FS#46 git-svn-id: http://www.observium.org/svn/observer/trunk@1341 61d68cd4-352d-0410-923a-c4978735b2b8 --- includes/discovery/toner.inc.php | 100 +++++++++++++++---------------- 1 file changed, 47 insertions(+), 53 deletions(-) diff --git a/includes/discovery/toner.inc.php b/includes/discovery/toner.inc.php index 32f288e70d..5058e7f15f 100644 --- a/includes/discovery/toner.inc.php +++ b/includes/discovery/toner.inc.php @@ -2,68 +2,62 @@ if ($config['enable_printers']) { - -$id = $device['device_id']; -$hostname = $device['hostname']; -$community = $device['community']; -$snmpver = $device['snmpver']; -$port = $device['port']; - $valid_toner = array(); - -echo("Toner : "); - -if ($device['os'] == "dell-laser" || $device['os'] == "jetdirect") -{ - $oids = trim(snmp_walk($device, "SNMPv2-SMI::mib-2.43.12.1.1.2.1 ", "-OsqnU")); - if ($debug) { echo($oids."\n"); } - if ($oids) echo("Jetdirect "); - foreach(explode("\n", $oids) as $data) + + echo("Toner : "); + + if ($device['os'] == "dell-laser" || $device['os'] == "jetdirect") { - $data = trim($data); - if ($data) + $oids = trim(snmp_walk($device, "SNMPv2-SMI::mib-2.43.12.1.1.2.1 ", "-OsqnU")); + if ($debug) { echo($oids."\n"); } + if ($oids) echo("Jetdirect "); + foreach(explode("\n", $oids) as $data) { - list($oid,$kind) = explode(" ", $data); - $split_oid = explode('.',$oid); - $index = $split_oid[count($split_oid)-1]; - if ($kind == 1) + $data = trim($data); + if ($data) { - $toner_oid = ".1.3.6.1.2.1.43.11.1.1.9.1.$index"; - $descr_oid = ".1.3.6.1.2.1.43.11.1.1.6.1.$index"; - $capacity_oid = ".1.3.6.1.2.1.43.11.1.1.8.1.$index"; - $descr = trim(str_replace("\n","",str_replace('"','',snmp_get($device, $descr_oid, "-Oqv")))); - $current = snmp_get($device, $toner_oid, "-Oqv"); - $capacity = snmp_get($device, $capacity_oid, "-Oqv"); - $current = $current / $capacity * 100; - $type = "jetdirect"; - if (isHexString($descr)) { $descr = snmp_hexstring($descr); } - echo discover_toner($valid_toner,$device, $toner_oid, $index, $type, $descr, $capacity, $current); + list($oid,$kind) = explode(" ", $data); + $split_oid = explode('.',$oid); + $index = $split_oid[count($split_oid)-1]; + if ($kind == 1) + { + $toner_oid = ".1.3.6.1.2.1.43.11.1.1.9.1.$index"; + $descr_oid = ".1.3.6.1.2.1.43.11.1.1.6.1.$index"; + $capacity_oid = ".1.3.6.1.2.1.43.11.1.1.8.1.$index"; + $descr = trim(str_replace("\n","",str_replace('"','',snmp_get($device, $descr_oid, "-Oqv")))); + if ($descr != "") + { + $current = snmp_get($device, $toner_oid, "-Oqv"); + $capacity = snmp_get($device, $capacity_oid, "-Oqv"); + $current = $current / $capacity * 100; + $type = "jetdirect"; + if (isHexString($descr)) { $descr = snmp_hexstring($descr); } + echo discover_toner($valid_toner,$device, $toner_oid, $index, $type, $descr, $capacity, $current); + } + } } } } -} - -## Delete removed toners - -if($debug) { echo("\n Checking ... \n"); print_r($valid_toner); } - -$sql = "SELECT * FROM toner WHERE device_id = '".$device['device_id']."'"; -if ($query = mysql_query($sql)) -{ - while ($test_toner = mysql_fetch_array($query)) + + ## Delete removed toners + if($debug) { echo("\n Checking ... \n"); print_r($valid_toner); } + + $sql = "SELECT * FROM toner WHERE device_id = '".$device['device_id']."'"; + if ($query = mysql_query($sql)) { - $toner_index = $test_toner['toner_index']; - $toner_type = $test_toner['toner_type']; - if(!$valid_toner[$toner_type][$toner_index]) { - echo("-"); - mysql_query("DELETE FROM `toner` WHERE toner_id = '" . $test_toner['toner_id'] . "'"); + while ($test_toner = mysql_fetch_array($query)) + { + $toner_index = $test_toner['toner_index']; + $toner_type = $test_toner['toner_type']; + if(!$valid_toner[$toner_type][$toner_index]) { + echo("-"); + mysql_query("DELETE FROM `toner` WHERE toner_id = '" . $test_toner['toner_id'] . "'"); + } } } -} - - - -unset($valid_toner); echo("\n"); - + + unset($valid_toner); echo("\n"); + } # if ($config['enable_printers']) ?> + \ No newline at end of file