From e3e3de1442bec8bc8c91253edfd75045f81a3c88 Mon Sep 17 00:00:00 2001 From: tarik Date: Wed, 6 Mar 2019 16:58:14 -0800 Subject: [PATCH] Printer paper tray status and error states (#9859) * adding paper tray status and error states * adding paper tray test data * Create jetdirect_papertray.json * Store printer supply type * Update json data * fix style --- LibreNMS/Util/StringHelpers.php | 10 + app/Models/Toner.php | 10 + html/includes/table/toner.inc.php | 5 +- html/pages/device/overview/toner.inc.php | 86 +- html/pages/health/toner.inc.php | 5 +- includes/discovery/sensors.inc.php | 4 + .../discovery/sensors/state/printer.inc.php | 106 ++ includes/discovery/toner.inc.php | 46 +- includes/polling/functions.inc.php | 2 + .../polling/sensors/state/printer.inc.php | 41 + tests/data/canonprinter_lbp.json | 8 +- tests/data/jetdirect.json | 8 +- tests/data/jetdirect_m252dw.json | 1201 +++++++++++++++++ tests/data/jetdirect_m880.json | 826 ++++++++++++ tests/data/konica.json | 136 +- tests/data/xerox.json | 96 +- tests/snmpsim/jetdirect_m252dw.snmprec | 397 ++++++ tests/snmpsim/jetdirect_m880.snmprec | 330 +++++ 18 files changed, 3146 insertions(+), 171 deletions(-) create mode 100644 app/Models/Toner.php create mode 100644 includes/discovery/sensors/state/printer.inc.php create mode 100644 includes/polling/sensors/state/printer.inc.php create mode 100644 tests/data/jetdirect_m252dw.json create mode 100644 tests/data/jetdirect_m880.json create mode 100644 tests/snmpsim/jetdirect_m252dw.snmprec create mode 100644 tests/snmpsim/jetdirect_m880.snmprec diff --git a/LibreNMS/Util/StringHelpers.php b/LibreNMS/Util/StringHelpers.php index e6855efffd..9c8bed7743 100644 --- a/LibreNMS/Util/StringHelpers.php +++ b/LibreNMS/Util/StringHelpers.php @@ -78,4 +78,14 @@ class StringHelpers return isset($replacements[$string]) ? $replacements[$string] : ucwords(str_replace(['_', '-'], ' ', $string)); } + + /** + * Convert a camel or studly case string to Title case (with spaces) + * @param $string + * @return string + */ + public static function camelToTitle($string) + { + return ucwords(implode(' ', preg_split('/(?=[A-Z])/', $string))); + } } diff --git a/app/Models/Toner.php b/app/Models/Toner.php new file mode 100644 index 0000000000..d33c609ffa --- /dev/null +++ b/app/Models/Toner.php @@ -0,0 +1,10 @@ + $toner['toner_descr'], 'graph' => $mini_graph, 'toner_used' => $bar_link, + 'toner_type' => StringHelpers::camelToTitle($type == 'opc' ? 'organicPhotoConductor' : $type), 'toner_current' => $perc.'%', ); diff --git a/html/pages/device/overview/toner.inc.php b/html/pages/device/overview/toner.inc.php index 99de31bde0..9983a7b3cd 100644 --- a/html/pages/device/overview/toner.inc.php +++ b/html/pages/device/overview/toner.inc.php @@ -1,62 +1,68 @@ where('device_id', $device['device_id'])->get()->groupBy('toner_type'); -if (count($toners)) { - echo ' +foreach ($supplies as $type => $supply) { + if (!empty($supply)) { + echo '
'; - foreach ($toners as $toner) { - $percent = round($toner['toner_current'], 0); - $total = formatStorage($toner['toner_size']); - $free = formatStorage($toner['toner_free']); - $used = formatStorage($toner['toner_used']); + foreach ($supply as $toner) { + $percent = round($toner['toner_current'], 0); + $total = formatStorage($toner['toner_size']); + $free = formatStorage($toner['toner_free']); + $used = formatStorage($toner['toner_used']); - $background = toner2colour($toner['toner_descr'], $percent); + $background = toner2colour($toner['toner_descr'], $percent); - $graph_array = array(); - $graph_array['height'] = '100'; - $graph_array['width'] = '210'; - $graph_array['to'] = $config['time']['now']; - $graph_array['id'] = $toner['toner_id']; - $graph_array['type'] = $graph_type; - $graph_array['from'] = $config['time']['day']; - $graph_array['legend'] = 'no'; + $graph_array = [ + 'height' => 100, + 'width' => 210, + 'to' => $config['time']['now'], + 'id' => $toner['toner_id'], + 'type' => $graph_type, + 'from' => $config['time']['day'], + 'legend' => 'no', + ]; - $link_array = $graph_array; - $link_array['page'] = 'graphs'; - unset($link_array['height'], $link_array['width'], $link_array['legend']); - $link = generate_url($link_array); + $link_array = $graph_array; + $link_array['page'] = 'graphs'; + unset($link_array['height'], $link_array['width'], $link_array['legend']); + $link = generate_url($link_array); - $overlib_content = generate_overlib_content($graph_array, $device['hostname'].' - '.$toner['toner_descr']); + $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . ' - ' . $toner['toner_descr']); - $graph_array['width'] = 80; - $graph_array['height'] = 20; - $graph_array['bg'] = 'ffffff00'; - // the 00 at the end makes the area transparent. - $minigraph = generate_lazy_graph_tag($graph_array); + $graph_array['width'] = 80; + $graph_array['height'] = 20; + $graph_array['bg'] = 'ffffff00'; + // the 00 at the end makes the area transparent. + $minigraph = generate_lazy_graph_tag($graph_array); - echo ' - - - + + + '; - }//end foreach + }//end foreach - echo '
'.overlib_link($link, $toner['toner_descr'], $overlib_content).''.overlib_link($link, $minigraph, $overlib_content).''.overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent.'%', 'ffffff', $background['right']), $overlib_content).' + echo '
' . overlib_link($link, $toner['toner_descr'], $overlib_content) . '' . overlib_link($link, $minigraph, $overlib_content) . '' . overlib_link($link, print_percentage_bar(200, 20, $percent, null, 'ffffff', $background['left'], $percent . '%', 'ffffff', $background['right']), $overlib_content) . '
'; - echo '
'; - echo '
'; - echo ''; -}//end if + echo ''; + echo ''; + echo ''; + echo ''; + }//end if +} unset($toner_rows); diff --git a/html/pages/health/toner.inc.php b/html/pages/health/toner.inc.php index f6dfefad83..1b413c2c39 100644 --- a/html/pages/health/toner.inc.php +++ b/html/pages/health/toner.inc.php @@ -30,11 +30,12 @@ $pagetitle[] = "Health :: Toner";
- +
+ @@ -44,7 +45,7 @@ $pagetitle[] = "Health :: Toner";
Device TonerType Used Usage