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$graph_type = "storage_usage";
15
16$sql  = "SELECT * FROM `storage`";
17//$sql .= " LEFT JOIN `storage-state` USING(`storage_id`)";
18$sql .= " WHERE `device_id` = ?";
19
20$drives = dbFetchRows($sql, array($device['device_id']));
21
22if (count($drives))
23{
24  $drives = array_sort_by($drives, 'storage_descr', SORT_ASC, SORT_STRING);
25
26  $box_args = array('title' => 'Storage',
27                    'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'health', 'metric' => 'storage')),
28                    'icon' => $config['icon']['storage'],
29                    );
30  echo generate_box_open($box_args);
31
32  echo('<table class="table table-condensed table-striped">');
33
34  foreach ($drives as $drive)
35  {
36    $skipdrive = FALSE;
37
38    if ($device["os"] == "junos")
39    {
40      foreach ($config['ignore_junos_os_drives'] as $jdrive)
41      {
42        if (preg_match($jdrive, $drive["storage_descr"]))
43        {
44          $skipdrive = TRUE;
45        }
46      }
47      $drive["storage_descr"] = preg_replace("/.*mounted on: (.*)/", "\\1", $drive["storage_descr"]);
48    }
49
50    if ($device['os'] == "freebsd")
51    {
52      foreach ($config['ignore_bsd_os_drives'] as $jdrive)
53      {
54        if (preg_match($jdrive, $drive["storage_descr"]))
55        {
56          $skipdrive = TRUE;
57        }
58      }
59    }
60    if ($drive['storage_ignore']) { $skipdrive = TRUE; }
61
62    if ($skipdrive) { continue; }
63    $drive["storage_descr"] = preg_replace("/(.*), type: (.*), dev: (.*)/", "\\1", $drive["storage_descr"]); // '/mnt/Media, type: zfs, dev: Media'
64    $drive["storage_descr"] = preg_replace("/(.*) Label:(.*) Serial Number (.*)/", "\\1", $drive["storage_descr"]); // E:\ Label:Large Space Serial Number 26ad0d98
65    $percent  = round($drive['storage_perc'], 0);
66    $total = formatStorage($drive['storage_size']);
67    $free = formatStorage($drive['storage_free']);
68    $used = formatStorage($drive['storage_used']);
69    $background = get_percentage_colours($percent);
70
71    $graph_array           = array();
72    $graph_array['height'] = "100";
73    $graph_array['width']  = "210";
74    $graph_array['to']     = $config['time']['now'];
75    $graph_array['id']     = $drive['storage_id'];
76    $graph_array['type']   = $graph_type;
77    $graph_array['from']   = $config['time']['day'];
78    $graph_array['legend'] = "no";
79
80    $link_array = $graph_array;
81    $link_array['page'] = "graphs";
82    unset($link_array['height'], $link_array['width'], $link_array['legend']);
83    $link = generate_url($link_array);
84
85    $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - " . $drive['storage_descr']);
86
87    $graph_array['width'] = 80; $graph_array['height'] = 20; $graph_array['bg'] = 'ffffff00';
88//    $graph_array['style'][] = 'margin-top: -6px';
89
90    $minigraph =  generate_graph_tag($graph_array);
91
92    echo('<tr class="'.$background['class'].'">
93           <td class="state-marker"></td>
94           <td class="entity" style="max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">'.generate_entity_link('storage', $drive).'</td>
95           <td style="width: 90px">'.overlib_link($link, $minigraph, $overlib_content).'</td>
96           <td style="width: 200px">'.overlib_link($link, print_percentage_bar (200, 20, $percent, $used."/".$total." (".$percent . "%)", "ffffff", $background['left'],
97                                                   $free . " (" . (100 - $percent) . "%)", "ffffff", $background['right']), $overlib_content).'</td>
98
99         </tr>');
100
101  }
102
103  echo("</table>");
104  echo generate_box_close();
105}
106
107unset ($drive_rows);
108
109// EOF
110