Added VRP ICMP SLA (NQA in huawei naming) support (#12973)

* added VRP icmpAppl SLA (NQA in huawei naming) support

* style

* style

* remove unnecessary values in RRD

* enable SLA for VRP devices

* tests
This commit is contained in:
PipoCanaja
2021-07-03 15:16:38 +02:00
committed by GitHub
parent e9c8a3c337
commit 7e2ce6179a
8 changed files with 289 additions and 3 deletions

View File

@@ -27,6 +27,8 @@ namespace LibreNMS\OS;
use App\Models\Device;
use App\Models\Mempool;
use App\Models\PortsNac;
use App\Models\Sla;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use LibreNMS\Device\Processor;
@@ -36,8 +38,10 @@ use LibreNMS\Interfaces\Discovery\OSDiscovery;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessApCountDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\Interfaces\Discovery\SlaDiscovery;
use LibreNMS\Interfaces\Polling\NacPolling;
use LibreNMS\Interfaces\Polling\OSPolling;
use LibreNMS\Interfaces\Polling\SlaPolling;
use LibreNMS\OS;
use LibreNMS\RRD\RrdDefinition;
@@ -48,6 +52,8 @@ class Vrp extends OS implements
NacPolling,
WirelessApCountDiscovery,
WirelessClientsDiscovery,
SlaDiscovery,
SlaPolling,
OSDiscovery
{
public function discoverMempools()
@@ -473,4 +479,99 @@ class Vrp extends OS implements
return $sensors;
}
public function discoverSlas()
{
$slas = collect();
// Get the index of the last finished test
// NQA-MIB::nqaScheduleLastFinishIndex
$sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'pingCtlTable', [], 'DISMAN-PING-MIB');
if (! empty($sla_table)) {
$sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'nqaAdminCtrlType', $sla_table, 'NQA-MIB');
$sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'nqaAdminParaTimeUnit', $sla_table, 'NQA-MIB');
$sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'nqaScheduleLastFinishIndex', $sla_table, 'NQA-MIB');
}
foreach ($sla_table as $sla_key => $sla_config) {
[$owner, $test] = explode('.', $sla_key, 2);
$slas->push(new Sla([
'sla_nr' => hexdec(hash('crc32', $owner . $test)), // indexed by owner+test, convert to int
'owner' => $owner,
'tag' => $test,
'rtt_type' => $sla_config['nqaAdminCtrlType'],
'rtt' => isset($sla_config['pingResultsAverageRtt']) ? $sla_config['pingResultsAverageRtt'] / 1000 : null,
'status' => ($sla_config['pingCtlAdminStatus'] == 'enabled') ? 1 : 0,
'opstatus' => ($sla_config['pingCtlRowStatus'] == 'active') ? 0 : 2,
]));
}
return $slas;
}
public function pollSlas($slas)
{
$device = $this->getDeviceArray();
// Go get some data from the device.
$data = snmpwalk_group($device, 'pingCtlRowStatus', 'DISMAN-PING-MIB', 2);
$data = snmpwalk_group($device, 'pingResultsProbeResponses', 'DISMAN-PING-MIB', 2, $data);
$data = snmpwalk_group($device, 'pingResultsSentProbes', 'DISMAN-PING-MIB', 2, $data);
//$data = snmpwalk_group($device, 'nqaScheduleLastFinishIndex', 'NQA-MIB', 2, $data);
//$data = snmpwalk_group($device, 'pingResultsMinRtt', 'DISMAN-PING-MIB', 2, $data);
//$data = snmpwalk_group($device, 'pingResultsMaxRtt', 'DISMAN-PING-MIB', 2, $data);
$data = snmpwalk_group($device, 'pingResultsAverageRtt', 'DISMAN-PING-MIB', 2, $data);
// Get the needed information
foreach ($slas as $sla) {
$sla_nr = $sla->sla_nr;
$rtt_type = $sla->rtt_type;
$owner = $sla->owner;
$test = $sla->tag;
$divisor = 1; //values are already returned in ms, and RRD expects them in ms
// Use DISMAN-PING Status codes. 0=Good 2=Critical
$sla->opstatus = $data[$owner][$test]['pingCtlRowStatus'] == '1' ? 0 : 2;
$sla->rtt = $data[$owner][$test]['pingResultsAverageRtt'] / $divisor;
$time = Carbon::parse($data[$owner][$test]['pingResultsLastGoodProbe'])->toDateTimeString();
echo 'SLA : ' . $rtt_type . ' ' . $owner . ' ' . $test . '... ' . $sla->rtt . 'ms at ' . $time . "\n";
$fields = [
'rtt' => $sla->rtt,
];
// The base RRD
$rrd_name = ['sla', $sla['sla_nr']];
$rrd_def = RrdDefinition::make()->addDataset('rtt', 'GAUGE', 0, 300000);
$tags = compact('sla_nr', 'rrd_name', 'rrd_def');
data_update($device, 'sla', $tags, $fields);
// Let's gather some per-type fields.
switch ($rtt_type) {
case 'icmpAppl':
$icmp = [
//'MinRtt' => $data[$owner][$test]['pingResultsMinRtt'] / $divisor,
//'MaxRtt' => $data[$owner][$test]['pingResultsMaxRtt'] / $divisor,
'ProbeResponses' => $data[$owner][$test]['pingResultsProbeResponses'],
'ProbeLoss' => (int) $data[$owner][$test]['pingResultsSentProbes'] - (int) $data[$owner][$test]['pingResultsProbeResponses'],
];
$rrd_name = ['sla', $sla_nr, $rtt_type];
$rrd_def = RrdDefinition::make()
//->addDataset('MinRtt', 'GAUGE', 0, 300000)
//->addDataset('MaxRtt', 'GAUGE', 0, 300000)
->addDataset('ProbeResponses', 'GAUGE', 0, 300000)
->addDataset('ProbeLoss', 'GAUGE', 0, 300000);
$tags = compact('rrd_name', 'rrd_def', 'sla_nr', 'rtt_type');
data_update($device, 'sla', $tags, $icmp);
$fields = array_merge($fields, $icmp);
break;
}
d_echo('The following datasources were collected for #' . $sla['sla_nr'] . ":\n");
d_echo($fields);
}
}
}

View File

@@ -15,3 +15,7 @@ discovery:
- VRP Software Version
- Software Version VRP
- Versatile Routing Platform Software
poller_modules:
slas: true
discovery_modules:
slas: true

View File

@@ -16,8 +16,8 @@ $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 .= ' 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 ';
$rrd_options .= ' GPRINT:rtt:MAX:%4.1lfms\\l ';

View File

@@ -0,0 +1,34 @@
<?php
/*
* LibreNMS module to Graph Huawei VRP Icmp metrics
*
* Copyright (c) 2021 PipoCanaja
*
* 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` = ?', [$vars['id']]);
require 'includes/html/graphs/common.inc.php';
$rrd_options .= ' -l 0 -E ';
$rrd_filename = Rrd::name($device['hostname'], ['sla', $sla['sla_nr'], 'icmpAppl']);
if (Rrd::checkRrdExists($rrd_filename)) {
$rrd_options .= " COMMENT:'Packet loss\: Cur Avg Min Max\\n' ";
// Calculating percentage
$rrd_options .= ' DEF:ProbeResponses=' . $rrd_filename . ':ProbeResponses:AVERAGE ';
$rrd_options .= ' DEF:ProbeLoss=' . $rrd_filename . ':ProbeLoss:AVERAGE ';
$rrd_options .= ' CDEF:ProbeCount=ProbeResponses,ProbeLoss,+ ';
$rrd_options .= ' CDEF:PercentageLoss=ProbeLoss,UNKN,NE,0,ProbeLoss,IF,ProbeCount,/,100,*,CEIL ';
$rrd_options .= " LINE1:PercentageLoss#CC0000:'PercentageLoss'";
$rrd_options .= ' GPRINT:PercentageLoss:LAST:%6.1lf%% ';
$rrd_options .= ' GPRINT:PercentageLoss:AVERAGE:%6.1lf%% ';
$rrd_options .= ' GPRINT:PercentageLoss:MIN:%6.1lf%% ';
$rrd_options .= ' GPRINT:PercentageLoss:MAX:%6.1lf%%\\l ';
}

View File

@@ -0,0 +1,15 @@
<div class="panel-heading">
<h3 class="panel-title">Packet Loss</h3>
</div>
<div class="panel-body">
<?php
$graph_array = [];
$graph_array['device'] = $device['device_id'];
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = \LibreNMS\Config::get('time.now');
$graph_array['type'] = 'device_sla_icmpAppl';
$graph_array['id'] = $vars['id'];
require 'includes/html/print-graphrow.inc.php';
?>
</div>

View File

@@ -117,7 +117,7 @@ if ($vars['id']) {
}
// These Types have more graphs. Display a sub-page
if (($sla['rtt_type'] == 'jitter') || ($sla['rtt_type'] == 'icmpjitter') || ($sla['rtt_type'] == 'IcmpEcho') || ($sla['rtt_type'] == 'IcmpTimeStamp')) {
if (($sla['rtt_type'] == 'jitter') || ($sla['rtt_type'] == 'icmpjitter') || ($sla['rtt_type'] == 'IcmpEcho') || ($sla['rtt_type'] == 'IcmpTimeStamp') || ($sla['rtt_type'] == 'icmpAppl')) {
$name = '<a href="' . \LibreNMS\Util\Url::generate($vars, ['tab' => 'slas', 'id' => $sla['sla_id']]) . '">' . $name . '</a>';
} else {
$name = htmlentities($name);

73
tests/data/vrp_slas.json Normal file
View File

@@ -0,0 +1,73 @@
{
"os": {
"discovery": {
"devices": [
{
"sysName": "<private>",
"sysObjectID": ".1.3.6.1.4.1.2011.2.23.291",
"sysDescr": "S5720-56C-PWR-EI-AC\nHuawei Versatile Routing Platform Software \r\n VRP (R) software,Version 5.170 (S5720 V200R019C10SPC500) \r\n Copyright (C) 2007 Huawei Technologies Co., Ltd.",
"sysContact": null,
"version": "5.170 (V200R019C10SPC500) [6]",
"hardware": "S5720-56C-PWR-EI-AC",
"features": null,
"os": "vrp",
"type": "network",
"serial": null,
"icon": "huawei.svg",
"location": null
}
]
},
"poller": "matches discovery"
},
"slas": {
"discovery": {
"slas": [
{
"sla_nr": 1696157968,
"owner": "Admin1",
"tag": "TEST_Local",
"rtt_type": "icmpAppl",
"rtt": null,
"status": 1,
"opstatus": 0,
"deleted": 0
},
{
"sla_nr": 3165814157,
"owner": "Admin2",
"tag": "TEST_Lnms_Neg",
"rtt_type": "icmpAppl",
"rtt": null,
"status": 1,
"opstatus": 0,
"deleted": 0
}
]
},
"poller": {
"slas": [
{
"sla_nr": 1696157968,
"owner": "Admin1",
"tag": "TEST_Local",
"rtt_type": "icmpAppl",
"rtt": 2,
"status": 1,
"opstatus": 0,
"deleted": 0
},
{
"sla_nr": 3165814157,
"owner": "Admin2",
"tag": "TEST_Lnms_Neg",
"rtt_type": "icmpAppl",
"rtt": 4,
"status": 1,
"opstatus": 0,
"deleted": 0
}
]
}
}
}

View File

@@ -0,0 +1,59 @@
1.3.6.1.2.1.1.1.0|4x|53353732302d3536432d5057522d45492d41430a48756177656920566572736174696c6520526f7574696e6720506c6174666f726d20536f667477617265200d0a205652502028522920736f6674776172652c56657273696f6e20352e3137302028533537323020563230305230313943313053504335303029200d0a20436f707972696768742028432920323030372048756177656920546563686e6f6c6f6769657320436f2e2c204c74642e
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.2011.2.23.291
1.3.6.1.2.1.1.3.0|67|2038026003
1.3.6.1.2.1.1.5.0|4|<private>
1.3.6.1.2.1.80.1.2.1.3.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|1
1.3.6.1.2.1.80.1.2.1.3.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|1
1.3.6.1.2.1.80.1.2.1.4.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|4|10.199.253.1
1.3.6.1.2.1.80.1.2.1.4.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|4|10.199.8.12
1.3.6.1.2.1.80.1.2.1.5.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|0
1.3.6.1.2.1.80.1.2.1.5.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|0
1.3.6.1.2.1.80.1.2.1.6.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|1
1.3.6.1.2.1.80.1.2.1.6.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|1
1.3.6.1.2.1.80.1.2.1.7.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|2
1.3.6.1.2.1.80.1.2.1.7.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|5
1.3.6.1.2.1.80.1.2.1.8.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|1
1.3.6.1.2.1.80.1.2.1.8.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|1
1.3.6.1.2.1.80.1.2.1.9.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|4|
1.3.6.1.2.1.80.1.2.1.9.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|4|
1.3.6.1.2.1.80.1.2.1.10.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|30
1.3.6.1.2.1.80.1.2.1.10.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|30
1.3.6.1.2.1.80.1.2.1.11.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|10
1.3.6.1.2.1.80.1.2.1.11.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|5
1.3.6.1.2.1.80.1.2.1.12.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|3
1.3.6.1.2.1.80.1.2.1.12.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|3
1.3.6.1.2.1.80.1.2.1.13.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|4|00
1.3.6.1.2.1.80.1.2.1.13.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|4|00
1.3.6.1.2.1.80.1.2.1.14.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|1
1.3.6.1.2.1.80.1.2.1.14.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|1
1.3.6.1.2.1.80.1.2.1.15.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|1
1.3.6.1.2.1.80.1.2.1.15.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|1
1.3.6.1.2.1.80.1.2.1.16.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|6|1.3.6.1.2.1.80.3.1
1.3.6.1.2.1.80.1.2.1.16.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|6|1.3.6.1.2.1.80.3.1
1.3.6.1.2.1.80.1.2.1.17.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|4|MaDescription sdgfsdgsg
1.3.6.1.2.1.80.1.2.1.17.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|4|Test Description
1.3.6.1.2.1.80.1.2.1.18.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|0
1.3.6.1.2.1.80.1.2.1.18.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|0
1.3.6.1.2.1.80.1.2.1.19.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|4|
1.3.6.1.2.1.80.1.2.1.19.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|4|
1.3.6.1.2.1.80.1.2.1.20.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|0
1.3.6.1.2.1.80.1.2.1.20.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|0
1.3.6.1.2.1.80.1.2.1.21.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|2
1.3.6.1.2.1.80.1.2.1.21.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|2
1.3.6.1.2.1.80.1.2.1.22.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|0
1.3.6.1.2.1.80.1.2.1.22.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|0
1.3.6.1.2.1.80.1.2.1.23.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|1
1.3.6.1.2.1.80.1.2.1.23.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|1
1.3.6.1.2.1.80.1.3.1.6.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|2
1.3.6.1.2.1.80.1.3.1.6.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|4
1.3.6.1.2.1.80.1.3.1.7.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|2
1.3.6.1.2.1.80.1.3.1.7.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|5
1.3.6.1.2.1.80.1.3.1.8.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|66|2
1.3.6.1.2.1.80.1.3.1.8.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|66|5
1.3.6.1.4.1.2011.5.25.111.2.1.1.4.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|6
1.3.6.1.4.1.2011.5.25.111.2.1.1.4.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|6
1.3.6.1.4.1.2011.5.25.111.2.2.1.83.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|2
1.3.6.1.4.1.2011.5.25.111.2.2.1.83.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|2
1.3.6.1.4.1.2011.5.25.111.2.3.1.8.6.65.100.109.105.110.49.10.84.69.83.84.95.76.111.99.97.108|2|27
1.3.6.1.4.1.2011.5.25.111.2.3.1.8.6.65.100.109.105.110.50.13.84.69.83.84.95.76.110.109.115.95.78.101.103|2|24
1.3.6.1.6.3.10.2.1.3.0|2|20380155