Issues (2963)

includes/html/graphs/port/cbqos_generic.inc.php (1 issue)

1
<?php
2
/*
3
 * LibreNMS module to display Cisco Class-Based QoS Details
4
 *
5
 * Copyright (c) 2015 Aaron Daniels <[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
$options = [];
16
$options['filter']['type'] = ['=', 'Cisco-CBQOS'];
17
$components = $component->getComponents($device['device_id'], $options);
18
19
// We only care about our device id.
20
$components = $components[$device['device_id']];
21
22
// Determine a policy to show.
23
if (! isset($vars['policy'])) {
24
    foreach ($components as $id => $array) {
25
        if (($array['qos-type'] == 1) && ($array['ifindex'] == $port['ifIndex']) && ($array['parent'] == 0)) {
26
            // Found the first policy
27
            $vars['policy'] = $id;
28
            continue;
29
        }
30
    }
31
}
32
33
include 'includes/html/graphs/common.inc.php';
34
$rrd_options .= ' -l 0 -E ';
35
$rrd_options .= " COMMENT:'Class-Map              Now      Avg      Max\\n'";
36
$rrd_additions = '';
37
38
$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

38
$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...
39
$count = 0;
40
41
d_echo('<pre>Policy: ' . $vars['policy']);
42
d_echo("\nSP-OBJ: " . $components[$vars['policy']]['sp-obj']);
43
foreach ($components as $id => $array) {
44
    $addtograph = false;
45
46
    // We only care about children of the selected policy.
47
    if (($array['qos-type'] == 2) && ($array['parent'] == $components[$vars['policy']]['sp-obj']) && ($array['sp-id'] == $components[$vars['policy']]['sp-id'])) {
48
        // Are we trying to only graph a single class?
49
        if (isset($vars['class'])) {
50
            // Yes, is this the selected class
51
            if ($vars['class'] == $id) {
52
                $addtograph = true;
53
            }
54
        } else {
55
            // No, Graph everything
56
            $addtograph = true;
57
        }
58
59
        // Add the class map to the graph
60
        if ($addtograph === true) {
61
            d_echo("\n  Class: " . $components[$id]['label'] . "\t+ added to the graph");
62
            $rrd_filename = Rrd::name($device['hostname'], ['port', $array['ifindex'], 'cbqos', $array['sp-id'], $array['sp-obj']]);
63
64
            if (Rrd::checkRrdExists($rrd_filename)) {
65
                // Stack the area on the second and subsequent DS's
66
                $stack = '';
67
                if ($count != 0) {
68
                    $stack = ':STACK ';
69
                }
70
71
                // Grab a colour from the array.
72
                if (isset($colours[$count])) {
73
                    $colour = $colours[$count];
74
                } else {
75
                    d_echo("\nError: Out of colours. Have: " . (count($colours) - 1) . ', Requesting:' . $count);
76
                }
77
78
                $rrd_additions .= ' DEF:DS' . $count . '=' . $rrd_filename . ':' . $cbqos_parameter_name . ':AVERAGE ';
79
                $rrd_additions .= ' CDEF:MOD' . $count . '=DS' . $count . ',' . $cbqos_operator_param . ',' . $cbqos_operator . ' ';
80
                $rrd_additions .= ' AREA:MOD' . $count . '#' . $colour . ":'" . str_pad(substr($components[$id]['label'], 0, 15), 15) . "'" . $stack;
81
                $rrd_additions .= ' GPRINT:MOD' . $count . ':LAST:%6.2lf%s ';
82
                $rrd_additions .= ' GPRINT:MOD' . $count . ':AVERAGE:%6.2lf%s ';
83
                $rrd_additions .= ' GPRINT:MOD' . $count . ":MAX:%6.2lf%s\\\l ";
84
85
                $count++;
86
            } // End if file exists
87
        } else {
88
            d_echo("\n  Class: " . $components[$id]['label'] . "\t- NOT added to the graph");
89
        } // End if addtograph
90
    }
91
}
92
d_echo('</pre>');
93
94
if ($rrd_additions == '') {
95
    // We didn't add any data sources.
96
    d_echo('<pre>No DS to add</pre>');
97
} else {
98
    $rrd_options .= $rrd_additions;
99
}
100