1<?php
2
3/**
4 * Observium
5 *
6 *   This file is part of Observium.
7 *
8 * @package    observium
9 * @subpackage poller
10 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
11 *
12 */
13
14$supply_data = dbFetchRows("SELECT * FROM `printersupplies` WHERE `device_id` = ?", array($device['device_id']));
15
16foreach ($supply_data as $supply)
17{
18  echo("Checking " . $supply['supply_descr'] . " (" . nicecase($supply['supply_type']) . ")... ");
19
20  // Fetch level and capacity
21  $data = snmp_get_multi_oid($device, $supply['supply_oid'] . ' ' . $supply['supply_capacity_oid'], array(), NULL, NULL, OBS_SNMP_ALL_NUMERIC);
22  print_debug_vars($data);
23
24  // Level
25  $level = $data[$supply['supply_oid']];
26
27  if ($supply['supply_mib'] == 'RicohPrivateMIB')
28  {
29    if ($level == '-100')
30    {
31      // Toner near empty
32      $level = '5'; // ~ 1-20%
33    }
34    else if ($level == '-3')
35    {
36      $level = '80'; // ~ 10-100%
37    }
38
39  } else {
40
41    /**
42     * .1.3.6.1.2.1.43.11.1.1.9 prtMarkerSuppliesLevel
43     *  The value (-1) means other and specifically indicates that the sub-unit places
44     *  no restrictions on this parameter. The value (-2) means unknown.
45     *  A value of (-3) means that the printer knows that there is some supply/remaining space,
46     *  respectively.
47     */
48    switch ($level)
49    {
50      case '-1':
51        $level = 100; // Unlimit
52        break;
53      case '-2':
54        $level = 0;   // Unknown
55        break;
56      case '-3':
57        $level = 1;   // This is wrong SuppliesLevel (1%), but better than nothing
58        break;
59    }
60  }
61
62  // Capacity
63  if (strlen($supply['supply_capacity_oid']))
64  {
65    $capacity = $data[$supply['supply_capacity_oid']];
66  }
67  else if ($supply['supply_capacity'])
68  {
69    $capacity = $supply['supply_capacity'];
70  } else {
71    $capacity = 100;
72  }
73
74  /**
75   * .1.3.6.1.2.1.43.11.1.1.8 prtMarkerSuppliesMaxCapacity
76   *  The value (-1) means other and specifically indicates that the sub-unit places
77   *  no restrictions on this parameter. The value (-2) means unknown.
78   */
79  switch ($capacity)
80  {
81    case '-1':
82      $capacity = 100; // Unlimit
83      break;
84    //case '-2':
85    //  $capacity = 0;   // Unknown
86    //  break;
87  }
88
89  // Supply percent
90  if ($level >= 0 && $capacity > 0)
91  {
92    //$supplyperc = round($level / $supply['supply_capacity'] * 100);
93    $supplyperc = round($level / $capacity * 100);
94  } else {
95    $supplyperc = $level;
96  }
97
98  echo($supplyperc . " %\n");
99
100  rrdtool_update_ng($device, 'toner', array('level' => $supplyperc),  $supply['supply_index']);
101
102  if ($supplyperc > $supply['supply_value'] && $capacity >= 0)
103  {
104    log_event('Printer supply ' . $supply['supply_descr'] . ' (type ' . nicecase($supply['supply_type']) . ') was replaced (new level: ' . $supplyperc . '%)', $device, 'toner', $supply['supply_id']);
105  }
106
107  // Update DB
108  $supply_update = array();
109  if ($supply['supply_value']    != $supplyperc) { $supply_update['supply_value']    = $supplyperc; }
110  if ($supply['supply_capacity'] != $capacity)   { $supply_update['supply_capacity'] = $capacity; }
111  if ($supply_update)
112  {
113    dbUpdate($supply_update, 'printersupplies', '`supply_id` = ?', array($supply['supply_id']));
114  }
115
116  // Check metrics
117  check_entity('printersupply', $supply, array('supply_value' => $supplyperc));
118
119  $graphs['printersupplies'] = TRUE;
120}
121
122// EOF
123