mirror of
https://github.com/stylersnico/librenms.git
synced 2026-07-27 16:08:55 +02:00
Merge pull request #1407 from laf/smokeping
Smokeping improvement + script to generate config
This commit is contained in:
@@ -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.
|
||||
@@ -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,*";
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -1,25 +1,3 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$smokeping_files = get_smokeping_files($device);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
if (is_numeric($vars['id']) && ($auth || device_permitted($vars['id']))) {
|
||||
$device = device_by_id_cache($vars['id']);
|
||||
if (is_numeric($vars['device']) && ($auth || device_permitted($vars['src']))) {
|
||||
$device = device_by_id_cache($vars['device']);
|
||||
$title = generate_device_link($device);
|
||||
$graph_title = $device['hostname'];
|
||||
$auth = true;
|
||||
|
||||
@@ -30,18 +30,19 @@ else {
|
||||
$rrd_options .= " COMMENT:'".substr(str_pad($unit_text, ($descr_len + 5)), 0, ($descr_len + 5))." RTT Loss SDev RTT\:SDev \l'";
|
||||
}
|
||||
|
||||
$filename_dir = generate_smokeping_file($device);
|
||||
if ($src['hostname'] == $config['own_hostname']) {
|
||||
$filename = $config['smokeping']['dir'].$device['hostname'].'.rrd';
|
||||
if (!file_exists($filename)) {
|
||||
$filename = $filename_dir . $device['hostname'].'.rrd';
|
||||
if (!file_exists($filename_dir.$device['hostname'].'.rrd')) {
|
||||
// Try with dots in hostname replaced by underscores
|
||||
$filename = $config['smokeping']['dir'].str_replace('.', '_', $device['hostname']).'.rrd';
|
||||
$filename = $filename_dir . str_replace('.', '_', $device['hostname']).'.rrd';
|
||||
}
|
||||
}
|
||||
else {
|
||||
$filename = $config['smokeping']['dir'].$device['hostname'].'~'.$src['hostname'].'.rrd';
|
||||
$filename = $filename_dir . $device['hostname'] .'~'.$src['hostname'].'.rrd';
|
||||
if (!file_exists($filename)) {
|
||||
// Try with dots in hostname replaced by underscores
|
||||
$filename = $config['smokeping']['dir'].str_replace('.', '-', $device['hostname']).'~'.$src['hostname'].'.rrd';
|
||||
$filename = $filename_dir . str_replace('.', '-', $device['hostname']) .'~'.$src['hostname'].'.rrd';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -123,29 +123,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device']) {
|
||||
</li>';
|
||||
}
|
||||
|
||||
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 '<li class="'.$select['latency'].'">
|
||||
|
||||
@@ -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 '<tr><td>';
|
||||
echo '<h3>'.generate_device_link($host).'</h3>';
|
||||
echo '<h3>'.generate_device_link($dest).'</h3>';
|
||||
$graph_array['type'] = 'smokeping_in';
|
||||
$graph_array['device'] = $device['device_id'];
|
||||
$graph_array['src'] = $host['device_id'];
|
||||
|
||||
+40
-2
@@ -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
|
||||
|
||||
?>
|
||||
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* LibreNMS
|
||||
*
|
||||
* Copyright (c) 2015 Søren Friis Rosiak <sorenrosiak@gmail.com>
|
||||
* 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
|
||||
|
||||
<?php
|
||||
|
||||
foreach (dbFetchRows("SELECT `type` FROM `devices` WHERE `ignore` = 0 AND `disabled` = 0 AND `type` != '' GROUP BY `type`") as $groups) {
|
||||
echo '+ ' . $groups['type'] . PHP_EOL;
|
||||
echo 'menu = ' . $groups['type'] . PHP_EOL;
|
||||
echo 'title = ' . $groups['type'] . PHP_EOL;
|
||||
foreach (dbFetchRows("SELECT `hostname` FROM `devices` WHERE `type` = ? AND `ignore` = 0 AND `disabled` = 0", array($groups['type'])) as $devices) {
|
||||
//Dot needs to be replaced, since smokeping doesn't accept it at this level
|
||||
echo '++ ' . str_replace(".","_",$devices['hostname']) . PHP_EOL;
|
||||
echo 'menu = ' . $devices['hostname'] . PHP_EOL;
|
||||
echo 'title = ' . $devices['hostname'] . PHP_EOL;
|
||||
echo 'host = ' . $devices['hostname'] . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user