From e38c2f688578c5e3cf99077d06a2914bf2a714a4 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 17 Jan 2016 15:00:15 +1000 Subject: [PATCH] Show only relevant MIB graphs This reduces noise in the drop-down by only displaying MIB graphs defined for the device. --- html/pages/graphs.inc.php | 2 +- includes/common.php | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/html/pages/graphs.inc.php b/html/pages/graphs.inc.php index bcb1c92437..dcef1cb0cb 100644 --- a/html/pages/graphs.inc.php +++ b/html/pages/graphs.inc.php @@ -64,7 +64,7 @@ else { onchange="window.open(this.options[this.selectedIndex].value,'_top')" > $type."_".$avail_type, 'page' => "graphs"))."'"); if ($avail_type == $subtype) { echo(" selected"); diff --git a/includes/common.php b/includes/common.php index f80583a83f..687c40e121 100644 --- a/includes/common.php +++ b/includes/common.php @@ -649,9 +649,9 @@ function is_client_authorized($clientip) { /* * @return an array of all graph subtypes for the given type - * FIXME not all of these are going to be valid */ -function get_graph_subtypes($type) { +function get_graph_subtypes($type, $device = null) +{ global $config; $types = array(); @@ -669,7 +669,7 @@ function get_graph_subtypes($type) { // find the MIB subtypes foreach ($config['graph_types'] as $type => $unused1) { foreach ($config['graph_types'][$type] as $subtype => $unused2) { - if (is_mib_graph($type, $subtype)) { + if (is_mib_graph($type, $subtype) && $device != null && is_device_graph($device, $subtype)) { $types[] = $subtype; } } @@ -680,6 +680,13 @@ function get_graph_subtypes($type) { } // get_graph_subtypes +function is_device_graph($device, $subtype) +{ + $query = 'SELECT COUNT(*) FROM `device_graphs` WHERE `device_id` = ? AND `graph` = ?'; + return dbFetchCell($query, array($device['device_id'], $subtype)) > 0; +} // is_device_graph + + function get_smokeping_files($device) { global $config; $smokeping_files = array();