2010-03-12 17:33:58 +00:00
|
|
|
<?php
|
|
|
|
|
2010-03-12 18:13:30 +00:00
|
|
|
if ($config['enable_printers'])
|
2010-03-12 17:33:58 +00:00
|
|
|
{
|
2011-05-16 20:33:51 +00:00
|
|
|
$toner_data = dbFetchRows("SELECT * FROM toner WHERE device_id = ?", array($device['device_id']));
|
2011-03-16 01:11:27 +00:00
|
|
|
|
2011-05-16 20:33:51 +00:00
|
|
|
foreach ($toner_data as $toner)
|
2010-03-12 17:33:58 +00:00
|
|
|
{
|
|
|
|
echo("Checking toner " . $toner['toner_descr'] . "... ");
|
|
|
|
|
2011-05-16 20:33:51 +00:00
|
|
|
# FIXME poll capacity maybe also here, when toner is replaced capacity can change, leading to "154% of toner"
|
2011-04-21 10:37:55 +00:00
|
|
|
|
2011-09-19 10:10:07 +00:00
|
|
|
$tonerperc = round(snmp_get($device, $toner['toner_oid'], "-OUqnv") / $toner['toner_capacity'] * 100);
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2011-05-03 20:13:15 +00: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");
|
|
|
|
|
|
|
|
if (!is_file($tonerrrd) && is_file($old_tonerrrd))
|
|
|
|
{
|
|
|
|
rename($old_tonerrrd, $tonerrrd);
|
|
|
|
}
|
2010-03-12 17:33:58 +00:00
|
|
|
|
2011-03-16 01:11:27 +00:00
|
|
|
if (!is_file($tonerrrd))
|
2010-03-12 17:33:58 +00:00
|
|
|
{
|
2011-03-16 01:11:27 +00:00
|
|
|
rrdtool_create($tonerrrd,"--step 300 \
|
2010-03-12 18:28:18 +00:00
|
|
|
DS:toner:GAUGE:600:0:20000 \
|
2010-03-12 17:33:58 +00:00
|
|
|
RRA:AVERAGE:0.5:1:1200 \
|
|
|
|
RRA:MIN:0.5:12:2400 \
|
|
|
|
RRA:MAX:0.5:12:2400 \
|
2011-03-16 01:11:27 +00:00
|
|
|
RRA:AVERAGE:0.5:12:2400");
|
2010-03-12 17:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo($tonerperc . " %\n");
|
|
|
|
|
|
|
|
rrdtool_update($tonerrrd,"N:$tonerperc");
|
|
|
|
|
2011-04-21 10:37:55 +00:00
|
|
|
#FIXME should report for toner out... :)
|
|
|
|
|
2011-09-20 09:55:11 +00:00
|
|
|
# Log toner swap
|
2011-04-21 10:37:55 +00:00
|
|
|
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
|
|
|
|
2011-05-16 20:33:51 +00:00
|
|
|
dbUpdate(array('toner_current' => $tonerperc, 'toner_capacity' => $toner['toner_capacity']), 'toner', '`toner_id` = ?', array($toner['toner_id']));
|
2010-03-12 17:33:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-03 20:13:15 +00:00
|
|
|
?>
|