2010-03-11 19:09:19 +00:00
|
|
|
<?php
|
|
|
|
|
2020-04-17 17:37:56 -05:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
$valid_toner = array();
|
2011-03-16 17:53:20 +00:00
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
if ($device['os_group'] == 'printer') {
|
2016-10-14 18:14:18 -05:00
|
|
|
echo 'Toner: ';
|
2011-03-16 17:53:20 +00:00
|
|
|
|
2018-04-05 21:20:33 +01:00
|
|
|
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesLevel', [], 'Printer-MIB');
|
2016-10-14 18:14:18 -05:00
|
|
|
if (!empty($oids)) {
|
2019-03-06 16:58:14 -08:00
|
|
|
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesType', $oids, 'Printer-MIB');
|
2016-10-14 18:14:18 -05:00
|
|
|
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesMaxCapacity', $oids, 'Printer-MIB');
|
|
|
|
$oids = snmpwalk_cache_oid($device, 'prtMarkerSuppliesDescription', $oids, 'Printer-MIB', null, '-OQUsa');
|
2016-08-24 18:42:06 +01:00
|
|
|
}
|
2011-03-16 17:53:20 +00:00
|
|
|
|
2016-10-14 18:14:18 -05:00
|
|
|
foreach ($oids as $index => $data) {
|
|
|
|
$last_index = substr($index, strrpos($index, '.') + 1);
|
2018-03-29 04:13:45 +01:00
|
|
|
|
2017-01-13 15:30:39 +00:00
|
|
|
$raw_toner = $data['prtMarkerSuppliesLevel'];
|
|
|
|
$descr = $data['prtMarkerSuppliesDescription'];
|
|
|
|
$raw_capacity = $data['prtMarkerSuppliesMaxCapacity'];
|
|
|
|
$raw_toner = $data['prtMarkerSuppliesLevel'];
|
|
|
|
$toner_oid = ".1.3.6.1.2.1.43.11.1.1.9.$index";
|
|
|
|
$capacity_oid = ".1.3.6.1.2.1.43.11.1.1.8.$index";
|
|
|
|
|
|
|
|
if (empty($raw_toner)) {
|
2016-10-14 18:14:18 -05:00
|
|
|
$toner_oid = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.5.$last_index";
|
2017-01-13 15:30:39 +00:00
|
|
|
$raw_toner = snmp_get($device, $toner_oid, '-Oqv');
|
|
|
|
}
|
2016-08-24 19:47:06 +03:00
|
|
|
|
2018-03-29 04:13:45 +01:00
|
|
|
if (empty($raw_toner)) {
|
|
|
|
$raw_toner = snmp_get($device, $toner_oid, '-Oqv');
|
|
|
|
}
|
|
|
|
|
2017-01-13 15:30:39 +00:00
|
|
|
if (empty($descr)) {
|
|
|
|
$descr_oid = ".1.3.6.1.4.1.367.3.2.1.2.24.1.1.3.$last_index";
|
2016-10-14 18:14:18 -05:00
|
|
|
$descr = snmp_get($device, $descr_oid, '-Oqva');
|
2017-01-13 15:30:39 +00:00
|
|
|
}
|
|
|
|
|
2018-03-29 04:13:45 +01:00
|
|
|
// trim part & serial number from devices that include it
|
2020-04-17 17:37:56 -05:00
|
|
|
if (Str::contains($descr, ', PN')) {
|
2018-03-29 04:13:45 +01:00
|
|
|
$descr = explode(', PN', $descr)[0];
|
2016-10-14 18:14:18 -05:00
|
|
|
}
|
2016-08-24 18:42:06 +01:00
|
|
|
|
2016-10-14 18:14:18 -05:00
|
|
|
$capacity = get_toner_capacity($data['prtMarkerSuppliesMaxCapacity']);
|
|
|
|
$current = get_toner_levels($device, $raw_toner, $capacity);
|
2016-10-13 17:35:29 +03:00
|
|
|
|
2017-01-31 08:07:50 +00:00
|
|
|
if (is_numeric($current)) {
|
|
|
|
discover_toner(
|
|
|
|
$valid_toner,
|
|
|
|
$device,
|
|
|
|
$toner_oid,
|
|
|
|
$last_index,
|
2019-03-06 16:58:14 -08:00
|
|
|
$data['prtMarkerSuppliesType'] ?: 'markerSupply',
|
2017-01-31 08:07:50 +00:00
|
|
|
$descr,
|
|
|
|
$capacity_oid,
|
|
|
|
$capacity,
|
|
|
|
$current
|
|
|
|
);
|
|
|
|
}
|
2016-10-03 19:49:23 +03:00
|
|
|
}
|
2019-03-06 16:58:14 -08:00
|
|
|
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
|
2019-03-07 19:51:39 -06:00
|
|
|
$current = 50;
|
2019-03-06 16:58:14 -08:00
|
|
|
} 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
|
|
|
|
);
|
|
|
|
}
|
2016-10-03 19:49:23 +03:00
|
|
|
}
|
2015-07-13 20:10:26 +02:00
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
// Delete removed toners
|
2016-10-14 18:14:18 -05:00
|
|
|
d_echo("\n Checking valid toner ... \n");
|
2016-08-24 18:42:06 +01:00
|
|
|
d_echo($valid_toner);
|
2011-03-16 17:53:20 +00:00
|
|
|
|
2019-03-06 16:58:14 -08:00
|
|
|
$toners = dbFetchRows("SELECT * FROM toner WHERE device_id = ?", [$device['device_id']]);
|
|
|
|
//d_echo($toners);
|
2017-01-13 15:30:39 +00:00
|
|
|
foreach ($toners as $test_toner) {
|
|
|
|
$toner_oid = $test_toner['toner_oid'];
|
2016-10-03 19:49:23 +03:00
|
|
|
$toner_type = $test_toner['toner_type'];
|
2017-01-13 15:30:39 +00:00
|
|
|
if (!$valid_toner[$toner_type][$toner_oid]) {
|
2016-08-24 18:42:06 +01:00
|
|
|
echo '-';
|
|
|
|
dbDelete('toner', '`toner_id` = ?', array($test_toner['toner_id']));
|
2015-07-13 20:10:26 +02:00
|
|
|
}
|
2016-08-24 18:42:06 +01:00
|
|
|
}
|
2011-03-28 20:29:34 +00:00
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
unset($valid_toner);
|
2016-10-14 18:14:18 -05:00
|
|
|
echo PHP_EOL;
|