Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printer paper tray status and error states #9859

Merged
merged 6 commits into from Mar 7, 2019
Merged
Changes from 2 commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -38,6 +38,10 @@
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',
@@ -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);
}
@@ -58,6 +58,38 @@
);
}
}
echo PHP_EOL, 'Tray Paper Level', PHP_EOL;
$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);
$type = 'jetpapertray';

This comment has been minimized.

Copy link
@murrant

murrant Mar 2, 2019

Member

Can probably drop jet here and just go papertray (jetdirect above is for legacy reasons)

$capacity = $data['prtInputMaxCapacity'];
$current = $data['prtInputCurrentLevel'] / $capacity * 100;
$descr = $data['prtInputName'];
$tray_oid = ".1.3.6.1.2.1.43.8.2.1.10.$index";
$capacity_oid = ".1.3.6.1.2.1.43.8.2.1.9.$index";
if (is_numeric($current)) {
discover_toner(
$valid_toner,
$device,
$tray_oid,
$last_index,
$type,
$descr,
$capacity_oid,
$capacity,
$current
);
}
}
}
// Delete removed toners
@@ -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') {
@@ -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);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.