2010-03-12 17:33:58 +00:00
|
|
|
<?php
|
|
|
|
|
2017-02-23 22:45:50 +00:00
|
|
|
use LibreNMS\RRD\RrdDefinition;
|
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
$toner_data = dbFetchRows('SELECT * FROM toner WHERE device_id = ?', array($device['device_id']));
|
2011-03-16 01:11:27 +00:00
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
foreach ($toner_data as $toner) {
|
|
|
|
echo 'Checking toner '.$toner['toner_descr'].'... ';
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2016-10-14 18:14:18 -05:00
|
|
|
$raw_toner = snmp_get($device, $toner['toner_oid'], '-OUqnv');
|
|
|
|
$tonerperc = get_toner_levels($device, $raw_toner, $toner['toner_capacity']);
|
2016-08-24 18:42:06 +01:00
|
|
|
echo $tonerperc." %\n";
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
$tags = array(
|
2017-02-23 22:45:50 +00:00
|
|
|
'rrd_def' => RrdDefinition::make()->addDataset('toner', 'GAUGE', 0, 20000),
|
2016-08-24 18:42:06 +01:00
|
|
|
'rrd_name' => array('toner', $toner['toner_index']),
|
|
|
|
'rrd_oldname' => array('toner', $toner['toner_descr']),
|
|
|
|
'index' => $toner['toner_index'],
|
|
|
|
);
|
|
|
|
data_update($device, 'toner', $tags, $tonerperc);
|
2015-08-19 20:58:02 +00:00
|
|
|
|
2016-10-14 18:14:18 -05:00
|
|
|
// Log empty supplies (but only once)
|
|
|
|
if ($tonerperc == 0 && $toner['toner_current'] > 0) {
|
2017-02-14 00:32:02 +02:00
|
|
|
log_event('Toner ' . $toner['toner_descr'] . ' is empty', $device, 'toner', 5, $toner['toner_id']);
|
2016-10-14 18:14:18 -05:00
|
|
|
}
|
|
|
|
|
2016-08-24 18:42:06 +01:00
|
|
|
// Log toner swap
|
|
|
|
if ($tonerperc > $toner['toner_current']) {
|
2017-02-14 00:32:02 +02:00
|
|
|
log_event('Toner ' . $toner['toner_descr'] . ' was replaced (new level: ' . $tonerperc . '%)', $device, 'toner', 3, $toner['toner_id']);
|
2016-08-24 18:42:06 +01:00
|
|
|
}
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2017-02-14 11:44:16 +00:00
|
|
|
dbUpdate(array('toner_current' => $tonerperc, 'toner_capacity' => $toner['toner_capacity']), 'toner', '`toner_id` = ?', array($toner['toner_id']));
|
2016-08-24 18:42:06 +01:00
|
|
|
}//end foreach
|