Issues (2963)

graphs/device/bigip_ltm_allpm_currconns.inc.php (3 issues)

1
<?php
2
/*
3
 * LibreNMS module to display F5 LTM Virtual Server Details
4
 *
5
 * Copyright (c) 2021 Martin Bergström <[email protected]>
6
 *
7
 * This program is free software: you can redistribute it and/or modify it
8
 * under the terms of the GNU General Public License as published by the
9
 * Free Software Foundation, either version 3 of the License, or (at your
10
 * option) any later version.  Please see LICENSE.txt at the top level of
11
 * the source code distribution for details.
12
 */
13
14
$component = new LibreNMS\Component();
15
$components = $component->getComponents($device['device_id']);
16
17
// We only care about our device id.
18
$components = $components[$device['device_id']];
19
20
// We extracted all the components for this device, now lets only get the LTM ones.
21
$keep = [];
22
$types = ['f5-ltm-pool', 'f5-ltm-poolmember'];
23
foreach ($components as $k => $v) {
24
    foreach ($types as $type) {
25
        if ($v['type'] == $type) {
26
            $keep[$k] = $v;
27
        }
28
    }
29
}
30
$components = $keep;
31
32
include 'includes/html/graphs/common.inc.php';
33
$rrd_options .= ' -l 0 -E ';
34
$rrd_options .= " COMMENT:'LTM Pool Members                               Now      Avg      Max\\n'";
35
$colours = array_merge(\LibreNMS\Config::get('graph_colours.mixed'), \LibreNMS\Config::get('graph_colours.manycolours'), \LibreNMS\Config::get('graph_colours.manycolours'));
0 ignored issues
show
It seems like LibreNMS\Config::get('graph_colours.mixed') can also be of type null; however, parameter $arrays of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
$colours = array_merge(/** @scrutinizer ignore-type */ \LibreNMS\Config::get('graph_colours.mixed'), \LibreNMS\Config::get('graph_colours.manycolours'), \LibreNMS\Config::get('graph_colours.manycolours'));
Loading history...
36
$count = 0;
37
d_echo('<pre>');
38
39
// Is the ID we are looking for a valid LTM VS Pool
40
if ($components[$vars['id']]['type'] == 'f5-ltm-pool') {
41
    $parent = $components[$vars['id']]['UID'];
42
43
    // Find all pool members
44
    foreach ($components as $compid => $comp) {
45
        if ($comp['type'] != 'f5-ltm-poolmember') {
46
            continue;
47
        }
48
        if (! strstr($comp['UID'], $parent)) {
49
            continue;
50
        }
51
52
        $label = $comp['label'];
53
        $hash = $comp['hash'];
54
        $rrd_filename = Rrd::name($device['hostname'], [$comp['type'], $label, $hash, 'currconns']);
0 ignored issues
show
The method name() does not exist on App\Facades\Rrd. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        /** @scrutinizer ignore-call */ 
55
        $rrd_filename = Rrd::name($device['hostname'], [$comp['type'], $label, $hash, 'currconns']);
Loading history...
55
        if (Rrd::checkRrdExists($rrd_filename)) {
0 ignored issues
show
The method checkRrdExists() does not exist on App\Facades\Rrd. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        if (Rrd::/** @scrutinizer ignore-call */ checkRrdExists($rrd_filename)) {
Loading history...
56
            d_echo("\n  Adding PM: " . $label . "\t+ added to the graph");
57
58
            // Grab a colour from the array.
59
            if (isset($colours[$count])) {
60
                $colour = $colours[$count];
61
            } else {
62
                d_echo("\nError: Out of colours. Have: " . (count($colours) - 1) . ', Requesting:' . $count);
63
            }
64
65
            $rrd_options .= ' DEF:DS' . $count . '=' . $rrd_filename . ':currconns:AVERAGE ';
66
            $rrd_options .= ' LINE1.25:DS' . $count . '#' . $colour . ":'" . str_pad(substr($label, 0, 40), 40) . "'";
67
            $rrd_options .= ' GPRINT:DS' . $count . ':LAST:%6.2lf%s ';
68
            $rrd_options .= ' GPRINT:DS' . $count . ':AVERAGE:%6.2lf%s ';
69
            $rrd_options .= ' GPRINT:DS' . $count . ":MAX:%6.2lf%s\l ";
70
            $count++;
71
        }
72
    } // End Foreach
73
}
74
d_echo('</pre>');
75