48 lines
1.7 KiB
PHP
Raw Normal View History

<?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']));
2015-07-13 20:10:26 +02:00
foreach ($toner_data as $toner) {
echo 'Checking toner '.$toner['toner_descr'].'... ';
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');
}
2015-07-13 20:10:26 +02:00
$tonerperc = round((snmp_get($device, $toner['toner_oid'], '-OUqnv') / $toner['toner_capacity'] * 100));
2015-07-13 20:10:26 +02:00
$old_tonerrrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('toner-'.$toner['toner_descr'].'.rrd');
$tonerrrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('toner-'.$toner['toner_index'].'.rrd');
2015-07-13 20:10:26 +02:00
if (!is_file($tonerrrd) && is_file($old_tonerrrd)) {
rename($old_tonerrrd, $tonerrrd);
}
2015-07-13 20:10:26 +02:00
if (!is_file($tonerrrd)) {
rrdtool_create(
$tonerrrd,
2015-09-28 08:24:57 +00:00
'--step 300
2015-07-13 20:10:26 +02:00
DS:toner:GAUGE:600:0:20000 '.$config['rrd_rra']
);
}
2015-07-13 20:10:26 +02:00
echo $tonerperc." %\n";
$fields = array(
'toner' => $tonerperc,
);
rrdtool_update($tonerrrd, $fields);
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']);
}
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