From f1ab68deedf993ac3e7db3a43fdf8f8c653682de Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 21 Jun 2015 12:05:59 +1000 Subject: [PATCH 01/42] Gather Ruckus radio stats table --- includes/polling/os/ruckuswireless.inc.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/polling/os/ruckuswireless.inc.php b/includes/polling/os/ruckuswireless.inc.php index a83f69b1ec..a56e88a34d 100644 --- a/includes/polling/os/ruckuswireless.inc.php +++ b/includes/polling/os/ruckuswireless.inc.php @@ -45,8 +45,9 @@ if (isset($ruckuscountry) && $ruckuscountry != '') { } $ruckus_mibs = array( - 'ruckusZDSystemStats' => 'RUCKUS-ZD-SYSTEM-MIB', - 'ruckusZDWLANTable' => 'RUCKUS-ZD-WLAN-MIB', - 'ruckusZDWLANAPTable' => 'RUCKUS-ZD-WLAN-MIB', + 'ruckusZDSystemStats' => 'RUCKUS-ZD-SYSTEM-MIB', + 'ruckusZDWLANTable' => 'RUCKUS-ZD-WLAN-MIB', + 'ruckusZDWLANAPTable' => 'RUCKUS-ZD-WLAN-MIB', + 'ruckusZDWLANAPRadioStatsTable' => 'RUCKUS-ZD-WLAN-MIB', ); poll_mibs($ruckus_mibs, $device, $graphs); From 7752bc049462bad3c6e95d18def530524097186c Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 24 Jun 2015 19:41:53 +1000 Subject: [PATCH 02/42] Move to fixed DS names in MIB-based polling; add script to convert RRDs --- contrib/convert-mib-graphs.sh | 17 +++++++++++++++++ html/includes/graphs/device/mib.inc.php | 8 +++----- includes/common.php | 19 ------------------- includes/snmp.inc.php | 5 ++--- 4 files changed, 22 insertions(+), 27 deletions(-) create mode 100755 contrib/convert-mib-graphs.sh diff --git a/contrib/convert-mib-graphs.sh b/contrib/convert-mib-graphs.sh new file mode 100755 index 0000000000..dedc06fdab --- /dev/null +++ b/contrib/convert-mib-graphs.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# Script to convert RRDs from the experimental first release of MIB-based polling. + +set -e +set -u + +for i; do + base=${i%%.rrd} + mv $i $i.old + echo "Processing $i" + rrdtool dump $i.old | sed -e 's|.*|mibval|' > $base.xml + rrdtool restore $base.xml $i + rm -f $base.xml +done + +exit 0 diff --git a/html/includes/graphs/device/mib.inc.php b/html/includes/graphs/device/mib.inc.php index 08241e9226..21fe1d7eeb 100644 --- a/html/includes/graphs/device/mib.inc.php +++ b/html/includes/graphs/device/mib.inc.php @@ -16,14 +16,12 @@ $rrd_list = array(); $prefix = rrd_name($device['hostname'], array($subtype, ''), ''); foreach (glob($prefix.'*.rrd') as $filename) { // find out what * expanded to - $globpart = str_replace($prefix, '', $filename); - // take off the prefix - $instance = substr($globpart, 0, -4); - // take off ".rrd" + $globpart = str_replace($prefix, '', $filename); // take off the prefix + $instance = substr($globpart, 0, -4); // take off ".rrd" $ds = array(); $mibparts = explode('-', $subtype); $mibvar = end($mibparts); - $ds['ds'] = name_shorten($mibvar); + $ds['ds'] = 'mibval'; $ds['descr'] = "$mibvar-$instance"; $ds['filename'] = $filename; $rrd_list[] = $ds; diff --git a/includes/common.php b/includes/common.php index de68cfd788..222be702bc 100644 --- a/includes/common.php +++ b/includes/common.php @@ -611,25 +611,6 @@ function d_print_r($var, $no_debug_text = null) { } } -/* - * Shorten the name so it works as an RRD data source name (limited to 19 chars by default). - * Substitute for $subst if necessary. - * @return the shortened name - */ -function name_shorten($name, $common = null, $subst = "mibval", $len = 19) { - if ($common !== null) { - // remove common from the beginning of the string, if present - if (strlen($name) > $len && strpos($name, $common) >= 0) { - $newname = str_replace($common, '', $name); - $name = $newname; - } - } - if (strlen($name) > $len) { - $name = $subst; - } - return $name; -} - /* * @return the name of the rrd file for $host's $extra component * @param host Host name diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index f4603e5135..c0ee2e1dd9 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -828,7 +828,6 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { if ($f[1] && $f[1] == 'OBJECT-TYPE') { $result['object_type'] = $f[0]; $result['shortname'] = str_replace($mib, '', $f[0]); - $result['dsname'] = name_shorten($f[0], $mib); continue; } @@ -1081,8 +1080,8 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) { $mibdef[$oid]['shortname'], $index, ), - array('DS:'.$mibdef[$oid]['dsname'].":$type"), - array($mibdef[$oid]['dsname'] => $val) + array("DS:mibval:$type"), + array("mibval" => $val) ); } } From 724f55e809c175ab8dceeda2d1f34188ddddc54e Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 08:07:01 +1000 Subject: [PATCH 03/42] Remove old roadmap stuff --- doc/General/Roadmap.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/doc/General/Roadmap.md b/doc/General/Roadmap.md index 6680a000a7..b697b7ac88 100644 --- a/doc/General/Roadmap.md +++ b/doc/General/Roadmap.md @@ -1,10 +1,3 @@ -- Device support: - - Ruckus wireless controllers - - Investigate generic device support based on MIBs. It should be - possible to do basic graphs based just on the MIB. They would - obviously not be as customised as the specifically supported devices - but should still be useful to users. - - Functionality/performance improvements: - Investigate solutions for poller performance improvement. - Investigate solutions for multiple communities per device. From 45499e6aa95bb1e8a3c45cff72eca786f7d9ecc7 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 08:08:06 +1000 Subject: [PATCH 04/42] Allow area graphs in generic_multi_line --- html/includes/graphs/generic_multi_line.inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/html/includes/graphs/generic_multi_line.inc.php b/html/includes/graphs/generic_multi_line.inc.php index 513b23674c..e4758958e7 100644 --- a/html/includes/graphs/generic_multi_line.inc.php +++ b/html/includes/graphs/generic_multi_line.inc.php @@ -36,6 +36,9 @@ foreach ($rrd_list as $rrd) { } $colour = $config['graph_colours'][$colours][$iter]; + if (!empty($rrd['area']) && empty($rrd['areacolour'])) { + $rrd['areacolour'] = $colour."20"; + } $ds = $rrd['ds']; $filename = $rrd['filename']; @@ -69,8 +72,8 @@ foreach ($rrd_list as $rrd) { } } - $rrd_optionsb .= ' GPRINT:'.$id.':LAST:%5.2lf%s GPRINT:'.$id.'min:MIN:%5.2lf%s'; - $rrd_optionsb .= ' GPRINT:'.$id.'max:MAX:%5.2lf%s GPRINT:'.$id.":AVERAGE:'%5.2lf%s\\n'"; + $rrd_optionsb .= ' GPRINT:'.$id.':LAST:%5.2lf%s'.$units.' GPRINT:'.$id.'min:MIN:%5.2lf%s'.$units; + $rrd_optionsb .= ' GPRINT:'.$id.'max:MAX:%5.2lf%s'.$units.' GPRINT:'.$id.":AVERAGE:'%5.2lf%s$units\\n'"; $i++; $iter++; From 4fab952696af1b5b7a9147948e117a573f0415df Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 08:08:31 +1000 Subject: [PATCH 05/42] Check for custom & MIB graphs before looking for a file --- html/includes/graphs/graph.inc.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/html/includes/graphs/graph.inc.php b/html/includes/graphs/graph.inc.php index d7ed4cbc89..3e30d4b8e4 100644 --- a/html/includes/graphs/graph.inc.php +++ b/html/includes/graphs/graph.inc.php @@ -43,12 +43,15 @@ if ($auth !== true && $auth != 1) { require $config['install_dir']."/html/includes/graphs/$type/auth.inc.php"; -if ($auth === true && is_file($config['install_dir']."/html/includes/graphs/$type/$subtype.inc.php")) { - include $config['install_dir']."/html/includes/graphs/$type/$subtype.inc.php"; +if ($auth === true && is_custom_graph($type, $subtype, $device)) { + include($config['install_dir'] . "/html/includes/graphs/custom.inc.php"); } else if ($auth === true && is_mib_graph($type, $subtype)) { include $config['install_dir']."/html/includes/graphs/$type/mib.inc.php"; } +elseif ($auth === true && is_file($config['install_dir']."/html/includes/graphs/$type/$subtype.inc.php")) { + include $config['install_dir']."/html/includes/graphs/$type/$subtype.inc.php"; +} else { graph_error("$type*$subtype "); // Graph Template Missing"); From e5549e9423612c7580373d95a84ab7679ac32d4d Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 08:09:02 +1000 Subject: [PATCH 06/42] Remove unused files --- html/pages/device/graphs/cpu.inc.php | 8 --- html/pages/device/graphs/hrprocesses.inc.php | 8 --- html/pages/device/graphs/hrusers.inc.php | 8 --- html/pages/device/graphs/netstats.inc.php | 70 ------------------- .../device/graphs/netstats_icmp_info.inc.php | 8 --- .../pages/device/graphs/netstats_snmp.inc.php | 13 ---- html/pages/device/graphs/uptime.inc.php | 6 -- 7 files changed, 121 deletions(-) delete mode 100644 html/pages/device/graphs/cpu.inc.php delete mode 100644 html/pages/device/graphs/hrprocesses.inc.php delete mode 100644 html/pages/device/graphs/hrusers.inc.php delete mode 100644 html/pages/device/graphs/netstats.inc.php delete mode 100644 html/pages/device/graphs/netstats_icmp_info.inc.php delete mode 100644 html/pages/device/graphs/netstats_snmp.inc.php delete mode 100644 html/pages/device/graphs/uptime.inc.php diff --git a/html/pages/device/graphs/cpu.inc.php b/html/pages/device/graphs/cpu.inc.php deleted file mode 100644 index 10b1086d0e..0000000000 --- a/html/pages/device/graphs/cpu.inc.php +++ /dev/null @@ -1,8 +0,0 @@ - Date: Wed, 1 Jul 2015 08:11:06 +1000 Subject: [PATCH 07/42] Make things clearer by not trying to cram into one line --- includes/load_db_graph_types.inc.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/includes/load_db_graph_types.inc.php b/includes/load_db_graph_types.inc.php index b455308a7d..dc7f605859 100644 --- a/includes/load_db_graph_types.inc.php +++ b/includes/load_db_graph_types.inc.php @@ -14,9 +14,14 @@ // load graph types from the database foreach (dbFetchRows('select * from graph_types') as $graph) { - // remove leading 'graph_' from column names foreach ($graph as $k => $v) { - $key = strpos($k, 'graph_') == 0 ? str_replace('graph_', '', $k) : $k; + if (strpos($k, 'graph_') == 0) { + // remove leading 'graph_' from column name + $key = str_replace('graph_', '', $k); + } + else { + $key = $k; + } $g[$key] = $v; } From b8601b589603db312d0ec64bc677284f0c314dd1 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 08:14:23 +1000 Subject: [PATCH 08/42] Skeleton framework for allowing MIB values to feed CPU & memory health graphs --- html/pages/device.inc.php | 6 +++- html/pages/device/graphs.inc.php | 7 +--- html/pages/device/health.inc.php | 4 +-- includes/common.php | 61 ++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php index 1a68f9dbf3..1bd0326842 100644 --- a/html/pages/device.inc.php +++ b/html/pages/device.inc.php @@ -57,7 +57,11 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) { '; - $health = (dbFetchCell("SELECT COUNT(*) FROM storage WHERE device_id = '".$device['device_id']."'") + dbFetchCell("SELECT COUNT(sensor_id) FROM sensors WHERE device_id = '".$device['device_id']."'") + dbFetchCell("SELECT COUNT(*) FROM mempools WHERE device_id = '".$device['device_id']."'") + dbFetchCell("SELECT COUNT(*) FROM processors WHERE device_id = '".$device['device_id']."'")); + $health = dbFetchCell("SELECT COUNT(*) FROM storage WHERE device_id = '" . $device['device_id'] . "'") + + dbFetchCell("SELECT COUNT(sensor_id) FROM sensors WHERE device_id = '" . $device['device_id'] . "'") + + dbFetchCell("SELECT COUNT(*) FROM mempools WHERE device_id = '" . $device['device_id'] . "'") + + dbFetchCell("SELECT COUNT(*) FROM processors WHERE device_id = '" . $device['device_id'] . "'") + + count_mib_health($device); if ($health) { echo '
  • diff --git a/html/pages/device/graphs.inc.php b/html/pages/device/graphs.inc.php index 154cbbfb51..8c8512b50e 100644 --- a/html/pages/device/graphs.inc.php +++ b/html/pages/device/graphs.inc.php @@ -22,11 +22,7 @@ foreach (dbFetchRows('SELECT * FROM device_graphs WHERE device_id = ? ORDER BY g } } -// These are standard graphs we should have for all systems -$graph_enable['poller']['poller_perf'] = 'device_poller_perf'; -if (can_ping_device($attribs) === true) { - $graph_enable['poller']['ping_perf'] = 'device_ping_perf'; -} +enable_graphs($device, $graph_enable); $sep = ''; foreach ($graph_enable as $section => $nothing) { @@ -56,7 +52,6 @@ print_optionbar_end(); $graph_enable = $graph_enable[$vars['group']]; -// foreach ($config['graph_types']['device'] as $graph => $entry) foreach ($graph_enable as $graph => $entry) { $graph_array = array(); if ($graph_enable[$graph]) { diff --git a/html/pages/device/health.inc.php b/html/pages/device/health.inc.php index 794ff9a8d0..21f41389b2 100644 --- a/html/pages/device/health.inc.php +++ b/html/pages/device/health.inc.php @@ -2,8 +2,8 @@ $storage = dbFetchCell('select count(*) from storage WHERE device_id = ?', array($device['device_id'])); $diskio = dbFetchCell('select count(*) from ucd_diskio WHERE device_id = ?', array($device['device_id'])); -$mempools = dbFetchCell('select count(*) from mempools WHERE device_id = ?', array($device['device_id'])); -$processor = dbFetchCell('select count(*) from processors WHERE device_id = ?', array($device['device_id'])); +$mempools = dbFetchCell('select count(*) from mempools WHERE device_id = ?', array($device['device_id'])) + count_mib_mempools($device); +$processor = dbFetchCell('select count(*) from processors WHERE device_id = ?', array($device['device_id'])) + count_mib_processors($device); $charge = dbFetchCell("select count(*) from sensors WHERE sensor_class='charge' AND device_id = ?", array($device['device_id'])); $temperatures = dbFetchCell("select count(*) from sensors WHERE sensor_class='temperature' AND device_id = ?", array($device['device_id'])); diff --git a/includes/common.php b/includes/common.php index 222be702bc..b32b46a263 100644 --- a/includes/common.php +++ b/includes/common.php @@ -739,6 +739,67 @@ function round_Nth($val = 0, $round_to) { } } // end round_Nth +function count_mib_mempools($device) +{ + if ($device['os'] == 'ruckuswireless') { + return 1; + } + return 0; +} + +function count_mib_processors($device) +{ + if ($device['os'] == 'ruckuswireless') { + return 1; + } + return 0; +} + +function count_mib_health($device) +{ + return count_mib_mempools($device) + count_mib_processors($device); +} + +/* + * @return true if there is a custom graph defined for this type, subtype, and device + */ +function is_custom_graph($type, $subtype, $device) +{ + if ($device['os'] == 'ruckuswireless' && $type == 'device') { + switch ($subtype) { + case 'cpumem': + case 'mempool': + case 'processor': + return true; + } + } + return false; +} + +/* + * Set section/graph entries in $graph_enable for graphs specific to $os. + */ +function enable_os_graphs($os, &$graph_enable) +{ + /* + foreach (dbFetchRows("SELECT * FROM graph_conditions WHERE graph_type = 'device' AND condition_name = 'os' AND condition_value = ?", array($os)) as $graph) { + $graph_enable[$graph['graph_section']][$graph['graph_subtype']] = "device_".$graph['graph_subtype']; + } + */ +} + +/* + * For each os-based or global graph relevant to $device, set its section/graph entry in $graph_enable. + */ +function enable_graphs($device, &$graph_enable) +{ + // These are standard graphs we should have for all systems + $graph_enable['poller']['poller_perf'] = 'device_poller_perf'; + $graph_enable['poller']['ping_perf'] = 'device_ping_perf'; + + enable_os_graphs($device['os'], $graph_enable); +} + /** * Checks if config allows us to ping this device * $attribs contains an array of all of this devices From cb7c87d76f6f9dad784ba255771027ca917dc4e9 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 21:03:02 +1000 Subject: [PATCH 09/42] Use stacked graphs for multi-instance MIBs; add larger colour palette --- html/includes/graphs/device/mib.inc.php | 22 +++++++++++++++++----- includes/defaults.inc.php | 11 +++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/html/includes/graphs/device/mib.inc.php b/html/includes/graphs/device/mib.inc.php index 21fe1d7eeb..b97cca8556 100644 --- a/html/includes/graphs/device/mib.inc.php +++ b/html/includes/graphs/device/mib.inc.php @@ -13,8 +13,10 @@ */ $rrd_list = array(); -$prefix = rrd_name($device['hostname'], array($subtype, ''), ''); -foreach (glob($prefix.'*.rrd') as $filename) { +$prefix = rrd_name($device['hostname'], array($subtype, ''), ''); +$filenames = glob($prefix."*.rrd"); +$count = count($filenames); +foreach ($filenames as $filename) { // find out what * expanded to $globpart = str_replace($prefix, '', $filename); // take off the prefix $instance = substr($globpart, 0, -4); // take off ".rrd" @@ -27,9 +29,19 @@ foreach (glob($prefix.'*.rrd') as $filename) { $rrd_list[] = $ds; } -$colours = 'mixed'; $scale_min = '0'; -$nototal = 0; $simple_rrd = true; -require 'includes/graphs/generic_multi_line.inc.php'; +// If there are multiple matching files, use a stacked graph instead of a line graph +if ($count > 1) { + $nototal = 1; + $divider = $count; + $text_orig = 1; + $colours = 'manycolours'; + include "includes/graphs/generic_multi_simplex_seperated.inc.php"; +} +else { + $colours = 'mixed'; + $nototal = 0; + include "includes/graphs/generic_multi_line.inc.php"; +} diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 407402746f..4c93db9d11 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -315,6 +315,17 @@ $config['graph_colours']['purples'] = array( ); $config['graph_colours']['default'] = $config['graph_colours']['blues']; +// Colour values from http://www.sapdesignguild.org/goodies/diagram_guidelines/color_palettes.html +$config['graph_colours']['manycolours'] = array( + "FFF8A3", "FAE16B", "F8D753", "F3C01C", "F0B400", // yellows + "A9CC8F", "82B16A", "5C9746", "3D8128", "1E6C0B", // greens + "B2C8D9", "779DBF", "3E75A7", "205F9A", "00488C", // blues + "BEA37A", "907A52", "7A653E", "63522B", "3D3000", // browns + "F3AA79", "EB8953", "E1662A", "DC5313", "D84000", // oranges + "B5B5A9", "8B8D82", "74796F", "5D645A", "434C43", // greys + "E6A4A5", "D6707B", "C4384F", "BC1C39", "B30023", // pinks +); + // Map colors $config['network_map_legend'] = array( '0' => '#aeaeae', From f0a7ed8e095e9d87bfc8ef9340d19d98e31de82a Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 21:03:22 +1000 Subject: [PATCH 10/42] Don't convert if we've already done it --- contrib/convert-mib-graphs.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/convert-mib-graphs.sh b/contrib/convert-mib-graphs.sh index dedc06fdab..44a554f11d 100755 --- a/contrib/convert-mib-graphs.sh +++ b/contrib/convert-mib-graphs.sh @@ -7,6 +7,9 @@ set -u for i; do base=${i%%.rrd} + if [ -e $i.old ]; then + continue + fi mv $i $i.old echo "Processing $i" rrdtool dump $i.old | sed -e 's|.*|mibval|' > $base.xml From 97412879bdbdb3092a23469a854127426d5351d8 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 1 Jul 2015 21:03:42 +1000 Subject: [PATCH 11/42] Ignore 3rd-party libraries when searching --- contrib/findit | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/findit b/contrib/findit index 14151b2f95..09fd96359e 100755 --- a/contrib/findit +++ b/contrib/findit @@ -5,6 +5,7 @@ find . \ -path ./html/includes/geshi -prune -o \ -path ./html/includes/jpgraph -prune -o \ -path ./html/js/jqplot -prune -o \ + -path ./lib -prune -o \ -path ./junk -prune -o \ -path ./logs -prune -o \ -path ./mibs -prune -o \ From 9b6496b4040668b38c523bc614353761e4837ef6 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Thu, 2 Jul 2015 09:42:00 +1000 Subject: [PATCH 12/42] Add debugging of MIB objects again --- includes/snmp.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index c0ee2e1dd9..edda9fc63f 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -922,7 +922,7 @@ function snmp_mib_load($mib, $module, $mibdir=null) { foreach (snmp_mib_walk($mib, $module, $mibdir) as $obj) { $mibs[$obj['object_type']] = $obj; } - + d_print_r($mibs); return $mibs; }//end snmp_mib_load() From 4d6e671e7114c7b4cdca376eb3d3a9a050b7e85b Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 15 Jul 2015 20:12:49 +1000 Subject: [PATCH 13/42] Add code to populate mibdefs table; note about moving some items to discovery --- includes/discovery/os/ruckuswireless.inc.php | 13 +++ includes/polling/os/ruckuswireless.inc.php | 1 + includes/snmp.inc.php | 102 ++++++++++++++----- 3 files changed, 88 insertions(+), 28 deletions(-) diff --git a/includes/discovery/os/ruckuswireless.inc.php b/includes/discovery/os/ruckuswireless.inc.php index 2321b1300d..26ea091cd0 100644 --- a/includes/discovery/os/ruckuswireless.inc.php +++ b/includes/discovery/os/ruckuswireless.inc.php @@ -3,6 +3,8 @@ * LibreNMS Ruckus Wireless OS information module * * Copyright (c) 2015 Søren Friis Rosiak + * Copyright (c) 2015 Gear Consulting Pty Ltd + * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your @@ -13,5 +15,16 @@ if (!$os) { if (strstr($sysObjectId, '.1.3.6.1.4.1.25053.3.1')) { $os = 'ruckuswireless'; + + // FIXME: Implement + /* + $ruckus_mibs = array( + "ruckusZDSystemStats" => "RUCKUS-ZD-SYSTEM-MIB", + "ruckusZDWLANTable" => "RUCKUS-ZD-WLAN-MIB", + "ruckusZDWLANAPTable" => "RUCKUS-ZD-WLAN-MIB", + "ruckusZDWLANAPRadioStatsTable" => "RUCKUS-ZD-WLAN-MIB", + ); + register_mibs($device, $register_mibs); + */ } } diff --git a/includes/polling/os/ruckuswireless.inc.php b/includes/polling/os/ruckuswireless.inc.php index a56e88a34d..22f2cf93fd 100644 --- a/includes/polling/os/ruckuswireless.inc.php +++ b/includes/polling/os/ruckuswireless.inc.php @@ -44,6 +44,7 @@ if (isset($ruckuscountry) && $ruckuscountry != '') { $version .= " ($ruckuscountry)"; } +// FIXME: Move this to discovery, and just retrieve the list of MIBs from the database during polling $ruckus_mibs = array( 'ruckusZDSystemStats' => 'RUCKUS-ZD-SYSTEM-MIB', 'ruckusZDWLANTable' => 'RUCKUS-ZD-WLAN-MIB', diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index edda9fc63f..1c08acde0d 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -911,18 +911,57 @@ function snmp_mib_walk($mib, $module, $mibdir=null) { }//end snmp_mib_walk() +function join_array($a, $b) +{ + return "$a=$b"; +} + /* - * @return an array containing all of the mib objects, keyed by object-type; - * returns an empty array if something goes wrong. + * Update the given table in the database with the given row & column data. + * @param tablename The table to update + * @param columns An array of column names + * @param numkeys The number of columns which are in the primary key of the table; these primary keys must be first in the list of columns + * @param rows Row data to insert, an array of arrays with column names as the second-level keys */ +function update_db_table($tablename, $columns, $numkeys, $rows) +{ + foreach ($rows as $nothing => $obj) { + // create a parameter list based on the columns + $params = array(); + foreach ($columns as $column) { + $params[] = $obj[$column]; + } + $column_placeholders = array_fill(0, count($columns), '?'); + // build the "ON DUPLICATE KEY" part + $non_key_columns = array_slice($columns, $numkeys); + $non_key_placeholders = array_slice($column_placeholders, $numkeys); + $update_definitions = array_map("join_array", $non_key_columns, $non_key_placeholders); + $non_key_params = array_slice($params, $numkeys); -function snmp_mib_load($mib, $module, $mibdir=null) { + $sql = 'INSERT INTO `' . $tablename . '` (' . implode(',', $columns) . + ') VALUES (' . implode(',', $column_placeholders) . + ') ON DUPLICATE KEY UPDATE ' . implode(',', $update_definitions); + $result = dbQuery($sql, array_merge($params, $non_key_params)); + d_echo("Result: $result\n"); + } +} + +/* + * @return an array containing all of the MIB objects keyed by object-type, + * or an empty array if something goes wrong. + */ +function snmp_mib_load($mib, $module, $mibdir = null) +{ $mibs = array(); + // FIXME: Measure whether it's more efficient to use the database + // to cache this rather than parse it via snmptranslate every time. foreach (snmp_mib_walk($mib, $module, $mibdir) as $obj) { $mibs[$obj['object_type']] = $obj; } d_print_r($mibs); + $columns = array('module', 'mib', 'object_type', 'oid', 'syntax', 'description', 'max_access', 'status'); + update_db_table('mibdefs', $columns, 3, $mibs); return $mibs; }//end snmp_mib_load() @@ -935,9 +974,8 @@ function snmp_mib_load($mib, $module, $mibdir=null) { * snmptranslate -m all -M mibs .1.3.6.1.4.1.8072.3.2.10 2>/dev/null * NET-SNMP-TC::linux */ - - -function snmp_translate($oid, $module, $mibdir=null) { +function snmp_translate($oid, $module, $mibdir = null) +{ if ($module !== 'all') { $oid = "$module::$oid"; } @@ -972,9 +1010,8 @@ function snmp_translate($oid, $module, $mibdir=null) { * check if the type of the oid is a numeric type, and if so, * @return the name of RRD type that is best suited to saving it */ - - -function oid_rrd_type($oid, $mibdef) { +function oid_rrd_type($oid, $mibdef) +{ if (!isset($mibdef[$oid])) { return false; } @@ -1007,9 +1044,8 @@ function oid_rrd_type($oid, $mibdef) { * Update the database with graph definitions as needed. * We don't include the index in the graph name - that is handled at display time. */ - - -function tag_graphs($mibname, $oids, $mibdef, &$graphs) { +function tag_graphs($mibname, $oids, $mibdef, &$graphs) +{ foreach ($oids as $index => $array) { foreach ($array as $oid => $val) { $graphname = $mibname.'-'.$mibdef[$oid]['shortname']; @@ -1023,9 +1059,8 @@ function tag_graphs($mibname, $oids, $mibdef, &$graphs) { /* * Ensure a graph_type definition exists in the database for the entities in this MIB */ - - -function update_mib_graph_types($mibname, $oids, $mibdef, $graphs) { +function update_mib_graph_types($mibname, $oids, $mibdef, $graphs) +{ $seengraphs = array(); // Get the list of graphs currently in the database @@ -1061,9 +1096,8 @@ function update_mib_graph_types($mibname, $oids, $mibdef, $graphs) { /* * Save all of the measurable oids for the device in their own RRDs. */ - - -function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) { +function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) +{ $usedoids = array(); foreach ($oids as $index => $array) { foreach ($array as $oid => $val) { @@ -1093,12 +1127,12 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) { /* - * Take a list of MIB name => module pairs. - * Validate MIBs and poll based on the results. + * FIXME: Get list of MIBs from the database + * Poll based on the results. */ - - -function poll_mibs($list, $device, &$graphs) { +function poll_mibs($list, $device, &$graphs) +{ + // FIXME: check that mib polling module is enabled if (!is_dev_attrib_enabled($device, 'poll_mib')) { d_echo('MIB module disabled for '.$device['hostname']."\n"); return; @@ -1116,16 +1150,28 @@ function poll_mibs($list, $device, &$graphs) { $mod = $translated[0]; $nam = $translated[1]; $mibdefs[$nam] = snmp_mib_load($nam, $mod); - $oids = snmpwalk_cache_oid($device, $nam, array(), $mod, null, '-OQUsb'); - d_print_r($oids); - save_mibs($device, $nam, $oids, $mibdefs[$nam], $graphs); + if (count($mibdefs[$nam] > 0)) { + $oids = snmpwalk_cache_oid($device, $nam, array(), $mod, null, "-OQUsb"); + d_print_r($oids); + save_mibs($device, $nam, $oids, $mibdefs[$nam], $graphs); + } + else { + echo("MIB: Could not load definition for $mod::$nam\n"); + } } else { d_echo("MIB: no match for $module::$name\n"); } } - d_echo('Done MIB-based polling'); echo "\n"; - }//end poll_mibs() + +/* + * Take a list of MIB name => module pairs. + * Validate MIBs and store the device->mib mapping in the database. + * FIXME: Implement; most of code can be moved in from poll_mibs() above. + */ +function register_mibs($device, $mibs) +{ +} From f2370bbcba461d7c1a31bda056f7d90b20a31959 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Fri, 17 Jul 2015 13:48:22 +1000 Subject: [PATCH 14/42] Add MIB browser --- html/includes/print-menubar.php | 2 + html/includes/table/mibs.inc.php | 91 ++++++++++++++++++++++++++++++++ html/pages/mibs.inc.php | 36 +++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 html/includes/table/mibs.inc.php create mode 100644 html/pages/mibs.inc.php diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 424d273ab5..2a4e59c047 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -110,6 +110,8 @@ if ( dbFetchCell("SELECT 1 from `packages` LIMIT 1") ) {
  • IPv6 Search
  • MAC Search
  • ARP Tables
  • + +
  • MIB definitions
  • '; + if (device_permitted($device['device_id'])) { + echo '
  • + + MIB + +
  • '; + } + echo '
  • https
  • ssh
  • diff --git a/html/pages/device/mib.inc.php b/html/pages/device/mib.inc.php new file mode 100644 index 0000000000..f6ecdb9a4b --- /dev/null +++ b/html/pages/device/mib.inc.php @@ -0,0 +1,52 @@ + + * + * Author: Paul Gear + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if (!isset($vars['section'])) { + $vars['section'] = "mib"; +} +?> + +

    Device MIB associations

    +
    + + + + + + + + + +
    ModuleMIBIncluded byLast Modified
    +
    + + From ceeb362e405b6f3285230fc6271cdafdff793212 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 20 Jul 2015 13:58:13 +1000 Subject: [PATCH 17/42] Update global MIB viewer --- html/includes/table/mibs.inc.php | 4 ++-- html/pages/mibs.inc.php | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/html/includes/table/mibs.inc.php b/html/includes/table/mibs.inc.php index a300bc9fe9..0407036856 100644 --- a/html/includes/table/mibs.inc.php +++ b/html/includes/table/mibs.inc.php @@ -25,7 +25,8 @@ $columns = array( 'description', 'max_access', 'status', - 'last_used', + 'included_by', + 'last_modified', ); function search_phrase_column($c) @@ -87,6 +88,5 @@ $output = array( 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total, - 'sql' => $sql, ); echo _json_encode($output); diff --git a/html/pages/mibs.inc.php b/html/pages/mibs.inc.php index 63cd434ab4..43769fc73b 100644 --- a/html/pages/mibs.inc.php +++ b/html/pages/mibs.inc.php @@ -1,4 +1,20 @@ -

    Loaded MIB definitions

    + + * + * Author: Paul Gear + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ +?> + +

    All MIB definitions

    @@ -9,9 +25,10 @@ - - - + + +
    Object Id Syntax DescriptionMaximum AccessStatusLast UsedIncluded byLast modified
    From 40a1cef050d31382a8d3010b6a33d6e6cbc41ed0 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 20 Jul 2015 14:02:16 +1000 Subject: [PATCH 18/42] Generalise arp discovery cache; move to common --- includes/common.php | 25 +++++++++++++++++++++--- includes/discovery/discovery-arp.inc.php | 4 ++-- includes/discovery/functions.inc.php | 22 --------------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/includes/common.php b/includes/common.php index b32b46a263..e19d0160f4 100644 --- a/includes/common.php +++ b/includes/common.php @@ -800,6 +800,28 @@ function enable_graphs($device, &$graph_enable) enable_os_graphs($device['os'], $graph_enable); } +// +// maintain a simple cache of objects +// + +function object_add_cache($section, $obj) +{ + global $object_cache; + $object_cache[$section][$obj] = true; +} + + +function object_is_cached($section, $obj) +{ + global $object_cache; + if (array_key_exists($obj, $object_cache)) { + return $object_cache[$obj]; + } + else { + return false; + } +} + /** * Checks if config allows us to ping this device * $attribs contains an array of all of this devices @@ -812,9 +834,6 @@ function can_ping_device($attribs) { if ($config['icmp_check'] === true && $attribs['override_icmp_disable'] != "true") { return true; } - else { - return false; - } } // end can_ping_device /** diff --git a/includes/discovery/discovery-arp.inc.php b/includes/discovery/discovery-arp.inc.php index fd5442b062..6894e0cc65 100644 --- a/includes/discovery/discovery-arp.inc.php +++ b/includes/discovery/discovery-arp.inc.php @@ -60,12 +60,12 @@ foreach (dbFetchRows($sql, array($deviceid)) as $entry) { } // Attempt discovery of each IP only once per run. - if (arp_discovery_is_cached($ip)) { + if (object_is_cached('arp_discovery', $ip)) { echo '.'; continue; } - arp_discovery_add_cache($ip); + object_add_cache('arp_discovery', $ip); $name = gethostbyaddr($ip); echo '+'; diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index a90a65d41e..af421323bf 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -704,25 +704,3 @@ function discover_process_ipv6(&$valid, $ifIndex, $ipv6_address, $ipv6_prefixlen }//end if }//end discover_process_ipv6() - - -// maintain a simple cache of seen IPs during ARP discovery - - -function arp_discovery_add_cache($ip) { - global $arp_discovery; - $arp_discovery[$ip] = true; - -}//end arp_discovery_add_cache() - - -function arp_discovery_is_cached($ip) { - global $arp_discovery; - if (array_key_exists($ip, $arp_discovery)) { - return $arp_discovery[$ip]; - } - else { - return false; - } - -}//end arp_discovery_is_cached() From 7619a340d6006e8bf5346b099541716b06b51bfa Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 20 Jul 2015 14:07:23 +1000 Subject: [PATCH 19/42] Split polling & discovery of MIB-based poller --- includes/common.php | 44 ++++++ includes/discovery/os/ruckuswireless.inc.php | 5 +- includes/polling/mib.inc.php | 3 +- includes/polling/os/ruckuswireless.inc.php | 9 -- includes/snmp.inc.php | 143 ++++++++++++++----- 5 files changed, 152 insertions(+), 52 deletions(-) diff --git a/includes/common.php b/includes/common.php index e19d0160f4..6430ba3084 100644 --- a/includes/common.php +++ b/includes/common.php @@ -836,6 +836,50 @@ function can_ping_device($attribs) { } } // end can_ping_device +/* + * @return true if the requested module type & name is globally enabled + */ +function is_module_enabled($type, $module) +{ + global $config; + if (isset($config[$type.'_modules'][$module])) { + return $config[$type.'_modules'][$module] == 1; + } + else { + return false; + } +} // is_module_enabled + +/* + * @return true if every string in $arr begins with $str + */ +function begins_with($str, $arr) +{ + foreach ($arr as $s) { + $pos = strpos($s, $str); + if ($pos === false || $pos > 0) { + return false; + } + } + return true; +} // begins_with + +/* + * @return the longest starting portion of $str that matches everything in $arr + */ +function longest_matching_prefix($str, $arr) +{ + $len = strlen($str); + while ($len > 0) { + $prefix = substr($str, 0, $len); + if (begins_with($prefix, $arr)) { + return $prefix; + } + $len -= 1; + } + return ''; +} // longest_matching_prefix + /** * Constructs the path to an RRD for the Ceph application * @param string $gtype The type of rrd we're looking for diff --git a/includes/discovery/os/ruckuswireless.inc.php b/includes/discovery/os/ruckuswireless.inc.php index 26ea091cd0..dad1284847 100644 --- a/includes/discovery/os/ruckuswireless.inc.php +++ b/includes/discovery/os/ruckuswireless.inc.php @@ -16,15 +16,12 @@ if (!$os) { if (strstr($sysObjectId, '.1.3.6.1.4.1.25053.3.1')) { $os = 'ruckuswireless'; - // FIXME: Implement - /* $ruckus_mibs = array( "ruckusZDSystemStats" => "RUCKUS-ZD-SYSTEM-MIB", "ruckusZDWLANTable" => "RUCKUS-ZD-WLAN-MIB", "ruckusZDWLANAPTable" => "RUCKUS-ZD-WLAN-MIB", "ruckusZDWLANAPRadioStatsTable" => "RUCKUS-ZD-WLAN-MIB", ); - register_mibs($device, $register_mibs); - */ + register_mibs($device, $ruckus_mibs, "includes/discovery/os/ruckuswireless.inc.php"); } } diff --git a/includes/polling/mib.inc.php b/includes/polling/mib.inc.php index f1137cdbae..70396b9612 100644 --- a/includes/polling/mib.inc.php +++ b/includes/polling/mib.inc.php @@ -12,5 +12,4 @@ * the source code distribution for details. */ -$devicemib = array($device['sysObjectID'] => 'all'); -poll_mibs($devicemib, $device, $graphs); +poll_mibs($device, $graphs); diff --git a/includes/polling/os/ruckuswireless.inc.php b/includes/polling/os/ruckuswireless.inc.php index 22f2cf93fd..013fe2aa1f 100644 --- a/includes/polling/os/ruckuswireless.inc.php +++ b/includes/polling/os/ruckuswireless.inc.php @@ -43,12 +43,3 @@ $ruckuscountry = first_oid_match($device, $ruckuscountries); if (isset($ruckuscountry) && $ruckuscountry != '') { $version .= " ($ruckuscountry)"; } - -// FIXME: Move this to discovery, and just retrieve the list of MIBs from the database during polling -$ruckus_mibs = array( - 'ruckusZDSystemStats' => 'RUCKUS-ZD-SYSTEM-MIB', - 'ruckusZDWLANTable' => 'RUCKUS-ZD-WLAN-MIB', - 'ruckusZDWLANAPTable' => 'RUCKUS-ZD-WLAN-MIB', - 'ruckusZDWLANAPRadioStatsTable' => 'RUCKUS-ZD-WLAN-MIB', -); -poll_mibs($ruckus_mibs, $device, $graphs); diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 1c08acde0d..207cfb6011 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -827,7 +827,6 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { // then the name of the object type if ($f[1] && $f[1] == 'OBJECT-TYPE') { $result['object_type'] = $f[0]; - $result['shortname'] = str_replace($mib, '', $f[0]); continue; } @@ -948,21 +947,21 @@ function update_db_table($tablename, $columns, $numkeys, $rows) } /* - * @return an array containing all of the MIB objects keyed by object-type, - * or an empty array if something goes wrong. + * Load the given MIB into the database. + * @return count of objects loaded */ -function snmp_mib_load($mib, $module, $mibdir = null) +function snmp_mib_load($mib, $module, $included_by, $mibdir = null) { $mibs = array(); - // FIXME: Measure whether it's more efficient to use the database - // to cache this rather than parse it via snmptranslate every time. foreach (snmp_mib_walk($mib, $module, $mibdir) as $obj) { $mibs[$obj['object_type']] = $obj; + $mibs[$obj['object_type']]['included_by'] = $included_by; } d_print_r($mibs); - $columns = array('module', 'mib', 'object_type', 'oid', 'syntax', 'description', 'max_access', 'status'); + // NOTE: `last_modified` omitted due to being automatically maintained by MySQL + $columns = array('module', 'mib', 'object_type', 'oid', 'syntax', 'description', 'max_access', 'status', 'included_by'); update_db_table('mibdefs', $columns, 3, $mibs); - return $mibs; + return count($mibs); }//end snmp_mib_load() @@ -1125,53 +1124,123 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) }//end save_mibs() +/* + * @return an array of MIB objects matching $module, $name, keyed by object_type + */ +function load_mibdefs($module, $name) +{ + $params = array($module, $name); + $result = array(); + $object_types = array(); + foreach (dbFetchRows("SELECT * FROM `mibdefs` WHERE `module` = ? AND `mib` = ?", $params) as $row) { + $mib = $row['object_type']; + $object_types[] = $mib; + $result[$mib] = $row; + } + + // add shortname to each element + $prefix = longest_matching_prefix($name, $object_types); + foreach ($result as $mib => $m) { + $result[$mib]['shortname'] = str_replace($prefix, '', $m['object_type']); + } + + d_print_r($result); + return $result; +} /* - * FIXME: Get list of MIBs from the database - * Poll based on the results. + * @return an array of MIB names and modules for $device from the database */ -function poll_mibs($list, $device, &$graphs) +function load_device_mibs($device) { - // FIXME: check that mib polling module is enabled + $params = array($device['device_id']); + $result = array(); + foreach (dbFetchRows("SELECT `mib`, `module` FROM device_mibs WHERE device_id = ?", $params) as $row) { + $result[$row['mib']] = $row['module']; + } + return $result; +} + + +/* + * @return true if this device should be polled with MIB-based discovery + */ +function is_mib_poller_enabled($device) +{ + if (!is_module_enabled('poller', 'mib')) { + d_echo("MIB polling module disabled globally.\n"); + return false; + } + if (!is_dev_attrib_enabled($device, 'poll_mib')) { d_echo('MIB module disabled for '.$device['hostname']."\n"); + return false; + } + + return true; +} + +/* + * Run MIB-based polling for $device. Update $graphs with the results. + */ +function poll_mibs($device, &$graphs) +{ + if (!is_mib_poller_enabled($device)) { return; } - $mibdefs = array(); - echo 'MIB-based polling:'; + echo 'MIB: polling '; d_echo("\n"); - foreach ($list as $name => $module) { - $translated = snmp_translate($name, $module); - if ($translated) { - echo " $module::$name"; - d_echo("\n"); - $mod = $translated[0]; - $nam = $translated[1]; - $mibdefs[$nam] = snmp_mib_load($nam, $mod); - if (count($mibdefs[$nam] > 0)) { - $oids = snmpwalk_cache_oid($device, $nam, array(), $mod, null, "-OQUsb"); - d_print_r($oids); - save_mibs($device, $nam, $oids, $mibdefs[$nam], $graphs); - } - else { - echo("MIB: Could not load definition for $mod::$nam\n"); - } - } - else { - d_echo("MIB: no match for $module::$name\n"); - } + foreach (load_device_mibs($device) as $name => $module) { + echo "$name "; + d_echo("\n"); + $oids = snmpwalk_cache_oid($device, $name, array(), $module, null, "-OQUsb"); + d_print_r($oids); + save_mibs($device, $name, $oids, load_mibdefs($module, $name), $graphs); } - d_echo('Done MIB-based polling'); echo "\n"; }//end poll_mibs() /* * Take a list of MIB name => module pairs. * Validate MIBs and store the device->mib mapping in the database. - * FIXME: Implement; most of code can be moved in from poll_mibs() above. + * See includes/discovery/os/ruckuswireless.inc.php for an example of usage. */ -function register_mibs($device, $mibs) +function register_mibs($device, $mibs, $included_by) { + if (!is_mib_poller_enabled($device)) { + return; + } + + echo "MIB: registering\n"; + + foreach ($mibs as $name => $module) { + $translated = snmp_translate($name, $module); + if ($translated) { + $mod = $translated[0]; + $nam = $translated[1]; + echo " $mod::$nam\n"; + if (snmp_mib_load($nam, $mod, $included_by) > 0) { + // NOTE: `last_modified` omitted due to being automatically maintained by MySQL + $columns = array('device_id', 'module', 'mib', 'included_by'); + $rows = array(); + $rows[] = array( + 'device_id' => $device['device_id'], + 'module' => $mod, + 'mib' => $nam, + 'included_by' => $included_by, + ); + update_db_table('device_mibs', $columns, 3, $rows); + } + else { + echo("MIB: Could not load definition for $mod::$nam\n"); + } + } + else { + echo("MIB: Could not find $module::$name\n"); + } + } + + echo "\n"; } From 161e2b82e19743194303055bdf04c41a5704cf6a Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 20 Jul 2015 14:08:23 +1000 Subject: [PATCH 20/42] Include copyright --- includes/snmp.inc.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 207cfb6011..1f7d0e92f5 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -1,4 +1,19 @@ + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ function string_to_oid($string) { $oid = strlen($string); @@ -1021,8 +1036,16 @@ function oid_rrd_type($oid, $mibdef) return false; case 'TimeTicks': - // Need to find a way to flag that this should be parsed - // return 'COUNTER'; + // FIXME + return false; + + case 'INTEGER': + case 'Integer32': + // FIXME + return false; + + case 'Counter32': + // FIXME return false; case 'Counter64': From 5d5376172719b4ea678f91a2e6f79196b2e18d97 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 16 Aug 2015 22:07:48 +1000 Subject: [PATCH 21/42] Trivial cleanups --- html/includes/table/device_mibs.inc.php | 2 +- html/pages/device/mib.inc.php | 2 +- includes/common.php | 8 ++++++++ includes/snmp.inc.php | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/html/includes/table/device_mibs.inc.php b/html/includes/table/device_mibs.inc.php index 086ef4140d..6c109dc3eb 100644 --- a/html/includes/table/device_mibs.inc.php +++ b/html/includes/table/device_mibs.inc.php @@ -34,7 +34,7 @@ function quote_sql_word($c) } -$params = array( +$params = array( $_POST['device_id'], ); diff --git a/html/pages/device/mib.inc.php b/html/pages/device/mib.inc.php index f6ecdb9a4b..fc7f32b69f 100644 --- a/html/pages/device/mib.inc.php +++ b/html/pages/device/mib.inc.php @@ -1,6 +1,6 @@ * diff --git a/includes/common.php b/includes/common.php index 6430ba3084..929163c9bd 100644 --- a/includes/common.php +++ b/includes/common.php @@ -739,6 +739,9 @@ function round_Nth($val = 0, $round_to) { } } // end round_Nth +/* + * FIXME: Dummy implementation + */ function count_mib_mempools($device) { if ($device['os'] == 'ruckuswireless') { @@ -747,6 +750,9 @@ function count_mib_mempools($device) return 0; } +/* + * FIXME: Dummy implementation + */ function count_mib_processors($device) { if ($device['os'] == 'ruckuswireless') { @@ -761,6 +767,7 @@ function count_mib_health($device) } /* + * FIXME: Dummy implementation * @return true if there is a custom graph defined for this type, subtype, and device */ function is_custom_graph($type, $subtype, $device) @@ -777,6 +784,7 @@ function is_custom_graph($type, $subtype, $device) } /* + * FIXME: Dummy implementation * Set section/graph entries in $graph_enable for graphs specific to $os. */ function enable_os_graphs($os, &$graph_enable) diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 1f7d0e92f5..d70f4e0975 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -904,7 +904,8 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { */ -function snmp_mib_walk($mib, $module, $mibdir=null) { +function snmp_mib_walk($mib, $module, $mibdir=null) +{ $cmd = 'snmptranslate -Ts'; $cmd .= mibdir($mibdir); $cmd .= ' -m '.$module; From 953ea3fa152044b09c7a07fee33c138af0243b17 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 16 Aug 2015 22:09:17 +1000 Subject: [PATCH 22/42] Add device OID storage and display --- html/includes/table/device_oids.inc.php | 94 +++++++++++++++++++++++++ html/pages/device/mib.inc.php | 36 ++++++++++ includes/discovery/functions.inc.php | 5 ++ includes/snmp.inc.php | 39 ++++++++-- 4 files changed, 168 insertions(+), 6 deletions(-) create mode 100644 html/includes/table/device_oids.inc.php diff --git a/html/includes/table/device_oids.inc.php b/html/includes/table/device_oids.inc.php new file mode 100644 index 0000000000..f016a85839 --- /dev/null +++ b/html/includes/table/device_oids.inc.php @@ -0,0 +1,94 @@ + + * + * by Paul Gear + * based on code by Søren Friis Rosiak + * in commit 054bf3ae209f34a2c3bc8968300722004903df1b + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +$columns = array( + 'module', + 'mib', + 'object_type', + 'oid', + 'value', + 'numvalue', + 'last_modified', +); + +function search_phrase_column($c) +{ + global $searchPhrase; + return "$c LIKE '%$searchPhrase%'"; +} + +function quote_sql_word($c) +{ + return "`$c`"; +} + + +$params = array( + $_POST['device_id'], +); + +// start of sql definition +$sql = 'SELECT * FROM `device_oids`'; + +$wheresql = ' WHERE `device_id` = ?'; + +// all columns are searchable - search across them +if (isset($searchPhrase) && !empty($searchPhrase)) { + $searchsql = implode(' OR ', array_map("search_phrase_column", array_map("quote_sql_word", $columns))); + $wheresql .= " AND ( $searchsql )"; +} +$sql .= $wheresql; + +// get total +$count_sql = "SELECT COUNT(*) FROM `device_oids`".$wheresql; +$total = dbFetchCell($count_sql, $params); +if (empty($total)) { + $total = 0; +} + +// sort by first three columns by default +if (!isset($sort) || empty($sort)) { + $sort = implode(', ', array_map("quote_sql_word", array_slice($columns, 0, 3))); +} +$sql .= " ORDER BY $sort"; + +// select only the required rows +if (isset($current)) { + $limit_low = (($current * $rowCount) - ($rowCount)); + $limit_high = $rowCount; +} +if ($rowCount != -1) { + $sql .= " LIMIT $limit_low,$limit_high"; +} + +// load data from database into response array +$response = array(); +foreach (dbFetchRows($sql, $params) as $mib) { + $mibrow = array(); + foreach ($columns as $col) { + $mibrow[$col] = $mib[$col]; + } + $response[] = $mibrow; +} + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); +echo _json_encode($output); diff --git a/html/pages/device/mib.inc.php b/html/pages/device/mib.inc.php index fc7f32b69f..7c56d57c3b 100644 --- a/html/pages/device/mib.inc.php +++ b/html/pages/device/mib.inc.php @@ -32,6 +32,23 @@ if (!isset($vars['section'])) {
    +

    Device MIB values

    +
    + + + + + + + + + + + + +
    ModuleMIBObject typeOIDValueNumeric ValueLast Modified
    +
    + + + diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index af421323bf..98a91e853e 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -131,6 +131,11 @@ function discover_device($device, $options=null) { } } + if (is_mib_poller_enabled($device)) { + $devicemib = array($device['sysObjectID'] => 'all'); + register_mibs($device, $devicemib, "includes/discovery/functions.inc.php"); + } + // Set type to a predefined type for the OS if it's not already set if ($device['type'] == 'unknown' || $device['type'] == '') { if ($config['os'][$device['os']]['type']) { diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index d70f4e0975..d3c83337c7 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -926,11 +926,18 @@ function snmp_mib_walk($mib, $module, $mibdir=null) }//end snmp_mib_walk() +function quote_column($a) +{ + return '`'.$a.'`'; +} + + function join_array($a, $b) { - return "$a=$b"; + return quote_column($a).'='.$b; } + /* * Update the given table in the database with the given row & column data. * @param tablename The table to update @@ -940,6 +947,7 @@ function join_array($a, $b) */ function update_db_table($tablename, $columns, $numkeys, $rows) { + dbBeginTransaction(); foreach ($rows as $nothing => $obj) { // create a parameter list based on the columns $params = array(); @@ -954,12 +962,14 @@ function update_db_table($tablename, $columns, $numkeys, $rows) $update_definitions = array_map("join_array", $non_key_columns, $non_key_placeholders); $non_key_params = array_slice($params, $numkeys); - $sql = 'INSERT INTO `' . $tablename . '` (' . implode(',', $columns) . + $sql = 'INSERT INTO `' . $tablename . '` (' . + implode(',', array_map("quote_column", $columns)) . ') VALUES (' . implode(',', $column_placeholders) . ') ON DUPLICATE KEY UPDATE ' . implode(',', $update_definitions); $result = dbQuery($sql, array_merge($params, $non_key_params)); d_echo("Result: $result\n"); } + dbCommitTransaction(); } /* @@ -1118,23 +1128,37 @@ function update_mib_graph_types($mibname, $oids, $mibdef, $graphs) /* * Save all of the measurable oids for the device in their own RRDs. + * Save the current value of all the oids in the database. */ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) { $usedoids = array(); + $deviceoids = array(); foreach ($oids as $index => $array) { - foreach ($array as $oid => $val) { - $type = oid_rrd_type($oid, $mibdef); + foreach ($array as $obj => $val) { + // build up the device_oid row for saving into the database + $numvalue = preg_match('/^\d+$/', $val) ? $val : null; + $deviceoids[] = array( + 'device_id' => $device['device_id'], + 'oid' => $mibdef[$obj]['oid'].".".$index, + 'module' => $mibdef[$obj]['module'], + 'mib' => $mibdef[$obj]['mib'], + 'object_type' => $obj, + 'value' => $val, + 'numvalue' => $numvalue, + ); + + $type = oid_rrd_type($obj, $mibdef); if ($type === false) { continue; } - $usedoids[$index][$oid] = $val; + $usedoids[$index][$obj] = $val; rrd_create_update( $device, array( $mibname, - $mibdef[$oid]['shortname'], + $mibdef[$obj]['shortname'], $index, ), array("DS:mibval:$type"), @@ -1146,6 +1170,9 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) tag_graphs($mibname, $usedoids, $mibdef, $graphs); update_mib_graph_types($mibname, $usedoids, $mibdef, $graphs); + // update database + $columns = array('device_id', 'oid', 'module', 'mib', 'object_type', 'value', 'numvalue'); + update_db_table('device_oids', $columns, 2, $deviceoids); }//end save_mibs() /* From b52f7f5e86d876a47ce300c2d8722b0d6347c6a0 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sat, 24 Oct 2015 14:21:19 +1000 Subject: [PATCH 23/42] Fix rebase for can_ping_device --- includes/common.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/common.php b/includes/common.php index 929163c9bd..e31d70d2cd 100644 --- a/includes/common.php +++ b/includes/common.php @@ -803,7 +803,9 @@ function enable_graphs($device, &$graph_enable) { // These are standard graphs we should have for all systems $graph_enable['poller']['poller_perf'] = 'device_poller_perf'; - $graph_enable['poller']['ping_perf'] = 'device_ping_perf'; + if (can_ping_device($attribs) === true) { + $graph_enable['poller']['ping_perf'] = 'device_ping_perf'; + } enable_os_graphs($device['os'], $graph_enable); } @@ -842,6 +844,9 @@ function can_ping_device($attribs) { if ($config['icmp_check'] === true && $attribs['override_icmp_disable'] != "true") { return true; } + else { + return false; + } } // end can_ping_device /* From ed15e2a6cf343005e908b62029475512cb02d4c7 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sat, 24 Oct 2015 15:59:37 +1000 Subject: [PATCH 24/42] Restore name_shorten so we can provide backwards compatibility --- includes/common.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/includes/common.php b/includes/common.php index e31d70d2cd..52b1bb0182 100644 --- a/includes/common.php +++ b/includes/common.php @@ -611,6 +611,26 @@ function d_print_r($var, $no_debug_text = null) { } } +/* + * WARNING: DEPRECATED - used only by first release of MIB poller. + * Shorten the name so it works as an RRD data source name (limited to 19 chars by default). + * Substitute for $subst if necessary. + * @return the shortened name + */ +function name_shorten($name, $common = null, $subst = "mibval", $len = 19) { + if ($common !== null) { + // remove common from the beginning of the string, if present + if (strlen($name) > $len && strpos($name, $common) >= 0) { + $newname = str_replace($common, '', $name); + $name = $newname; + } + } + if (strlen($name) > $len) { + $name = $subst; + } + return $name; +} + /* * @return the name of the rrd file for $host's $extra component * @param host Host name From 18c1a190a17bc37bc870dac10ace76973413d500 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Tue, 10 Nov 2015 06:58:44 +1000 Subject: [PATCH 25/42] Add custom graph include --- html/includes/graphs/custom.inc.php | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 html/includes/graphs/custom.inc.php diff --git a/html/includes/graphs/custom.inc.php b/html/includes/graphs/custom.inc.php new file mode 100644 index 0000000000..274eadab6f --- /dev/null +++ b/html/includes/graphs/custom.inc.php @@ -0,0 +1,43 @@ + + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +// FIXME: Dummy implementation which only supports ruckuswireless processor & mempool + +$i = 0; +$rrd_list = array(); +if ($subtype == 'processor') { + $rrd_list[0] = array( + 'area' => 1, + 'ds' => 'mibval', + 'descr' => 'CPU Utilization', + 'filename' => rrd_name($device['hostname'], array('ruckusZDSystemStats-CPUUtil-0')), + ); +} + +if ($subtype == 'mempool') { + $rrd_list[0] = array( + 'area' => 1, + 'ds' => 'mibval', + 'descr' => 'Memory Utilization', + 'filename' => rrd_name($device['hostname'], array('ruckusZDSystemStats-MemoryUtil-0')), + ); +} + +$units = '%%'; +$colours = 'mixed'; +$scale_min = '0'; +$scale_max = '100'; +$nototal = 1; + +require_once 'includes/graphs/generic_multi_line.inc.php'; From 4d3b39e0aef624fe689b10483cf6c2aa3a7809e2 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Thu, 12 Nov 2015 08:42:26 +1000 Subject: [PATCH 26/42] Display sysObjectID on device overview screen --- html/includes/dev-overview-data.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/html/includes/dev-overview-data.inc.php b/html/includes/dev-overview-data.inc.php index de602c18fd..6ff78d43c4 100644 --- a/html/includes/dev-overview-data.inc.php +++ b/html/includes/dev-overview-data.inc.php @@ -49,6 +49,13 @@ if ($device['serial']) { '; } +if ($device['sysObjectID']) { + echo ' + Object ID + '.$device['sysObjectID'].' + '; +} + if ($device['sysContact']) { echo ' Contact'; From 22bd2d3a1b9988c053c48399658b9b53ad85fc3f Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 15 Nov 2015 17:38:15 +1000 Subject: [PATCH 27/42] Overhaul documentation for MIB-based poller --- doc/{General => Extensions}/MIB-based-polling.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename doc/{General => Extensions}/MIB-based-polling.md (100%) diff --git a/doc/General/MIB-based-polling.md b/doc/Extensions/MIB-based-polling.md similarity index 100% rename from doc/General/MIB-based-polling.md rename to doc/Extensions/MIB-based-polling.md From 1b0614ad87138d305a175264f87547bb396620e1 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 15 Nov 2015 17:38:26 +1000 Subject: [PATCH 28/42] Overhaul documentation for MIB-based poller --- doc/Extensions/MIB-based-polling.md | 133 ++++++++++++++++++++-------- includes/snmp.inc.php | 2 +- 2 files changed, 96 insertions(+), 39 deletions(-) diff --git a/doc/Extensions/MIB-based-polling.md b/doc/Extensions/MIB-based-polling.md index 5b390387b9..8851ec15f0 100644 --- a/doc/Extensions/MIB-based-polling.md +++ b/doc/Extensions/MIB-based-polling.md @@ -5,7 +5,7 @@ destroy your data, set your routers on fire, and kick your cat. It has been tested against a very limited set of devices (namely Ruckus ZD1000 wireless controllers, and `net-snmp` on Linux). It may fail badly on other hardware. -The approach taken is fairly basic and I claim no special expertise in +The approach taken is fairly simplistic and I claim no special expertise in understanding MIBs. Most of my understanding of SNMP comes from reading net-snmp man pages, and reverse engineering the output of snmptranslate and snmpwalk and trying to make devices work with LibreNMS. I may have made @@ -16,85 +16,142 @@ Paul Gear ## Overview ## +This is the 2nd experimental release of MIB polling. If you used the 1st +release, you MUST perform a data conversion of the MIB-based polling files +using the script `contrib/convert-mib-graphs.sh`. Failure to do so will +result in your data collection silently stopping. + MIB-based polling is disabled by default; you must set `$config['poller_modules']['mib'] = 1;` in `config.php` to enable it. -The components involved in of MIB-based support are: +## Preparation ## + +MIB-based polling results in the creation of a separate RRD file for each +device-MIB-OID-index combination encountered by LibreNMS. Thus it can cause +your disk space requirements to grow enormously and rapidly. As an example, +enabling MIB-based polling on my test Ruckus ZD1000 wireless controller with +one (1) AP and one (1) user on that AP resulted in a 5 MB increase in RRD +space usage for that device. Each RRD file is around 125 KB in size (on +x64-64) systems and is pre-allocated, so after the first discovery and poller +run of each devicewith MIB-based polling enabled, disk space should be stable. +However, monitoring disk usage is your responsibility. (The good news: you +can do this with LibreNMS. :-) + +Unless you are running LibreNMS on a powerful system with pure SSD for RRD +storage, it is strongly recommended that you enable rrdcached and ensure it is +working *before* enabling MIB-based polling. + +## Components ## + +The components involved in MIB-based polling are: ### Discovery ### - - MIB-based detection is not involved; any work done here would have to be - duplicated by the poller and thus would only increase load. + - OS discovery determines whether there are MIBs which should be polled. If + so, they are registered in the `device_mibs` association table as relevant + to that device. MIB associations for each device can be viewed at: + http://your.librenms.server/device/device=XXXX/tab=mib/ + All MIBs used by MIB-based polling may be viewed at: + http://your.librenms.server/mibs/ + + - In addition, all devices are checked for a MIB matching their sysObjectID. + If there is a matching MIB available, it is automatically included. + The sysObjectID for each device is now displayed on the overview page: + http://your.librenms.server/device/device=XXXX/ + + - Note that the above means that no MIB-based polling will occur until the + devices in question are rediscovered. If you want to begin MIB-based + polling immediately, you must force rediscovery from the web UI, or run it + from the CLI using `./discovery.php -h HOSTNAME` + + - During discovery, relevant MIBs are parsed using `snmptranslate`, and the + data returned is used to populate a database which guides the poller in + what to store. At the moment, only OIDs with Unsigned32 and Counter64 + data types are parsed. + + - Devices may be excluded from MIB polling by changing the setting in the + device edit screen: + http://your.librenms.server/device/device=XXXX/tab=edit/section=modules/ ### Polling ### - - The file `includes/snmp.inc.php` now contains code which can parse MIBs - using `snmptranslate` and use the data returned to populate an array - which guides the poller in what to store. At the moment, only OIDs with - Unsigned32 and Counter64 data types are parsed. - - `includes/polling/mib.inc.php` looks for a MIB matching sysObjectID in - the MIB directory; if one is found, it: - - parses it - - walks that MIB on the device - - stores any numeric results in individual RRD files - - updates/adds graph definitions in the previously-unused graph_types - database table - - Individual OSes (`includes/polling/os/*.inc.php`) can poll extra MIBs - for a given OS by calling `poll_mib()`. At the moment, this actually - happens before the general MIB polling. - - Devices may be excluded from MIB polling by changing the setting in the - device edit screen (`/device/device=ID/tab=edit/section=modules/`) + - During polling the MIB associations for the device are looked up, and the + MIB is polled for current values. You can see the values which LibreNMS + has retrieved from the MIB poller in the "Device MIB values" section of + http://your.librenms.server/device/device=XXXX/tab=mib/ + + - Data from the latest poll is saved in the table `device_oids`, and RRD + files are saved in the relevant device directory as + mibName-oidName-index.rrd ### Graphing ### - For each graph type defined in the database, a graph will appear in: - Device -> Graphs -> MIB + http://your.librenms.server/device/device=XXXX/tab=graphs/group=mib/ - MIB graphs are generated generically by - `html/includes/graphs/device/mib.inc.php` - - At the moment, all units are placed in the same graph. This is probably + `html/includes/graphs/device/mib.inc.php` + There is presently no customisation of graphs available. + - If there is only one index under a given OID, it is displayed as a normal + line graph; if there multiple OIDs, they are displayed as a stacked graph. + At the moment, all indices are placed in the same graph. This is non-optimal for, e.g., wifi controllers with hundreds of APs attached. +### Alerting ### + +There is no specific support for alerting in the MIB-based polling engine, but +the data it collects may be used in alerts. Here's an example of an alert +which detects when a Ruckus wireless controller reports meshing disabled on an +access point: + http://libertysys.com.au/imagebin/3btw98DR.png + + ## Adding/testing other device types ## -One of the goals of this work is to help take out the heavy lifting of -adding new device types. Even if you want fully customised graphs or -tables, you can use the automatic collection of MIBs to make it easy to -gather the data you want. +One of the goals of this work is to help take out the heavy lifting of adding +new device types. Even if you want fully-customised graphs or tables, you can +still use the MIB-based poller to make it easy to gather the data you want to +graph. ### How to add a new device MIB ### 1. Ensure the manufacturer's MIB is present in the mibs directory. If you plan to submit your work to LibreNMS, make sure you attribute the source - of the MIB, including the exact download URL. + of the MIB, including the exact download URL if possible, or explicit + instructions about how to obtain it. 2. Check that `snmptranslate -Ts -M mibs -m MODULE | grep mibName` produces - a named list of OIDs. See the comments for `snmp_mib_walk()` in + a named list of OIDs. See the comments on `snmp_mib_walk()` in `includes/snmp.inc.php` for an example. 3. Check that `snmptranslate -Td -On -M mibs -m MODULE MODULE::mibName` produces a parsed description of the OID values. An example can be found in the comments for `snmp_mib_parse()` in `includes/snmp.inc.php`. 4. Get the `sysObjectID` from a device, for example: - ```snmpget -v2c -c public -OUsb -m SNMPv2-MIB -M /opt/librenms/mibs -t 30 hostname sysObjectID.0``` + ```snmpget -v2c -c public -OUsb -m SNMPv2-MIB -M /opt/librenms/mibs -t 30 hostname sysObjectID.0``` 5. Ensure `snmptranslate -m all -M /opt/librenms/mibs OID 2>/dev/null` (where OID is the value returned for sysObjectID above) results in a valid name for the MIB. See the comments for `snmp_translate()` in `includes/snmp.inc.php` for an example. If this step fails, it means there is something wrong with the MIB and `net-snmp` cannot parse it. 6. Add any additional MIBs you wish to poll for specific device types to - `includes/polling/os/OSNAME.inc.php` by calling `poll_mibs()` with the - MIB module and name. See `includes/polling/os/ruckuswireless.inc.php` for - an example. + `includes/discovery/os/OSNAME.inc.php` by calling `poll_mibs()` with the + MIB module and name. See `includes/discovery/os/ruckuswireless.inc.php` + for an example. 7. That should be all you need to see MIB graphs! + 8. If you want to develop more customised support for a particular OS, you + can follow the above process, then use the resultant data collected by + LibreNMS in the RRD files or the database tables `device_oids` + ## TODO ## - - Save the most recent MIB data in the database (including string types - which cannot be graphed). Display it in the appropriate places. +What's not included in MIB-based polling at present? These may be present in +future versions. Pull requests gratefully accepted! + - Parse and save integer and timetick data types. - Filter MIBs/OIDs from being polled and/or saved. - - Move graphs from the MIB section to elsewhere. e.g. There is already - specific support for wireless APs - this should be utilised, but isn't - yet. + - Move graphs from the MIB section to elsewhere. e.g. If a device uses a + unique MIB for CPU utilisation, we should display it under the relevant + health tab. - Combine multiple MIB values into graphs automatically on a predefined or user-defined basis. - Include MIB types in stats submissions. diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index d3c83337c7..a6d981339c 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -802,7 +802,7 @@ function snmp_gen_auth(&$device) { /* - * Translate the given MIB into a vaguely useful PHP array. Each keyword becomes an array index. + * Translate the given MIB into a PHP array. Each keyword becomes an array index. * * Example: * snmptranslate -Td -On -M mibs -m RUCKUS-ZD-SYSTEM-MIB RUCKUS-ZD-SYSTEM-MIB::ruckusZDSystemStatsNumSta From 8a20ad4896e6816324d203a872bee8f1f3916588 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 15 Nov 2015 18:01:09 +1000 Subject: [PATCH 29/42] Move rrd handling functions into includes/rrdtool.inc.php; add backwards compatibility with file naming in old version of MIB-based polling --- includes/common.php | 11 ------ includes/polling/functions.inc.php | 25 ------------ includes/rrdtool.inc.php | 62 +++++++++++++++++++++++++++++- includes/snmp.inc.php | 10 +++++ 4 files changed, 71 insertions(+), 37 deletions(-) diff --git a/includes/common.php b/includes/common.php index 52b1bb0182..ba9448655f 100644 --- a/includes/common.php +++ b/includes/common.php @@ -631,17 +631,6 @@ function name_shorten($name, $common = null, $subst = "mibval", $len = 19) { return $name; } -/* - * @return the name of the rrd file for $host's $extra component - * @param host Host name - * @param extra Components of RRD filename - will be separated with "-" - */ -function rrd_name($host, $extra, $exten = ".rrd") { - global $config; - $filename = safename(is_array($extra) ? implode("-", $extra) : $extra); - return implode("/", array($config['rrd_dir'], $host, $filename.$exten)); -} - /* * @return true if the given graph type is a dynamic MIB graph */ diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index f9b6221e24..a00151639e 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -395,31 +395,6 @@ function poll_mib_def($device, $mib_name_table, $mib_subdir, $mib_oids, $mib_gra }//end poll_mib_def() -/* - * Please use this instead of creating & updating RRD files manually. - * @param device Device object - only 'hostname' is used at present - * @param name Array of rrdname components - * @param def Array of data definitions - * @param val Array of value definitions - * - */ - - -function rrd_create_update($device, $name, $def, $val, $step=300) { - global $config; - $rrd = rrd_name($device['hostname'], $name); - - if (!is_file($rrd) && $def != null) { - // add the --step and the rra definitions to the array - $newdef = "--step $step ".implode(' ', $def).$config['rrd_rra']; - rrdtool_create($rrd, $newdef); - } - - rrdtool_update($rrd, $val); - -}//end rrd_create_update() - - function get_main_serial($device) { if ($device['os_group'] == 'cisco') { $serial_output = snmp_get_multi($device, 'entPhysicalSerialNum.1 entPhysicalSerialNum.1001', '-OQUs', 'ENTITY-MIB:OLD-CISCO-CHASSIS-MIB'); diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index 9566497441..da7af3c387 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -296,7 +296,18 @@ function rrdtool_escape($string, $maxlength=null){ $result = str_replace(':', '\:', $result); # escape colons return $result.' '; +} // rrdtool_escape + +/* + * @return the name of the rrd file for $host's $extra component + * @param host Host name + * @param extra Components of RRD filename - will be separated with "-" + */ +function rrd_name($host, $extra, $exten = ".rrd") { + global $config; + $filename = safename(is_array($extra) ? implode("-", $extra) : $extra); + return implode("/", array($config['rrd_dir'], $host, $filename.$exten)); } function rrdtool_tune($type, $filename, $max) { @@ -314,4 +325,53 @@ function rrdtool_tune($type, $filename, $max) { $options = "--maximum " . implode(":$max --maximum ", $fields). ":$max"; rrdtool('tune', $filename, $options); } -} +} // rrdtool_tune + +/* + * Please use this instead of creating & updating RRD files manually. + * @param device Device object - only 'hostname' is used at present + * @param name Array of rrdname components + * @param def Array of data definitions + * @param val Array of value definitions + * + */ + +function rrd_create_update($device, $name, $def, $val, $step=300) { + global $config; + $rrd = rrd_name($device['hostname'], $name); + + if (!is_file($rrd) && $def != null) { + // add the --step and the rra definitions to the array + $newdef = "--step $step ".implode(' ', $def).$config['rrd_rra']; + rrdtool_create($rrd, $newdef); + } + + rrdtool_update($rrd, $val); + +} // rrd_create_update + + +/* + * @return bool indicating existence of RRD file + * @param device Device object as used with rrd_create_update() + * @param name RRD name array as used with rrd_create_update() and rrd_name() + */ +function rrd_file_exists($device, $name) +{ + return is_file(rrd_name($device['hostname'], $name)); +} // rrd_file_exists + + + +/* + * @return bool indicating rename success or failure + * @param device Device object as used with rrd_create_update() + * @param oldname RRD name array as used with rrd_create_update() and rrd_name() + * @param newname RRD name array as used with rrd_create_update() and rrd_name() + */ +function rrd_file_rename($device, $oldname, $newname) +{ + $oldrrd = rrd_name($device['hostname'], $oldname); + $newrrd = rrd_name($device['hostname'], $newname); + return rename($oldrrd, $newrrd); +} // rrd_file_rename diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index a6d981339c..a444b50fd2 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -1154,6 +1154,16 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) } $usedoids[$index][$obj] = $val; + + // if there's a file from the previous version of MIB-based polling, rename it + if (rrd_file_exists($device, array($mibname, $mibdef[$obj]['object_type'], $index)) + && !rrd_file_exists($device, array($mibname, $mibdef[$obj]['shortname'], $index))) { + rrd_file_rename($device, + array($mibname, $mibdef[$obj]['object_type'], $index), + array($mibname, $mibdef[$obj]['shortname'], $index)); + // Note: polling proceeds regardless of rename result + } + rrd_create_update( $device, array( From fbc5555eab31dd07ff6b79a2408c5e4122b150a4 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 15 Nov 2015 18:02:29 +1000 Subject: [PATCH 30/42] Minor doc tidy --- doc/Extensions/MIB-based-polling.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/Extensions/MIB-based-polling.md b/doc/Extensions/MIB-based-polling.md index 8851ec15f0..92c6786a4b 100644 --- a/doc/Extensions/MIB-based-polling.md +++ b/doc/Extensions/MIB-based-polling.md @@ -6,11 +6,11 @@ tested against a very limited set of devices (namely Ruckus ZD1000 wireless controllers, and `net-snmp` on Linux). It may fail badly on other hardware. The approach taken is fairly simplistic and I claim no special expertise in -understanding MIBs. Most of my understanding of SNMP comes from reading -net-snmp man pages, and reverse engineering the output of snmptranslate and -snmpwalk and trying to make devices work with LibreNMS. I may have made -false assumptions and probably use wrong terminology in many places. Feel -free to offer corrections/suggestions via pull requests or email. +understanding MIBs. Most of my knowledge of SNMP comes from reading net-snmp +man pages, and reverse engineering the output of snmptranslate and snmpwalk +and trying to make devices work with LibreNMS. I may have made false +assumptions and probably use wrong terminology in many places. Feel free to +offer corrections/suggestions via pull requests or email. Paul Gear From 84b7d2e54583eafcd5c0db332468260aec2c18ae Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 15 Nov 2015 18:04:06 +1000 Subject: [PATCH 31/42] Remove roadmap; no longer relevant, covered by issue database --- doc/General/Roadmap.md | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 doc/General/Roadmap.md diff --git a/doc/General/Roadmap.md b/doc/General/Roadmap.md deleted file mode 100644 index b697b7ac88..0000000000 --- a/doc/General/Roadmap.md +++ /dev/null @@ -1,13 +0,0 @@ -- Functionality/performance improvements: - - Investigate solutions for poller performance improvement. - - Investigate solutions for multiple communities per device. - - Eliminate interface churn for transient interfaces (e.g. ppp/tun) on - net-snmp. - -- Consider adding some non-monitoring administrative functions: - - enabling/disabling ports - - changing access port VLANs - - editing port labels - -- Integrate as many usability improvements as time permits: - - Front page: more automation; GUI configuration From 2558aa9bdab94f44efc174ff66eb55de536d9637 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 15 Nov 2015 18:18:13 +1000 Subject: [PATCH 32/42] Fix up some funky formatting; add/tidy end-of-function markers to reduce diff churn --- includes/common.php | 68 ++++++++++++++++++++-------------------- includes/rrdtool.inc.php | 31 ++++++++---------- includes/snmp.inc.php | 39 +++++++++++------------ 3 files changed, 65 insertions(+), 73 deletions(-) diff --git a/includes/common.php b/includes/common.php index ba9448655f..d11e101296 100644 --- a/includes/common.php +++ b/includes/common.php @@ -580,6 +580,7 @@ function edit_service($service, $descr, $service_ip, $service_param = "", $servi } + /* * convenience function - please use this instead of 'if ($debug) { echo ...; }' */ @@ -596,7 +597,8 @@ function d_echo($text, $no_debug_text = null) { elseif ($no_debug_text) { echo "$no_debug_text"; } -} +} // d_echo + /* * convenience function - please use this instead of 'if ($debug) { print_r ...; }' @@ -609,27 +611,8 @@ function d_print_r($var, $no_debug_text = null) { elseif ($no_debug_text) { echo "$no_debug_text"; } -} +} // d_print_r -/* - * WARNING: DEPRECATED - used only by first release of MIB poller. - * Shorten the name so it works as an RRD data source name (limited to 19 chars by default). - * Substitute for $subst if necessary. - * @return the shortened name - */ -function name_shorten($name, $common = null, $subst = "mibval", $len = 19) { - if ($common !== null) { - // remove common from the beginning of the string, if present - if (strlen($name) > $len && strpos($name, $common) >= 0) { - $newname = str_replace($common, '', $name); - $name = $newname; - } - } - if (strlen($name) > $len) { - $name = $subst; - } - return $name; -} /* * @return true if the given graph type is a dynamic MIB graph @@ -637,7 +620,8 @@ function name_shorten($name, $common = null, $subst = "mibval", $len = 19) { function is_mib_graph($type, $subtype) { global $config; return $config['graph_types'][$type][$subtype]['section'] == 'mib'; -} +} // is_mib_graph + /* * @return true if client IP address is authorized to access graphs @@ -660,7 +644,8 @@ function is_client_authorized($clientip) { } return false; -} +} // is_client_authorized + /* * @return an array of all graph subtypes for the given type @@ -692,7 +677,8 @@ function get_graph_subtypes($type) { sort($types); return $types; -} +} // get_graph_subtypes + function get_smokeping_files($device) { global $config; @@ -723,6 +709,7 @@ function get_smokeping_files($device) { return $smokeping_files; } // end get_smokeping_files + function generate_smokeping_file($device,$file='') { global $config; if ($config['smokeping']['integration'] === true) { @@ -731,7 +718,8 @@ function generate_smokeping_file($device,$file='') { else { return $config['smokeping']['dir'] . '/' . $file; } -} +} // generate_smokeping_file + /* * @return rounded value to 10th/100th/1000th depending on input (valid: 10, 100, 1000) @@ -748,6 +736,7 @@ function round_Nth($val = 0, $round_to) { } } // end round_Nth + /* * FIXME: Dummy implementation */ @@ -757,7 +746,8 @@ function count_mib_mempools($device) return 1; } return 0; -} +} // count_mib_mempools + /* * FIXME: Dummy implementation @@ -768,12 +758,14 @@ function count_mib_processors($device) return 1; } return 0; -} +} // count_mib_processors + function count_mib_health($device) { return count_mib_mempools($device) + count_mib_processors($device); -} +} // count_mib_health + /* * FIXME: Dummy implementation @@ -790,7 +782,8 @@ function is_custom_graph($type, $subtype, $device) } } return false; -} +} // is_custom_graph + /* * FIXME: Dummy implementation @@ -803,7 +796,8 @@ function enable_os_graphs($os, &$graph_enable) $graph_enable[$graph['graph_section']][$graph['graph_subtype']] = "device_".$graph['graph_subtype']; } */ -} +} // enable_os_graphs + /* * For each os-based or global graph relevant to $device, set its section/graph entry in $graph_enable. @@ -817,7 +811,8 @@ function enable_graphs($device, &$graph_enable) } enable_os_graphs($device['os'], $graph_enable); -} +} // enable_graphs + // // maintain a simple cache of objects @@ -827,7 +822,7 @@ function object_add_cache($section, $obj) { global $object_cache; $object_cache[$section][$obj] = true; -} +} // object_add_cache function object_is_cached($section, $obj) @@ -839,7 +834,8 @@ function object_is_cached($section, $obj) else { return false; } -} +} // object_is_cached + /** * Checks if config allows us to ping this device @@ -858,6 +854,7 @@ function can_ping_device($attribs) { } } // end can_ping_device + /* * @return true if the requested module type & name is globally enabled */ @@ -872,6 +869,7 @@ function is_module_enabled($type, $module) } } // is_module_enabled + /* * @return true if every string in $arr begins with $str */ @@ -886,6 +884,7 @@ function begins_with($str, $arr) return true; } // begins_with + /* * @return the longest starting portion of $str that matches everything in $arr */ @@ -902,6 +901,7 @@ function longest_matching_prefix($str, $arr) return ''; } // longest_matching_prefix + /** * Constructs the path to an RRD for the Ceph application * @param string $gtype The type of rrd we're looking for @@ -921,7 +921,7 @@ function ceph_rrd($gtype) { $rrd = join('-', array('app', 'ceph', $vars['id'], $gtype, $var)).'.rrd'; return join('/', array($config['rrd_dir'], $device['hostname'], $rrd)); -} +} // ceph_rrd /** * Parse location field for coordinates diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index da7af3c387..d61b4ab5a9 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -230,7 +230,8 @@ function rrdtool_create($filename, $options) { */ -function rrdtool_update($filename, $options) { +function rrdtool_update($filename, $options) +{ $values = array(); // Do some sanitisation on the data if passed as an array. @@ -250,26 +251,25 @@ function rrdtool_update($filename, $options) { else { return 'Bad options passed to rrdtool_update'; } - -} +} // rrdtool_update -function rrdtool_fetch($filename, $options) { +function rrdtool_fetch($filename, $options) +{ return rrdtool('fetch', $filename, $options); - -} +} // rrdtool_fetch -function rrdtool_last($filename, $options) { +function rrdtool_last($filename, $options) +{ return rrdtool('last', $filename, $options); - -} +} // rrdtool_last -function rrdtool_lastupdate($filename, $options){ +function rrdtool_lastupdate($filename, $options) +{ return rrdtool('lastupdate', $filename, $options); - -} +} // rrdtool_lastupdate /** @@ -280,8 +280,6 @@ function rrdtool_lastupdate($filename, $options){ * @param string string to escape * @param integer if passed, string will be padded and trimmed to exactly this length (after rrdtool unescapes it) */ - - function rrdtool_escape($string, $maxlength=null){ $result = shorten_interface_type($string); $result = str_replace("'", '', $result); # remove quotes @@ -308,7 +306,7 @@ function rrd_name($host, $extra, $exten = ".rrd") { global $config; $filename = safename(is_array($extra) ? implode("-", $extra) : $extra); return implode("/", array($config['rrd_dir'], $host, $filename.$exten)); -} +} // rrd_name function rrdtool_tune($type, $filename, $max) { $fields = array(); @@ -335,7 +333,6 @@ function rrdtool_tune($type, $filename, $max) { * @param val Array of value definitions * */ - function rrd_create_update($device, $name, $def, $val, $step=300) { global $config; $rrd = rrd_name($device['hostname'], $name); @@ -347,7 +344,6 @@ function rrd_create_update($device, $name, $def, $val, $step=300) { } rrdtool_update($rrd, $val); - } // rrd_create_update @@ -362,7 +358,6 @@ function rrd_file_exists($device, $name) } // rrd_file_exists - /* * @return bool indicating rename success or failure * @param device Device object as used with rrd_create_update() diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index a444b50fd2..6e1db3aac6 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -816,8 +816,6 @@ function snmp_gen_auth(&$device) { * ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) ruckusRootMIB(25053) ruckusObjects(1) ruckusZD(2) ruckusZDSystemModule(1) ruckusZDSystemMIB(1) ruckusZDSystemObjects(1) * ruckusZDSystemStats(15) 30 } */ - - function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { global $debug; @@ -886,8 +884,7 @@ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { else { return null; } - -}//end snmp_mib_parse() +} // snmp_mib_parse /* @@ -923,19 +920,19 @@ function snmp_mib_walk($mib, $module, $mibdir=null) return $result; -}//end snmp_mib_walk() +} // snmp_mib_walk function quote_column($a) { return '`'.$a.'`'; -} +} // quote_column function join_array($a, $b) { return quote_column($a).'='.$b; -} +} // join_array /* @@ -970,7 +967,7 @@ function update_db_table($tablename, $columns, $numkeys, $rows) d_echo("Result: $result\n"); } dbCommitTransaction(); -} +} // update_db_table /* * Load the given MIB into the database. @@ -989,7 +986,7 @@ function snmp_mib_load($mib, $module, $included_by, $mibdir = null) update_db_table('mibdefs', $columns, 3, $mibs); return count($mibs); -}//end snmp_mib_load() +} // snmp_mib_load /* @@ -1028,7 +1025,7 @@ function snmp_translate($oid, $module, $mibdir = null) $matches[2], ); -}//end snmp_translate() +} // snmp_translate /* @@ -1068,7 +1065,7 @@ function oid_rrd_type($oid, $mibdef) return false; -}//end oid_rrd_type() +} // oid_rrd_type /* @@ -1086,7 +1083,7 @@ function tag_graphs($mibname, $oids, $mibdef, &$graphs) } } -}//end tag_graphs() +} // tag_graphs /* @@ -1121,9 +1118,8 @@ function update_mib_graph_types($mibname, $oids, $mibdef, $graphs) dbInsert($graphdef, 'graph_types'); } } - }//end foreach - -}//end update_mib_graph_types() + } +} // update_mib_graph_types /* @@ -1183,7 +1179,8 @@ function save_mibs($device, $mibname, $oids, $mibdef, &$graphs) // update database $columns = array('device_id', 'oid', 'module', 'mib', 'object_type', 'value', 'numvalue'); update_db_table('device_oids', $columns, 2, $deviceoids); -}//end save_mibs() +} // save_mibs + /* * @return an array of MIB objects matching $module, $name, keyed by object_type @@ -1207,7 +1204,7 @@ function load_mibdefs($module, $name) d_print_r($result); return $result; -} +} // load_mibdefs /* * @return an array of MIB names and modules for $device from the database @@ -1220,7 +1217,7 @@ function load_device_mibs($device) $result[$row['mib']] = $row['module']; } return $result; -} +} // load_device_mibs /* @@ -1239,7 +1236,7 @@ function is_mib_poller_enabled($device) } return true; -} +} // is_mib_poller_enabled /* * Run MIB-based polling for $device. Update $graphs with the results. @@ -1261,7 +1258,7 @@ function poll_mibs($device, &$graphs) save_mibs($device, $name, $oids, load_mibdefs($module, $name), $graphs); } echo "\n"; -}//end poll_mibs() +} // poll_mibs /* * Take a list of MIB name => module pairs. @@ -1304,4 +1301,4 @@ function register_mibs($device, $mibs, $included_by) } echo "\n"; -} +} // register_mibs From 3fb5210d21a99ea4432d072cd6e898676de0f3e4 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Mon, 16 Nov 2015 07:42:51 +1000 Subject: [PATCH 33/42] Make formatting changes consistent --- includes/rrdtool.inc.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/includes/rrdtool.inc.php b/includes/rrdtool.inc.php index d61b4ab5a9..2c12dac627 100644 --- a/includes/rrdtool.inc.php +++ b/includes/rrdtool.inc.php @@ -22,7 +22,8 @@ */ -function rrdtool_pipe_open(&$rrd_process, &$rrd_pipes) { +function rrdtool_pipe_open(&$rrd_process, &$rrd_pipes) +{ global $config; $command = $config['rrdtool'].' -'; @@ -73,7 +74,8 @@ function rrdtool_pipe_open(&$rrd_process, &$rrd_pipes) { */ -function rrdtool_pipe_close($rrd_process, &$rrd_pipes) { +function rrdtool_pipe_close($rrd_process, &$rrd_pipes) +{ d_echo(stream_get_contents($rrd_pipes[1])); d_echo(stream_get_contents($rrd_pipes[2])); @@ -100,7 +102,8 @@ function rrdtool_pipe_close($rrd_process, &$rrd_pipes) { */ -function rrdtool_graph($graph_file, $options) { +function rrdtool_graph($graph_file, $options) +{ global $config, $debug; rrdtool_pipe_open($rrd_process, $rrd_pipes); @@ -163,7 +166,8 @@ function rrdtool_graph($graph_file, $options) { */ -function rrdtool($command, $filename, $options) { +function rrdtool($command, $filename, $options) +{ global $config, $debug, $rrd_pipes, $console_color; if ($config['rrdcached'] && @@ -209,7 +213,8 @@ function rrdtool($command, $filename, $options) { */ -function rrdtool_create($filename, $options) { +function rrdtool_create($filename, $options) +{ global $config; if( $config['rrdcached'] && $config['rrdtool_version'] >= 1.5 ) { $chk = rrdtool('info', $filename, ''); @@ -302,7 +307,8 @@ function rrdtool_escape($string, $maxlength=null){ * @param host Host name * @param extra Components of RRD filename - will be separated with "-" */ -function rrd_name($host, $extra, $exten = ".rrd") { +function rrd_name($host, $extra, $exten = ".rrd") +{ global $config; $filename = safename(is_array($extra) ? implode("-", $extra) : $extra); return implode("/", array($config['rrd_dir'], $host, $filename.$exten)); @@ -333,7 +339,8 @@ function rrdtool_tune($type, $filename, $max) { * @param val Array of value definitions * */ -function rrd_create_update($device, $name, $def, $val, $step=300) { +function rrd_create_update($device, $name, $def, $val, $step=300) +{ global $config; $rrd = rrd_name($device['hostname'], $name); From ea29977d296dfe92e77e265f4352ca943e68aae9 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 2 Dec 2015 19:40:21 +1000 Subject: [PATCH 34/42] Support MIB-based overrides in processor & memory pools --- html/pages/device/health/mempool.inc.php | 45 ++++++++++++++++---- html/pages/device/health/processor.inc.php | 31 ++++++++++---- includes/common.php | 48 +++++++++++++++++++++- 3 files changed, 106 insertions(+), 18 deletions(-) diff --git a/html/pages/device/health/mempool.inc.php b/html/pages/device/health/mempool.inc.php index c53189caf7..b21c0fc29e 100644 --- a/html/pages/device/health/mempool.inc.php +++ b/html/pages/device/health/mempool.inc.php @@ -4,8 +4,16 @@ $graph_type = 'mempool_usage'; $i = '1'; +if (count_mib_mempools($device) > 0) { + $mempools = get_mib_mempools($device); + $graph_type = 'device_mempool'; +} +else { + $mempools = dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($device['device_id'])); +} + // FIXME css alternating colours -foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($device['device_id'])) as $mempool) { +foreach ($mempools as $mempool) { if (!is_integer($i / 2)) { $row_colour = $list_colour_a; } @@ -15,30 +23,49 @@ foreach (dbFetchRows('SELECT * FROM `mempools` WHERE device_id = ?', array($devi $text_descr = rewrite_entity_descr($mempool['mempool_descr']); - $mempool_url = 'graphs/id='.$mempool['mempool_id'].'/type=mempool_usage/'; - $mini_url = 'graph.php?id='.$mempool['mempool_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; + if ($graph_type == 'device_mempool') { + $id = 'device'; + $val = $device['device_id']; + } + else { + $id = 'id'; + $val = $mempool['mempool_id']; + } + $mempool_url = 'graphs/'.$id.'='.$val.'/type='.$graph_type.'/'; + $mini_url = 'graph.php?'.$id.'='.$val.'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; $mempool_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; - $mempool_popup .= "
    "; + $mempool_popup .= ""; $mempool_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; $total = formatStorage($mempool['mempool_total']); $used = formatStorage($mempool['mempool_used']); $free = formatStorage($mempool['mempool_free']); - $perc = round(($mempool['mempool_used'] / $mempool['mempool_total'] * 100)); + // don't bother recalculating if mempools use percentage + if ($mempool['percentage'] === true) { + $perc = round($mempool['mempool_used']); + } + else { + $perc = round(($mempool['mempool_used'] / $mempool['mempool_total'] * 100)); + } $background = get_percentage_colours($percent); $right_background = $background['right']; $left_background = $background['left']; - $graph_array['id'] = $mempool['mempool_id']; + $graph_array[$id] = $val; $graph_array['type'] = $graph_type; echo "
    -
    -

    $text_descr
    $used/$total - $perc% used

    -
    "; +
    "; + if ($mempool['percentage'] === true) { + echo "

    $text_descr
    $perc% used

    "; + } + else { + echo "

    $text_descr
    $used/$total - $perc% used

    "; + } + echo "
    "; echo "
    "; include 'includes/print-graphrow.inc.php'; echo "
    "; diff --git a/html/pages/device/health/processor.inc.php b/html/pages/device/health/processor.inc.php index dd60448a3b..1ffdc2a6bb 100644 --- a/html/pages/device/health/processor.inc.php +++ b/html/pages/device/health/processor.inc.php @@ -3,21 +3,36 @@ $graph_type = 'processor_usage'; $i = '1'; -foreach (dbFetchRows('SELECT * FROM `processors` WHERE device_id = ?', array($device['device_id'])) as $proc) { - $proc_url = 'graphs/id='.$proc['processor_id'].'/type=processor_usage/'; - $mini_url = 'graph.php?id='.$proc['processor_id'].'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now'].'&width=80&height=20&bg=f4f4f4'; +if (count_mib_processors($device) > 0) { + $processors = get_mib_processors($device); + $graph_type = 'device_processor'; +} +else { + $processors = dbFetchRows('SELECT * FROM `processors` WHERE device_id = ?', array($device['device_id'])); +} - $text_descr = $proc['processor_descr']; +foreach ($processors as $proc) { + if ($graph_type == 'device_processor') { + $id = 'device'; + $val = $device['device_id']; + } + else { + $id = 'id'; + $val = $proc['processor_id']; + } + $proc_url = 'graphs/'.$id.'='.$val.'/type='.$graph_type.'/'; + $base_url = 'graph.php?'.$id.'='.$val.'&type='.$graph_type.'&from='.$config['time']['day'].'&to='.$config['time']['now']; + $mini_url = $base_url.'&width=80&height=20&bg=f4f4f4'; - $text_descr = rewrite_entity_descr($text_descr); + $text_descr = rewrite_entity_descr($proc['processor_descr']); $proc_popup = "onmouseover=\"return overlib('
    ".$device['hostname'].' - '.$text_descr; - $proc_popup .= "
    "; + $proc_popup .= ""; $proc_popup .= "', RIGHT".$config['overlib_defaults'].');" onmouseout="return nd();"'; $percent = round($proc['processor_usage']); - $graph_array['id'] = $proc['processor_id']; + $graph_array[$id] = $val; $graph_array['type'] = $graph_type; echo "
    @@ -27,4 +42,4 @@ foreach (dbFetchRows('SELECT * FROM `processors` WHERE device_id = ?', array($de echo "
    "; include 'includes/print-graphrow.inc.php'; echo "
    "; -}//end foreach \ No newline at end of file +}//end foreach diff --git a/includes/common.php b/includes/common.php index d11e101296..bf5b76d019 100644 --- a/includes/common.php +++ b/includes/common.php @@ -767,8 +767,54 @@ function count_mib_health($device) } // count_mib_health +function get_mibval($device, $oid) +{ + $sql = 'SELECT * FROM `device_oids` WHERE `device_id` = ? AND `oid` = ?'; + return dbFetchRow($sql, array($device['device_id'], $oid)); +} // get_mibval + + /* - * FIXME: Dummy implementation + * FIXME: Dummy implementation - needs an abstraction for each device + */ +function get_mib_mempools($device) +{ + $mempools = array(); + if ($device['os'] == 'ruckuswireless') { + $mempool = array(); + $mibvals = get_mibval($device, '.1.3.6.1.4.1.25053.1.2.1.1.1.15.14.0'); + $mempool['mempool_descr'] = $mibvals['object_type']; + $mempool['mempool_id'] = 0; + $mempool['mempool_total'] = 100; + $mempool['mempool_used'] = $mibvals['numvalue']; + $mempool['mempool_free'] = 100 - $mibvals['numvalue']; + $mempool['percentage'] = true; + $mempools[] = $mempool; + } + return $mempools; +} // get_mib_mempools + + +/* + * FIXME: Dummy implementation - needs an abstraction for each device + */ +function get_mib_processors($device) +{ + $processors = array(); + if ($device['os'] == 'ruckuswireless') { + $proc = array(); + $mibvals = get_mibval($device, '.1.3.6.1.4.1.25053.1.2.1.1.1.15.13.0'); + $proc['processor_descr'] = $mibvals['object_type']; + $proc['processor_id'] = 0; + $proc['processor_usage'] = $mibvals['numvalue']; + $processors[] = $proc; + } + return $processors; +} // get_mib_processors + + +/* + * FIXME: Dummy implementation - needs an abstraction for each device * @return true if there is a custom graph defined for this type, subtype, and device */ function is_custom_graph($type, $subtype, $device) From d862b9c10066209ba43df5d6c34ab6873d57b32f Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Wed, 2 Dec 2015 21:32:06 +1000 Subject: [PATCH 35/42] Add SQL schema --- sql-schema/085.sql | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 sql-schema/085.sql diff --git a/sql-schema/085.sql b/sql-schema/085.sql new file mode 100644 index 0000000000..6383926070 --- /dev/null +++ b/sql-schema/085.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS `mibdefs` ( `module` varchar(255) NOT NULL, `mib` varchar(255) NOT NULL, `object_type` varchar(255) NOT NULL, `oid` varchar(255) NOT NULL, `syntax` varchar(255) NOT NULL, `description` varchar(255), `max_access` varchar(255), `status` varchar(255), `included_by` varchar(255) NOT NULL, `last_modified` timestamp NOT NULL, PRIMARY KEY (`module`, `mib`, `object_type`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='MIB definitions'; +CREATE TABLE IF NOT EXISTS `device_mibs` ( `device_id` integer(11) NOT NULL, `module` varchar(255) NOT NULL, `mib` varchar(255) NOT NULL, `included_by` varchar(255) NOT NULL, `last_modified` timestamp NOT NULL, PRIMARY KEY (`device_id`, `module`, `mib`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Device to MIB mappings'; +CREATE TABLE IF NOT EXISTS `device_oids` ( `device_id` int(11) NOT NULL, `oid` varchar(255) NOT NULL, `module` varchar(255) NOT NULL, `mib` varchar(255) NOT NULL, `object_type` varchar(255) NOT NULL, `value` varchar(255), `numvalue` bigint, `last_modified` timestamp NOT NULL, PRIMARY KEY (`device_id`, `oid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Per-device MIB data'; +DELETE FROM `device_graphs`; +ALTER TABLE `device_graphs` CHANGE `graph` `graph` VARCHAR(255); From 2244a5f31dc467b8ed96a5882dc53571a5ff2625 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 6 Dec 2015 18:07:51 +1000 Subject: [PATCH 36/42] Fix issues flagged by scrutinizer --- html/includes/table/device_mibs.inc.php | 12 ------------ html/includes/table/device_oids.inc.php | 11 ----------- html/includes/table/mibs.inc.php | 11 ----------- includes/common.php | 17 +++++++++++++++-- includes/discovery/functions.inc.php | 2 -- includes/snmp.inc.php | 19 +++++-------------- 6 files changed, 20 insertions(+), 52 deletions(-) diff --git a/html/includes/table/device_mibs.inc.php b/html/includes/table/device_mibs.inc.php index 6c109dc3eb..be85f4bcf9 100644 --- a/html/includes/table/device_mibs.inc.php +++ b/html/includes/table/device_mibs.inc.php @@ -22,18 +22,6 @@ $columns = array( 'last_modified', ); -function search_phrase_column($c) -{ - global $searchPhrase; - return "$c LIKE '%$searchPhrase%'"; -} - -function quote_sql_word($c) -{ - return "`$c`"; -} - - $params = array( $_POST['device_id'], ); diff --git a/html/includes/table/device_oids.inc.php b/html/includes/table/device_oids.inc.php index f016a85839..f06ebae1dc 100644 --- a/html/includes/table/device_oids.inc.php +++ b/html/includes/table/device_oids.inc.php @@ -25,17 +25,6 @@ $columns = array( 'last_modified', ); -function search_phrase_column($c) -{ - global $searchPhrase; - return "$c LIKE '%$searchPhrase%'"; -} - -function quote_sql_word($c) -{ - return "`$c`"; -} - $params = array( $_POST['device_id'], diff --git a/html/includes/table/mibs.inc.php b/html/includes/table/mibs.inc.php index 0407036856..af41b91761 100644 --- a/html/includes/table/mibs.inc.php +++ b/html/includes/table/mibs.inc.php @@ -29,17 +29,6 @@ $columns = array( 'last_modified', ); -function search_phrase_column($c) -{ - global $searchPhrase; - return "$c LIKE '%$searchPhrase%'"; -} - -function quote_sql_word($c) -{ - return "`$c`"; -} - // start of sql definition $sql = 'SELECT * FROM `mibdefs`'; diff --git a/includes/common.php b/includes/common.php index bf5b76d019..5ec323956e 100644 --- a/includes/common.php +++ b/includes/common.php @@ -852,7 +852,7 @@ function enable_graphs($device, &$graph_enable) { // These are standard graphs we should have for all systems $graph_enable['poller']['poller_perf'] = 'device_poller_perf'; - if (can_ping_device($attribs) === true) { + if (can_ping_device($device) === true) { $graph_enable['poller']['ping_perf'] = 'device_ping_perf'; } @@ -875,7 +875,7 @@ function object_is_cached($section, $obj) { global $object_cache; if (array_key_exists($obj, $object_cache)) { - return $object_cache[$obj]; + return $object_cache[$section][$obj]; } else { return false; @@ -948,6 +948,19 @@ function longest_matching_prefix($str, $arr) } // longest_matching_prefix +function search_phrase_column($c) +{ + global $searchPhrase; + return "$c LIKE '%$searchPhrase%'"; +} // search_phrase_column + + +function quote_sql_word($c) +{ + return "`$c`"; +} // quote_sql_word + + /** * Constructs the path to an RRD for the Ceph application * @param string $gtype The type of rrd we're looking for diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 98a91e853e..309998f0f9 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -580,7 +580,6 @@ function discover_processor(&$valid, $device, $oid, $index, $type, $descr, $prec 'processor_precision' => $precision, ); dbUpdate($update_data, 'processors', '`device_id`=? AND `processor_index`=? AND `processor_type`=?', array($device['device_id'], $index, $type)); - d_echo($query."\n"); }//end if $valid[$type][$index] = 1; }//end if @@ -635,7 +634,6 @@ function discover_mempool(&$valid, $device, $index, $type, $descr, $precision='1 } dbUpdate($update_data, 'mempools', 'device_id=? AND mempool_index=? AND mempool_type=?', array($device['device_id'], $index, $type)); - d_echo($query."\n"); }//end if $valid[$type][$index] = 1; }//end if diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 6e1db3aac6..cb83d80683 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -215,7 +215,7 @@ function snmp_walk($device, $oid, $options=null, $mib=null, $mibdir=null) { function snmpwalk_cache_cip($device, $oid, $array=array(), $mib=0) { - global $config; + global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); @@ -251,7 +251,6 @@ function snmpwalk_cache_cip($device, $oid, $array=array(), $mib=0) { } $data = trim(external_exec($cmd)); - $device_id = $device['device_id']; // echo("Caching: $oid\n"); foreach (explode("\n", $data) as $entry) { @@ -287,7 +286,7 @@ function snmpwalk_cache_cip($device, $oid, $array=array(), $mib=0) { function snmp_cache_ifIndex($device) { // FIXME: this is not yet using our own snmp_* - global $config; + global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); @@ -318,7 +317,6 @@ function snmp_cache_ifIndex($device) { } $data = trim(external_exec($cmd)); - $device_id = $device['device_id']; $array = array(); foreach (explode("\n", $data) as $entry) { @@ -448,7 +446,7 @@ function snmpwalk_cache_triple_oid($device, $oid, $array, $mib=null, $mibdir=nul function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib=0) { - global $config; + global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); @@ -485,7 +483,6 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib=0) { $data = trim(external_exec($cmd)); - $device_id = $device['device_id']; foreach (explode("\n", $data) as $entry) { list($oid,$value) = explode('=', $entry, 2); $oid = trim($oid); @@ -539,7 +536,6 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib=0) { $data = trim(external_exec($cmd)); - $device_id = $device['device_id']; foreach (explode("\n", $data) as $entry) { list($oid,$value) = explode('=', $entry, 2); $oid = trim($oid); @@ -562,7 +558,7 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib=0) { function snmp_cache_slotport_oid($oid, $device, $array, $mib=0) { - global $config; + global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); @@ -598,7 +594,6 @@ function snmp_cache_slotport_oid($oid, $device, $array, $mib=0) { } $data = trim(external_exec($cmd)); - $device_id = $device['device_id']; foreach (explode("\n", $data) as $entry) { $entry = str_replace($oid.'.', '', $entry); @@ -624,7 +619,7 @@ function snmp_cache_oid($oid, $device, $array, $mib=0) { function snmp_cache_port_oids($oids, $port, $device, $array, $mib=0) { - global $config; + global $config, $debug; $timeout = prep_snmp_setting($device, 'timeout'); $retries = prep_snmp_setting($device, 'retries'); @@ -695,7 +690,6 @@ function snmp_cache_portIfIndex($device, $array) { $cmd .= ' '.$device['transport'].':'.$device['hostname'].':'.$device['port'].' portIfIndex'; $output = trim(external_exec($cmd)); - $device_id = $device['device_id']; foreach (explode("\n", $output) as $entry) { $entry = str_replace('CISCO-STACK-MIB::portIfIndex.', '', $entry); @@ -732,7 +726,6 @@ function snmp_cache_portName($device, $array) { $cmd .= ' '.$device['transport'].':'.$device['hostname'].':'.$device['port'].' portName'; $output = trim(external_exec($cmd)); - $device_id = $device['device_id']; // echo("Caching: portName\n"); foreach (explode("\n", $output) as $entry) { $entry = str_replace('portName.', '', $entry); @@ -817,8 +810,6 @@ function snmp_gen_auth(&$device) { * ruckusZDSystemStats(15) 30 } */ function snmp_mib_parse($oid, $mib, $module, $mibdir=null) { - global $debug; - $fulloid = explode('.', $oid); $lastpart = end($fulloid); From 6fae9874b036d34a1d2c5b9e3575c5ec2ae7b8d9 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 6 Dec 2015 19:25:24 +1000 Subject: [PATCH 37/42] Add global MIB association table --- html/includes/print-menubar.php | 2 + html/includes/table/device_mibs.inc.php | 31 +++++++++++----- html/pages/mib_assoc.inc.php | 49 +++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 html/pages/mib_assoc.inc.php diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 2a4e59c047..7059a269e1 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -169,6 +169,8 @@ if ($_SESSION['userlevel'] >= '10') { } echo ' +
  • 'mib_assoc')).'> MIB associations
  • + '; if ($config['navbar']['manage_groups']['hide'] === 0) { diff --git a/html/includes/table/device_mibs.inc.php b/html/includes/table/device_mibs.inc.php index be85f4bcf9..bc9af0a246 100644 --- a/html/includes/table/device_mibs.inc.php +++ b/html/includes/table/device_mibs.inc.php @@ -22,14 +22,25 @@ $columns = array( 'last_modified', ); -$params = array( - $_POST['device_id'], -); - -// start of sql definition -$sql = 'SELECT * FROM `device_mibs`'; - -$wheresql = ' WHERE `device_id` = ?'; +if (isset($_POST['device_id'])) { + // device_id supplied - get details for a single device + // used by device MIB page + $params = array( + $_POST['device_id'], + ); + $sql = 'SELECT * FROM `device_mibs`'; + $wheresql = ' WHERE `device_id` = ?'; + $sortcolumns = 3; +} +else { + // device_id not supplied - get details for a all devices + // used by all device MIBs page + $params = array(); + $sql = 'SELECT `d`.`hostname` as `hostname`, `dm`.* FROM `devices` `d`, `device_mibs` `dm`'; + $wheresql = ' WHERE `d`.`device_id` = `dm`.`device_id`'; + array_unshift($columns, 'hostname'); + $sortcolumns = 4; +} // all columns are searchable - search across them if (isset($searchPhrase) && !empty($searchPhrase)) { @@ -45,9 +56,9 @@ if (empty($total)) { $total = 0; } -// sort by first three columns by default +// set up default sort if (!isset($sort) || empty($sort)) { - $sort = implode(', ', array_map("quote_sql_word", array_slice($columns, 0, 3))); + $sort = implode(', ', array_map("quote_sql_word", array_slice($columns, 0, $sortcolumns))); } $sql .= " ORDER BY $sort"; diff --git a/html/pages/mib_assoc.inc.php b/html/pages/mib_assoc.inc.php new file mode 100644 index 0000000000..a792e57966 --- /dev/null +++ b/html/pages/mib_assoc.inc.php @@ -0,0 +1,49 @@ + + * + * Author: Paul Gear + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +?> + +

    MIB associations for all devices

    +
    + + + + + + + + + + +
    HostnameModuleMIBIncluded byLast Modified
    +
    + + From ce880a6d23c8884956fa7797728b6a87997add9c Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 6 Dec 2015 19:26:32 +1000 Subject: [PATCH 38/42] Fix count & create device link in global MIB association table --- html/includes/table/device_mibs.inc.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/html/includes/table/device_mibs.inc.php b/html/includes/table/device_mibs.inc.php index bc9af0a246..22b77e8fc1 100644 --- a/html/includes/table/device_mibs.inc.php +++ b/html/includes/table/device_mibs.inc.php @@ -31,6 +31,7 @@ if (isset($_POST['device_id'])) { $sql = 'SELECT * FROM `device_mibs`'; $wheresql = ' WHERE `device_id` = ?'; $sortcolumns = 3; + $count_sql = "SELECT COUNT(*) FROM `device_mibs`".$wheresql; } else { // device_id not supplied - get details for a all devices @@ -40,6 +41,7 @@ else { $wheresql = ' WHERE `d`.`device_id` = `dm`.`device_id`'; array_unshift($columns, 'hostname'); $sortcolumns = 4; + $count_sql = "SELECT COUNT(*) FROM `devices` `d`, `device_mibs` `dm`".$wheresql; } // all columns are searchable - search across them @@ -50,8 +52,7 @@ if (isset($searchPhrase) && !empty($searchPhrase)) { $sql .= $wheresql; // get total -$count_sql = "SELECT COUNT(*) FROM `device_mibs`".$wheresql; -$total = dbFetchCell($count_sql, $params); +$total = dbFetchCell($count_sql, $params); if (empty($total)) { $total = 0; } @@ -78,6 +79,11 @@ foreach (dbFetchRows($sql, $params) as $mib) { foreach ($columns as $col) { $mibrow[$col] = $mib[$col]; } + if (!isset($_POST['device_id'])) { + $device = device_by_id_cache($mib['device_id']); + $mibrow['hostname'] = generate_device_link($device, + $mib['hostname'], array('tab' => 'mib')); + } $response[] = $mibrow; } From ddb18e94e6a77237e1ecfbeb200a5329fc532b48 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 6 Dec 2015 21:03:59 +1000 Subject: [PATCH 39/42] Minor doc fix --- doc/Extensions/MIB-based-polling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Extensions/MIB-based-polling.md b/doc/Extensions/MIB-based-polling.md index 92c6786a4b..50cf7b3fb7 100644 --- a/doc/Extensions/MIB-based-polling.md +++ b/doc/Extensions/MIB-based-polling.md @@ -33,7 +33,7 @@ your disk space requirements to grow enormously and rapidly. As an example, enabling MIB-based polling on my test Ruckus ZD1000 wireless controller with one (1) AP and one (1) user on that AP resulted in a 5 MB increase in RRD space usage for that device. Each RRD file is around 125 KB in size (on -x64-64) systems and is pre-allocated, so after the first discovery and poller +x64-64 systems) and is pre-allocated, so after the first discovery and poller run of each devicewith MIB-based polling enabled, disk space should be stable. However, monitoring disk usage is your responsibility. (The good news: you can do this with LibreNMS. :-) From b98e69187f95e4886daf926a05b758038ca8dd9f Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 6 Dec 2015 21:05:02 +1000 Subject: [PATCH 40/42] Minor doc fix --- doc/Extensions/MIB-based-polling.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/Extensions/MIB-based-polling.md b/doc/Extensions/MIB-based-polling.md index 50cf7b3fb7..d7892fffbb 100644 --- a/doc/Extensions/MIB-based-polling.md +++ b/doc/Extensions/MIB-based-polling.md @@ -54,6 +54,8 @@ The components involved in MIB-based polling are: http://your.librenms.server/device/device=XXXX/tab=mib/ All MIBs used by MIB-based polling may be viewed at: http://your.librenms.server/mibs/ + All device associations created by MIB-based polling may be viewed at: + http://your.librenms.server/mib_assoc/ (Devices -> MIB associations) - In addition, all devices are checked for a MIB matching their sysObjectID. If there is a matching MIB available, it is automatically included. From e89984e316bca994227de722d311c6d4650c9ecb Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sun, 6 Dec 2015 21:23:06 +1000 Subject: [PATCH 41/42] Fix display of Mikrotik CPU; probably unrelated to MIB-based polling changes --- html/includes/graphs/device/processor_separate.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html/includes/graphs/device/processor_separate.inc.php b/html/includes/graphs/device/processor_separate.inc.php index 2b59802566..de0760ac68 100644 --- a/html/includes/graphs/device/processor_separate.inc.php +++ b/html/includes/graphs/device/processor_separate.inc.php @@ -18,7 +18,7 @@ foreach ($procs as $proc) { $unit_text = 'Load %'; -$units = '%'; +$units = ''; $total_units = '%'; $colours = 'mixed'; From eb1dbc74c74cbf8955e5f9df6e870ad012e11202 Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Fri, 11 Dec 2015 19:09:28 +1000 Subject: [PATCH 42/42] Remove redundant function --- html/includes/table/device_mibs.inc.php | 4 ++-- html/includes/table/device_oids.inc.php | 4 ++-- html/includes/table/mibs.inc.php | 4 ++-- includes/common.php | 6 ------ 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/html/includes/table/device_mibs.inc.php b/html/includes/table/device_mibs.inc.php index 22b77e8fc1..6228df94c3 100644 --- a/html/includes/table/device_mibs.inc.php +++ b/html/includes/table/device_mibs.inc.php @@ -46,7 +46,7 @@ else { // all columns are searchable - search across them if (isset($searchPhrase) && !empty($searchPhrase)) { - $searchsql = implode(' OR ', array_map("search_phrase_column", array_map("quote_sql_word", $columns))); + $searchsql = implode(' OR ', array_map("search_phrase_column", array_map("mres", $columns))); $wheresql .= " AND ( $searchsql )"; } $sql .= $wheresql; @@ -59,7 +59,7 @@ if (empty($total)) { // set up default sort if (!isset($sort) || empty($sort)) { - $sort = implode(', ', array_map("quote_sql_word", array_slice($columns, 0, $sortcolumns))); + $sort = implode(', ', array_map("mres", array_slice($columns, 0, $sortcolumns))); } $sql .= " ORDER BY $sort"; diff --git a/html/includes/table/device_oids.inc.php b/html/includes/table/device_oids.inc.php index f06ebae1dc..3c10730d25 100644 --- a/html/includes/table/device_oids.inc.php +++ b/html/includes/table/device_oids.inc.php @@ -37,7 +37,7 @@ $wheresql = ' WHERE `device_id` = ?'; // all columns are searchable - search across them if (isset($searchPhrase) && !empty($searchPhrase)) { - $searchsql = implode(' OR ', array_map("search_phrase_column", array_map("quote_sql_word", $columns))); + $searchsql = implode(' OR ', array_map("search_phrase_column", array_map("mres", $columns))); $wheresql .= " AND ( $searchsql )"; } $sql .= $wheresql; @@ -51,7 +51,7 @@ if (empty($total)) { // sort by first three columns by default if (!isset($sort) || empty($sort)) { - $sort = implode(', ', array_map("quote_sql_word", array_slice($columns, 0, 3))); + $sort = implode(', ', array_map("mres", array_slice($columns, 0, 3))); } $sql .= " ORDER BY $sort"; diff --git a/html/includes/table/mibs.inc.php b/html/includes/table/mibs.inc.php index af41b91761..2c9319b37e 100644 --- a/html/includes/table/mibs.inc.php +++ b/html/includes/table/mibs.inc.php @@ -35,7 +35,7 @@ $sql = 'SELECT * FROM `mibdefs`'; // all columns are searchable - search across them if (isset($searchPhrase) && !empty($searchPhrase)) { - $searchsql = implode(' OR ', array_map("search_phrase_column", array_map("quote_sql_word", $columns))); + $searchsql = implode(' OR ', array_map("search_phrase_column", array_map("mres", $columns))); $wheresql .= " WHERE ( $searchsql )"; $sql .= $wheresql; } @@ -49,7 +49,7 @@ if (empty($total)) { // sort by first three columns by default if (!isset($sort) || empty($sort)) { - $sort = implode(', ', array_map("quote_sql_word", array_slice($columns, 0, 3))); + $sort = implode(', ', array_map("mres", array_slice($columns, 0, 3))); } $sql .= " ORDER BY $sort"; diff --git a/includes/common.php b/includes/common.php index 5ec323956e..559df195ae 100644 --- a/includes/common.php +++ b/includes/common.php @@ -955,12 +955,6 @@ function search_phrase_column($c) } // search_phrase_column -function quote_sql_word($c) -{ - return "`$c`"; -} // quote_sql_word - - /** * Constructs the path to an RRD for the Ceph application * @param string $gtype The type of rrd we're looking for