mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Updated toner discovery (#4637)
This commit is contained in:
@@ -891,3 +891,68 @@ function get_device_divisor($device, $serial, $sensor)
|
||||
}
|
||||
return $divisor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $device
|
||||
* @param $capacity_oid
|
||||
* @return int
|
||||
*/
|
||||
function get_toner_capacity($device, $capacity_oid)
|
||||
{
|
||||
if ($device['os'] == 'ricoh' || $device['os'] == 'nrg' || $device['os'] == 'lanier') {
|
||||
$capacity = 100;
|
||||
} else {
|
||||
$capacity = snmp_get($device, $capacity_oid, '-Oqv');
|
||||
}
|
||||
|
||||
return $capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $device
|
||||
* @param $oid_value
|
||||
* @param $oid_capacity
|
||||
* @return float|int
|
||||
*/
|
||||
function get_toner_levels($device, $oid_value, $oid_capacity)
|
||||
{
|
||||
if ($device['os'] == 'ricoh' || $device['os'] == 'nrg' || $device['os'] == 'lanier') {
|
||||
if ($oid_value == '-3') {
|
||||
$current = 50;
|
||||
} elseif ($oid_value == '-100') {
|
||||
$current = 0;
|
||||
} else {
|
||||
$current = ($oid_value / $oid_capacity * 100);
|
||||
}
|
||||
} elseif ($device['os'] == 'brother') {
|
||||
if (str_contains($device['hardware'], 'NC-8600h')) {
|
||||
switch ($oid_value) {
|
||||
case '0':
|
||||
$current = 0;
|
||||
break;
|
||||
case '-3':
|
||||
$current = 50;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch ($oid_value) {
|
||||
case '0':
|
||||
$current = 100;
|
||||
break;
|
||||
case '1':
|
||||
$current = 5;
|
||||
break;
|
||||
case '2':
|
||||
$current = 0;
|
||||
break;
|
||||
case '3':
|
||||
$current = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$current = ($oid_value / $oid_capacity * 100);
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ if ($device['os_group'] == 'printer') {
|
||||
$oids = trim(snmp_walk($device, 'SNMPv2-SMI::mib-2.43.11.1.1.2.1 ', '-OsqnU'));
|
||||
}
|
||||
|
||||
d_echo($oids."\n");
|
||||
d_echo($oids . "\n");
|
||||
|
||||
if ($oids) {
|
||||
echo 'Jetdirect ';
|
||||
@@ -17,60 +17,29 @@ if ($device['os_group'] == 'printer') {
|
||||
foreach (explode("\n", $oids) as $data) {
|
||||
$data = trim($data);
|
||||
if ($data) {
|
||||
list($oid,$role) = explode(' ', $data);
|
||||
$split_oid = explode('.', $oid);
|
||||
$index = $split_oid[(count($split_oid) - 1)];
|
||||
list($oid, $role) = explode(' ', $data);
|
||||
$split_oid = explode('.', $oid);
|
||||
$index = $split_oid[(count($split_oid) - 1)];
|
||||
if (is_numeric($role)) {
|
||||
//ricoh using private oids to expose toner levels
|
||||
if ($os == 'ricoh' || $os == 'nrg' || $os == 'lanier') {
|
||||
$toner_oid = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.$index";
|
||||
$descr_oid = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.3.$index";
|
||||
$capacity_oid = '';
|
||||
} else {
|
||||
$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";
|
||||
$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", '', preg_replace('/[^ \w]+/', '', snmp_get($device, $descr_oid, '-Oqv'))));
|
||||
|
||||
if ($descr != '') {
|
||||
$current = snmp_get($device, $toner_oid, '-Oqv');
|
||||
$oid_toner = snmp_get($device, $toner_oid, '-Oqv');
|
||||
$oid_capacity = snmp_get($device, $capacity_oid, '-Oqv');
|
||||
|
||||
//ricoh private mibs returns values as percent, no capacity is disclosed as it is not needed
|
||||
if ($os == 'ricoh' || $os == 'nrg' || $os == 'lanier') {
|
||||
$capacity = 100;
|
||||
} else {
|
||||
$capacity = snmp_get($device, $capacity_oid, '-Oqv');
|
||||
}
|
||||
|
||||
//fix for ricoh devices returning garbage and devices returning percentage
|
||||
if ($os == 'ricoh' || $os == 'nrg' || $os == 'lanier') {
|
||||
if ($current == '-3') {
|
||||
$current = 50;
|
||||
} elseif ($current == '-100') {
|
||||
$current = 0;
|
||||
} else {
|
||||
$current = ($current / $capacity * 100);
|
||||
}
|
||||
} elseif ($os == 'brother') {
|
||||
switch ($current) {
|
||||
case '0':
|
||||
$current = 100;
|
||||
break;
|
||||
case '1':
|
||||
$current = 5;
|
||||
break;
|
||||
case '2':
|
||||
$current = 0;
|
||||
break;
|
||||
case '3':
|
||||
$current = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
//normal devices returning toner values
|
||||
$current = ($current / $capacity * 100);
|
||||
}
|
||||
$capacity = get_toner_capacity($device, $oid_capacity);
|
||||
$current = get_toner_levels($device, $oid_toner, $oid_capacity);
|
||||
|
||||
$type = 'jetdirect';
|
||||
if (isHexString($descr)) {
|
||||
@@ -80,18 +49,18 @@ if ($device['os_group'] == 'printer') {
|
||||
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']."'";
|
||||
$sql = "SELECT * FROM toner WHERE device_id = '" . $device['device_id'] . "'";
|
||||
foreach (dbFetchRows($sql) as $test_toner) {
|
||||
$toner_index = $test_toner['toner_index'];
|
||||
$toner_type = $test_toner['toner_type'];
|
||||
$toner_type = $test_toner['toner_type'];
|
||||
if (!$valid_toner[$toner_type][$toner_index]) {
|
||||
echo '-';
|
||||
dbDelete('toner', '`toner_id` = ?', array($test_toner['toner_id']));
|
||||
|
Reference in New Issue
Block a user