Passed
Push — master ( 608a4b...d03ea5 )
by Patrick
03:11
created
library/Trapdirector/TrapsProcess/Mib.php 1 patch
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      * @param Logging $logClass : where to log
33 33
      * @param Database $dbClass : Database
34 34
      */
35
-    function __construct($logClass,$dbClass,$snmptrans,$snmptransdir)
35
+    function __construct($logClass, $dbClass, $snmptrans, $snmptransdir)
36 36
     {
37 37
         $this->logging=$logClass;
38 38
         $this->trapsDB=$dbClass;
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
             }
60 60
             $oidIndex=$this->dbOidIndex[$this->oidDesc['oid']]['key']; // Get index in dbOidAll
61 61
             $dbOid=$this->dbOidAll[$oidIndex]; // Get array of element
62
-            if ( $this->oidDesc['name'] != $dbOid['name'] ||
62
+            if ($this->oidDesc['name'] != $dbOid['name'] ||
63 63
                 $this->oidDesc['mib'] != $dbOid['mib'] ||
64
-                $this->oidDesc['type'] !=$dbOid['type']
64
+                $this->oidDesc['type'] != $dbOid['type']
65 65
                )
66 66
             { // Do update
67 67
                 $sql='UPDATE '.$this->trapsDB->dbPrefix.'mib_cache SET '.
@@ -75,22 +75,22 @@  discard block
 block discarded – undo
75 75
                     ':type' => $this->oidDesc['type'],
76 76
                     ':mib' => $this->oidDesc['mib'],
77 77
                     ':tc' =>  $this->oidDesc['textconv']??'null',
78
-                    ':display_hint' => $this->oidDesc['dispHint']??'null' ,
79
-                    ':syntax' => $this->oidDesc['syntax']==null??'null',
78
+                    ':display_hint' => $this->oidDesc['dispHint']??'null',
79
+                    ':syntax' => $this->oidDesc['syntax'] == null??'null',
80 80
                     ':type_enum' => $this->oidDesc['type_enum']??'null',
81 81
                     ':description' => $this->oidDesc['description']??'null',
82 82
                     ':id' => $this->dbOidAll[$this->dbOidIndex[$this->oidDesc['oid']]['id']]
83 83
                 );
84 84
                 
85 85
                 if ($sqlQuery->execute($sqlParam) === false) {
86
-                    $this->logging->log('Error in query : ' . $sql,ERROR,'');
86
+                    $this->logging->log('Error in query : '.$sql, ERROR, '');
87 87
                 }
88
-                $this->logging->log('Trap updated : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
88
+                $this->logging->log('Trap updated : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
89 89
                 return 1;
90 90
             }
91 91
             else
92 92
             {
93
-                $this->logging->log('Trap unchanged : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],DEBUG );
93
+                $this->logging->log('Trap unchanged : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], DEBUG);
94 94
                 return 0;
95 95
             }
96 96
         }
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
         
101 101
         $sql='INSERT INTO '.$this->trapsDB->dbPrefix.'mib_cache '.
102 102
             '(oid, name, type , mib, textual_convention, display_hint '.
103
-            ', syntax, type_enum , description ) ' .
103
+            ', syntax, type_enum , description ) '.
104 104
             'values (:oid, :name , :type ,:mib ,:tc , :display_hint'.
105 105
             ', :syntax, :type_enum, :description )';
106 106
         
107
-        if ($this->trapsDB->trapDBType == 'pgsql') $sql .= 'RETURNING id';
107
+        if ($this->trapsDB->trapDBType == 'pgsql') $sql.='RETURNING id';
108 108
         
109 109
         $sqlQuery=$db_conn->prepare($sql);
110 110
         
@@ -113,15 +113,15 @@  discard block
 block discarded – undo
113 113
             ':name' => $this->oidDesc['name'],
114 114
             ':type' => $this->oidDesc['type'],
115 115
             ':mib' => $this->oidDesc['mib'],
116
-            ':tc' =>  ($this->oidDesc['textconv']==null)?'null':$this->oidDesc['textconv'] ,
117
-            ':display_hint' => ($this->oidDesc['dispHint']==null)?'null':$this->oidDesc['dispHint'] ,
118
-            ':syntax' => ($this->oidDesc['syntax']==null)?'null':$this->oidDesc['syntax'],
119
-            ':type_enum' => ($this->oidDesc['type_enum']==null)?'null':$this->oidDesc['type_enum'],
120
-            ':description' => ($this->oidDesc['description']==null)?'null':$this->oidDesc['description']
116
+            ':tc' =>  ($this->oidDesc['textconv'] == null) ? 'null' : $this->oidDesc['textconv'],
117
+            ':display_hint' => ($this->oidDesc['dispHint'] == null) ? 'null' : $this->oidDesc['dispHint'],
118
+            ':syntax' => ($this->oidDesc['syntax'] == null) ? 'null' : $this->oidDesc['syntax'],
119
+            ':type_enum' => ($this->oidDesc['type_enum'] == null) ? 'null' : $this->oidDesc['type_enum'],
120
+            ':description' => ($this->oidDesc['description'] == null) ? 'null' : $this->oidDesc['description']
121 121
         );
122 122
         
123 123
         if ($sqlQuery->execute($sqlParam) === false) {
124
-            $this->logging->log('Error in query : ' . $sql,1,'');
124
+            $this->logging->log('Error in query : '.$sql, 1, '');
125 125
         }
126 126
         
127 127
         switch ($this->trapsDB->trapDBType)
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
             case 'pgsql':
130 130
                 // Get last id to insert oid/values in secondary table
131 131
                 if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) === false) {
132
-                    $this->logging->log('Error getting id - pgsql - ',1,'');
132
+                    $this->logging->log('Error getting id - pgsql - ', 1, '');
133 133
                 }
134
-                if (! isset($inserted_id_ret['id'])) {
135
-                    $this->logging->log('Error getting id - pgsql - empty.',1,'');
134
+                if (!isset($inserted_id_ret['id'])) {
135
+                    $this->logging->log('Error getting id - pgsql - empty.', 1, '');
136 136
                 }
137 137
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id_ret['id'];
138 138
                 break;
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
                 // Get last id to insert oid/values in secondary table
141 141
                 $sql='SELECT LAST_INSERT_ID();';
142 142
                 if (($ret_code=$db_conn->query($sql)) === false) {
143
-                    $this->logging->log('Erreur getting id - mysql - ',1,'');
143
+                    $this->logging->log('Erreur getting id - mysql - ', 1, '');
144 144
                 }
145 145
                 
146 146
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
147
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
147
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
148 148
                 $this->dbOidIndex[$this->oidDesc['oid']]['id']=$inserted_id;
149 149
                 break;
150 150
             default:
151
-                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType,1,'');
151
+                $this->logging->log('Error SQL type Unknown : '.$this->trapsDB->trapDBType, 1, '');
152 152
         }
153 153
         
154 154
         // Set as newly created.
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
         $db_conn=$this->trapsDB->db_connect_trap();
168 168
         // Get all objects
169 169
         $sql='SELECT * FROM '.$this->trapsDB->dbPrefix.'mib_cache_trap_object where trap_id='.$trapId.';';
170
-        $this->logging->log('SQL query get all traps: '.$sql,DEBUG );
170
+        $this->logging->log('SQL query get all traps: '.$sql, DEBUG);
171 171
         if (($ret_code=$db_conn->query($sql)) === false) {
172
-            $this->logging->log('No result in query : ' . $sql,1,'');
172
+            $this->logging->log('No result in query : '.$sql, 1, '');
173 173
         }
174 174
         $dbObjectsRaw=$ret_code->fetchAll();
175 175
         
@@ -186,30 +186,30 @@  discard block
 block discarded – undo
186 186
  * @param string $trapmib : mib of trap
187 187
  * @return NULL|array : null if not found, or output of snmptranslate
188 188
  */
189
-    private function get_object_details($object,$trapmib)
189
+    private function get_object_details($object, $trapmib)
190 190
     {
191 191
         $match=$snmptrans=array();
192 192
         $retVal=0;
193 193
         $this->oidDesc['mib']=$trapmib;
194
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
195
-            ' -On -Td '.$this->oidDesc['mib'].'::'.$object . ' 2>/dev/null',$snmptrans,$retVal);
196
-        if ($retVal!=0)
194
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
195
+            ' -On -Td '.$this->oidDesc['mib'].'::'.$object.' 2>/dev/null', $snmptrans, $retVal);
196
+        if ($retVal != 0)
197 197
         {
198 198
             // Maybe not trap mib, search with IR
199
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
200
-                ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal);
201
-            if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match))
199
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
200
+                ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal);
201
+            if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match))
202 202
             { // Not found -> continue with warning
203
-                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object,2,'');
203
+                $this->logging->log('Error finding trap object : '.$trapmib.'::'.$object, 2, '');
204 204
                 return null;
205 205
             }
206 206
             $this->oidDesc['mib']=$match[1];
207 207
             
208 208
             // Do the snmptranslate again.
209
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
210
-                ' -On -Td '.$this->oidDesc['mib'].'::'.$object,$snmptrans,$retVal);
211
-            if ($retVal!=0) {
212
-                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object,2,'');
209
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
210
+                ' -On -Td '.$this->oidDesc['mib'].'::'.$object, $snmptrans, $retVal);
211
+            if ($retVal != 0) {
212
+                $this->logging->log('Error finding trap object : '.$this->oidDesc['mib'].'::'.$object, 2, '');
213 213
                 return null;
214 214
             }
215 215
             
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
         
230 230
         foreach ($snmptrans as $line)
231 231
         {
232
-            if ($indesc===true)
232
+            if ($indesc === true)
233 233
             {
234
-                $line=preg_replace('/[\t ]+/',' ',$line);
235
-                if (preg_match('/(.*)"$/', $line,$match))
234
+                $line=preg_replace('/[\t ]+/', ' ', $line);
235
+                if (preg_match('/(.*)"$/', $line, $match))
236 236
                 {
237
-                    $this->oidDesc['description'] = $tmpdesc . $match[1];
237
+                    $this->oidDesc['description']=$tmpdesc.$match[1];
238 238
                     $indesc=false;
239 239
                 }
240 240
                 $tmpdesc.=$line;
@@ -245,34 +245,34 @@  discard block
 block discarded – undo
245 245
                 $this->oidDesc['oid']=$line;
246 246
                 continue;
247 247
             }
248
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match))
248
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match))
249 249
             {
250 250
                 $this->oidDesc['syntax']=$match[1];
251 251
                 $this->oidDesc['type_enum']=$match[2];
252 252
                 continue;
253 253
             }
254
-            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match))
254
+            if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match))
255 255
             {
256 256
                 $this->oidDesc['syntax']=$match[1];
257 257
                 continue;
258 258
             }
259
-            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match))
259
+            if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match))
260 260
             {
261 261
                 $this->oidDesc['dispHint']=$match[1];
262 262
                 continue;
263 263
             }
264
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match))
264
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match))
265 265
             {
266 266
                 $this->oidDesc['description']=$match[1];
267 267
                 continue;
268 268
             }
269
-            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match))
269
+            if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match))
270 270
             {
271 271
                 $tmpdesc=$match[1];
272 272
                 $indesc=true;
273 273
                 continue;
274 274
             }
275
-            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match))
275
+            if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match))
276 276
             {
277 277
                 $this->oidDesc['textconv']=$match[1];
278 278
                 continue;
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
      * @param array $objects : array of objects name (without MIB)
288 288
      * @param bool $check_existing : check instead of create
289 289
      */
290
-    public function trap_objects($trapOID,$trapmib,$objects,$check_existing)
290
+    public function trap_objects($trapOID, $trapmib, $objects, $check_existing)
291 291
     {              
292
-        $trapId = $this->dbOidIndex[$trapOID]['id']; // Get id of trap
292
+        $trapId=$this->dbOidIndex[$trapOID]['id']; // Get id of trap
293 293
         
294 294
         if ($check_existing === true)
295 295
         {
@@ -306,9 +306,9 @@  discard block
 block discarded – undo
306 306
             
307 307
             $this->parse_object($snmptrans);
308 308
 
309
-            $this->oidDesc['name'] = $object;
309
+            $this->oidDesc['name']=$object;
310 310
             
311
-            $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'],DEBUG );
311
+            $this->logging->log("Adding object ".$this->oidDesc['name']." : ".$this->oidDesc['oid']." / ".$this->oidDesc['syntax']." / ".$this->oidDesc['type_enum']." / ".$this->oidDesc['dispHint']." / ".$this->oidDesc['textconv'], DEBUG);
312 312
 
313 313
             // Update
314 314
             $this->update_oid();
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
             );
334 334
             
335 335
             if ($sqlQuery->execute($sqlParam) === false) {
336
-                $this->logging->log('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$this->oidDesc['oid']]['id'] ,1,'');
336
+                $this->logging->log('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$this->oidDesc['oid']]['id'], 1, '');
337 337
             }
338 338
         }
339 339
         if ($check_existing === true)
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
         $this->oidDesc['type']=null;
351 351
         $this->oidDesc['mib']=null;
352 352
         $this->oidDesc['textconv']=null;
353
-        $this->oidDesc['dispHint'] =null;
353
+        $this->oidDesc['dispHint']=null;
354 354
         $this->oidDesc['syntax']=null;
355 355
         $this->oidDesc['type_enum']=null;
356 356
         $this->oidDesc['description']=null;
@@ -364,17 +364,17 @@  discard block
 block discarded – undo
364 364
     {
365 365
         $retVal=0;
366 366
         // Get all mib objects from all mibs
367
-        $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
368
-        $this->logging->log('Getting all traps : '.$snmpCommand,DEBUG );
367
+        $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.' -On -Tto 2>/dev/null';
368
+        $this->logging->log('Getting all traps : '.$snmpCommand, DEBUG);
369 369
         unset($this->objectsAll);
370
-        exec($snmpCommand,$this->objectsAll,$retVal);
371
-        if ($retVal!=0)
370
+        exec($snmpCommand, $this->objectsAll, $retVal);
371
+        if ($retVal != 0)
372 372
         {
373
-            $this->logging->log('error executing snmptranslate',ERROR,'');
373
+            $this->logging->log('error executing snmptranslate', ERROR, '');
374 374
         }
375 375
         // Count elements to show progress
376 376
         $numElements=count($this->objectsAll);
377
-        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements,INFO );
377
+        $this->logging->log('Total snmp objects returned by snmptranslate : '.$numElements, INFO);
378 378
         return $numElements;
379 379
     }
380 380
 
@@ -388,14 +388,14 @@  discard block
 block discarded – undo
388 388
         $db_conn=$this->trapsDB->db_connect_trap();
389 389
         
390 390
         $sql='SELECT * from '.$this->trapsDB->dbPrefix.'mib_cache;';
391
-        $this->logging->log('SQL query : '.$sql,DEBUG );
391
+        $this->logging->log('SQL query : '.$sql, DEBUG);
392 392
         if (($ret_code=$db_conn->query($sql)) === false) {
393
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
393
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
394 394
         }
395 395
         $this->dbOidAll=$ret_code->fetchAll();
396 396
         $this->dbOidIndex=array();
397 397
         // Create the index for db;
398
-        foreach($this->dbOidAll as $key=>$val)
398
+        foreach ($this->dbOidAll as $key=>$val)
399 399
         {
400 400
             $this->dbOidIndex[$val['oid']]['key']=$key;
401 401
             $this->dbOidIndex[$val['oid']]['id']=$val['id'];
@@ -428,13 +428,13 @@  discard block
 block discarded – undo
428 428
      * @param bool $onlyTraps : set to false to get all and not only traps.
429 429
      * @return boolean : false if it's a trap , true if not
430 430
      */
431
-    private function detect_trap($curElement,$onlyTraps)
431
+    private function detect_trap($curElement, $onlyTraps)
432 432
     {
433 433
         // Get oid or pass if not found
434
-        if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement]))
434
+        if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement]))
435 435
         {
436
-            $this->timing['base_parse_time'] += microtime(true) - $this->timing['base_time'];
437
-            $this->timing['base_parse_num'] ++;
436
+            $this->timing['base_parse_time']+=microtime(true) - $this->timing['base_time'];
437
+            $this->timing['base_parse_num']++;
438 438
             return true;
439 439
         }
440 440
         $this->oidDesc['oid']=$this->objectsAll[$curElement];
@@ -443,9 +443,9 @@  discard block
 block discarded – undo
443 443
         $curElement++;
444 444
         $match=$snmptrans=array();
445 445
         if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/',
446
-            $this->objectsAll[$curElement],$match))
446
+            $this->objectsAll[$curElement], $match))
447 447
         {
448
-            $this->timing['base_check_time'] += microtime(true) - $this->timing['base_time'];
448
+            $this->timing['base_check_time']+=microtime(true) - $this->timing['base_time'];
449 449
             $this->timing['base_check_num']++;
450 450
             return true;
451 451
         }
@@ -453,22 +453,22 @@  discard block
 block discarded – undo
453 453
         $this->oidDesc['name']=$match[1]; // Name
454 454
         $this->oidDesc['type']=$match[2]; // type (21=trap, 0: may be trap, else : not trap
455 455
         
456
-        if ($this->oidDesc['type']==0) // object type=0 : check if v1 trap
456
+        if ($this->oidDesc['type'] == 0) // object type=0 : check if v1 trap
457 457
         {
458 458
             // Check if next is suboid -> in that case is cannot be a trap
459
-            if (preg_match("/^".$this->oidDesc['oid']."/",$this->objectsAll[$curElement+1]))
459
+            if (preg_match("/^".$this->oidDesc['oid']."/", $this->objectsAll[$curElement + 1]))
460 460
             {
461
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
461
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
462 462
                 $this->timing['type0_check_num']++;
463 463
                 return true;
464 464
             }
465 465
             unset($snmptrans);
466 466
             $retVal=0;
467
-            exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
468
-                ' -Td '.$this->oidDesc['oid'] . ' | grep OBJECTS ',$snmptrans,$retVal);
469
-            if ($retVal!=0)
467
+            exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
468
+                ' -Td '.$this->oidDesc['oid'].' | grep OBJECTS ', $snmptrans, $retVal);
469
+            if ($retVal != 0)
470 470
             {
471
-                $this->timing['type0_check_time'] += microtime(true) - $this->timing['base_time'];
471
+                $this->timing['type0_check_time']+=microtime(true) - $this->timing['base_time'];
472 472
                 $this->timing['type0_check_num']++;
473 473
                 return true;
474 474
             }
@@ -476,9 +476,9 @@  discard block
 block discarded – undo
476 476
             // Force as trap.
477 477
             $this->oidDesc['type']=21;
478 478
         }
479
-        if ($onlyTraps===true && $this->oidDesc['type']!=21) // if only traps and not a trap, continue
479
+        if ($onlyTraps === true && $this->oidDesc['type'] != 21) // if only traps and not a trap, continue
480 480
         {
481
-            $this->timing['nottrap_time'] += microtime(true) - $this->timing['base_time'];
481
+            $this->timing['nottrap_time']+=microtime(true) - $this->timing['base_time'];
482 482
             $this->timing['nottrap_num']++;
483 483
             return true;
484 484
         }
@@ -489,33 +489,33 @@  discard block
 block discarded – undo
489 489
     {
490 490
         $retVal=0;
491 491
         $match=$snmptrans=array();
492
-        exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslateDirs.
493
-            ' -Td '.$this->oidDesc['oid'],$snmptrans,$retVal);
494
-        if ($retVal!=0)
492
+        exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslateDirs.
493
+            ' -Td '.$this->oidDesc['oid'], $snmptrans, $retVal);
494
+        if ($retVal != 0)
495 495
         {
496
-            $this->logging->log('error executing snmptranslate',ERROR);
496
+            $this->logging->log('error executing snmptranslate', ERROR);
497 497
         }
498 498
         
499
-        if (!preg_match('/^(.*)::/',$snmptrans[0],$match))
499
+        if (!preg_match('/^(.*)::/', $snmptrans[0], $match))
500 500
         {
501
-            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : ' . $snmptrans[0],ERROR);
501
+            $this->logging->log('Error getting mib from trap '.$this->oidDesc['oid'].' : '.$snmptrans[0], ERROR);
502 502
         }
503 503
         $this->oidDesc['mib']=$match[1];
504 504
         
505 505
         $numLine=1;
506
-        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++;
506
+        while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++;
507 507
         if (isset($snmptrans[$numLine]))
508 508
         {
509
-            $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]);
509
+            $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]);
510 510
             
511
-            while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine]))
511
+            while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine]))
512 512
             {
513
-                $this->oidDesc['description'].=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]);
513
+                $this->oidDesc['description'].=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]);
514 514
                 $numLine++;
515 515
             }
516 516
             if (isset($snmptrans[$numLine])) {
517
-                $this->oidDesc['description'].=preg_replace('/".*/','',$snmptrans[$numLine]);
518
-                $this->oidDesc['description']=preg_replace('/[\t ]+/',' ',$this->oidDesc['description']);
517
+                $this->oidDesc['description'].=preg_replace('/".*/', '', $snmptrans[$numLine]);
518
+                $this->oidDesc['description']=preg_replace('/[\t ]+/', ' ', $this->oidDesc['description']);
519 519
             }
520 520
             
521 521
         }
@@ -533,23 +533,23 @@  discard block
 block discarded – undo
533 533
         $match=array();
534 534
         foreach ($snmptrans as $line)
535 535
         {
536
-            if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match))
536
+            if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match))
537 537
             {
538 538
                 $objectName=$match[1];
539 539
             }
540 540
         }
541 541
         if ($objectName == null)
542 542
         {
543
-            $this->logging->log('No objects for ' . $this->oidDesc['oid'],DEBUG);
544
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
543
+            $this->logging->log('No objects for '.$this->oidDesc['oid'], DEBUG);
544
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
545 545
             return null;
546 546
         }
547 547
         
548 548
         $trapObjects=array();
549
-        while (preg_match('/ *([^ ,]+) *,* */',$objectName,$match))
549
+        while (preg_match('/ *([^ ,]+) *,* */', $objectName, $match))
550 550
         {
551
-            array_push($trapObjects,$match[1]);
552
-            $objectName=preg_replace('/'.$match[0].'/','',$objectName);
551
+            array_push($trapObjects, $match[1]);
552
+            $objectName=preg_replace('/'.$match[0].'/', '', $objectName);
553 553
         }
554 554
         return $trapObjects;
555 555
     }
@@ -561,18 +561,18 @@  discard block
 block discarded – undo
561 561
      * @param boolean $onlyTraps : only cache traps and objects (true) or all (false)
562 562
      * @param string $startOID : only cache under startOID (NOT IMPLEMENTED)
563 563
      */
564
-    public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1')
564
+    public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1')
565 565
     {
566 566
         // Global Timing
567
-        $timeTaken = microtime(true);
567
+        $timeTaken=microtime(true);
568 568
         
569 569
         $numElements=$this->load_mibs_snmptranslate(); // Load objectsAll
570 570
         
571 571
         $this->load_mibs_from_db(); // Load from db dbOidAll & dbOidIndex
572 572
         
573
-        $step=$basestep=$numElements/10; // output display of % done
573
+        $step=$basestep=$numElements / 10; // output display of % done
574 574
         $num_step=0;
575
-        $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds
575
+        $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds
576 576
         
577 577
         // Create index for trap objects
578 578
         $this->trapObjectsIndex=array();
@@ -580,33 +580,33 @@  discard block
 block discarded – undo
580 580
         // detailed timing (time_* vars)
581 581
         $this->reset_update_timers();
582 582
         
583
-        for ($curElement=0;$curElement < $numElements;$curElement++)
583
+        for ($curElement=0; $curElement < $numElements; $curElement++)
584 584
         {
585
-            $this->timing['base_time']= microtime(true);
585
+            $this->timing['base_time']=microtime(true);
586 586
             if ($display_progress)
587 587
             {
588
-                if ((microtime(true)-$timeFiveSec) > 2)
588
+                if ((microtime(true) - $timeFiveSec) > 2)
589 589
                 { // echo a . every 2 sec
590 590
                     echo '.';
591
-                    $timeFiveSec = microtime(true);
591
+                    $timeFiveSec=microtime(true);
592 592
                 }
593
-                if ($curElement>$step)
593
+                if ($curElement > $step)
594 594
                 { // display progress
595 595
                     $num_step++;
596 596
                     $step+=$basestep;   
597
-                    echo "\n" . ($num_step*10). '% : ';
597
+                    echo "\n".($num_step * 10).'% : ';
598 598
                 }
599 599
             }
600 600
             
601 601
             $this->reset_oidDesc();
602
-            if ($this->detect_trap($curElement,$onlyTraps)===true)
602
+            if ($this->detect_trap($curElement, $onlyTraps) === true)
603 603
             {
604 604
                 continue;
605 605
             }
606 606
             
607 607
             $this->timing['num_traps']++;
608 608
             
609
-            $this->logging->log('Found trap : '.$this->oidDesc['name'] . ' / OID : '.$this->oidDesc['oid'],INFO );
609
+            $this->logging->log('Found trap : '.$this->oidDesc['name'].' / OID : '.$this->oidDesc['oid'], INFO);
610 610
             if ($display_progress) echo '#'; // echo a # when trap found
611 611
 
612 612
             // get trap objects & source MIB
@@ -616,14 +616,14 @@  discard block
 block discarded – undo
616 616
 
617 617
             $update=$this->update_oid(); // Do update of trap.
618 618
             
619
-            $this->timing['update_time'] += microtime(true) - $this->timing['base_time'];
619
+            $this->timing['update_time']+=microtime(true) - $this->timing['base_time'];
620 620
             $this->timing['update_num']++;
621 621
             
622
-            $this->timing['base_time']= microtime(true); // Reset to check object time
622
+            $this->timing['base_time']=microtime(true); // Reset to check object time
623 623
             
624
-            if (($update==0) && ($check_change===false))
624
+            if (($update == 0) && ($check_change === false))
625 625
             { // Trapd didn't change & force check disabled
626
-                $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
626
+                $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
627 627
                 if ($display_progress) echo "C";
628 628
                 continue;
629 629
             }
@@ -636,17 +636,17 @@  discard block
 block discarded – undo
636 636
            
637 637
             $this->trap_objects($this->oidDesc['oid'], $this->oidDesc['mib'], $trapObjects, false);
638 638
             
639
-            $this->timing['objects_time'] += microtime(true) - $this->timing['base_time'];
639
+            $this->timing['objects_time']+=microtime(true) - $this->timing['base_time'];
640 640
             $this->timing['objects_num']++;
641 641
         }
642 642
         
643 643
         if ($display_progress)
644 644
         {
645
-            echo "\nNumber of processed traps :  ". $this->timing['num_traps'] ."\n";
646
-            echo "\nParsing : " . number_format($this->timing['base_parse_time']+$this->timing['base_check_time'],1) ." sec / " . ($this->timing['base_parse_num']+ $this->timing['base_check_num'])  . " occurences\n";
647
-            echo "Detecting traps : " . number_format($this->timing['type0_check_time']+$this->timing['nottrap_time'],1) . " sec / " . ($this->timing['type0_check_num']+$this->timing['nottrap_num']) ." occurences\n";
648
-            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'],1)." sec , ";
649
-            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'],1)." sec \n";
645
+            echo "\nNumber of processed traps :  ".$this->timing['num_traps']."\n";
646
+            echo "\nParsing : ".number_format($this->timing['base_parse_time'] + $this->timing['base_check_time'], 1)." sec / ".($this->timing['base_parse_num'] + $this->timing['base_check_num'])." occurences\n";
647
+            echo "Detecting traps : ".number_format($this->timing['type0_check_time'] + $this->timing['nottrap_time'], 1)." sec / ".($this->timing['type0_check_num'] + $this->timing['nottrap_num'])." occurences\n";
648
+            echo "Trap processing (".$this->timing['update_num']."): ".number_format($this->timing['update_time'], 1)." sec , ";
649
+            echo "Objects processing (".$this->timing['objects_num'].") : ".number_format($this->timing['objects_time'], 1)." sec \n";
650 650
             
651 651
             $timeTaken=microtime(true) - $timeTaken;
652 652
             echo "Global time : ".round($timeTaken)." seconds\n";
Please login to merge, or discard this patch.
application/clicommands/MibCommand.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -38,39 +38,39 @@  discard block
 block discarded – undo
38 38
 	*/
39 39
 	public function updateAction()
40 40
 	{
41
-	    $background = $this->params->get('pid', null);
42
-	    $logLevel= $this->params->has('verb') ? 4 : 2;
43
-	    if ($this->params->has('force-check')) { echo "Not implemented"; return;}
44
-	    $forceCheck=$this->params->has('force-check')?True:False;
41
+	    $background=$this->params->get('pid', null);
42
+	    $logLevel=$this->params->has('verb') ? 4 : 2;
43
+	    if ($this->params->has('force-check')) { echo "Not implemented"; return; }
44
+	    $forceCheck=$this->params->has('force-check') ?True:False;
45 45
 	    $pid=1;
46 46
 	    if ($background != null)
47 47
 	    {
48
-	        $file=@fopen($background,'w');
48
+	        $file=@fopen($background, 'w');
49 49
 	        if ($file == false)
50 50
 	        {
51 51
 	            echo 'Error : cannot open pid file '.$background;
52 52
 	            return 1;
53 53
 	        }
54
-	        $pid = pcntl_fork();
54
+	        $pid=pcntl_fork();
55 55
 	        if ($pid == -1) {
56 56
 	            echo 'Error : Cannot fork process';
57 57
 	            return 1;
58 58
 	        }
59 59
 	    }
60 60
 	    $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName());
61
-		require_once($module->getBaseDir() .'/bin/trap_class.php');
61
+		require_once($module->getBaseDir().'/bin/trap_class.php');
62 62
 		$icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc');
63
-		$trap = new Trap($icingaweb2_etc);
63
+		$trap=new Trap($icingaweb2_etc);
64 64
 		if ($pid == 1)
65 65
 		{
66
-		    $trap->setLogging($logLevel,'display');
66
+		    $trap->setLogging($logLevel, 'display');
67 67
 		}
68 68
 		else
69 69
 		{  // use default display TODO : if default is 'display' son process will be killed at first output....
70 70
 		    if ($pid != 0)
71 71
 		    {
72 72
 		        // father process
73
-		        fwrite($file,$pid);
73
+		        fwrite($file, $pid);
74 74
 		        fclose($file);
75 75
 		        echo "OK : process $pid in bckground";
76 76
 		        return 0;
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
                 fclose(STDERR);
85 85
                 try
86 86
                 {
87
-                    $trap->mibClass->update_mib_database(false,$forceCheck);
87
+                    $trap->mibClass->update_mib_database(false, $forceCheck);
88 88
                 }
89 89
                 catch (Exception $e)
90 90
                 {
91
-                    $trap->trapLog('Error in updating : ' . $e->getMessage(),2);
91
+                    $trap->trapLog('Error in updating : '.$e->getMessage(), 2);
92 92
                 }
93 93
                 unlink($background);
94 94
                 return 0;
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
 		{
101 101
 			echo "Update main mib database : \n";
102 102
 			echo "# (trap found) C (trap already processed) . (every 2 seconds) : \n";
103
-			$trap->mibClass->update_mib_database(true,$forceCheck);
103
+			$trap->mibClass->update_mib_database(true, $forceCheck);
104 104
 			echo "Done\n";
105 105
 			
106 106
 		}
107 107
 		catch (Exception $e)
108 108
 		{
109
-			echo 'Error in updating : ' . $e->getMessage();
109
+			echo 'Error in updating : '.$e->getMessage();
110 110
 		}
111 111
 		if ($pid != 1)
112 112
 		{
@@ -134,23 +134,23 @@  discard block
 block discarded – undo
134 134
 		    return;
135 135
 		}
136 136
 		
137
-		$Config = new TrapModuleConfig($db_prefix);
137
+		$Config=new TrapModuleConfig($db_prefix);
138 138
 		
139 139
 		try
140 140
 		{
141 141
 			
142 142
 			$dbresource=$this->Config()->get('config', 'database');
143 143
 			echo "DB name : $dbresource\n";
144
-			$db = IcingaDbConnection::fromResourceName($dbresource)->getConnection();
144
+			$db=IcingaDbConnection::fromResourceName($dbresource)->getConnection();
145 145
 			
146
-			$query = $db->delete(
146
+			$query=$db->delete(
147 147
 			    $Config->getMIBCacheTableName(),
148 148
 			    'id>0');
149
-            echo 'Deleted '. $query . " traps and objects\n";
149
+            echo 'Deleted '.$query." traps and objects\n";
150 150
 		}
151 151
 		catch (Exception $e)
152 152
 		{
153
-			echo 'Error in DB : ' . $e->getMessage();
153
+			echo 'Error in DB : '.$e->getMessage();
154 154
 		}	   
155 155
 	}  	 	
156 156
 
Please login to merge, or discard this patch.