From 7e2ce6179abd019d990c3cee455b553435705865 Mon Sep 17 00:00:00 2001 From: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com> Date: Sat, 3 Jul 2021 15:16:38 +0200 Subject: [PATCH] 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 --- LibreNMS/OS/Vrp.php | 101 ++++++++++++++++++ includes/definitions/vrp.yaml | 4 + includes/html/graphs/device/sla.inc.php | 4 +- .../html/graphs/device/sla_icmpAppl.inc.php | 34 ++++++ .../html/pages/device/sla/icmpAppl.inc.php | 15 +++ includes/html/pages/device/slas.inc.php | 2 +- tests/data/vrp_slas.json | 73 +++++++++++++ tests/snmpsim/vrp_slas.snmprec | 59 ++++++++++ 8 files changed, 289 insertions(+), 3 deletions(-) create mode 100644 includes/html/graphs/device/sla_icmpAppl.inc.php create mode 100644 includes/html/pages/device/sla/icmpAppl.inc.php create mode 100644 tests/data/vrp_slas.json create mode 100644 tests/snmpsim/vrp_slas.snmprec diff --git a/LibreNMS/OS/Vrp.php b/LibreNMS/OS/Vrp.php index 694e4265e4..222c664bae 100644 --- a/LibreNMS/OS/Vrp.php +++ b/LibreNMS/OS/Vrp.php @@ -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); + } + } } diff --git a/includes/definitions/vrp.yaml b/includes/definitions/vrp.yaml index 66c9538878..3d6626dd23 100644 --- a/includes/definitions/vrp.yaml +++ b/includes/definitions/vrp.yaml @@ -15,3 +15,7 @@ discovery: - VRP Software Version - Software Version VRP - Versatile Routing Platform Software +poller_modules: + slas: true +discovery_modules: + slas: true diff --git a/includes/html/graphs/device/sla.inc.php b/includes/html/graphs/device/sla.inc.php index 1d22313c00..5ac2330bb9 100644 --- a/includes/html/graphs/device/sla.inc.php +++ b/includes/html/graphs/device/sla.inc.php @@ -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 '; diff --git a/includes/html/graphs/device/sla_icmpAppl.inc.php b/includes/html/graphs/device/sla_icmpAppl.inc.php new file mode 100644 index 0000000000..736be701c5 --- /dev/null +++ b/includes/html/graphs/device/sla_icmpAppl.inc.php @@ -0,0 +1,34 @@ + +

Packet Loss

+ +
+ +
diff --git a/includes/html/pages/device/slas.inc.php b/includes/html/pages/device/slas.inc.php index 1840d9d3d5..af633e8135 100644 --- a/includes/html/pages/device/slas.inc.php +++ b/includes/html/pages/device/slas.inc.php @@ -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 = '' . $name . ''; } else { $name = htmlentities($name); diff --git a/tests/data/vrp_slas.json b/tests/data/vrp_slas.json new file mode 100644 index 0000000000..fbafe2f37e --- /dev/null +++ b/tests/data/vrp_slas.json @@ -0,0 +1,73 @@ +{ + "os": { + "discovery": { + "devices": [ + { + "sysName": "", + "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 + } + ] + } + } +} diff --git a/tests/snmpsim/vrp_slas.snmprec b/tests/snmpsim/vrp_slas.snmprec new file mode 100644 index 0000000000..78e5b9f10f --- /dev/null +++ b/tests/snmpsim/vrp_slas.snmprec @@ -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| +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