Issues (2963)

LibreNMS/OS/Vrp.php (2 issues)

1
<?php
2
/**
3
 * Vrp.php
4
 *
5
 * Huawei VRP
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 *
20
 * @link       https://www.librenms.org
21
 *
22
 * @copyright  2018 Tony Murray
23
 * @author     Tony Murray <[email protected]>
24
 */
25
26
namespace LibreNMS\OS;
27
28
use App\Models\Device;
29
use App\Models\Mempool;
30
use App\Models\PortsNac;
31
use App\Models\Sla;
32
use Carbon\Carbon;
33
use Illuminate\Support\Arr;
34
use Illuminate\Support\Str;
35
use LibreNMS\Device\Processor;
36
use LibreNMS\Device\WirelessSensor;
37
use LibreNMS\Interfaces\Discovery\MempoolsDiscovery;
38
use LibreNMS\Interfaces\Discovery\OSDiscovery;
39
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
40
use LibreNMS\Interfaces\Discovery\Sensors\WirelessApCountDiscovery;
41
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
42
use LibreNMS\Interfaces\Discovery\SlaDiscovery;
43
use LibreNMS\Interfaces\Polling\NacPolling;
44
use LibreNMS\Interfaces\Polling\OSPolling;
45
use LibreNMS\Interfaces\Polling\SlaPolling;
46
use LibreNMS\OS;
47
use LibreNMS\RRD\RrdDefinition;
48
49
class Vrp extends OS implements
50
    MempoolsDiscovery,
51
    OSPolling,
52
    ProcessorDiscovery,
53
    NacPolling,
54
    WirelessApCountDiscovery,
55
    WirelessClientsDiscovery,
56
    SlaDiscovery,
57
    SlaPolling,
58
    OSDiscovery
59
{
60
    public function discoverMempools()
61
    {
62
        $mempools = collect();
63
        $mempools_array = snmpwalk_cache_multi_oid($this->getDeviceArray(), 'hwEntityMemUsage', [], 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
64
        $mempools_array = snmpwalk_cache_multi_oid($this->getDeviceArray(), 'hwEntityMemSize', $mempools_array, 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
65
        $mempools_array = snmpwalk_cache_multi_oid($this->getDeviceArray(), 'hwEntityBomEnDesc', $mempools_array, 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
66
        $mempools_array = snmpwalk_cache_multi_oid($this->getDeviceArray(), 'hwEntityMemSizeMega', $mempools_array, 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
67
        $mempools_array = snmpwalk_cache_multi_oid($this->getDeviceArray(), 'entPhysicalName', $mempools_array, 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
68
69
        foreach (Arr::wrap($mempools_array) as $index => $entry) {
70
            $size = empty($entry['hwEntityMemSizeMega']) ? $entry['hwEntityMemSize'] : $entry['hwEntityMemSizeMega'];
71
            $descr = empty($entry['entPhysicalName']) ? $entry['hwEntityBomEnDesc'] : $entry['entPhysicalName'];
72
73
            if ($size != 0 && $descr && ! Str::contains($descr, 'No') && ! Str::contains($entry['hwEntityMemUsage'], 'No')) {
74
                $mempools->push((new Mempool([
75
                    'mempool_index' => $index,
76
                    'mempool_type' => 'vrp',
77
                    'mempool_class' => 'system',
78
                    'mempool_precision' => empty($entry['hwEntityMemSizeMega']) ? 1 : 1048576,
79
                    'mempool_descr' => substr("$descr Memory", 0, 64),
80
                    'mempool_perc_oid' => ".1.3.6.1.4.1.2011.5.25.31.1.1.1.1.7.$index",
81
                    'mempool_perc_warn' => 90,
82
                ]))->fillUsage(null, $size, null, $entry['hwEntityMemUsage']));
83
            }
84
        }
85
86
        return $mempools;
87
    }
88
89
    public function discoverOS(Device $device): void
90
    {
91
        parent::discoverOS($device); // yaml
92
93
        //Huawei VRP devices are not providing the HW description in a unified way
94
        preg_match('/Version (\S+)/', $device->sysDescr, $matches);
95
        $device->version = isset($matches[1]) ? ($matches[1] . ($device->version ? " ($device->version)" : '')) : null; // version from yaml sysDescr
96
97
        if ($device->version) {
98
            $patch = snmp_getnext($this->getDeviceArray(), 'HUAWEI-SYS-MAN-MIB::hwPatchVersion', '-OQv');
99
            if ($patch) {
100
                $device->version .= " [$patch]";
101
            }
102
        }
103
104
        if ($device->hardware && preg_match("/$device->hardware\S+/", $device->sysDescr, $matches)) {
105
            $device->hardware = $matches[0];
106
        }
107
    }
108
109
    public function pollOS()
110
    {
111
        // Polling the Wireless data TODO port to module
112
        $apTable = snmpwalk_group($this->getDeviceArray(), 'hwWlanApName', 'HUAWEI-WLAN-AP-MIB', 2);
113
114
        //Check for existence of at least 1 AP to continue the polling)
115
        if (! empty($apTable)) {
116
            $apTableOids = [
117
                'hwWlanApSn',
118
                'hwWlanApTypeInfo',
119
            ];
120
            foreach ($apTableOids as $apTableOid) {
121
                $apTable = snmpwalk_group($this->getDeviceArray(), $apTableOid, 'HUAWEI-WLAN-AP-MIB', 2, $apTable);
122
            }
123
124
            $apRadioTableOids = [ // hwWlanRadioInfoTable
125
                'hwWlanRadioMac',
126
                'hwWlanRadioChUtilizationRate',
127
                'hwWlanRadioChInterferenceRate',
128
                'hwWlanRadioActualEIRP',
129
                'hwWlanRadioFreqType',
130
                'hwWlanRadioWorkingChannel',
131
            ];
132
133
            $clientPerRadio = [];
134
            $radioTable = [];
135
            foreach ($apRadioTableOids as $apRadioTableOid) {
136
                $radioTable = snmpwalk_group($this->getDeviceArray(), $apRadioTableOid, 'HUAWEI-WLAN-AP-RADIO-MIB', 2, $radioTable);
137
            }
138
139
            $numClients = 0;
140
            $vapInfoTable = snmpwalk_group($this->getDeviceArray(), 'hwWlanVapStaOnlineCnt', 'HUAWEI-WLAN-VAP-MIB', 3);
141
            foreach ($vapInfoTable as $ap_id => $ap) {
142
                //Convert mac address (hh:hh:hh:hh:hh:hh) to dec OID (ddd.ddd.ddd.ddd.ddd.ddd)
143
                //$a_index_oid = implode(".", array_map("hexdec", explode(":", $ap_id)));
144
                foreach ($ap as $r_id => $radio) {
145
                    foreach ($radio as $s_index => $ssid) {
146
                        $clientPerRadio[$ap_id][$r_id] += $ssid['hwWlanVapStaOnlineCnt'];
147
                        $numClients += $ssid['hwWlanVapStaOnlineCnt'];
148
                    }
149
                }
150
            }
151
152
            $numRadios = count($radioTable);
153
154
            $rrd_def = RrdDefinition::make()
155
                ->addDataset('NUMAPS', 'GAUGE', 0, 12500000000)
156
                ->addDataset('NUMCLIENTS', 'GAUGE', 0, 12500000000);
157
158
            $fields = [
159
                'NUMAPS' => $numRadios,
160
                'NUMCLIENTS' => $numClients,
161
            ];
162
163
            $tags = compact('rrd_def');
164
            data_update($this->getDeviceArray(), 'vrp', $tags, $fields);
165
166
            $ap_db = dbFetchRows('SELECT * FROM `access_points` WHERE `device_id` = ?', [$this->getDeviceArray()['device_id']]);
167
168
            foreach ($radioTable as $ap_id => $ap) {
169
                foreach ($ap as $r_id => $radio) {
170
                    $channel = $radio['hwWlanRadioWorkingChannel'];
171
                    $mac = $radio['hwWlanRadioMac'];
172
                    $name = $apTable[$ap_id]['hwWlanApName'] . ' Radio ' . $r_id;
173
                    $radionum = $r_id;
174
                    $txpow = $radio['hwWlanRadioActualEIRP'];
175
                    $interference = $radio['hwWlanRadioChInterferenceRate'];
176
                    $radioutil = $radio['hwWlanRadioChUtilizationRate'];
177
                    $numasoclients = $clientPerRadio[$ap_id][$r_id];
178
179
                    switch ($radio['hwWlanRadioFreqType']) {
180
                        case 1:
181
                            $type = '2.4Ghz';
182
                            break;
183
                        case 2:
184
                            $type = '5Ghz';
185
                            break;
186
                        default:
187
                            $type = 'unknown (huawei ' . $radio['hwWlanRadioFreqType'] . ')';
188
                    }
189
190
                    // TODO
191
                    $numactbssid = 0;
192
                    $nummonbssid = 0;
193
                    $nummonclients = 0;
194
195
                    d_echo("  name: $name\n");
196
                    d_echo("  radionum: $radionum\n");
197
                    d_echo("  type: $type\n");
198
                    d_echo("  channel: $channel\n");
199
                    d_echo("  txpow: $txpow\n");
200
                    d_echo("  radioutil: $radioutil\n");
201
                    d_echo("  numasoclients: $numasoclients\n");
202
                    d_echo("  interference: $interference\n");
203
204
                    $rrd_name = ['arubaap', $name . $radionum];
205
                    $rrd_def = RrdDefinition::make()
206
                        ->addDataset('channel', 'GAUGE', 0, 200)
207
                        ->addDataset('txpow', 'GAUGE', 0, 200)
208
                        ->addDataset('radioutil', 'GAUGE', 0, 100)
209
                        ->addDataset('nummonclients', 'GAUGE', 0, 500)
210
                        ->addDataset('nummonbssid', 'GAUGE', 0, 200)
211
                        ->addDataset('numasoclients', 'GAUGE', 0, 500)
212
                        ->addDataset('interference', 'GAUGE', 0, 2000);
213
214
                    $fields = [
215
                        'channel' => $channel,
216
                        'txpow' => $txpow,
217
                        'radioutil' => $radioutil,
218
                        'nummonclients' => $nummonclients,
219
                        'nummonbssid' => $nummonbssid,
220
                        'numasoclients' => $numasoclients,
221
                        'interference' => $interference,
222
                    ];
223
224
                    $tags = compact('name', 'radionum', 'rrd_name', 'rrd_def');
225
                    data_update($this->getDeviceArray(), 'arubaap', $tags, $fields);
226
227
                    $foundid = 0;
228
229
                    for ($z = 0; $z < sizeof($ap_db); $z++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function sizeof() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
230
                        if ($ap_db[$z]['name'] == $name && $ap_db[$z]['radio_number'] == $radionum) {
231
                            $foundid = $ap_db[$z]['accesspoint_id'];
232
                            $ap_db[$z]['seen'] = 1;
233
                            continue;
234
                        }
235
                    }
236
237
                    if ($foundid == 0) {
238
                        $ap_id = dbInsert(
239
                            [
240
                                'device_id' => $this->getDeviceArray()['device_id'],
241
                                'name' => $name,
242
                                'radio_number' => $radionum,
243
                                'type' => $type,
244
                                'mac_addr' => $mac,
245
                                'channel' => $channel,
246
                                'txpow' => $txpow,
247
                                'radioutil' => $radioutil,
248
                                'numasoclients' => $numasoclients,
249
                                'nummonclients' => $nummonclients,
250
                                'numactbssid' => $numactbssid,
251
                                'nummonbssid' => $nummonbssid,
252
                                'interference' => $interference,
253
                            ],
254
                            'access_points'
255
                        );
256
                    } else {
257
                        dbUpdate(
258
                            [
259
                                'mac_addr' => $mac,
260
                                'type' => $type,
261
                                'deleted' => 0,
262
                                'channel' => $channel,
263
                                'txpow' => $txpow,
264
                                'radioutil' => $radioutil,
265
                                'numasoclients' => $numasoclients,
266
                                'nummonclients' => $nummonclients,
267
                                'numactbssid' => $numactbssid,
268
                                'nummonbssid' => $nummonbssid,
269
                                'interference' => $interference,
270
                            ],
271
                            'access_points',
272
                            '`accesspoint_id` = ?',
273
                            [$foundid]
274
                        );
275
                    }
276
                }//end foreach 1
277
            }//end foreach 2
278
279
            for ($z = 0; $z < sizeof($ap_db); $z++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function sizeof() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
280
                if (! isset($ap_db[$z]['seen']) && $ap_db[$z]['deleted'] == 0) {
281
                    dbUpdate(['deleted' => 1], 'access_points', '`accesspoint_id` = ?', [$ap_db[$z]['accesspoint_id']]);
282
                }
283
            }
284
        }
285
    }
286
287
    /**
288
     * Discover processors.
289
     * Returns an array of LibreNMS\Device\Processor objects that have been discovered
290
     *
291
     * @return array Processors
292
     */
293
    public function discoverProcessors()
294
    {
295
        $device = $this->getDeviceArray();
296
297
        $processors_data = snmpwalk_cache_multi_oid($device, 'hwEntityCpuUsage', [], 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
298
299
        if (! empty($processors_data)) {
300
            $processors_data = snmpwalk_cache_multi_oid($device, 'hwEntityMemSize', $processors_data, 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
301
            $processors_data = snmpwalk_cache_multi_oid($device, 'hwEntityBomEnDesc', $processors_data, 'HUAWEI-ENTITY-EXTENT-MIB', 'huawei');
302
        }
303
304
        d_echo($processors_data);
305
306
        $processors = [];
307
        foreach ($processors_data as $index => $entry) {
308
            if ($entry['hwEntityMemSize'] != 0) {
309
                d_echo($index . ' ' . $entry['hwEntityBomEnDesc'] . ' -> ' . $entry['hwEntityCpuUsage'] . ' -> ' . $entry['hwEntityMemSize'] . "\n");
310
311
                $usage_oid = '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1.5.' . $index;
312
                $descr = $entry['hwEntityBomEnDesc'];
313
                $usage = $entry['hwEntityCpuUsage'];
314
315
                if (empty($descr) || Str::contains($descr, 'No') || Str::contains($usage, 'No')) {
316
                    continue;
317
                }
318
319
                $processors[] = Processor::discover(
320
                    $this->getName(),
321
                    $this->getDeviceId(),
322
                    $usage_oid,
323
                    $index,
324
                    $descr,
325
                    1,
326
                    $usage
327
                );
328
            }
329
        }
330
331
        return $processors;
332
    }
333
334
    /**
335
     * Discover the Network Access Control informations (dot1X etc etc)
336
     */
337
    public function pollNac()
338
    {
339
        $nac = collect();
340
        // We collect the first table
341
        $portAuthSessionEntry = snmpwalk_cache_oid($this->getDeviceArray(), 'hwAccessInterface', [], 'HUAWEI-AAA-MIB');
342
343
        if (! empty($portAuthSessionEntry)) {
344
            // If it is not empty, lets add all the necessary OIDs
345
            $hwAccessOids = [
346
                'hwAccessMACAddress',
347
                'hwAccessDomain',
348
                'hwAccessUserName',
349
                'hwAccessIPAddress',
350
                'hwAccessType',
351
                'hwAccessAuthorizetype',
352
                'hwAccessSessionTimeout',
353
                'hwAccessOnlineTime',
354
                'hwAccessCurAuthenPlace',
355
                'hwAccessAuthtype',
356
                'hwAccessVLANID',
357
            ];
358
            foreach ($hwAccessOids as $hwAccessOid) {
359
                $portAuthSessionEntry = snmpwalk_cache_oid($this->getDeviceArray(), $hwAccessOid, $portAuthSessionEntry, 'HUAWEI-AAA-MIB');
360
            }
361
            // We cache a port_ifName -> port_id map
362
            $ifName_map = $this->getDevice()->ports()->pluck('port_id', 'ifName');
363
364
            // update the DB
365
            foreach ($portAuthSessionEntry as $authId => $portAuthSessionEntryParameters) {
366
                $mac_address = strtolower(implode(array_map('zeropad', explode(':', $portAuthSessionEntryParameters['hwAccessMACAddress']))));
367
                $port_id = $ifName_map->get($portAuthSessionEntryParameters['hwAccessInterface'], 0);
368
                if ($port_id <= 0) {
369
                    continue; //this would happen for an SSH session for instance
370
                }
371
                $nac->put($mac_address, new PortsNac([
372
                    'port_id' => $ifName_map->get($portAuthSessionEntryParameters['hwAccessInterface'], 0),
373
                    'mac_address' => $mac_address,
374
                    'auth_id' => $authId,
375
                    'domain' => $portAuthSessionEntryParameters['hwAccessDomain'],
376
                    'username' => '' . $portAuthSessionEntryParameters['hwAccessUserName'],
377
                    'ip_address' => $portAuthSessionEntryParameters['hwAccessIPAddress'],
378
                    'authz_by' => '' . $portAuthSessionEntryParameters['hwAccessType'],
379
                    'authz_status' => '' . $portAuthSessionEntryParameters['hwAccessAuthorizetype'],
380
                    'host_mode' => is_null($portAuthSessionEntryParameters['hwAccessAuthType']) ? 'default' : $portAuthSessionEntryParameters['hwAccessAuthType'],
381
                    'timeout' => $portAuthSessionEntryParameters['hwAccessSessionTimeout'],
382
                    'time_elapsed' => $portAuthSessionEntryParameters['hwAccessOnlineTime'],
383
                    'authc_status' => $portAuthSessionEntryParameters['hwAccessCurAuthenPlace'],
384
                    'method' => '' . $portAuthSessionEntryParameters['hwAccessAuthtype'],
385
                    'vlan' => $portAuthSessionEntryParameters['hwAccessVLANID'],
386
                ]));
387
            }
388
        }
389
390
        return $nac;
391
    }
392
393
    public function discoverWirelessApCount()
394
    {
395
        $sensors = [];
396
        $ap_number = snmpwalk_cache_oid($this->getDeviceArray(), 'hwWlanCurJointApNum.0', [], 'HUAWEI-WLAN-GLOBAL-MIB');
397
398
        $sensors[] = new WirelessSensor(
399
            'ap-count',
400
            $this->getDeviceId(),
401
            '.1.3.6.1.4.1.2011.6.139.12.1.2.1.0',
402
            'vrp-ap-count',
403
            'ap-count',
404
            'AP Count',
405
            $ap_number[0]['hwWlanCurJointApNum']
406
        );
407
408
        return $sensors;
409
    }
410
411
    public function discoverWirelessClients()
412
    {
413
        $sensors = [];
414
415
        $staTable = snmpwalk_cache_oid($this->getDeviceArray(), 'hwWlanSsid2gStaCnt', [], 'HUAWEI-WLAN-VAP-MIB');
416
        $staTable = snmpwalk_cache_oid($this->getDeviceArray(), 'hwWlanSsid5gStaCnt', $staTable, 'HUAWEI-WLAN-VAP-MIB');
417
418
        //Map OIDs and description
419
        $oidMap = [
420
            'hwWlanSsid5gStaCnt' => '.1.3.6.1.4.1.2011.6.139.17.1.2.1.3.',
421
            'hwWlanSsid2gStaCnt' => '.1.3.6.1.4.1.2011.6.139.17.1.2.1.2.',
422
        ];
423
        $descrMap = [
424
            'hwWlanSsid5gStaCnt' => '5 GHz',
425
            'hwWlanSsid2gStaCnt' => '2.4 GHz',
426
        ];
427
        $ssid_total_oid_array = []; // keep all OIDs so we can compute the total of all STA
428
429
        foreach ($staTable as $ssid => $sta) {
430
            //Convert string to num_oid
431
            $numSsid = strlen($ssid) . '.' . implode('.', unpack('c*', $ssid));
432
            $ssid_oid_array = []; // keep all OIDs of different freqs for a single SSID, to compute each SSID sta count, all freqs included
433
            foreach ($sta as $staFreq => $count) {
434
                $oid = $oidMap[$staFreq] . $numSsid;
435
                $ssid_oid_array[] = $oid;
436
                $ssid_total_oid_array[] = $oid;
437
                $sensors[] = new WirelessSensor(
438
                    'clients',
439
                    $this->getDeviceId(),
440
                    $oid,
441
                    'vrpi-clients',
442
                    $staFreq . '-' . $ssid,
443
                    'SSID: ' . $ssid . ' (' . $descrMap[$staFreq] . ')',
444
                    $count,
445
                    1,
446
                    1,
447
                    'sum'
448
                );
449
            }
450
451
            // And we add a sensor with all frequencies for each SSID
452
            $sensors[] = new WirelessSensor(
453
                'clients',
454
                $this->getDeviceId(),
455
                $ssid_oid_array,
456
                'vrp-clients',
457
                'total-' . $ssid,
458
                'SSID: ' . $ssid,
459
                0,
460
                1,
461
                1,
462
                'sum'
463
            );
464
        }
465
        if (count($ssid_total_oid_array) > 0) {
466
            // We have at least 1 SSID, so we can count the total of STA
467
            $sensors[] = new WirelessSensor(
468
                'clients',
469
                    $this->getDeviceId(),
470
                $ssid_total_oid_array,
471
                'vrp-clients',
472
                'total-all-ssids',
473
                'Total Clients',
474
                0,
475
                1,
476
                1,
477
                'sum'
478
            );
479
        }
480
481
        return $sensors;
482
    }
483
484
    public function discoverSlas()
485
    {
486
        $slas = collect();
487
        // Get the index of the last finished test
488
        // NQA-MIB::nqaScheduleLastFinishIndex
489
490
        $sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'pingCtlTable', [], 'DISMAN-PING-MIB');
491
492
        if (! empty($sla_table)) {
493
            $sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'nqaAdminCtrlType', $sla_table, 'NQA-MIB');
494
            $sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'nqaAdminParaTimeUnit', $sla_table, 'NQA-MIB');
495
            $sla_table = snmpwalk_cache_oid($this->getDeviceArray(), 'nqaScheduleLastFinishIndex', $sla_table, 'NQA-MIB');
496
        }
497
498
        foreach ($sla_table as $sla_key => $sla_config) {
499
            [$owner, $test] = explode('.', $sla_key, 2);
500
501
            $slas->push(new Sla([
502
                'sla_nr' => hexdec(hash('crc32', $owner . $test)), // indexed by owner+test, convert to int
503
                'owner' => $owner,
504
                'tag' => $test,
505
                'rtt_type' => $sla_config['nqaAdminCtrlType'] ?? '',
506
                'rtt' => isset($sla_config['pingResultsAverageRtt']) ? $sla_config['pingResultsAverageRtt'] / 1000 : null,
507
                'status' => ($sla_config['pingCtlAdminStatus'] == 'enabled') ? 1 : 0,
508
                'opstatus' => ($sla_config['pingCtlRowStatus'] == 'active') ? 0 : 2,
509
            ]));
510
        }
511
512
        return $slas;
513
    }
514
515
    public function pollSlas($slas)
516
    {
517
        $device = $this->getDeviceArray();
518
519
        // Go get some data from the device.
520
        $data = snmpwalk_group($device, 'pingCtlRowStatus', 'DISMAN-PING-MIB', 2);
521
        $data = snmpwalk_group($device, 'pingResultsProbeResponses', 'DISMAN-PING-MIB', 2, $data);
522
        $data = snmpwalk_group($device, 'pingResultsSentProbes', 'DISMAN-PING-MIB', 2, $data);
523
        //$data = snmpwalk_group($device, 'nqaScheduleLastFinishIndex', 'NQA-MIB', 2, $data);
524
        //$data = snmpwalk_group($device, 'pingResultsMinRtt', 'DISMAN-PING-MIB', 2, $data);
525
        //$data = snmpwalk_group($device, 'pingResultsMaxRtt', 'DISMAN-PING-MIB', 2, $data);
526
        $data = snmpwalk_group($device, 'pingResultsAverageRtt', 'DISMAN-PING-MIB', 2, $data);
527
528
        // Get the needed information
529
        foreach ($slas as $sla) {
530
            $sla_nr = $sla->sla_nr;
531
            $rtt_type = $sla->rtt_type;
532
            $owner = $sla->owner;
533
            $test = $sla->tag;
534
            $divisor = 1; //values are already returned in ms, and RRD expects them in ms
535
536
            // Use DISMAN-PING Status codes. 0=Good 2=Critical
537
            $sla->opstatus = $data[$owner][$test]['pingCtlRowStatus'] == '1' ? 0 : 2;
538
539
            $sla->rtt = $data[$owner][$test]['pingResultsAverageRtt'] / $divisor;
540
            $time = Carbon::parse($data[$owner][$test]['pingResultsLastGoodProbe'])->toDateTimeString();
541
            echo 'SLA : ' . $rtt_type . ' ' . $owner . ' ' . $test . '... ' . $sla->rtt . 'ms at ' . $time . "\n";
542
543
            $fields = [
544
                'rtt' => $sla->rtt,
545
            ];
546
547
            // The base RRD
548
            $rrd_name = ['sla', $sla['sla_nr']];
549
            $rrd_def = RrdDefinition::make()->addDataset('rtt', 'GAUGE', 0, 300000);
550
            $tags = compact('sla_nr', 'rrd_name', 'rrd_def');
551
            data_update($device, 'sla', $tags, $fields);
552
553
            // Let's gather some per-type fields.
554
            switch ($rtt_type) {
555
                case 'icmpAppl':
556
                    $icmp = [
557
                        //'MinRtt' => $data[$owner][$test]['pingResultsMinRtt'] / $divisor,
558
                        //'MaxRtt' => $data[$owner][$test]['pingResultsMaxRtt'] / $divisor,
559
                        'ProbeResponses' => $data[$owner][$test]['pingResultsProbeResponses'],
560
                        'ProbeLoss' => (int) $data[$owner][$test]['pingResultsSentProbes'] - (int) $data[$owner][$test]['pingResultsProbeResponses'],
561
                    ];
562
                    $rrd_name = ['sla', $sla_nr, $rtt_type];
563
                    $rrd_def = RrdDefinition::make()
564
                        //->addDataset('MinRtt', 'GAUGE', 0, 300000)
565
                        //->addDataset('MaxRtt', 'GAUGE', 0, 300000)
566
                        ->addDataset('ProbeResponses', 'GAUGE', 0, 300000)
567
                        ->addDataset('ProbeLoss', 'GAUGE', 0, 300000);
568
                    $tags = compact('rrd_name', 'rrd_def', 'sla_nr', 'rtt_type');
569
                    data_update($device, 'sla', $tags, $icmp);
570
                    $fields = array_merge($fields, $icmp);
571
                    break;
572
            }
573
574
            d_echo('The following datasources were collected for #' . $sla['sla_nr'] . ":\n");
575
            d_echo($fields);
576
        }
577
    }
578
}
579