2010-03-12 17:33:58 +00:00
|
|
|
<?php
|
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
if ($config['enable_printers']) {
|
|
|
|
$toner_data = dbFetchRows('SELECT * FROM toner WHERE device_id = ?', array($device['device_id']));
|
2011-03-16 01:11:27 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
foreach ($toner_data as $toner) {
|
|
|
|
echo 'Checking toner '.$toner['toner_descr'].'... ';
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
if ($toner['toner_capacity_oid']) {
|
|
|
|
// FIXME this if can go on 1-Sep-2012
|
|
|
|
$toner['toner_capacity'] = snmp_get($device, $toner['toner_capacity_oid'], '-OUqnv');
|
|
|
|
}
|
2011-10-10 12:51:52 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
$tonerperc = round((snmp_get($device, $toner['toner_oid'], '-OUqnv') / $toner['toner_capacity'] * 100));
|
|
|
|
echo $tonerperc." %\n";
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2016-01-10 19:31:39 +10:00
|
|
|
$old = array('toner', $toner['toner_descr']);
|
|
|
|
$new = array('toner', $toner['toner_index']);
|
|
|
|
rrd_file_rename($device, $old, $new);
|
2011-04-21 10:37:55 +00:00
|
|
|
|
2016-01-10 19:31:39 +10:00
|
|
|
$tags = array(
|
|
|
|
'rrd_def' => 'DS:toner:GAUGE:600:0:20000',
|
|
|
|
'rrd_name' => $new,
|
|
|
|
'index' => $toner['toner_index'],
|
|
|
|
);
|
|
|
|
data_update($device, 'toner', $tags, $tonerperc);
|
2015-08-19 20:58:02 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
// FIXME should report for toner out... :)
|
|
|
|
// Log toner swap
|
|
|
|
if ($tonerperc > $toner['toner_current']) {
|
|
|
|
log_event('Toner '.$toner['toner_descr'].' was replaced (new level: '.$tonerperc.'%)', $device, 'toner', $toner['toner_id']);
|
|
|
|
}
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2015-07-13 20:10:26 +02:00
|
|
|
dbUpdate(array('toner_current' => $tonerperc, 'toner_capacity' => $toner['toner_capacity']), 'toner', '`toner_id` = ?', array($toner['toner_id']));
|
|
|
|
}//end foreach
|
|
|
|
}//end if
|