diff --git a/doc/Extensions/Smokeping.md b/doc/Extensions/Smokeping.md new file mode 100644 index 000000000..902b14f2a --- /dev/null +++ b/doc/Extensions/Smokeping.md @@ -0,0 +1,45 @@ +# Smokeping integration + +We currently have two ways to use Smokeping with LibreNMS, the first is using the included script generator to generate the config for Smokeping. The +second is to utilise an existing Smokeping setup. + +### Included Smokeping script + +To use this, please add something similar to your smokeping config file: + +```bash +@include /opt/smokeping/etc/librenms.conf +``` + +Then you need to generate the config file (maybe even add a cron to schedule this in and reload smokeping). We've assumed a few locations for smokeping, the config file you want +to call it and where LibreNMS is: + +```bash +cd /opt/librenms/scripts/ +php ./gen_smokeping.php > /opt/smokeping/etc/librenms.conf +/opt/smokeping/bin/smokeping --reload +``` + +Sample cron: + +```bash +15 0 * * * root cd /opt/librenms/scripts && php ./gen_smokeping.php > /opt/smokeping/etc/librenms.conf && /opt/smokeping/bin/smokeping --reload >> /dev/null 2>&1 +``` + +Now configure LibreNMS (make sure you point dir to your smokeping data directory: + +```php +$config['smokeping']['dir'] = '/opt/smokeping/data'; +$config['smokeping']['integration'] = true; +``` + +### Standard Smokeping + +This is quite simple, just point your dir at the smokeping data directory - please be aware that all RRD files need to be within this dir and NOT sub dirs: + +```php +$config['smokeping']['dir'] = '/opt/smokeping/data'; +$config['own_hostname'] +``` + +You should now see a new tab in your device page called ping. diff --git a/html/includes/graphs/device/smokeping_all_common.inc.php b/html/includes/graphs/device/smokeping_all_common.inc.php index 962ac8f51..a9e7b86b7 100644 --- a/html/includes/graphs/device/smokeping_all_common.inc.php +++ b/html/includes/graphs/device/smokeping_all_common.inc.php @@ -38,7 +38,7 @@ foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filena $descr = rrdtool_escape($source, $descr_len); - $filename = $config['smokeping']['dir'].$filename; + $filename = generate_smokeping_file($device,$filename); $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE '; $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE'; $rrd_options .= " CDEF:ploss$i=loss$i,$pings,/,100,*"; diff --git a/html/includes/graphs/device/smokeping_all_common_avg.inc.php b/html/includes/graphs/device/smokeping_all_common_avg.inc.php index c77d51021..97c5d40fb 100644 --- a/html/includes/graphs/device/smokeping_all_common_avg.inc.php +++ b/html/includes/graphs/device/smokeping_all_common_avg.inc.php @@ -39,7 +39,7 @@ foreach ($smokeping_files[$direction][$device['hostname']] as $source => $filena $descr = rrdtool_escape($source, $descr_len); - $filename = $config['smokeping']['dir'].$filename; + $filename = generate_smokeping_file($device,$filename); $rrd_options .= " DEF:median$i=".$filename.':median:AVERAGE '; $rrd_options .= " CDEF:dm$i=median$i,UN,0,median$i,IF"; $rrd_options .= " DEF:loss$i=".$filename.':loss:AVERAGE'; diff --git a/html/includes/graphs/device/smokeping_common.inc.php b/html/includes/graphs/device/smokeping_common.inc.php index 006eb4197..ce9df8a4e 100644 --- a/html/includes/graphs/device/smokeping_common.inc.php +++ b/html/includes/graphs/device/smokeping_common.inc.php @@ -1,25 +1,3 @@ '; } - if (isset($config['smokeping']['dir'])) { - $smokeping_files = array(); - if ($handle = opendir($config['smokeping']['dir'])) { - while (false !== ($file = readdir($handle))) { - if ($file != '.' && $file != '..') { - if (eregi('.rrd', $file)) { - if (eregi('~', $file)) { - list($target,$slave) = explode('~', str_replace('.rrd', '', $file)); - $target = str_replace('_', '.', $target); - $smokeping_files['in'][$target][$slave] = $file; - $smokeping_files['out'][$slave][$target] = $file; - } - else { - $target = str_replace('.rrd', '', $file); - $target = str_replace('_', '.', $target); - $smokeping_files['in'][$target][$config['own_hostname']] = $file; - $smokeping_files['out'][$config['own_hostname']][$target] = $file; - } - } - } - } - }//end if - }//end if + $smokeping_files = get_smokeping_files($device); if (count($smokeping_files['in'][$device['hostname']]) || count($smokeping_files['out'][$device['hostname']])) { echo '
  • diff --git a/html/pages/device/latency.inc.php b/html/pages/device/latency.inc.php index 571916fc0..bc3f962e4 100644 --- a/html/pages/device/latency.inc.php +++ b/html/pages/device/latency.inc.php @@ -63,9 +63,15 @@ if ($vars['view'] == 'incoming') { foreach ($smokeping_files['in'][$device['hostname']] as $src => $host) { $hostname = str_replace('.rrd', '', $host); $host = device_by_name($src); + if ($config['smokeping']['integration'] === true) { + $dest = device_by_name(str_replace("_",".",$hostname)); + } + else { + $dest = $host; + } if (is_numeric($host['device_id'])) { echo ''; - echo '

    '.generate_device_link($host).'

    '; + echo '

    '.generate_device_link($dest).'

    '; $graph_array['type'] = 'smokeping_in'; $graph_array['device'] = $device['device_id']; $graph_array['src'] = $host['device_id']; diff --git a/includes/common.php b/includes/common.php index af127932c..9f4f182bd 100644 --- a/includes/common.php +++ b/includes/common.php @@ -699,6 +699,45 @@ function get_graph_subtypes($type) { return $types; } +function get_smokeping_files($device) { + global $config; + $smokeping_files = array(); + if (isset($config['smokeping']['dir'])) { + $smokeping_dir = generate_smokeping_file($device); + if ($handle = opendir($smokeping_dir)) { + while (false !== ($file = readdir($handle))) { + if ($file != '.' && $file != '..') { + if (eregi('.rrd', $file)) { + if (eregi('~', $file)) { + list($target,$slave) = explode('~', str_replace('.rrd', '', $file)); + $target = str_replace('_', '.', $target); + $smokeping_files['in'][$target][$slave] = $file; + $smokeping_files['out'][$slave][$target] = $file; + } + else { + $target = str_replace('.rrd', '', $file); + $target = str_replace('_', '.', $target); + $smokeping_files['in'][$target][$config['own_hostname']] = $file; + $smokeping_files['out'][$config['own_hostname']][$target] = $file; + } + } + } + } + } + } + return $smokeping_files; +} // end get_smokeping_files + +function generate_smokeping_file($device,$file='') { + global $config; + if ($config['smokeping']['integration'] === true) { + return $config['smokeping']['dir'] .'/'. $device['type'] .'/' . $file; + } + else { + return $config['smokeping']['dir'] . '/' . $file; + } +} + /* * @return rounded value to 10th/100th/1000th depending on input (valid: 10, 100, 1000) */ @@ -712,6 +751,5 @@ function round_Nth($val = 0, $round_to) { } return $ret; } -} +} // end round_Nth -?> diff --git a/scripts/gen_smokeping.php b/scripts/gen_smokeping.php new file mode 100755 index 000000000..9421af137 --- /dev/null +++ b/scripts/gen_smokeping.php @@ -0,0 +1,35 @@ + +* 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. +*/ + +include_once("../config.php"); +include_once("../includes/defaults.inc.php"); +include_once("../includes/definitions.inc.php"); + +?> + +menu = Top +title = Network Latency Grapher + +