Subversion Repositories vnag

Rev

Rev 39 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 39 Rev 52
1
<?php /* <ViaThinkSoftSignature>
1
<?php /* <ViaThinkSoftSignature>
2
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
23
g==
23
Q==
24
</ViaThinkSoftSignature> */ ?>
24
</ViaThinkSoftSignature> */ ?>
25
<?php
25
<?php
26
 
26
 
27
/*
27
/*
28
 * VNag - Nagios Framework for PHP
28
 * VNag - Nagios Framework for PHP
29
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
29
 * Developed by Daniel Marschall, ViaThinkSoft <www.viathinksoft.com>
30
 * Licensed under the terms of the Apache 2.0 license
30
 * Licensed under the terms of the Apache 2.0 license
31
 *
31
 *
32
 * Revision 2018-07-19
32
 * Revision 2018-07-19
33
 */
33
 */
34
 
34
 
35
# IMPORTANT
35
# IMPORTANT
36
# The log files have to be named YYYY_MM_DD_HH.log and need to be cleared (zeroed) every hour and dumped at least every hour (every minute is also possible)
36
# The log files have to be named YYYY_MM_DD_HH.log and need to be cleared (zeroed) every hour and dumped at least every hour (every minute is also possible)
37
# Please see the file INSTALL
37
# Please see the file INSTALL
38
 
38
 
39
# ---
39
# ---
40
 
40
 
41
# TODO: trennen zwischen server (ip1, ip2) ermöglichen...
41
# TODO: trennen zwischen server (ip1, ip2) ermöglichen...
42
# TODO: prüfen lassen ob die config von ipfm korrekt ist (dumped every 1 hour)
42
# TODO: prüfen lassen ob die config von ipfm korrekt ist (dumped every 1 hour)
43
# TODO: monat vor/zurückscrollen? (mon/year)
43
# TODO: monat vor/zurückscrollen? (mon/year)
44
# TODO: anstelle "year .... overview" lieber "last 12 months"
44
# TODO: anstelle "year .... overview" lieber "last 12 months"
45
# TODO: Some hosts might reset the traffic counter at any other day of the month. Should we also support this?
45
# TODO: Some hosts might reset the traffic counter at any other day of the month. Should we also support this?
46
 
46
 
47
# ---
47
# ---
48
 
48
 
49
declare(ticks=1);
49
declare(ticks=1);
50
 
50
 
51
# Attention: This constant must be a valid Nagios UOM!
51
# Attention: This constant must be a valid Nagios UOM!
52
# TODO: Make it configurable via command line? Should we use the UOM from the w/c/l arguments?
52
# TODO: Make it configurable via command line? Should we use the UOM from the w/c/l arguments?
53
define('OUTPUT_UOM', 'GB');
53
define('OUTPUT_UOM', 'GB');
54
 
54
 
55
# ---
55
# ---
56
 
56
 
57
class IpFlowMonitorCheck extends VNag {
57
class IpFlowMonitorCheck extends VNag {
58
        protected $argLogDir = null;
58
        protected $argLogDir = null;
59
        protected $argLimit = null;
59
        protected $argLimit = null;
60
 
60
 
61
        public function __construct() {
61
        public function __construct() {
62
                parent::__construct();
62
                parent::__construct();
63
 
63
 
64
                $this->registerExpectedStandardArguments('Vhtwc');
64
                $this->registerExpectedStandardArguments('Vhtwc');
65
 
65
 
66
                $this->getHelpManager()->setPluginName('check_ipfm');
66
                $this->getHelpManager()->setPluginName('check_ipfm');
67
                $this->getHelpManager()->setVersion('1.0');
67
                $this->getHelpManager()->setVersion('1.0');
68
                $this->getHelpManager()->setShortDescription('This plugin checks the network traffic monitored by ipfm.');
68
                $this->getHelpManager()->setShortDescription('This plugin checks the network traffic monitored by ipfm.');
69
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
69
                $this->getHelpManager()->setCopyright('Copyright (C) 2011-$CURYEAR$ Daniel Marschall, ViaThinkSoft.');
70
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-w currentGB[,expectedGB]] [-c currentGB[,expectedGB]] [-l limitGB] [-L path]');
70
                $this->getHelpManager()->setSyntax('$SCRIPTNAME$ [-w currentGB[,expectedGB]] [-c currentGB[,expectedGB]] [-l limitGB] [-L path]');
71
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
71
                $this->getHelpManager()->setFootNotes('If you encounter bugs, please contact ViaThinkSoft at www.viathinksoft.com');
72
 
72
 
73
                // This is the amount of traffic which is free. Every byte above this limit will cost additional money.
73
                // This is the amount of traffic which is free. Every byte above this limit will cost additional money.
74
                // You should therefore set your warning and critical limit below this limit.
74
                // You should therefore set your warning and critical limit below this limit.
75
                // Don't set this argument if you have an unlimited connection.
75
                // Don't set this argument if you have an unlimited connection.
76
                // This value is only for visual output. It does not influence the OK/Warning/Critial result.
76
                // This value is only for visual output. It does not influence the OK/Warning/Critial result.
77
                $this->addExpectedArgument($this->argLimit = new VNagArgument('l', 'limit', VNagArgument::VALUE_REQUIRED, 'limit', '"Traffic inclusive" limit (e.g. 10TB)', null));
77
                $this->addExpectedArgument($this->argLimit = new VNagArgument('l', 'limit', VNagArgument::VALUE_REQUIRED, 'limit', '"Traffic inclusive" limit (e.g. 10TB)', null));
78
 
78
 
79
                $this->addExpectedArgument($this->argLogDir = new VNagArgument('L', 'logdir', VNagArgument::VALUE_REQUIRED, 'path', 'Location of the ipfm log dir (Default: /var/log/ipfm)', '/var/log/ipfm'));
79
                $this->addExpectedArgument($this->argLogDir = new VNagArgument('L', 'logdir', VNagArgument::VALUE_REQUIRED, 'path', 'Location of the ipfm log dir (Default: /var/log/ipfm)', '/var/log/ipfm'));
80
 
80
 
81
                // When the user writes "-w 10GB" then he actually means "-w @10GB:~" or "-w ~:10GB", so these commands allow this notation:
-
 
82
                $this->warningSingleValueRangeBehaviors[0]  = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
81
#               $this->warningSingleValueRangeBehaviors[0]  = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
83
                $this->warningSingleValueRangeBehaviors[1]  = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
82
#               $this->warningSingleValueRangeBehaviors[1]  = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
84
                $this->criticalSingleValueRangeBehaviors[0] = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
83
#               $this->criticalSingleValueRangeBehaviors[0] = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
85
                $this->criticalSingleValueRangeBehaviors[1] = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
84
#               $this->criticalSingleValueRangeBehaviors[1] = self::SINGLEVALUE_RANGE_VAL_GT_X_BAD;
86
        }
85
        }
87
 
86
 
88
        protected function interprete_ipfm_logfile($logfile) {
87
        protected function interprete_ipfm_logfile($logfile) {
89
                $res = array();
88
                $res = array();
90
 
89
 
91
                $ary = file($logfile);
90
                $ary = file($logfile);
92
                foreach ($ary as $a) {
91
                foreach ($ary as $a) {
93
                        $a = trim($a);
92
                        $a = trim($a);
94
                        if ($a == '') continue;
93
                        if ($a == '') continue;
95
                        if (substr($a, 0, 1) == '#') continue;
94
                        if (substr($a, 0, 1) == '#') continue;
96
                        $a = preg_replace("|\s+|ism", ' ', $a);
95
                        $a = preg_replace("|\s+|ism", ' ', $a);
97
                        $bry = explode(' ', $a);
96
                        $bry = explode(' ', $a);
98
                        $res[$bry[0]] = array($bry[1], $bry[2], $bry[3]);
97
                        $res[$bry[0]] = array($bry[1], $bry[2], $bry[3]);
99
                }
98
                }
100
 
99
 
101
                return $res;
100
                return $res;
102
        }
101
        }
103
 
102
 
104
        protected function cbRun($optional_args=array()) {
103
        protected function cbRun($optional_args=array()) {
105
                if (!defined('USE_DYGRAPH')) define('USE_DYGRAPH', false);
104
                if (!defined('USE_DYGRAPH')) define('USE_DYGRAPH', false);
106
 
105
 
107
                $logDir = $this->argLogDir->getValue();
106
                $logDir = $this->argLogDir->getValue();
108
                if (!is_dir($logDir)) throw new Exception("Log dir $logDir not found");
107
                if (!is_dir($logDir)) throw new Exception("Log dir $logDir not found");
109
 
108
 
110
                $monthLimit = $this->argLimit->getValue();
109
                $monthLimit = $this->argLimit->getValue();
111
                if (!is_null($monthLimit)) {
110
                if (!is_null($monthLimit)) {
112
                        $p = (new VNagValueUomPair($monthLimit))->normalize(OUTPUT_UOM);
111
                        $p = (new VNagValueUomPair($monthLimit))->normalize(OUTPUT_UOM);
113
                        $monthLimitValue = $p->getValue();
112
                        $monthLimitValue = $p->getValue();
114
                        $monthLimitUom = $p->getUom();
113
                        $monthLimitUom = $p->getUom();
115
                }
114
                }
116
 
115
 
117
                ob_start();
116
                ob_start();
118
 
117
 
119
                ?>
118
                ?>
120
 
119
 
121
                <script type="text/javascript">
120
                <script type="text/javascript">
122
                        google.load("visualization", "1", {packages:['imageareachart', 'corechart']});
121
                        google.load("visualization", "1", {packages:['imageareachart', 'corechart']});
123
                        google.setOnLoadCallback(drawChart);
122
                        google.setOnLoadCallback(drawChart);
124
                        function drawChart() {
123
                        function drawChart() {
125
                                var data = new google.visualization.DataTable();
124
                                var data = new google.visualization.DataTable();
126
                                data.addColumn('string', 'Year');
125
                                data.addColumn('string', 'Year');
127
                                data.addColumn('number', 'Total');
126
                                data.addColumn('number', 'Total');
128
                                data.addColumn('number', 'In');
127
                                data.addColumn('number', 'In');
129
                                data.addRows([
128
                                data.addRows([
130
 
129
 
131
                <?php
130
                <?php
132
 
131
 
133
                $day = date('d');
132
                $day = date('d');
134
                $mon = date('m');
133
                $mon = date('m');
135
                $year = date('Y');
134
                $year = date('Y');
136
 
135
 
137
                $didata = '';
136
                $didata = '';
138
                $logfiles = glob($logDir.'/*.log');
137
                $logfiles = glob($logDir.'/*.log');
139
                sort($logfiles);
138
                sort($logfiles);
140
 
139
 
141
                $monthtotal[$year][$mon] = 0;
140
                $monthtotal[$year][$mon] = 0;
142
                $daystotal = array();
141
                $daystotal = array();
143
                $max = 0;
142
                $max = 0;
144
                $first = true;
143
                $first = true;
145
                foreach ($logfiles as $logfile) {
144
                foreach ($logfiles as $logfile) {
146
                        $stat = $this->interprete_ipfm_logfile($logfile);
145
                        $stat = $this->interprete_ipfm_logfile($logfile);
147
 
146
 
148
                        $date = '';
147
                        $date = '';
149
                        if (preg_match('/^.*_00\.log$/', $logfile)) {
148
                        if (preg_match('/^.*_00\.log$/', $logfile)) {
150
                                preg_match('@(\d{4})_(\d{2})_(\d{2})@ismU', $logfile, $m);
149
                                preg_match('@(\d{4})_(\d{2})_(\d{2})@ismU', $logfile, $m);
151
                                $t_day = $m[3];
150
                                $t_day = $m[3];
152
                                $t_mon = $m[2];
151
                                $t_mon = $m[2];
153
                                $t_year = $m[1];
152
                                $t_year = $m[1];
154
                                // $date = "$t_day.$t_mon.$t_year";
153
                                // $date = "$t_day.$t_mon.$t_year";
155
                                $date = $t_day;
154
                                $date = $t_day;
156
                        //} else if (preg_match('/^.*_(02|04|06|08|10|12|14|16|18|20|22)\.log$/', $logfile, $m)) {
155
                        //} else if (preg_match('/^.*_(02|04|06|08|10|12|14|16|18|20|22)\.log$/', $logfile, $m)) {
157
                        //      $date = $m[1].':00';
156
                        //      $date = $m[1].':00';
158
                        }
157
                        }
159
 
158
 
160
                        $in = $out = $total = 0;
159
                        $in = $out = $total = 0;
161
                        foreach ($stat as $s) {
160
                        foreach ($stat as $s) {
162
                                $in += $s[0];
161
                                $in += $s[0];
163
                                $out += $s[1];
162
                                $out += $s[1];
164
                                $total += $s[2];
163
                                $total += $s[2];
165
                        }
164
                        }
166
 
165
 
167
                        $in    = (new VNagValueUomPair($in.'B'))->normalize(OUTPUT_UOM)->getValue();
166
                        $in    = (new VNagValueUomPair($in.'B'))->normalize(OUTPUT_UOM)->getValue();
168
                        $out   = (new VNagValueUomPair($out.'B'))->normalize(OUTPUT_UOM)->getValue();
167
                        $out   = (new VNagValueUomPair($out.'B'))->normalize(OUTPUT_UOM)->getValue();
169
                        $total = (new VNagValueUomPair($total.'B'))->normalize(OUTPUT_UOM)->getValue();
168
                        $total = (new VNagValueUomPair($total.'B'))->normalize(OUTPUT_UOM)->getValue();
170
 
169
 
171
                        if (preg_match('/^.*(\d{4})_(\d{2})_(\d{2})_(\d{2})\.log$/', $logfile, $m)) {
170
                        if (preg_match('/^.*(\d{4})_(\d{2})_(\d{2})_(\d{2})\.log$/', $logfile, $m)) {
172
                                $t_year = $m[1];
171
                                $t_year = $m[1];
173
                                $t_mon = $m[2];
172
                                $t_mon = $m[2];
174
                                $t_day = $m[3];
173
                                $t_day = $m[3];
175
                                $t_hour = $m[4];
174
                                $t_hour = $m[4];
176
                                if (isset($monthtotal[$t_year][$t_mon])) {
175
                                if (isset($monthtotal[$t_year][$t_mon])) {
177
                                        $monthtotal[$t_year][$t_mon] += $total;
176
                                        $monthtotal[$t_year][$t_mon] += $total;
178
                                } else {
177
                                } else {
179
                                        $monthtotal[$t_year][$t_mon] = $total;
178
                                        $monthtotal[$t_year][$t_mon] = $total;
180
                                }
179
                                }
181
 
180
 
182
                                if (($t_year == $year) && ($t_mon == $mon)) {
181
                                if (($t_year == $year) && ($t_mon == $mon)) {
183
                                        if (isset($daystotal[$t_day])) {
182
                                        if (isset($daystotal[$t_day])) {
184
                                                $daystotal[$t_day] += $total;
183
                                                $daystotal[$t_day] += $total;
185
                                        } else {
184
                                        } else {
186
                                                $daystotal[$t_day] = $total;
185
                                                $daystotal[$t_day] = $total;
187
                                        }
186
                                        }
188
                                        if (!$first) echo ","; else $first = false;
187
                                        if (!$first) echo ","; else $first = false;
189
                                        echo "['$date', ".round($total,2).", ".round($in,2)."]\n";
188
                                        echo "['$date', ".round($total,2).", ".round($in,2)."]\n";
190
                                        $didata .= '"'.$t_year.'-'.$t_mon.'-'.$t_day.' '.$t_hour.':00:00,'.round($in,2).','.round($out,2).','.round($total,2).'\n" +'."\n";
189
                                        $didata .= '"'.$t_year.'-'.$t_mon.'-'.$t_day.' '.$t_hour.':00:00,'.round($in,2).','.round($out,2).','.round($total,2).'\n" +'."\n";
191
                                }
190
                                }
192
                        }
191
                        }
193
 
192
 
194
                        if ($total > $max) $max = $total;
193
                        if ($total > $max) $max = $total;
195
                }
194
                }
196
 
195
 
197
                $num_days_in_month = date('t', mktime(0, 0, 0, intval($mon), 1, intval($year)));
196
                $num_days_in_month = date('t', mktime(0, 0, 0, intval($mon), 1, intval($year)));
198
                $expected = $monthtotal[$year][$mon]/$day * $num_days_in_month;
197
                $expected = $monthtotal[$year][$mon]/$day * $num_days_in_month;
199
 
198
 
200
                ?>
199
                ?>
201
                        ]);
200
                        ]);
202
 
201
 
203
                        var chart = new google.visualization.ImageAreaChart(document.getElementById('chart_div'));
202
                        var chart = new google.visualization.ImageAreaChart(document.getElementById('chart_div'));
204
                <?php if (!USE_DYGRAPH) { ?>
203
                <?php if (!USE_DYGRAPH) { ?>
205
                        chart.draw(data, {width: 800, height: 440, min: 0, max: <?php echo $max; ?>, title: 'Traffic in <?php echo $mon.'/'.$year; ?> [in <?php echo OUTPUT_UOM; ?>/h]'});
204
                        chart.draw(data, {width: 800, height: 440, min: 0, max: <?php echo $max; ?>, title: 'Traffic in <?php echo $mon.'/'.$year; ?> [in <?php echo OUTPUT_UOM; ?>/h]'});
206
                <?php } ?>
205
                <?php } ?>
207
 
206
 
208
                        // ---
207
                        // ---
209
 
208
 
210
                        var data_month = new google.visualization.DataTable();
209
                        var data_month = new google.visualization.DataTable();
211
                        data_month.addColumn('string', 'Day');
210
                        data_month.addColumn('string', 'Day');
212
                        data_month.addColumn('number', 'Total');
211
                        data_month.addColumn('number', 'Total');
213
 
212
 
214
                        data_month.addRows([
213
                        data_month.addRows([
215
                <?php
214
                <?php
216
 
215
 
217
                $first = true;
216
                $first = true;
218
                foreach ($daystotal as $t_day => $traffic) {
217
                foreach ($daystotal as $t_day => $traffic) {
219
                        if (!$first) echo ","; else $first = false;
218
                        if (!$first) echo ","; else $first = false;
220
                        echo "['$t_day.$mon.$year', ".round($traffic,2)."]\n";
219
                        echo "['$t_day.$mon.$year', ".round($traffic,2)."]\n";
221
                }
220
                }
222
 
221
 
223
                ?>
222
                ?>
224
                        ]);
223
                        ]);
225
 
224
 
226
                        var options_month = {
225
                        var options_month = {
227
                                width: 800, height: 440,
226
                                width: 800, height: 440,
228
                                vAxis: { viewWindow: { min: 0 } },
227
                                vAxis: { viewWindow: { min: 0 } },
229
                                title: 'Month overview for <?php echo $mon.'/'.$year; ?> [GiB]'
228
                                title: 'Month overview for <?php echo $mon.'/'.$year; ?> [GiB]'
230
                        };
229
                        };
231
 
230
 
232
                        var chart_month = new google.visualization.ColumnChart(document.getElementById('chart_div3'));
231
                        var chart_month = new google.visualization.ColumnChart(document.getElementById('chart_div3'));
233
                        chart_month.draw(data_month, options_month);
232
                        chart_month.draw(data_month, options_month);
234
 
233
 
235
                        // ---
234
                        // ---
236
 
235
 
237
                        var data_year = new google.visualization.DataTable();
236
                        var data_year = new google.visualization.DataTable();
238
                        data_year.addColumn('string', 'Month/Year');
237
                        data_year.addColumn('string', 'Month/Year');
239
                        data_year.addColumn('number', 'Total');
238
                        data_year.addColumn('number', 'Total');
240
 
239
 
241
                        data_year.addRows([
240
                        data_year.addRows([
242
                <?php
241
                <?php
243
 
242
 
244
                ksort($monthtotal); // First sort by year
243
                ksort($monthtotal); // First sort by year
245
 
244
 
246
                $first = true;
245
                $first = true;
247
                foreach ($monthtotal as $t_year => $x) {
246
                foreach ($monthtotal as $t_year => $x) {
248
                        ksort($x); // Then sort by month
247
                        ksort($x); // Then sort by month
249
                        foreach ($x as $t_mon => $traffic) {
248
                        foreach ($x as $t_mon => $traffic) {
250
                                if ($t_year != $year) continue; // Only this year
249
                                if ($t_year != $year) continue; // Only this year
251
 
250
 
252
                                $date = "$t_mon/$t_year";
251
                                $date = "$t_mon/$t_year";
253
 
252
 
254
                                if (!$first) echo ","; else $first = false;
253
                                if (!$first) echo ","; else $first = false;
255
                                echo "['$date', ".round($traffic,2)."]\n";
254
                                echo "['$date', ".round($traffic,2)."]\n";
256
                        }
255
                        }
257
                        echo ",['Expected in $mon/$year', $expected]\n";
256
                        echo ",['Expected in $mon/$year', $expected]\n";
258
                }
257
                }
259
 
258
 
260
                ?>
259
                ?>
261
                        ]);
260
                        ]);
262
 
261
 
263
                        var options_year = {
262
                        var options_year = {
264
                                width: 800, height: 440,
263
                                width: 800, height: 440,
265
                                vAxis: { viewWindow: { min: 0 } },
264
                                vAxis: { viewWindow: { min: 0 } },
266
                                title: 'Year <?php echo $year; ?> overview [GiB]'
265
                                title: 'Year <?php echo $year; ?> overview [GiB]'
267
                        };
266
                        };
268
 
267
 
269
                        var chart_year = new google.visualization.ColumnChart(document.getElementById('chart_div2'));
268
                        var chart_year = new google.visualization.ColumnChart(document.getElementById('chart_div2'));
270
                        chart_year.draw(data_year, options_year);
269
                        chart_year.draw(data_year, options_year);
271
                }
270
                }
272
 
271
 
273
                </script>
272
                </script>
274
 
273
 
275
                <?php if (USE_DYGRAPH) { ?>
274
                <?php if (USE_DYGRAPH) { ?>
276
                        <script type="text/javascript">
275
                        <script type="text/javascript">
277
                                g = new Dygraph(
276
                                g = new Dygraph(
278
                                        document.getElementById("graphdiv"),
277
                                        document.getElementById("graphdiv"),
279
                                        "Date,In,Out,Total\n" +
278
                                        "Date,In,Out,Total\n" +
280
                                        <?php echo $didata; ?>""
279
                                        <?php echo $didata; ?>""
281
                                );
280
                                );
282
                        </script>
281
                        </script>
283
                <?php } ?>
282
                <?php } ?>
284
 
283
 
285
                <?php
284
                <?php
286
 
285
 
287
                if (!is_null($monthLimit)) {
286
                if (!is_null($monthLimit)) {
288
                        echo "<p>Constraint: Max ".$monthLimitValue.' '.OUTPUT_UOM."/Month</p>";
287
                        echo "<p>Constraint: Max ".$monthLimitValue.' '.OUTPUT_UOM."/Month</p>";
289
                }
288
                }
290
 
289
 
291
                $current = $monthtotal[$year][$mon];
290
                $current = $monthtotal[$year][$mon];
292
 
291
 
293
                $fontcolor = 'green';
292
                $fontcolor = 'green';
294
                if ($this->checkAgainstCriticalRange($current.OUTPUT_UOM, false, true, 0)) $fontcolor = 'red';
293
                if ($this->checkAgainstCriticalRange($current.OUTPUT_UOM, false, true, 0)) $fontcolor = 'red';
295
                if ($this->checkAgainstWarningRange($current.OUTPUT_UOM, false, true, 0))  $fontcolor = '#FF8000';
294
                if ($this->checkAgainstWarningRange($current.OUTPUT_UOM, false, true, 0))  $fontcolor = '#FF8000';
296
 
295
 
297
                if (!is_null($monthLimit)) {
296
                if (!is_null($monthLimit)) {
298
                        echo "<p>This month ($mon/$year): <font color=\"$fontcolor\">".round($current,0)." ".OUTPUT_UOM." (".round($current/$monthLimitValue*100,2)."%)</font></p>";
297
                        echo "<p>This month ($mon/$year): <font color=\"$fontcolor\">".round($current,0)." ".OUTPUT_UOM." (".round($current/$monthLimitValue*100,2)."%)</font></p>";
299
                } else {
298
                } else {
300
                        echo "<p>This month ($mon/$year): <font color=\"$fontcolor\">".round($current,0)." ".OUTPUT_UOM."</font></p>";
299
                        echo "<p>This month ($mon/$year): <font color=\"$fontcolor\">".round($current,0)." ".OUTPUT_UOM."</font></p>";
301
                }
300
                }
302
 
301
 
303
                $fontcolor = 'green';
302
                $fontcolor = 'green';
304
                if ($this->checkAgainstCriticalRange($expected.OUTPUT_UOM, false, true, 1)) $fontcolor = 'red';
303
                if ($this->checkAgainstCriticalRange($expected.OUTPUT_UOM, false, true, 1)) $fontcolor = 'red';
305
                if ($this->checkAgainstWarningRange($expected.OUTPUT_UOM, false, true, 1))  $fontcolor = '#FF8000';
304
                if ($this->checkAgainstWarningRange($expected.OUTPUT_UOM, false, true, 1))  $fontcolor = '#FF8000';
306
 
305
 
307
                if (!is_null($monthLimit)) {
306
                if (!is_null($monthLimit)) {
308
                        echo "<p>Expected for this month: <font color=\"$fontcolor\">".round($expected,0)." ".OUTPUT_UOM." (".round($expected/$monthLimitValue*100,2)."%)</font></p>";
307
                        echo "<p>Expected for this month: <font color=\"$fontcolor\">".round($expected,0)." ".OUTPUT_UOM." (".round($expected/$monthLimitValue*100,2)."%)</font></p>";
309
                } else {
308
                } else {
310
                        echo "<p>Expected for this month: <font color=\"$fontcolor\">".round($expected,0)." ".OUTPUT_UOM."</font></p>";
309
                        echo "<p>Expected for this month: <font color=\"$fontcolor\">".round($expected,0)." ".OUTPUT_UOM."</font></p>";
311
                }
310
                }
312
 
311
 
313
                ?>
312
                ?>
314
 
313
 
315
                <div id="chart_div"></div>
314
                <div id="chart_div"></div>
316
                <div id="graphdiv"></div>
315
                <div id="graphdiv"></div>
317
                <div id="chart_div3"></div>
316
                <div id="chart_div3"></div>
318
                <div id="chart_div2"></div>
317
                <div id="chart_div2"></div>
319
 
318
 
320
                <?php
319
                <?php
321
 
320
 
322
                $html = ob_get_contents();
321
                $html = ob_get_contents();
323
                ob_end_clean();
322
                ob_end_clean();
324
 
323
 
325
                $this->outputHTML($html, true);
324
                $this->outputHTML($html, true);
326
 
325
 
327
                if (!is_null($monthLimit)) {
326
                if (!is_null($monthLimit)) {
328
                        // TODO: should we put a percentage at "expected"? or if it exceeds, should we show how much it would exceed?
327
                        // TODO: should we put a percentage at "expected"? or if it exceeds, should we show how much it would exceed?
329
                        // TODO: It would be good if the UOM for displaying would be automatically detected, e.g. 200 MB / 10 TB instead of 0 GB / 10240 GB
328
                        // TODO: It would be good if the UOM for displaying would be automatically detected, e.g. 200 MB / 10 TB instead of 0 GB / 10240 GB
330
                        $this->setHeadline(round($current,0).' '.OUTPUT_UOM." / ".$monthLimitValue.' '.OUTPUT_UOM." (".round($current/$monthLimitValue*100,2)."%, expected ".round($expected,0).' '.OUTPUT_UOM.") traffic used this month ($mon/$year)", true);
329
                        $this->setHeadline(round($current,0).' '.OUTPUT_UOM." / ".$monthLimitValue.' '.OUTPUT_UOM." (".round($current/$monthLimitValue*100,2)."%, expected ".round($expected,0).' '.OUTPUT_UOM.") traffic used this month ($mon/$year)", true);
331
                } else {
330
                } else {
332
                        $this->setHeadline(round($current,0).' '.OUTPUT_UOM." (expected ".round($expected,0).' '.OUTPUT_UOM.") traffic used this month ($mon/$year)", true);
331
                        $this->setHeadline(round($current,0).' '.OUTPUT_UOM." (expected ".round($expected,0).' '.OUTPUT_UOM.") traffic used this month ($mon/$year)", true);
333
                }
332
                }
334
 
333
 
335
                $warn = is_null($this->getWarningRange(0)) ? null : $this->getWarningRange(0)->end->normalize(OUTPUT_UOM)->getValue();
334
                $warn = is_null($this->getWarningRange(0)) ? null : $this->getWarningRange(0)->end->normalize(OUTPUT_UOM)->getValue();
336
                $crit = is_null($this->getCriticalRange(0)) ? null : $this->getCriticalRange(0)->end->normalize(OUTPUT_UOM)->getValue();
335
                $crit = is_null($this->getCriticalRange(0)) ? null : $this->getCriticalRange(0)->end->normalize(OUTPUT_UOM)->getValue();
337
                $this->addPerformanceData(new VNagPerformanceData('Current', $current.OUTPUT_UOM, $warn, $crit, 0, is_null($monthLimit) ? null : $monthLimitValue));
336
                $this->addPerformanceData(new VNagPerformanceData('Current', $current.OUTPUT_UOM, $warn, $crit, 0, is_null($monthLimit) ? null : $monthLimitValue));
338
 
337
 
339
                $warn = is_null($this->getWarningRange(1)) ? null : $this->getWarningRange(1)->end->normalize(OUTPUT_UOM)->getValue();
338
                $warn = is_null($this->getWarningRange(1)) ? null : $this->getWarningRange(1)->end->normalize(OUTPUT_UOM)->getValue();
340
                $crit = is_null($this->getCriticalRange(1)) ? null : $this->getCriticalRange(1)->end->normalize(OUTPUT_UOM)->getValue();
339
                $crit = is_null($this->getCriticalRange(1)) ? null : $this->getCriticalRange(1)->end->normalize(OUTPUT_UOM)->getValue();
341
                $this->addPerformanceData(new VNagPerformanceData('Expected', $expected.OUTPUT_UOM, $warn, $crit, 0, is_null($monthLimit) ? null : $monthLimitValue));
340
                $this->addPerformanceData(new VNagPerformanceData('Expected', $expected.OUTPUT_UOM, $warn, $crit, 0, is_null($monthLimit) ? null : $monthLimitValue));
342
        }
341
        }
343
}
342
}
344
 
343