Issues (2963)

includes/html/graphs/generic_duplex.inc.php (1 issue)

1
<?php
2
/*
3
 * This program is free software: you can redistribute it and/or modify it
4
 * under the terms of the GNU General Public License as published by the
5
 * Free Software Foundation, either version 3 of the License, or (at your
6
 * option) any later version.  Please see LICENSE.txt at the top level of
7
 * the source code distribution for details.
8
 *
9
 * @package    LibreNMS
10
 * @subpackage graphs
11
 * @link       https://www.librenms.org
12
 * @copyright  2017 LibreNMS
13
 * @author     LibreNMS Contributors
14
*/
15
16
require 'includes/html/graphs/common.inc.php';
17
18
$stacked = generate_stacked_graphs();
19
20
$length = '10';
21
22
if (! isset($percentile)) {
23
    $length += '2';
24
}
25
26
if (! isset($out_text)) {
27
    $out_text = 'Out';
28
}
29
30
if (! isset($in_text)) {
31
    $in_text = 'In';
32
}
33
34
$unit_text = str_pad(truncate($unit_text, $length), $length);
0 ignored issues
show
It seems like truncate($unit_text, $length) can also be of type array; however, parameter $string of str_pad() does only seem to accept string, 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

34
$unit_text = str_pad(/** @scrutinizer ignore-type */ truncate($unit_text, $length), $length);
Loading history...
35
$in_text = str_pad(truncate($in_text, $length), $length);
36
$out_text = str_pad(truncate($out_text, $length), $length);
37
38
$rrd_options .= ' DEF:' . $out . '=' . $rrd_filename . ':' . $ds_out . ':AVERAGE';
39
$rrd_options .= ' DEF:' . $in . '=' . $rrd_filename . ':' . $ds_in . ':AVERAGE';
40
$rrd_options .= ' DEF:' . $out . '_max=' . $rrd_filename . ':' . $ds_out . ':MAX';
41
$rrd_options .= ' DEF:' . $in . '_max=' . $rrd_filename . ':' . $ds_in . ':MAX';
42
$rrd_options .= ' CDEF:dout_max=out_max,' . $stacked['stacked'] . ',*';
43
$rrd_options .= ' CDEF:dout=out,' . $stacked['stacked'] . ',*';
44
$rrd_options .= ' CDEF:both=in,out,+';
45
if ($print_total) {
46
    $rrd_options .= ' VDEF:totin=in,TOTAL';
47
    $rrd_options .= ' VDEF:totout=out,TOTAL';
48
    $rrd_options .= ' VDEF:tot=both,TOTAL';
49
}
50
51
if ($percentile) {
52
    $rrd_options .= ' VDEF:percentile_in=in,' . $percentile . ',PERCENT';
53
    $rrd_options .= ' VDEF:percentile_out=out,' . $percentile . ',PERCENT';
54
    $rrd_options .= ' VDEF:dpercentile_out=dout,' . $percentile . ',PERCENT';
55
}
56
57
if ($graph_max) {
58
    $rrd_options .= ' AREA:in_max#' . $colour_area_in_max . $stacked['transparency'] . ':';
59
    $rrd_options .= ' AREA:dout_max#' . $colour_area_out_max . $stacked['transparency'] . ':';
60
}
61
62
if ($_GET['previous'] == 'yes') {
63
    $rrd_options .= ' DEF:' . $out . 'X=' . $rrd_filename . ':' . $ds_out . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
64
    $rrd_options .= ' DEF:' . $in . 'X=' . $rrd_filename . ':' . $ds_in . ':AVERAGE:start=' . $prev_from . ':end=' . $from;
65
    $rrd_options .= ' DEF:' . $out . '_maxX=' . $rrd_filename . ':' . $ds_out . ':MAX:start=' . $prev_from . ':end=' . $from;
66
    $rrd_options .= ' DEF:' . $in . '_maxX=' . $rrd_filename . ':' . $ds_in . ':MAX:start=' . $prev_from . ':end=' . $from;
67
    $rrd_options .= ' SHIFT:' . $out . "X:$period";
68
    $rrd_options .= ' SHIFT:' . $in . "X:$period";
69
    $rrd_options .= ' SHIFT:' . $out . "_maxX:$period";
70
    $rrd_options .= ' SHIFT:' . $in . "_maxX:$period";
71
72
    $rrd_options .= ' CDEF:dout_maxX=out_maxX,' . $stacked['stacked'] . ',*';
73
    $rrd_options .= ' CDEF:doutX=outX,' . $stacked['stacked'] . ',*';
74
    $rrd_options .= ' CDEF:bothX=inX,outX,+';
75
    if ($print_total) {
76
        $rrd_options .= ' VDEF:totinX=inX,TOTAL';
77
        $rrd_options .= ' VDEF:totoutX=outX,TOTAL';
78
        $rrd_options .= ' VDEF:totX=bothX,TOTAL';
79
    }
80
81
    if ($percentile) {
82
        $rrd_options .= ' VDEF:percentile_inX=inX,' . $percentile . ',PERCENT';
83
        $rrd_options .= ' VDEF:percentile_outX=outX,' . $percentile . ',PERCENT';
84
        $rrd_options .= ' VDEF:dpercentile_outX=doutX,' . $percentile . ',PERCENT';
85
    }
86
87
    if ($graph_max) {
88
        $rrd_options .= ' AREA:in_max#' . $colour_area_in_max . ':';
89
        $rrd_options .= ' AREA:dout_max#' . $colour_area_out_max . ':';
90
    }
91
}//end if
92
93
$rrd_options .= ' AREA:in#' . $colour_area_in . $stacked['transparency'] . ':';
94
$rrd_options .= " COMMENT:'" . $unit_text . '      Now       Ave      Max';
95
96
if ($percentile) {
97
    $rrd_options .= '      ' . $percentile . 'th %';
98
}
99
100
$rrd_options .= "\\n'";
101
$rrd_options .= ' LINE1.25:in#' . $colour_line_in . ":'" . $in_text . "'";
102
$rrd_options .= ' GPRINT:in:LAST:%6.' . $float_precision . 'lf%s';
103
$rrd_options .= ' GPRINT:in:AVERAGE:%6.' . $float_precision . 'lf%s';
104
$rrd_options .= ' GPRINT:in_max:MAX:%6.' . $float_precision . 'lf%s';
105
106
if ($percentile) {
107
    $rrd_options .= ' GPRINT:percentile_in:%6.' . $float_precision . 'lf%s';
108
}
109
110
$rrd_options .= ' COMMENT:\\n';
111
$rrd_options .= ' AREA:dout#' . $colour_area_out . $stacked['transparency'] . ':';
112
$rrd_options .= ' LINE1.25:dout#' . $colour_line_out . ":'" . $out_text . "'";
113
$rrd_options .= ' GPRINT:out:LAST:%6.' . $float_precision . 'lf%s';
114
$rrd_options .= ' GPRINT:out:AVERAGE:%6.' . $float_precision . 'lf%s';
115
$rrd_options .= ' GPRINT:out_max:MAX:%6.' . $float_precision . 'lf%s';
116
117
if ($percentile) {
118
    $rrd_options .= ' GPRINT:percentile_out:%6.' . $float_precision . 'lf%s';
119
}
120
121
$rrd_options .= ' COMMENT:\\n';
122
123
if ($print_total) {
124
    $rrd_options .= " GPRINT:tot:'Total %6." . $float_precision . "lf%s'";
125
    $rrd_options .= " GPRINT:totin:'(In %6." . $float_precision . "lf%s'";
126
    $rrd_options .= " GPRINT:totout:'Out %6." . $float_precision . "lf%s)\l'";
127
}
128
129
if ($percentile) {
130
    $rrd_options .= ' LINE1:percentile_in#aa0000';
131
    $rrd_options .= ' LINE1:dpercentile_out#aa0000';
132
}
133
134
if ($_GET['previous'] == 'yes') {
135
    $rrd_options .= ' LINE1.25:in' . $format . "X#666666:'Prev In \\\\n'";
136
    $rrd_options .= ' AREA:in' . $format . 'X#99999966' . $stacked['transparency'] . ':';
137
    $rrd_options .= ' LINE1.25:dout' . $format . "X#666666:'Prev Out'";
138
    $rrd_options .= ' AREA:dout' . $format . 'X#99999966' . $stacked['transparency'] . ':';
139
}
140
141
$rrd_options .= ' HRULE:0#999999';
142
143
unset($stacked);
144