summaryrefslogtreecommitdiff
path: root/net-analyzer/pnp4nagios/files/pnp4nagios-0.6.26-sizeof.patch
blob: 360b4be4f76ec6c8f22ddac40a5136a8af024d24 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# https://github.com/lingej/pnp4nagios/commit/d5e04540d52238dfcb877d7116316ba1be8c1963
diff --git a/share/pnp/application/controllers/ajax.php b/share/pnp/application/controllers/ajax.php
index 9e0428d..c5f89e2 100644
--- a/share/pnp/application/controllers/ajax.php
+++ b/share/pnp/application/controllers/ajax.php
@@ -59,7 +59,7 @@ public function basket($action=FALSE){
 
         if($action == "list"){
             $basket = $this->session->get("basket");
-            if(is_array($basket) && sizeof($basket) > 0){
+            if(is_array($basket) && (!empty($basket))){
                 foreach($basket as $item){
                 printf("<li class=\"ui-state-default %s\" id=\"%s\"><a title=\"%s\" id=\"%s\"><img width=12px height=12px src=\"%smedia/images/remove.png\"></a>%s</li>\n",
                         "basket_action_remove",
@@ -135,7 +135,7 @@ public function basket($action=FALSE){
             echo "Action $action not known";
         }
         $basket = $this->session->get("basket");
-        if(is_array($basket) && sizeof($basket) == 0){
+        if(is_array($basket) && empty($basket)){
             echo Kohana::lang('common.basket-empty');
         }else{
             echo "<div align=\"center\" class=\"p2\">\n";
diff --git a/share/pnp/application/controllers/image.php b/share/pnp/application/controllers/image.php
index b41ca83..869435c 100644
--- a/share/pnp/application/controllers/image.php
+++ b/share/pnp/application/controllers/image.php
@@ -47,7 +47,7 @@ public function index()
                 $this->rrdtool->streamImage("ERROR: NOT_AUTHORIZED"); 
 
             #print Kohana::debug($this->data->STRUCT);
-            if(sizeof($this->data->STRUCT) > 0){
+            if(!empty($this->data->STRUCT)){
                 $image = $this->rrdtool->doImage($this->data->STRUCT[0]['RRD_CALL']);
             }else{
                 $image = FALSE;
diff --git a/share/pnp/application/controllers/page.php b/share/pnp/application/controllers/page.php
index 7bd877e..fcfffe8 100644
--- a/share/pnp/application/controllers/page.php
+++ b/share/pnp/application/controllers/page.php
@@ -58,7 +58,7 @@ public function index(){
 
     public function basket(){
         $basket = $this->session->get("basket");
-        if(is_array($basket) && sizeof($basket) > 0){
+        if(is_array($basket) && (!empty($basket))){
             $this->data->buildBasketStruct($basket,$this->view);
             $this->template->page->basket_box         = $this->add_view('basket_box');
             $this->template->page->header->title      = Kohana::lang('common.page-basket');
diff --git a/share/pnp/application/controllers/pdf.php b/share/pnp/application/controllers/pdf.php
index 15f2ab4..d590859 100644
--- a/share/pnp/application/controllers/pdf.php
+++ b/share/pnp/application/controllers/pdf.php
@@ -202,7 +202,7 @@ public function basket(){
         }
         $this->data->getTimeRange($this->start,$this->end,$this->view);
         $basket = $this->session->get("basket");
-        if(is_array($basket) && sizeof($basket) > 0){
+        if(is_array($basket) && (!empty($basket))){
              $this->data->buildBasketStruct($basket,$this->view);
         }
         //echo Kohana::debug($this->data->STRUCT);
diff --git a/share/pnp/application/helpers/rrd.php b/share/pnp/application/helpers/rrd.php
index 81bb257..ea9f99b 100644
--- a/share/pnp/application/helpers/rrd.php
+++ b/share/pnp/application/helpers/rrd.php
@@ -207,7 +207,7 @@ public static function gprint($vname=FALSE, $cf="AVERAGE", $text="%6.2lf %s"){
         if(is_array($cf)){
             foreach($cf as $key => $val){
                 $line .= sprintf("GPRINT:%s:%s:",$vname,$val);
-                if($key == sizeof($cf)-1){
+                if($key == count($cf)-1){
                     $line .= '"'.$text.' '.ucfirst(strtolower($val)).'\\l" ';
                 }else{
                     $line .= '"'.$text.' '.ucfirst(strtolower($val)).'" ';
@@ -234,7 +234,7 @@ public static function gprinta($vname=FALSE, $cf="AVERAGE", $text="%6.2lf %s", $
         if(is_array($cf)){
             foreach($cf as $key => $val){
                 $line .= sprintf("GPRINT:%s:%s:",$vname,$val);
-                if(($key == sizeof($cf)-1)and($align != "")){
+                if(($key == count($cf)-1)and($align != "")){
                     $line .= '"'.$text.' '.ucfirst(strtolower($val)).$align.'" ';
                 }else{
                     $line .= '"'.$text.' '.ucfirst(strtolower($val)).'" ';
diff --git a/share/pnp/application/lib/json.php b/share/pnp/application/lib/json.php
index 0cddbdd..d0e3171 100644
--- a/share/pnp/application/lib/json.php
+++ b/share/pnp/application/lib/json.php
@@ -375,7 +375,7 @@ function encode($var)
                 */
 
                 // treat as a JSON object
-                if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
+                if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) {
                     $properties = array_map(array($this, 'name_value'),
                                             array_keys($var),
                                             array_values($var));
diff --git a/share/pnp/application/models/auth.php b/share/pnp/application/models/auth.php
index 77f28d2..11d785a 100644
--- a/share/pnp/application/models/auth.php
+++ b/share/pnp/application/models/auth.php
@@ -116,11 +116,7 @@ public function is_authorized($host = FALSE, $service = NULL){
             $result = $this->queryLivestatus($query);
         }
 
-        if(sizeof($result) > 0){
-            return TRUE;
-        }else{
-            return FALSE;
-        }
+        return (!empty($result));
     }
 
 
diff --git a/share/pnp/application/models/config.php b/share/pnp/application/models/config.php
index 44e3d12..7a6b8e0 100644
--- a/share/pnp/application/models/config.php
+++ b/share/pnp/application/models/config.php
@@ -68,7 +68,7 @@ public function read_config(){
                 $views = array();
                 include ($config_file);
                 $array_b = $views;
-                if(sizeof($views) == 0 ){
+                if(empty($views)){
                     $views = $array_a;
                 }
             }
diff --git a/share/pnp/application/models/data.php b/share/pnp/application/models/data.php
index 63b0e24..74e8821 100644
--- a/share/pnp/application/models/data.php
+++ b/share/pnp/application/models/data.php
@@ -45,11 +45,11 @@ public function getSpecialTemplates(){
                 }
             }
         }
-        if(sizeof($templates) > 0){
+        if(empty($templates)){
+            return FALSE;
+        }else{
             sort($templates);
             return $templates;
-        }else{
-            return FALSE;
         }
     }
 
@@ -97,7 +97,9 @@ public function getHosts() {
                     throw new Kohana_User_Exception('Perfdata Dir', "Can not open $path");
                }
            }
-        if(sizeof($hosts)>0){
+        if(empty($hosts)){
+            throw new Kohana_Exception('error.perfdata-dir-empty', $conf['rrdbase'] );
+        }else{
             # Obtain a list of columns
             foreach ($hosts as $key => $row) {
                 $sort[$key]  = $row['sort'];
@@ -105,8 +107,6 @@ public function getHosts() {
             # Sort the data with volume descending, edition ascending
             # Add $data as the last parameter, to sort by the common key
             array_multisort($sort, SORT_ASC, $hosts);
-        }else{
-            throw new Kohana_Exception('error.perfdata-dir-empty', $conf['rrdbase'] );
         }
         return $hosts;
     }
@@ -147,7 +147,7 @@ function getRawServices($hostname) {
         }else{
             throw new Kohana_Exception('error.perfdata-dir-for-host', $path, $hostname );
         }
-        if( is_array($services) && sizeof($services) > 0){
+        if( is_array($services) && (!empty($services))){
             # Obtain a list of columns
             foreach ($services as $key => $row) {
                 $sort[$key]  = $row['name'];
@@ -205,7 +205,7 @@ function getServices($hostname) {
             $i++;
         }
         #print Kohana::debug($services);
-        if( is_array($services) && sizeof($services) > 0){
+        if( is_array($services) && (!empty($services))){
             # Obtain a list of columns
             foreach ($services as $key => $row) {
                 $sort[$key]  = $row['sort'];
@@ -214,7 +214,7 @@ function getServices($hostname) {
             # Add $data as the last parameter, to sort by the common key
             array_multisort($sort, SORT_STRING, $services);
         }        
-        if(is_array($host) && sizeof($host) > 0 ){
+        if(is_array($host) && (!empty($host))){
             array_unshift($services, $host[0]);
         }
         return $services;
@@ -232,7 +232,7 @@ public function getFirstService($hostname) {
                 break;
             }
         }
-        if(sizeof($srv) == 0){
+        if(empty($srv)){
             throw new Kohana_Exception('error.get-first-service', $hostname );
         }
         return $srv['name'];
@@ -250,7 +250,7 @@ public function getFirstHost() {
                 break;
             }
         }
-        if(sizeof($host) == 0){
+        if(empty($host)){
             throw new Kohana_Exception('error.get-first-host');
         }
         return $host['name'];
@@ -693,7 +693,7 @@ public function getTimeRange($start=FALSE ,$end=FALSE ,$view="") {
         }
         
            $view=intval( pnp::clean($view) );
-           if($view >= sizeof($this->config->views)){
+           if($view >= count($this->config->views)){
                $view = 1;
            }
 
@@ -735,7 +735,7 @@ public function getTimeRange($start=FALSE ,$end=FALSE ,$view="") {
            $timerange['f_end']   = date($this->config->conf['date_fmt'],$end);
            $timerange['cmd']     = " --start $start --end $end ";
            $timerange['type']    = "views";
-           for ($i = 0; $i < sizeof($this->config->views); $i++) {
+           for ($i = 0; $i < count($this->config->views); $i++) {
                $timerange[$i]['title']   = $this->config->views[$i]['title'];
                $timerange[$i]['start']   = $end - $this->config->views[$i]['start'];
                $timerange[$i]['f_start'] = date($this->config->conf['date_fmt'],$end - $this->config->views[$i]['start']);
@@ -747,7 +747,7 @@ public function getTimeRange($start=FALSE ,$end=FALSE ,$view="") {
     }
 
     public function buildBasketStruct($basket,$view = NULL){
-        if(is_array($basket) && sizeof($basket) > 0){
+        if(is_array($basket) && (!empty($basket))){
 	    if($view == ""){
                  $views = array_keys($this->config->views);
             }else{
@@ -757,9 +757,9 @@ public function buildBasketStruct($basket,$view = NULL){
                 foreach($basket as $item){
                     # explode host::service::source
                     $slices = explode("::",$item);
-                    if(sizeof($slices) == 2)
+                    if(count($slices) == 2)
                         $this->buildDataStruct($slices[0], $slices[1], $view);
-                    if(sizeof($slices) == 3)
+                    if(count($slices) == 3)
                         $this->buildDataStruct($slices[0], $slices[1], $view, $slices[2]);
                 }
                 # break on custom time ranges
@@ -806,12 +806,12 @@ public function buildPageStruct($page,$view){
             }
         }
         #print Kohana::debug($servicelist);
-        if(sizeof($servicelist) > 0 ){
+        if(empty($servicelist)){
+            $this->ERROR = "ERROR: ". Kohana::lang('error.no-data-for-page', $page.".cfg" );
+        }else{
             foreach($servicelist as $s){
                 $this->buildDataStruct($s['host'],$s['service'],$view,$s['source']);
             }
-        }else{
-            $this->ERROR = "ERROR: ". Kohana::lang('error.no-data-for-page', $page.".cfg" );
         }
     }
 
@@ -962,11 +962,11 @@ public function getPages() {
                 die("Cannot open directory:  $path");
             }
         }
-        if(sizeof($pages)>0){
+        if(empty($pages)){
+            return FALSE; 
+        }else{
             
             natsort($pages);
-        }else{
-            return FALSE; 
         }
         return $pages;
     }
@@ -976,10 +976,10 @@ public function getPages() {
     */
     public function getFirstPage(){
         $pages = $this->getPages();
-        if(sizeof($pages) > 0 ){
-            return urldecode($pages[0]);
-        }else{
+        if(empty($pages)){
             return FALSE;
+        }else{
+            return urldecode($pages[0]);
         }
     }
 
@@ -1093,7 +1093,7 @@ public function tplGetServices ($hostregex=FALSE, $serviceregex = ''){
             }
         }
 
-        if(sizeof($new_hosts) == 0){
+        if(empty($new_hosts)){
             throw new Kohana_Exception('error.tpl-no-hosts-found', $hostregex);
         }
 
@@ -1101,7 +1101,7 @@ public function tplGetServices ($hostregex=FALSE, $serviceregex = ''){
         $new_services = array();
         foreach($new_hosts as $host){
             $services = $this->getRawServices($host);
-            if(sizeof($services) == 0){
+            if(empty($services)){
                 throw new Kohana_Exception('error.tpl-no-services-found', $serviceregex);
             }
             foreach($services as $service){
@@ -1115,7 +1115,7 @@ public function tplGetServices ($hostregex=FALSE, $serviceregex = ''){
             }
         }
 
-        if(sizeof($new_services) == 0){
+        if(empty($new_services)){
             throw new Kohana_Exception('error.tpl-no-services-found', $serviceregex);
         }
 
diff --git a/share/pnp/application/views/basket_box.php b/share/pnp/application/views/basket_box.php
index ea8a72c..2a4e0e6 100644
--- a/share/pnp/application/views/basket_box.php
+++ b/share/pnp/application/views/basket_box.php
@@ -6,7 +6,7 @@
 echo Kohana::lang('common.basket-box-header')."</div>\n";
 echo "<div class=\"p4 ui-widget-content ui-corner-bottom\">\n";
 echo "<div id=\"basket_items\">\n";
-if(is_array($basket) && sizeof($basket) > 0 ){
+if(is_array($basket) && !empty($basket)){
 	foreach($basket as $key=>$item){
 		echo "<li class=\"ui-state-default basket_action_remove\" id=\"".
                      $item."\"><a title=\"".Kohana::lang('common.basket-remove', $item)."\"".
@@ -16,7 +16,7 @@
                      pnp::shorten($item)."</li>\n";
 	}
 }
-if(is_array($basket) && sizeof($basket) > 0 ){
+if(is_array($basket) && !empty($basket)){
     echo "<div align=\"center\" class=\"p2\">\n";
     echo "<button id=\"basket-show\">".Kohana::lang('common.basket-show')."</button>\n";
     echo "<button id=\"basket-clear\">".Kohana::lang('common.basket-clear')."</button>\n";
diff --git a/share/pnp/templates.dist/pnp-runtime.php b/share/pnp/templates.dist/pnp-runtime.php
index 21c4ae3..a668fdc 100644
--- a/share/pnp/templates.dist/pnp-runtime.php
+++ b/share/pnp/templates.dist/pnp-runtime.php
@@ -34,7 +34,7 @@
 #
 $ds_name[2] = "Errors and updates";
 $def[2] = '';
-for($i=2; $i <= sizeof($DS); $i++) {
+for($i=2; $i <= count($DS); $i++) {
 $def[2] .=  rrd::def("var$i", $RRDFILE[$i], $DS[$i] , "AVERAGE") ;
 $def[2] .= rrd::line1("var$i", rrd::color($i), rrd::cut(ucfirst($LABEL[$i]),12) );
 $def[2] .= rrd::gprint("var$i", array('LAST', 'MAX', 'AVERAGE'), "%4.0lf$UNIT[$i]");