mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Printer paper tray status and error states (#9859)
* adding paper tray status and error states * adding paper tray test data * Create jetdirect_papertray.json * Store printer supply type * Update json data * fix style
This commit is contained in:
@@ -38,6 +38,10 @@ if ($device['os'] == 'gw-eydfa') {
|
||||
include 'includes/discovery/sensors/gw-eydfa.inc.php';
|
||||
}
|
||||
|
||||
if ($device['os_group'] == 'printer') {
|
||||
include 'includes/discovery/sensors/state/printer.inc.php';
|
||||
}
|
||||
|
||||
$run_sensors = array(
|
||||
'airflow',
|
||||
'current',
|
||||
|
106
includes/discovery/sensors/state/printer.inc.php
Normal file
106
includes/discovery/sensors/state/printer.inc.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
echo 'Printer Status and Error State ';
|
||||
$state = snmp_get($device, "hrDeviceStatus.1", "-Ovqe", 'HOST-RESOURCES-MIB');
|
||||
if (is_numeric($state)) {
|
||||
//Create State Index
|
||||
$state_name = 'hrDeviceStatus';
|
||||
create_state_index(
|
||||
$state_name,
|
||||
[
|
||||
['value' => 1, 'generic' => 3, 'graph' => 0, 'descr' => 'Unknown'],
|
||||
['value' => 2, 'generic' => 0, 'graph' => 0, 'descr' => 'Running'],
|
||||
['value' => 3, 'generic' => 1, 'graph' => 0, 'descr' => 'Warning'],
|
||||
['value' => 4, 'generic' => 0, 'graph' => 0, 'descr' => 'Testing'],
|
||||
['value' => 5, 'generic' => 2, 'graph' => 0, 'descr' => 'Down'],
|
||||
]
|
||||
);
|
||||
$sensor_index = 0;
|
||||
discover_sensor(
|
||||
$valid['sensor'],
|
||||
'state',
|
||||
$device,
|
||||
'.1.3.6.1.2.1.25.3.2.1.5.1',
|
||||
$sensor_index,
|
||||
$state_name,
|
||||
'Printer Device Status',
|
||||
1,
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$state,
|
||||
'snmp',
|
||||
0
|
||||
);
|
||||
//Create Sensor To State Index
|
||||
create_sensor_to_state_index($device, $state_name, $sensor_index);
|
||||
}
|
||||
|
||||
$state = snmp_get($device, "hrPrinterDetectedErrorState.1", "-Ovqe", 'HOST-RESOURCES-MIB');
|
||||
if ($state) {
|
||||
// https://www.ietf.org/rfc/rfc1759.txt hrPrinterDetectedErrorState
|
||||
//Create State Index
|
||||
$printer_states =
|
||||
[
|
||||
['value' => 0, 'generic' => 0, 'graph' => 0, 'descr' => 'Normal'],
|
||||
['value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'Paper Low'],
|
||||
['value' => 2, 'generic' => 2, 'graph' => 0, 'descr' => 'No Paper'],
|
||||
['value' => 3, 'generic' => 1, 'graph' => 0, 'descr' => 'Toner Low'],
|
||||
['value' => 4, 'generic' => 2, 'graph' => 0, 'descr' => 'No Toner'],
|
||||
['value' => 5, 'generic' => 2, 'graph' => 0, 'descr' => 'Door Open'],
|
||||
['value' => 6, 'generic' => 2, 'graph' => 0, 'descr' => 'Jammed'],
|
||||
['value' => 7, 'generic' => 2, 'graph' => 0, 'descr' => 'Offline'],
|
||||
['value' => 8, 'generic' => 2, 'graph' => 0, 'descr' => 'Service Needed'],
|
||||
['value' => 9, 'generic' => 1, 'graph' => 0, 'descr' => 'Warning, multiple issues'],
|
||||
['value' => 10, 'generic' => 2, 'graph' => 0, 'descr' => 'Critical, multiple issues'],
|
||||
];
|
||||
$bit_flags = q_bridge_bits2indices($state);
|
||||
$is_critical = false;
|
||||
if (count($bit_flags) == 0) {
|
||||
$state = 0;
|
||||
} else {
|
||||
for ($i = 0; $i < count($bit_flags); $i++) {
|
||||
// second octet of error flags not reliable, skipping
|
||||
if ($bit_flags[$i] > 8) {
|
||||
continue;
|
||||
}
|
||||
$state = $printer_states[$bit_flags[$i]]['value'];
|
||||
if ($printer_states[$bit_flags[$i]]['generic'] == 2) {
|
||||
$is_critical = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// cannot create an index for each bit combination, instead warning or critical
|
||||
if (count($bit_flags) > 1) {
|
||||
$state = $is_critical?10:9;
|
||||
}
|
||||
}
|
||||
|
||||
$state_name = 'hrPrinterDetectedErrorState';
|
||||
create_state_index($state_name, $printer_states);
|
||||
|
||||
d_echo('Printer error state: '.$state_name.': '.$state);
|
||||
$sensor_index = 0;
|
||||
discover_sensor(
|
||||
$valid['sensor'],
|
||||
'state',
|
||||
$device,
|
||||
'.1.3.6.1.2.1.25.3.5.1.2.1',
|
||||
$sensor_index,
|
||||
$state_name,
|
||||
'Printer Error Status',
|
||||
1,
|
||||
1,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$state,
|
||||
'snmp',
|
||||
0
|
||||
);
|
||||
|
||||
//Create Sensor To State Index
|
||||
create_sensor_to_state_index($device, $state_name, $sensor_index);
|
||||
}
|
@@ -7,6 +7,7 @@ if ($device['os_group'] == 'printer') {
|
||||
|
||||
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesLevel', [], 'Printer-MIB');
|
||||
if (!empty($oids)) {
|
||||
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesType', $oids, 'Printer-MIB');
|
||||
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesMaxCapacity', $oids, 'Printer-MIB');
|
||||
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesDescription', $oids, 'Printer-MIB', null, '-OQUsa');
|
||||
}
|
||||
@@ -40,7 +41,6 @@ if ($device['os_group'] == 'printer') {
|
||||
$descr = explode(', PN', $descr)[0];
|
||||
}
|
||||
|
||||
$type = 'jetdirect';
|
||||
$capacity = get_toner_capacity($data['prtMarkerSuppliesMaxCapacity']);
|
||||
$current = get_toner_levels($device, $raw_toner, $capacity);
|
||||
|
||||
@@ -50,7 +50,7 @@ if ($device['os_group'] == 'printer') {
|
||||
$device,
|
||||
$toner_oid,
|
||||
$last_index,
|
||||
$type,
|
||||
$data['prtMarkerSuppliesType'] ?: 'markerSupply',
|
||||
$descr,
|
||||
$capacity_oid,
|
||||
$capacity,
|
||||
@@ -58,14 +58,52 @@ if ($device['os_group'] == 'printer') {
|
||||
);
|
||||
}
|
||||
}
|
||||
echo PHP_EOL;
|
||||
|
||||
echo 'Tray Paper Level: ';
|
||||
$tray_oids = snmpwalk_cache_oid($device, 'prtInputName', [], 'Printer-MIB');
|
||||
if (!empty($tray_oids)) {
|
||||
$tray_oids = snmpwalk_cache_oid($device, 'prtInputCurrentLevel', $tray_oids, 'Printer-MIB');
|
||||
$tray_oids = snmpwalk_cache_oid($device, 'prtInputMaxCapacity', $tray_oids, 'Printer-MIB');
|
||||
}
|
||||
|
||||
d_echo($tray_oids);
|
||||
foreach ($tray_oids as $index => $data) {
|
||||
$last_index = substr($index, strrpos($index, '.') + 1);
|
||||
|
||||
$capacity = $data['prtInputMaxCapacity'];
|
||||
$current = $data['prtInputCurrentLevel'];
|
||||
if (!is_numeric($current) || $current == -2) {
|
||||
// capacity unsupported
|
||||
d_echo('Input Capacity unsupported', 'X');
|
||||
continue;
|
||||
} elseif ($current == -3) {
|
||||
// at least one piece of paper in tray
|
||||
$current = $capacity;
|
||||
} else {
|
||||
$current = $current / $capacity * 100;
|
||||
}
|
||||
|
||||
discover_toner(
|
||||
$valid_toner,
|
||||
$device,
|
||||
".1.3.6.1.2.1.43.8.2.1.10.$index",
|
||||
$last_index,
|
||||
'input',
|
||||
$data['prtInputName'],
|
||||
".1.3.6.1.2.1.43.8.2.1.9.$index",
|
||||
$capacity,
|
||||
$current
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete removed toners
|
||||
d_echo("\n Checking valid toner ... \n");
|
||||
d_echo($valid_toner);
|
||||
|
||||
$toners = dbFetchRows("SELECT * FROM toner WHERE device_id = '" . $device['device_id'] . "'");
|
||||
d_echo($toners);
|
||||
$toners = dbFetchRows("SELECT * FROM toner WHERE device_id = ?", [$device['device_id']]);
|
||||
//d_echo($toners);
|
||||
foreach ($toners as $test_toner) {
|
||||
$toner_oid = $test_toner['toner_oid'];
|
||||
$toner_type = $test_toner['toner_type'];
|
||||
|
@@ -72,6 +72,8 @@ function poll_sensor($device, $class)
|
||||
|
||||
if (file_exists('includes/polling/sensors/'. $class .'/'. $device['os'] .'.inc.php')) {
|
||||
require 'includes/polling/sensors/'. $class .'/'. $device['os'] .'.inc.php';
|
||||
} elseif (file_exists('includes/polling/sensors/'. $class .'/'. $device['os_group'] .'.inc.php')) {
|
||||
require 'includes/polling/sensors/'. $class .'/'. $device['os_group'] .'.inc.php';
|
||||
}
|
||||
|
||||
if ($class == 'temperature') {
|
||||
|
41
includes/polling/sensors/state/printer.inc.php
Normal file
41
includes/polling/sensors/state/printer.inc.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
if ($device['os_group'] == 'printer') {
|
||||
if ($sensor['sensor_type'] === 'hrPrinterDetectedErrorState') {
|
||||
$printer_states =
|
||||
[
|
||||
['value' => 0, 'generic' => 0, 'graph' => 0, 'descr' => 'No issues'],
|
||||
['value' => 1, 'generic' => 1, 'graph' => 0, 'descr' => 'Paper Low'],
|
||||
['value' => 2, 'generic' => 2, 'graph' => 0, 'descr' => 'No Paper'],
|
||||
['value' => 3, 'generic' => 1, 'graph' => 0, 'descr' => 'Toner Low'],
|
||||
['value' => 4, 'generic' => 2, 'graph' => 0, 'descr' => 'No Toner'],
|
||||
['value' => 5, 'generic' => 2, 'graph' => 0, 'descr' => 'Door Open'],
|
||||
['value' => 6, 'generic' => 2, 'graph' => 0, 'descr' => 'Jammed'],
|
||||
['value' => 7, 'generic' => 2, 'graph' => 0, 'descr' => 'Offline'],
|
||||
['value' => 8, 'generic' => 2, 'graph' => 0, 'descr' => 'Service Needed'],
|
||||
['value' => 9, 'generic' => 1, 'graph' => 0, 'descr' => 'Warning, multiple issues'],
|
||||
['value' => 10, 'generic' => 2, 'graph' => 0, 'descr' => 'Critical, multiple issues'],
|
||||
];
|
||||
$bit_flags = q_bridge_bits2indices($sensor_value);
|
||||
$is_critical = false;
|
||||
if (count($bit_flags) == 0) {
|
||||
$sensor_value = 0;
|
||||
} else {
|
||||
for ($i = 0; $i < count($bit_flags); $i++) {
|
||||
if ($bit_flags[$i] > 8) {
|
||||
continue;
|
||||
}
|
||||
$sensor_value = $printer_states[$bit_flags[$i]]['value'];
|
||||
if ($printer_states[$bit_flags[$i]]['generic'] == 2) {
|
||||
$is_critical = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// cannot create an index for each bit combination, instead warning or critical
|
||||
if (count($bit_flags) > 1) {
|
||||
// multiple issues, check above list
|
||||
$sensor_value = $is_critical?10:9;
|
||||
}
|
||||
}
|
||||
d_echo('Polling hrPrinterDetectedErrorState: '.$sensor_value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user