- Change the IPSLA feature to allow different metrics to be collected per type.

- UDP Jitter metrics collected.
- Added opstatus code and DB field
- Discovery sets opstatus
- Added Status selector to SLA page
- Merged master and moved SQL
This commit is contained in:
Aaron Daniels
2016-08-08 16:59:29 +10:00
parent f1268848b0
commit ae7bb069ff
15 changed files with 526 additions and 96 deletions

View File

@@ -2,35 +2,19 @@
require 'includes/graphs/common.inc.php';
// FIXME - THIS IS BROKEN
$sla = dbFetchRow('SELECT * FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
$device = device_by_id_cache($sla['device_id']);
// if ($_GET['width'] >= "450") { $descr_len = "48"; } else { $descr_len = "21"; }
$descr_len = (intval(($_GET['width'] / 8)) * 0.8);
$unit_long = 'milliseconds';
$unit = 'ms';
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
$rrd_options .= ' -l 0 -E ';
$rrd_options .= " COMMENT:'".str_pad($unit_long, $descr_len)." Cur Min Max\\n'";
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'.rrd');
$name = '';
if ($sla['tag']) {
$name .= $sla['tag'];
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:'Round Trip Time Cur Min Max\\n'";
$rrd_options .= " DEF:rtt=$rrd_filename:rtt:AVERAGE ";
$rrd_options .= ' VDEF:avg=rtt,AVERAGE ';
$rrd_options .= " LINE1:avg#CCCCFF:'Average':dashes";
$rrd_options .= ' GPRINT:rtt:AVERAGE:%4.1lfms\\\l ';
$rrd_options .= " LINE1:rtt#CC0000:'RTT'";
$rrd_options .= ' GPRINT:rtt:LAST:%4.1lfms ';
$rrd_options .= ' GPRINT:rtt:MIN:%4.1lfms ';
$rrd_options .= ' GPRINT:rtt:MAX:%4.1lfms\\\l ';
}
if ($sla['owner']) {
$name .= ' (Owner: '.$sla['owner'].')';
}
$rrd_file = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('sla-'.$sla['sla_nr'].'.rrd');
$rrd_options .= " DEF:rtt=$rrd_file:rtt:AVERAGE ";
$rrd_options .= ' VDEF:avg=rtt,AVERAGE ';
$rrd_options .= " LINE1:avg#CCCCFF:'".str_pad('Average', ($descr_len - 3))."':dashes";
$rrd_options .= ' GPRINT:rtt:AVERAGE:%4.1lf'.$unit.'\\\l ';
$rrd_options .= " LINE1:rtt#CC0000:'".rrdtool_escape($descr, ($descr_len - 3))."'";
$rrd_options .= ' GPRINT:rtt:LAST:%4.1lf'.$unit.' ';
$rrd_options .= ' GPRINT:rtt:MIN:%4.1lf'.$unit.' ';
$rrd_options .= ' GPRINT:rtt:MAX:%4.1lf'.$unit.'\\\l ';

View File

@@ -0,0 +1,28 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
require 'includes/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'-jitter.rrd');
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
$rrd_options .= " DEF:ICPIF=" . $rrd_filename . ":ICPIF:AVERAGE ";
$rrd_options .= " LINE1.25:ICPIF#0000ee:'ICPIF ' ";
$rrd_options .= " GPRINT:ICPIF:LAST:%3.0lf ";
$rrd_options .= " GPRINT:ICPIF:MIN:%3.0lf ";
$rrd_options .= " GPRINT:ICPIF:MAX:%3.0lf\\\l ";
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
require 'includes/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'-jitter.rrd');
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
$rrd_options .= " DEF:SD=" . $rrd_filename . ":OWAvgSD:AVERAGE ";
$rrd_options .= " LINE1.25:SD#0000ee:'Src to Dst ' ";
$rrd_options .= " GPRINT:SD:LAST:%3.0lf ";
$rrd_options .= " GPRINT:SD:MIN:%3.0lf ";
$rrd_options .= " GPRINT:SD:MAX:%3.0lf\\\l ";
$rrd_options .= " DEF:DS=" . $rrd_filename . ":OWAvgDS:AVERAGE ";
$rrd_options .= " LINE1.25:DS#008C00:'Dst to Src ' ";
$rrd_options .= " GPRINT:DS:LAST:%3.0lf ";
$rrd_options .= " GPRINT:DS:MIN:%3.0lf ";
$rrd_options .= " GPRINT:DS:MAX:%3.0lf\\\l ";
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
require 'includes/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'-jitter.rrd');
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
$rrd_options .= " DEF:SD=" . $rrd_filename . ":PacketLossSD:AVERAGE ";
$rrd_options .= " LINE1.25:SD#0000ee:'Src to Dst ' ";
$rrd_options .= " GPRINT:SD:LAST:%3.0lf ";
$rrd_options .= " GPRINT:SD:MIN:%3.0lf ";
$rrd_options .= " GPRINT:SD:MAX:%3.0lf\\\l ";
$rrd_options .= " DEF:DS=" . $rrd_filename . ":PacketLossDS:AVERAGE ";
$rrd_options .= " LINE1.25:DS#008C00:'Dst to Src ' ";
$rrd_options .= " GPRINT:DS:LAST:%3.0lf ";
$rrd_options .= " GPRINT:DS:MIN:%3.0lf ";
$rrd_options .= " GPRINT:DS:MAX:%3.0lf\\\l ";
}

View File

@@ -0,0 +1,40 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
require 'includes/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'-jitter.rrd');
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
$rrd_options .= " DEF:POS=" . $rrd_filename . ":PacketOutOfSequence:AVERAGE ";
$rrd_options .= " LINE1.25:POS#0000ee:'Out of Sequence ' ";
$rrd_options .= " GPRINT:POS:LAST:%3.0lf ";
$rrd_options .= " GPRINT:POS:MIN:%3.0lf ";
$rrd_options .= " GPRINT:POS:MAX:%3.0lf\\\l ";
$rrd_options .= " DEF:MIA=" . $rrd_filename . ":PacketMIA:AVERAGE ";
$rrd_options .= " LINE1.25:MIA#008C00:'Missing in Action ' ";
$rrd_options .= " GPRINT:MIA:LAST:%3.0lf ";
$rrd_options .= " GPRINT:MIA:MIN:%3.0lf ";
$rrd_options .= " GPRINT:MIA:MAX:%3.0lf\\\l ";
$rrd_options .= " DEF:PLA=" . $rrd_filename . ":PacketLateArrival:AVERAGE ";
$rrd_options .= " LINE1.25:PLA#CC0000:'Late Arrival ' ";
$rrd_options .= " GPRINT:PLA:LAST:%3.0lf ";
$rrd_options .= " GPRINT:PLA:MIN:%3.0lf ";
$rrd_options .= " GPRINT:PLA:MAX:%3.0lf\\\l ";
}

View File

@@ -0,0 +1,28 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
require 'includes/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'-jitter.rrd');
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
$rrd_options .= " DEF:MOS=" . $rrd_filename . ":MOS:AVERAGE ";
$rrd_options .= " LINE1.25:MOS#0000ee:'Mean Opinion Score ' ";
$rrd_options .= " GPRINT:MOS:LAST:%3.0lf ";
$rrd_options .= " GPRINT:MOS:MIN:%3.0lf ";
$rrd_options .= " GPRINT:MOS:MAX:%3.0lf\\\l ";
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
require 'includes/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'-jitter.rrd');
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
$rrd_options .= " DEF:SD=" . $rrd_filename . ":AvgSDJ:AVERAGE ";
$rrd_options .= " LINE1.25:SD#0000ee:'Src to Dst ' ";
$rrd_options .= " GPRINT:SD:LAST:%3.0lf ";
$rrd_options .= " GPRINT:SD:MIN:%3.0lf ";
$rrd_options .= " GPRINT:SD:MAX:%3.0lf\\\l ";
$rrd_options .= " DEF:DS=" . $rrd_filename . ":AvgDSJ:AVERAGE ";
$rrd_options .= " LINE1.25:DS#008C00:'Dst to Src ' ";
$rrd_options .= " GPRINT:DS:LAST:%3.0lf ";
$rrd_options .= " GPRINT:DS:MIN:%3.0lf ";
$rrd_options .= " GPRINT:DS:MAX:%3.0lf\\\l ";
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
require 'includes/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = $config['rrd_dir']."/".$device['hostname']."/".safename('sla-'.$sla['sla_nr'].'-jitter.rrd');
if (file_exists($rrd_filename)) {
$rrd_options .= " COMMENT:' Cur Min Max\\n'";
$rrd_options .= " DEF:SD=" . $rrd_filename . ":AvgSDJ:AVERAGE ";
$rrd_options .= " LINE1.25:SD#0000ee:'Src to Dst ' ";
$rrd_options .= " GPRINT:SD:LAST:%3.0lf ";
$rrd_options .= " GPRINT:SD:MIN:%3.0lf ";
$rrd_options .= " GPRINT:SD:MAX:%3.0lf\\\l ";
$rrd_options .= " DEF:DS=" . $rrd_filename . ":AvgDSJ:AVERAGE ";
$rrd_options .= " LINE1.25:DS#008C00:'Dst to Src ' ";
$rrd_options .= " GPRINT:DS:LAST:%3.0lf ";
$rrd_options .= " GPRINT:DS:MIN:%3.0lf ";
$rrd_options .= " GPRINT:DS:MAX:%3.0lf\\\l ";
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* LibreNMS module to Graph Cisco IPSLA UDP Jitter metrics
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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.
*/
$sla = dbFetchRow('SELECT `sla_nr`,`rtt_type` FROM `slas` WHERE `sla_id` = ?', array($vars['id']));
?>
<div class="well well-sm">
<!-- Need some kind of header here to represent the SLA -->
</div>
<div class="panel panel-default" id="ipsla">
<?php
// All SLA's support the RTT metric
include 'sla/rtt.inc.php';
// Load the per-type SLA metrics
if (file_exists('pages/device/sla/'.$sla['rtt_type'].'.inc.php')) {
include 'sla/'.$sla['rtt_type'].'.inc.php';
}
?>
</div>
<?php

View File

@@ -0,0 +1,95 @@
<div class="panel-heading">
<h3 class="panel-title">Average Latency One Way</h3>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla_jitter-latency';
$graph_array['id'] = $vars['id'];
require 'includes/print-graphrow.inc.php';
?>
</div>
<div class="panel-heading">
<h3 class="panel-title">Average Jitter</h3>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla_jitter';
$graph_array['id'] = $vars['id'];
require 'includes/print-graphrow.inc.php';
?>
</div>
<div class="panel-heading">
<h3 class="panel-title">Packet Loss</h3>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla_jitter-loss';
$graph_array['id'] = $vars['id'];
require 'includes/print-graphrow.inc.php';
?>
</div>
<div class="panel-heading">
<h3 class="panel-title">Lost Packets (Out Of Sequence, Tail Drop, Late Arrival)</h3>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla_jitter-lost';
$graph_array['id'] = $vars['id'];
require 'includes/print-graphrow.inc.php';
?>
</div>
<div class="panel-heading">
<h3 class="panel-title">Mean Opinion Score</h3>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla_jitter-mos';
$graph_array['id'] = $vars['id'];
require 'includes/print-graphrow.inc.php';
?>
</div>
<div class="panel-heading">
<h3 class="panel-title">Impairment / Calculated Planning Impairment Factor</h3>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla_jitter-icpif';
$graph_array['id'] = $vars['id'];
require 'includes/print-graphrow.inc.php';
?>
</div>

View File

@@ -0,0 +1,15 @@
<div class="panel-heading">
<h3 class="panel-title">Round Trip Time</h3>
</div>
<div class="panel-body">
<?php
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla';
$graph_array['id'] = $vars['id'];
require 'includes/print-graphrow.inc.php';
?>
</div>

View File

@@ -2,8 +2,6 @@
print_optionbar_start();
echo "<span style='font-weight: bold;'>SLA</span> &#187; ";
$slas = dbFetchRows('SELECT * FROM `slas` WHERE `device_id` = ? AND `deleted` = 0 ORDER BY `sla_nr`', array($device['device_id']));
// Collect types
@@ -18,16 +16,23 @@ foreach ($slas as $sla) {
if (isset($config['sla_type_labels'][$sla_type])) {
$text = $config['sla_type_labels'][$sla_type];
}
}
else {
} else {
$text = ucfirst($sla_type);
}
$sla_types[$sla_type] = $text;
}
asort($sla_types);
$status_options = array(
'all' => 'All',
'up' => 'Up',
'down' => 'Down',
);
echo "<span style='font-weight: bold;'>SLA</span> &#187; ";
// SLA Types, on the left.
$sep = '';
foreach ($sla_types as $sla_type => $text) {
if (!$vars['view']) {
@@ -46,7 +51,27 @@ foreach ($sla_types as $sla_type => $text) {
$sep = ' | ';
}
unset($sep);
// The status option - on the right
echo '<div class="pull-right">';
echo "<span style='font-weight: bold;'>Status</span> &#187; ";
$sep = '';
foreach ($status_options as $option => $text) {
if (empty($vars['opstatus'])) {
$vars['opstatus'] = $option;
}
echo $sep;
if ($vars['opstatus'] == $option) {
echo "<span class='pagemenu-selected'>";
}
echo generate_link($text, $vars, array('opstatus' => $option));
if ($vars['opstatus'] == $option) {
echo '</span>';
}
$sep = ' | ';
}
unset($sep);
print_optionbar_end();
@@ -56,6 +81,12 @@ foreach ($slas as $sla) {
continue;
}
$opstatus = ($sla['opstatus'] === '0') ? 'up' : 'down';
d_echo("<br>Opstatus :: var: ".$vars['opstatus'].", db: ".$sla['opstatus'].", name: ".$opstatus."<br>");
if ($vars['opstatus'] != 'all' && $vars['opstatus'] != $opstatus) {
continue;
}
$name = 'SLA #'.$sla['sla_nr'].' - '.$sla_types[$sla['rtt_type']];
if ($sla['tag']) {
$name .= ': '.$sla['tag'];
@@ -65,11 +96,30 @@ foreach ($slas as $sla) {
$name .= ' (Owner: '.$sla['owner'].')';
}
$graph_array['type'] = 'device_sla';
$graph_array['id'] = $sla['sla_id'];
echo '<div class="panel panel-default">
// Jitter has more graphs. Display a sub-page
if ($sla['rtt_type'] == 'jitter') {
$name = '<a href="'.generate_url($vars, array('tab' => "sla", 'id' => $sla['sla_id'])).'">'.$name.'</a>';
} else {
$name = htmlentities($name);
}
// If we have an error highlight the row.
if ($sla['opstatus'] == 2) {
$danger = "panel-danger";
} else {
$danger = '';
}
$graph_array = array();
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = $config['time']['now'];
$graph_array['type'] = 'device_sla';
$graph_array['id'] = $sla['sla_id'];
echo '<div class="panel panel-default '.$danger.'">
<div class="panel-heading">
<h3 class="panel-title">'.htmlentities($name).'</h3>
<h3 class="panel-title">'.$name.'</h3>
</div>
<div class="panel-body">';
echo "<div class='row'>";
@@ -79,4 +129,4 @@ foreach ($slas as $sla) {
echo '</div>';
}
$pagetitle[] = 'SLAs';
$pagetitle[] = 'SLAs';

View File

@@ -43,6 +43,7 @@ if ($config['enable_sla'] && $device['os_group'] == 'cisco') {
'tag' => $sla_config['rttMonCtrlAdminTag'],
'rtt_type' => $sla_config['rttMonCtrlAdminRttType'],
'status' => ($sla_config['rttMonCtrlAdminStatus'] == 'active') ? 1 : 0,
'opstatus' => ($sla_config['rttMonLatestRttOperSense'] == 'ok') ? 0 : 2,
'deleted' => 0,
);

View File

@@ -1,70 +1,88 @@
<?php
$uptime = snmp_get($device, 'sysUpTime.0', '-Otv');
$time_offset = (time() - intval($uptime) / 100);
// Gather our SLA's from the DB.
$slas = dbFetchRows('SELECT * FROM `slas` WHERE `device_id` = ? AND `deleted` = 0', array($device['device_id']));
$slavals = snmp_walk($device, 'ciscoRttMonMIB.ciscoRttMonObjects.rttMonCtrl.rttMonLatestRttOperTable', '-OUsqt', '+CISCO-RTTMON-MIB');
if (count($slas > 0)) {
// We have SLA's, lets go!!!
$sla_table = array();
foreach (explode("\n", $slavals) as $sla) {
$key_val = explode(' ', $sla, 2);
if (count($key_val) != 2) {
$key_val[] = '';
}
// Go get some data from the device.
$rttMonLatestRttOperTable = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.42.1.2.10.1', 1);
$rttMonLatestOper = snmpwalk_array_num($device, '.1.3.6.1.4.1.9.9.42.1.5', 1);
$key = $key_val[0];
$value = $key_val[1];
$uptime = snmp_get($device, 'sysUpTime.0', '-Otv');
$time_offset = (time() - intval($uptime) / 100);
$prop_id = explode('.', $key);
if ((count($prop_id) != 2) || !ctype_digit($prop_id[1])) {
continue;
}
foreach ($slas as $sla) {
// Lets process each SLA
$unixtime = intval(($rttMonLatestRttOperTable['1.3.6.1.4.1.9.9.42.1.2.10.1.5'][$sla['sla_nr']] / 100 + $time_offset));
$time = strftime('%Y-%m-%d %H:%M:%S', $unixtime);
$update = array();
$property = str_replace('rttMonLatestRttOper', '', $prop_id[0]);
$id = intval($prop_id[1]);
// Use Nagios Status codes.
$opstatus = $rttMonLatestRttOperTable['1.3.6.1.4.1.9.9.42.1.2.10.1.2'][$sla['sla_nr']];
if ($opstatus == 1) {
$opstatus = 0; // 0=Good
} else {
$opstatus = 2; // 2=Critical
}
$sla_table[$id][$property] = trim($value);
}
// Populating the update array means we need to update the DB.
if ($opstatus != $sla['opstatus']) {
$update['opstatus'] = $opstatus;
}
// Update timestamps
foreach ($sla_table as &$sla) {
$sla['UnixTime'] = intval(($sla['Time'] / 100 + $time_offset));
$sla['TimeStr'] = strftime('%Y-%m-%d %H:%M:%S', $sla['UnixTime']);
}
$rtt = $rttMonLatestRttOperTable['1.3.6.1.4.1.9.9.42.1.2.10.1.1'][$sla['sla_nr']];
echo 'SLA '.$sla['sla_nr'].': '.$sla['rtt_type'].' '.$sla['owner'].' '.$sla['tag'].'... '.$rtt.'ms at '.$time.'\n';
unset($sla);
foreach (dbFetchRows('SELECT * FROM `slas` WHERE `device_id` = ? AND `deleted` = 0 AND `status` = 1', array($device['device_id'])) as $sla) {
echo 'SLA '.$sla['sla_nr'].': '.$sla['rtt_type'].' '.$sla['owner'].' '.$sla['tag'].'... ';
$slarrd = $config['rrd_dir'].'/'.$device['hostname'].'/'.safename('sla-'.$sla['sla_nr'].'.rrd');
if (!is_file($slarrd)) {
rrdtool_create(
$slarrd,
'--step 300
DS:rtt:GAUGE:600:0:300000 '.$config['rrd_rra']
$metrics = array(
'rtt' => $rtt,
);
// The base RRD
$filename = 'sla-'.$sla['sla_nr'].'.rrd';
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename);
if (!file_exists ($rrd_filename)) {
rrdtool_create ($rrd_filename, " DS:rtt:GAUGE:600:0:300000" . $config['rrd_rra']);
}
rrdtool_update($rrd_filename, $metrics);
// Let's gather some per-type metrics.
switch ($sla['rtt_type']) {
case 'jitter':
$jitter = array(
'PacketLossSD' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.26'][$sla['sla_nr']],
'PacketLossDS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.27'][$sla['sla_nr']],
'PacketOutOfSequence' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.28'][$sla['sla_nr']],
'PacketMIA' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.29'][$sla['sla_nr']],
'PacketLateArrival' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.30'][$sla['sla_nr']],
'MOS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.42'][$sla['sla_nr']]/100,
'ICPIF' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.43'][$sla['sla_nr']],
'OWAvgSD' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.49'][$sla['sla_nr']],
'OWAvgDS' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.50'][$sla['sla_nr']],
'AvgSDJ' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.47'][$sla['sla_nr']],
'AvgDSJ' => $rttMonLatestOper['1.3.6.1.4.1.9.9.42.1.5.2.1.48'][$sla['sla_nr']],
);
$filename = 'sla-'.$sla['sla_nr'].'-jitter.rrd';
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/" . safename ($filename);
if (!file_exists ($rrd_filename)) {
rrdtool_create ($rrd_filename, " DS:PacketLossSD:GAUGE:600:0:U DS:PacketLossDS:GAUGE:600:0:U DS:PacketOutOfSequence:GAUGE:600:0:U DS:PacketMIA:GAUGE:600:0:U DS:PacketLateArrival:GAUGE:600:0:U DS:MOS:GAUGE:600:0:U DS:ICPIF:GAUGE:600:0:U DS:OWAvgSD:GAUGE:600:0:U DS:OWAvgDS:GAUGE:600:0:U DS:AvgSDJ:GAUGE:600:0:U DS:AvgDSJ:GAUGE:600:0:U" . $config['rrd_rra']);
}
rrdtool_update($rrd_filename, $jitter);
$metrics = array_merge($metrics,$jitter);
break;
}
d_echo("The following metrics were collected for #".$sla['sla_nr'].":\n");
d_echo($metrics);
// Update influx
$tags = array('sla_nr' => $sla['sla_nr']);
influx_update($device,'sla',$tags,$metrics);
// Update the DB if necessary
if (count($update) > 0) {
$updated = dbUpdate($update, 'slas', '`sla_id` = ?', array($sla['sla_id']));
}
}
if (isset($sla_table[$sla['sla_nr']])) {
$slaval = $sla_table[$sla['sla_nr']];
echo $slaval['CompletionTime'].'ms at '.$slaval['TimeStr'];
$val = $slaval['CompletionTime'];
}
else {
echo 'NaN';
$val = 'U';
}
$fields = array(
'rtt' => $val,
);
rrdtool_update($slarrd, $fields);
$tags = array('sla_nr' => $sla['sla_nr']);
influx_update($device,'sla',$tags,$fields);
echo "\n";
}//end foreach
}

1
sql-schema/127.sql Normal file
View File

@@ -0,0 +1 @@
ALTER TABLE `slas` ADD `opstatus` TINYINT(1) NOT NULL DEFAULT '0' AFTER `status`;