1<?php
2
3/**
4 * Observium Network Management and Monitoring System
5 * Copyright (C) 2006-2015, Adam Armstrong - http://www.observium.org
6 *
7 * @package    observium
8 * @subpackage webui
9 * @author     Adam Armstrong <adama@observium.org>
10 * @copyright  (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited
11 *
12 */
13
14//$counter_types = array_keys($config['counter_types']);
15
16$sql = "SELECT * FROM `counters` WHERE `device_id` = ? AND `counter_deleted` = 0 ORDER BY `counter_class`, `counter_descr`"; // order numerically by entPhysicalIndex for ports
17
18// Cache all counters
19foreach (dbFetchRows($sql, array($device['device_id'])) as $entry)
20{
21    if (strlen($entry['measured_class']) && is_numeric($entry['measured_entity']))
22    {
23      // Counters bounded with measured class, mostly ports
24      // array index -> ['measured']['port']['345'][] = counter array
25      $counters_db['measured'][$entry['measured_class']][$entry['measured_entity']][] = $entry;
26    } else {
27      // Know counters in separate boxes, all other in counter box
28      $counter_type = isset($config['counter_types'][$entry['counter_class']]) ? $entry['counter_class'] : 'counter';
29      //$counter_type = 'counter'; // Keep all counters in single box
30      $counters_db[$counter_type][$entry['counter_id']] = $entry;
31    }
32}
33//r($counters_db['measured']);
34
35// Now print founded bundle (measured_class+counter)
36if (isset($counters_db['measured']))
37{
38  $vars['measured_icon'] = FALSE; // Hide measured icons
39  foreach ($counters_db['measured'] as $measured_class => $measured_entity)
40  {
41    $tab = $measured_class == 'printersupply' ? 'printing' : $measured_class . 's';
42    $box_args = array('title' => nicecase($measured_class).' Counters',
43                      'url'   => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => $tab, 'view' => 'counters')),
44                      'icon'  => $config['icon']['counter']
45                      );
46    echo generate_box_open($box_args);
47
48    echo' <table class="table table-condensed table-striped">';
49
50    foreach ($measured_entity as $entity_id => $entry)
51    {
52      $entity      = get_entity_by_id_cache($measured_class, $entity_id);
53      //r($entity);
54      $entity_link = generate_entity_link($measured_class, $entity);
55      $entity_type = entity_type_translate_array($measured_class);
56
57      // Remove port name from counter description
58      $rename_from = [];
59      if ($measured_class == 'port')
60      {
61        $rename_from[] = $entity['port_label'];
62        $rename_from[] = $entity['ifDescr'];
63        $rename_from[] = $entity['port_label_short'];
64        if (strlen($entity['port_label_base']) > 4) { $rename_from[] = $entity['port_label_base']; }
65        $rename_from = array_unique($rename_from);
66      } else {
67          // FIXME. I not remember what should be here, but not its incorrect
68        $rename_from[] = entity_rewrite($measured_class, $entity);
69      }
70      //r($rename_from);
71      //echo('      <tr class="'.$port['row_class'].'">
72      //  <td class="state-marker"></td>
73      echo('      <tr>
74        <td colspan="6" class="entity">' . get_icon($entity_type['icon']) . '&nbsp;' . $entity_link . '</td></tr>');
75      foreach ($entry as $counter)
76      {
77        $counter['counter_descr'] = trim(str_ireplace($rename_from, '', $counter['counter_descr']), ":- \t\n\r\0\x0B");
78        if (empty($counter['counter_descr']))
79        {
80          // Some time counter descriptions equals to entity name
81          $counter['counter_descr'] = nicecase($counter['counter_class']);
82        }
83
84        print_counter_row($counter, $vars);
85      }
86    }
87
88?>
89      </table>
90<?php
91    echo generate_box_close();
92  }
93  // End for print bounds, unset this array
94  unset($counters_db['measured']);
95}
96
97foreach ($counters_db as $counter_type => $counters)
98{
99  if ($counter_type == 'measured') { continue; } // Just be on the safe side
100
101  if (count($counters))
102  {
103    $box_args = array('title' => nicecase($counter_type),
104                      //'url'   => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => $counter_type)),
105                      'url'   => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'counter')),
106                      'icon'  => $config['counter_types'][$counter_type]['icon'],
107                      );
108    echo generate_box_open($box_args);
109
110    echo('<table class="table table-condensed table-striped">');
111    foreach ($counters as $counter)
112    {
113      print_counter_row($counter, $vars);
114    }
115
116    echo("</table>");
117    echo generate_box_close();
118  }
119}
120
121// EOF
122