mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
2b8178bb5b
git-svn-id: http://www.observium.org/svn/observer/trunk@3068 61d68cd4-352d-0410-923a-c4978735b2b8
46 lines
1.5 KiB
PHP
Executable File
46 lines
1.5 KiB
PHP
Executable File
<?php
|
|
|
|
if ($config['enable_printers'])
|
|
{
|
|
$toner_data = dbFetchRows("SELECT * FROM toner WHERE device_id = ?", array($device['device_id']));
|
|
|
|
foreach ($toner_data as $toner)
|
|
{
|
|
echo("Checking toner " . $toner['toner_descr'] . "... ");
|
|
|
|
$tonerperc = round(snmp_get($device, $toner['toner_oid'], "-OUqnv") / $toner['toner_capacity'] * 100);
|
|
# FIXME also repoll capacity, or tonerperc can be incorrect; then line below can go too
|
|
if ($tonerperc > 100) { $tonerperc = 100; } # ^
|
|
|
|
$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);
|
|
}
|
|
|
|
if (!is_file($tonerrrd))
|
|
{
|
|
rrdtool_create($tonerrrd,"--step 300 \
|
|
DS:toner:GAUGE:600:0:20000 ".$config['rrd_rra']);
|
|
}
|
|
|
|
echo($tonerperc . " %\n");
|
|
|
|
rrdtool_update($tonerrrd,"N:$tonerperc");
|
|
|
|
#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']);
|
|
}
|
|
|
|
dbUpdate(array('toner_current' => $tonerperc, 'toner_capacity' => $toner['toner_capacity']), 'toner', '`toner_id` = ?', array($toner['toner_id']));
|
|
}
|
|
}
|
|
|
|
?>
|