Passed
Push — master ( b100fb...491d6e )
by Patrick
01:48
created
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Spacing   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
     
53 53
     // Logs
54 54
     /** @var Logging Logging class. */
55
-    public $logging;    //< Logging class.
55
+    public $logging; //< Logging class.
56 56
     /** @var bool true if log was setup in constructor */
57
-    protected $logSetup;   //< bool true if log was setup in constructor
57
+    protected $logSetup; //< bool true if log was setup in constructor
58 58
     
59 59
     // Databases
60 60
     /** @var Database $trapsDB  Database class*/
61
-    public $trapsDB = null;
61
+    public $trapsDB=null;
62 62
     
63 63
     // Trap received data
64 64
     protected $receivingHost;
@@ -74,18 +74,18 @@  discard block
 block discarded – undo
74 74
     protected $trapToDb=true;
75 75
     
76 76
     /** @var Mib mib class */
77
-    public $mibClass = null;
77
+    public $mibClass=null;
78 78
     
79 79
     /** @var Rule rule class */
80
-    public $ruleClass = null;
80
+    public $ruleClass=null;
81 81
     
82 82
     /** @var Plugins plugins manager **/
83
-    public $pluginClass = null;
83
+    public $pluginClass=null;
84 84
     
85 85
     /** @var TrapApi $trapApiClass */
86
-    public $trapApiClass = null;
86
+    public $trapApiClass=null;
87 87
     
88
-    function __construct($etcDir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
88
+    function __construct($etcDir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
89 89
     {
90 90
         // Paths of ini files
91 91
         $this->icingaweb2Etc=$etcDir;
@@ -93,10 +93,10 @@  discard block
 block discarded – undo
93 93
         $this->icingaweb2Ressources=$this->icingaweb2Etc."/resources.ini";
94 94
 
95 95
         //************* Setup logging
96
-        $this->logging = new Logging();
96
+        $this->logging=new Logging();
97 97
         if ($baseLogLevel != null)
98 98
         {
99
-            $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
99
+            $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
100 100
             $this->logSetup=true;
101 101
         }
102 102
         else
@@ -108,17 +108,17 @@  discard block
 block discarded – undo
108 108
         
109 109
         // Create distributed API object
110 110
         
111
-        $this->trapApiClass = new TrapApi($this->logging);
111
+        $this->trapApiClass=new TrapApi($this->logging);
112 112
         
113 113
         //*************** Get options from ini files
114
-        if (! is_file($this->trapModuleConfig))
114
+        if (!is_file($this->trapModuleConfig))
115 115
         {
116 116
             throw new Exception("Ini file ".$this->trapModuleConfig." does not exists");
117 117
         }
118
-        $trapConfig=parse_ini_file($this->trapModuleConfig,true);
118
+        $trapConfig=parse_ini_file($this->trapModuleConfig, true);
119 119
         if ($trapConfig == false)
120 120
         {
121
-            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog');
121
+            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig, ERROR, 'syslog');
122 122
             throw new Exception("Error reading ini file : ".$this->trapModuleConfig);
123 123
         }
124 124
         $this->getMainOptions($trapConfig); // Get main options from ini file
@@ -132,10 +132,10 @@  discard block
 block discarded – undo
132 132
         if ($this->apiUse === true) $this->getAPI(); // Setup API
133 133
         
134 134
         //*************** Setup MIB
135
-        $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
135
+        $this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class
136 136
         
137 137
         //*************** Setup Rule
138
-        $this->ruleClass = new Rule($this); //< Create Rule class
138
+        $this->ruleClass=new Rule($this); //< Create Rule class
139 139
         
140 140
         $this->trapData=array(  // TODO : put this in a reset function (DAEMON_MODE)
141 141
             'source_ip'	=> 'unknown',
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
         
148 148
         //*************** Setup Plugins
149 149
         //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins
150
-        $this->pluginClass = new Plugins($this);
150
+        $this->pluginClass=new Plugins($this);
151 151
             
152 152
             
153 153
     }
@@ -176,15 +176,15 @@  discard block
 block discarded – undo
176 176
      *	@param  string $destination file/syslog/display
177 177
      *	@return void
178 178
      **/
179
-    public function trapLog( $message, $level, $destination ='') // OBSOLETE
179
+    public function trapLog($message, $level, $destination='') // OBSOLETE
180 180
     {
181 181
         // TODO : replace ref with $this->logging->log
182 182
         $this->logging->log($message, $level, $destination);
183 183
     }
184 184
     
185
-    public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
185
+    public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
186 186
     {
187
-        $this->logging->setLogging($debugLvl, $outputType,$outputOption);
187
+        $this->logging->setLogging($debugLvl, $outputType, $outputOption);
188 188
     }
189 189
     
190 190
     /**
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
     {
196 196
         if ($this->icinga2api == null)
197 197
         {
198
-            $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort);
198
+            $this->icinga2api=new Icinga2API($this->apiHostname, $this->apiPort);
199 199
         }
200 200
         return $this->icinga2api;
201 201
     }
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
         if ($input_stream === false)
215 215
         {
216 216
             $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
217
-            $this->logging->log("Error reading stdin !",ERROR,'');
217
+            $this->logging->log("Error reading stdin !", ERROR, '');
218 218
             return null; // note : exception thrown by logging
219 219
         }
220 220
         
@@ -223,21 +223,21 @@  discard block
 block discarded – undo
223 223
         if ($this->receivingHost === false)
224 224
         {
225 225
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
226
-            $this->logging->log("Error reading Host !",ERROR,'');
226
+            $this->logging->log("Error reading Host !", ERROR, '');
227 227
         }
228 228
         // line 2 IP:port=>IP:port
229 229
         $IP=chop(fgets($input_stream));
230 230
         if ($IP === false)
231 231
         {
232 232
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
233
-            $this->logging->log("Error reading IP !",ERROR,'');
233
+            $this->logging->log("Error reading IP !", ERROR, '');
234 234
         }
235 235
         $matches=array();
236
-        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
237
-        if ($ret_code===0 || $ret_code===false)
236
+        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
237
+        if ($ret_code === 0 || $ret_code === false)
238 238
         {
239 239
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
240
-            $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
240
+            $this->logging->log('Error parsing IP : '.$IP, ERROR, '');
241 241
         }
242 242
         else
243 243
         {
@@ -247,41 +247,41 @@  discard block
 block discarded – undo
247 247
             $this->trapData['destination_port']=$matches[4];
248 248
         }
249 249
         
250
-        while (($vars=fgets($input_stream)) !==false)
250
+        while (($vars=fgets($input_stream)) !== false)
251 251
         {
252 252
             $vars=chop($vars);
253
-            $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
254
-            if ($ret_code===0 || $ret_code===false)
253
+            $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
254
+            if ($ret_code === 0 || $ret_code === false)
255 255
             {
256
-                $this->logging->log('No match on trap data : '.$vars,WARN,'');
256
+                $this->logging->log('No match on trap data : '.$vars, WARN, '');
257 257
                 continue;
258 258
             }
259
-            if (($matches[1]=='.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1]=='.1.3.6.1.6.3.1.1.4.1'))
259
+            if (($matches[1] == '.1.3.6.1.6.3.1.1.4.1.0') || ($matches[1] == '.1.3.6.1.6.3.1.1.4.1'))
260 260
             {
261 261
                 $this->trapData['trap_oid']=$matches[2];
262 262
                 continue;
263 263
             }
264
-            if ( $this->useSnmpTrapAddess === TRUE &&  preg_match('/'.$this->snmpTrapAddressOID.'/', $matches[1]) == 1)
264
+            if ($this->useSnmpTrapAddess === TRUE && preg_match('/'.$this->snmpTrapAddressOID.'/', $matches[1]) == 1)
265 265
             {
266
-                $this->logging->log('Found relayed trap from ' . $matches[2] . ' relayed by ' .$this->trapData['source_ip'],DEBUG);
267
-                if (preg_match('/^[0-9\.]+$/',$matches[2]) == 0 && preg_match('/^[0-9a-fA-F:]+$/',$matches[2]) == 0)
266
+                $this->logging->log('Found relayed trap from '.$matches[2].' relayed by '.$this->trapData['source_ip'], DEBUG);
267
+                if (preg_match('/^[0-9\.]+$/', $matches[2]) == 0 && preg_match('/^[0-9a-fA-F:]+$/', $matches[2]) == 0)
268 268
                 {
269
-                    $this->logging->log('Value of SnmpTrapAddess ('.$this->snmpTrapAddressOID.') is not IP : ' .$matches[2],WARN,'');
269
+                    $this->logging->log('Value of SnmpTrapAddess ('.$this->snmpTrapAddressOID.') is not IP : '.$matches[2], WARN, '');
270 270
                     continue;
271 271
                 }
272
-                $this->trapData['source_ip'] = $matches[2];
272
+                $this->trapData['source_ip']=$matches[2];
273 273
                 continue;
274 274
             }
275
-            $object= new stdClass;
276
-            $object->oid =$matches[1];
277
-            $object->value = $matches[2];
278
-            array_push($this->trapDataExt,$object);
275
+            $object=new stdClass;
276
+            $object->oid=$matches[1];
277
+            $object->value=$matches[2];
278
+            array_push($this->trapDataExt, $object);
279 279
         }
280 280
         
281
-        if ($this->trapData['trap_oid']=='unknown')
281
+        if ($this->trapData['trap_oid'] == 'unknown')
282 282
         {
283
-            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']);
284
-            $this->logging->log('no trap oid found',ERROR,'');
283
+            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trapData['source_ip']);
284
+            $this->logging->log('no trap oid found', ERROR, '');
285 285
         }
286 286
         
287 287
         // Translate oids.
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
         }
304 304
         
305 305
         
306
-        $this->trapData['status']= 'waiting';
306
+        $this->trapData['status']='waiting';
307 307
         
308 308
         return $this->trapData;
309 309
     }
@@ -319,40 +319,40 @@  discard block
 block discarded – undo
319 319
         $db_conn=$this->trapsDB->db_connect_trap();
320 320
         
321 321
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';';
322
-        $this->logging->log('SQL query : '.$sql,DEBUG );
322
+        $this->logging->log('SQL query : '.$sql, DEBUG);
323 323
         if (($ret_code=$db_conn->query($sql)) === false) {
324
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
324
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
325 325
         }
326 326
         $name=$ret_code->fetch();
327 327
         if ($name['name'] != null)
328 328
         {
329
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
329
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
330 330
         }
331 331
         
332 332
         // Also check if it is an instance of OID
333
-        $oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
333
+        $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
334 334
         
335 335
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
336
-        $this->logging->log('SQL query : '.$sql,DEBUG );
336
+        $this->logging->log('SQL query : '.$sql, DEBUG);
337 337
         if (($ret_code=$db_conn->query($sql)) === false) {
338
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
338
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
339 339
         }
340 340
         $name=$ret_code->fetch();
341 341
         if ($name['name'] != null)
342 342
         {
343
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
343
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
344 344
         }
345 345
         
346 346
         // Try to get oid name from snmptranslate
347
-        $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
347
+        $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
348 348
             ' '.$oid);
349 349
         $matches=array();
350
-        $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
351
-        if ($ret_code===0 || $ret_code === false) {
350
+        $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
351
+        if ($ret_code === 0 || $ret_code === false) {
352 352
             return NULL;
353 353
         } else {
354
-            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
355
-            return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
354
+            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
355
+            return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
356 356
         }
357 357
     }
358 358
     
@@ -363,90 +363,90 @@  discard block
 block discarded – undo
363 363
      **/
364 364
     public function eraseOldTraps($days=0)
365 365
     {
366
-        if ($days==0)
366
+        if ($days == 0)
367 367
         {
368 368
             if (($days=$this->getDBConfig('db_remove_days')) == null)
369 369
             {
370
-                $this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
370
+                $this->logging->log('No days specified & no db value : no tap erase', WARN, '');
371 371
                 return;
372 372
             }
373 373
         }
374 374
         $db_conn=$this->trapsDB->db_connect_trap();
375
-        $daysago = strtotime("-".$days." day");
376
-        $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
375
+        $daysago=strtotime("-".$days." day");
376
+        $sql='delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
377 377
         if ($db_conn->query($sql) === false) {
378
-            $this->logging->log('Error erasing traps : '.$sql,ERROR,'');
378
+            $this->logging->log('Error erasing traps : '.$sql, ERROR, '');
379 379
         }
380
-        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
380
+        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
381 381
     }
382 382
     
383 383
     /** Write error to received trap database
384 384
      */
385
-    public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
385
+    public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
386 386
     {
387 387
         
388 388
         $db_conn=$this->trapsDB->db_connect_trap();
389 389
         
390 390
         // add date time
391
-        $insert_col ='date_received,status';
392
-        $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
391
+        $insert_col='date_received,status';
392
+        $insert_val="'".date("Y-m-d H:i:s")."','error'";
393 393
         
394
-        if ($sourceIP !=null)
394
+        if ($sourceIP != null)
395 395
         {
396
-            $insert_col .=',source_ip';
397
-            $insert_val .=",'". $sourceIP ."'";
396
+            $insert_col.=',source_ip';
397
+            $insert_val.=",'".$sourceIP."'";
398 398
         }
399
-        if ($trapoid !=null)
399
+        if ($trapoid != null)
400 400
         {
401
-            $insert_col .=',trap_oid';
402
-            $insert_val .=",'". $trapoid ."'";
401
+            $insert_col.=',trap_oid';
402
+            $insert_val.=",'".$trapoid."'";
403 403
         }
404
-        $insert_col .=',status_detail';
405
-        $insert_val .=",'". $message ."'";
404
+        $insert_col.=',status_detail';
405
+        $insert_val.=",'".$message."'";
406 406
         
407
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
407
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
408 408
         
409 409
         switch ($this->trapsDB->trapDBType)
410 410
         {
411 411
             case 'pgsql':
412
-                $sql .= ' RETURNING id;';
413
-                $this->logging->log('sql : '.$sql,INFO);
412
+                $sql.=' RETURNING id;';
413
+                $this->logging->log('sql : '.$sql, INFO);
414 414
                 if (($ret_code=$db_conn->query($sql)) === false) {
415
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
415
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
416 416
                 }
417
-                $this->logging->log('SQL insertion OK',INFO );
417
+                $this->logging->log('SQL insertion OK', INFO);
418 418
                 // Get last id to insert oid/values in secondary table
419 419
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
420 420
                     
421
-                    $this->logging->log('Erreur recuperation id',1,'');
421
+                    $this->logging->log('Erreur recuperation id', 1, '');
422 422
                 }
423
-                if (! isset($inserted_id_ret['id'])) {
424
-                    $this->logging->log('Error getting id',1,'');
423
+                if (!isset($inserted_id_ret['id'])) {
424
+                    $this->logging->log('Error getting id', 1, '');
425 425
                 }
426 426
                 $this->trapId=$inserted_id_ret['id'];
427 427
                 break;
428 428
             case 'mysql':
429
-                $sql .= ';';
430
-                $this->logging->log('sql : '.$sql,INFO );
429
+                $sql.=';';
430
+                $this->logging->log('sql : '.$sql, INFO);
431 431
                 if ($db_conn->query($sql) === false) {
432
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
432
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
433 433
                 }
434
-                $this->logging->log('SQL insertion OK',INFO );
434
+                $this->logging->log('SQL insertion OK', INFO);
435 435
                 // Get last id to insert oid/values in secondary table
436 436
                 $sql='SELECT LAST_INSERT_ID();';
437 437
                 if (($ret_code=$db_conn->query($sql)) === false) {
438
-                    $this->logging->log('Erreur recuperation id',1,'');
438
+                    $this->logging->log('Erreur recuperation id', 1, '');
439 439
                 }
440 440
                 
441 441
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
442
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
442
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
443 443
                 $this->trapId=$inserted_id;
444 444
                 break;
445 445
             default:
446
-                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
446
+                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
447 447
         }
448 448
         
449
-        $this->logging->log('id found: '. $this->trapId,INFO );
449
+        $this->logging->log('id found: '.$this->trapId, INFO);
450 450
     }
451 451
     
452 452
     /** Write trap data to trap database
@@ -463,86 +463,86 @@  discard block
 block discarded – undo
463 463
         $insert_col='';
464 464
         $insert_val='';
465 465
         // add date time
466
-        $this->trapData['date_received'] = date("Y-m-d H:i:s");
466
+        $this->trapData['date_received']=date("Y-m-d H:i:s");
467 467
         
468 468
         $firstcol=1;
469 469
         foreach ($this->trapData as $col => $val)
470 470
         {
471
-            if ($firstcol==0)
471
+            if ($firstcol == 0)
472 472
             {
473
-                $insert_col .=',';
474
-                $insert_val .=',';
473
+                $insert_col.=',';
474
+                $insert_val.=',';
475 475
             }
476
-            $insert_col .= $col ;
477
-            $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
476
+            $insert_col.=$col;
477
+            $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
478 478
             $firstcol=0;
479 479
         }
480 480
         
481
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
481
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
482 482
         switch ($this->trapsDB->trapDBType)
483 483
         {
484 484
             case 'pgsql':
485
-                $sql .= ' RETURNING id;';
486
-                $this->logging->log('sql : '.$sql,INFO );
485
+                $sql.=' RETURNING id;';
486
+                $this->logging->log('sql : '.$sql, INFO);
487 487
                 if (($ret_code=$db_conn->query($sql)) === false) {
488
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
488
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
489 489
                 }
490
-                $this->logging->log('SQL insertion OK',INFO );
490
+                $this->logging->log('SQL insertion OK', INFO);
491 491
                 // Get last id to insert oid/values in secondary table
492 492
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
493 493
                     
494
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
494
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
495 495
                 }
496
-                if (! isset($inserted_id_ret['id'])) {
497
-                    $this->logging->log('Error getting id',ERROR,'');
496
+                if (!isset($inserted_id_ret['id'])) {
497
+                    $this->logging->log('Error getting id', ERROR, '');
498 498
                 }
499 499
                 $this->trapId=$inserted_id_ret['id'];
500 500
                 break;
501 501
             case 'mysql':
502
-                $sql .= ';';
503
-                $this->logging->log('sql : '.$sql,INFO );
502
+                $sql.=';';
503
+                $this->logging->log('sql : '.$sql, INFO);
504 504
                 if ($db_conn->query($sql) === false) {
505
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
505
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
506 506
                 }
507
-                $this->logging->log('SQL insertion OK',INFO );
507
+                $this->logging->log('SQL insertion OK', INFO);
508 508
                 // Get last id to insert oid/values in secondary table
509 509
                 $sql='SELECT LAST_INSERT_ID();';
510 510
                 if (($ret_code=$db_conn->query($sql)) === false) {
511
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
511
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
512 512
                 }
513 513
                 
514 514
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
515
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
515
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
516 516
                 $this->trapId=$inserted_id;
517 517
                 break;
518 518
             default:
519
-                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
519
+                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
520 520
         }
521
-        $this->logging->log('id found: '.$this->trapId,INFO );
521
+        $this->logging->log('id found: '.$this->trapId, INFO);
522 522
         
523 523
         // Fill trap extended data table
524 524
         foreach ($this->trapDataExt as $value) {
525 525
             // TODO : detect if trap value is encoded and decode it to UTF-8 for database
526 526
             $firstcol=1;
527
-            $value->trap_id = $this->trapId;
527
+            $value->trap_id=$this->trapId;
528 528
             $insert_col='';
529 529
             $insert_val='';
530 530
             foreach ($value as $col => $val)
531 531
             {
532
-                if ($firstcol==0)
532
+                if ($firstcol == 0)
533 533
                 {
534
-                    $insert_col .=',';
535
-                    $insert_val .=',';
534
+                    $insert_col.=',';
535
+                    $insert_val.=',';
536 536
                 }
537
-                $insert_col .= $col;
538
-                $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
537
+                $insert_col.=$col;
538
+                $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
539 539
                 $firstcol=0;
540 540
             }
541 541
             
542
-            $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';
542
+            $sql='INSERT INTO '.$this->dbPrefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';
543 543
             
544 544
             if ($db_conn->query($sql) === false) {
545
-                $this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
545
+                $this->logging->log('Erreur insertion data : '.$sql, WARN, '');
546 546
             }
547 547
         }
548 548
     }
@@ -552,14 +552,14 @@  discard block
 block discarded – undo
552 552
      *	@param $oid string oid in numeric
553 553
      *	@return mixed|boolean : PDO object or false
554 554
      */
555
-    protected function getRules($ip,$oid)
555
+    protected function getRules($ip, $oid)
556 556
     {
557 557
         $db_conn=$this->trapsDB->db_connect_trap();
558 558
         // fetch rules based on IP in rule and OID
559 559
         $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' ';
560
-        $this->logging->log('SQL query : '.$sql,DEBUG );
560
+        $this->logging->log('SQL query : '.$sql, DEBUG);
561 561
         if (($ret_code=$db_conn->query($sql)) === false) {
562
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
562
+            $this->logging->log('No result in query : '.$sql, WARN, '');
563 563
             return false;
564 564
         }
565 565
         $rules_all=$ret_code->fetchAll();
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
         $rule_ret_key=0;
569 569
         foreach ($rules_all as $key => $rule)
570 570
         {
571
-            if ($rule['ip4']==$ip || $rule['ip6']==$ip)
571
+            if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
572 572
             {
573 573
                 $rules_ret[$rule_ret_key]=$rules_all[$key];
574 574
                 //TODO : get host name by API (and check if correct in rule).
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
                 continue;
577 577
             }
578 578
             // TODO : get hosts IP by API
579
-            if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
579
+            if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
580 580
             { // get ips of group members by oid
581 581
                 $db_conn2=$this->trapsDB->db_connect_ido();
582 582
                 $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -587,15 +587,15 @@  discard block
 block discarded – undo
587 587
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
588 588
 						WHERE o.name1='".$rule['host_group_name']."';";
589 589
                 if (($ret_code2=$db_conn2->query($sql)) === false) {
590
-                    $this->logging->log('No result in query : ' . $sql,WARN,'');
590
+                    $this->logging->log('No result in query : '.$sql, WARN, '');
591 591
                     continue;
592 592
                 }
593 593
                 $grouphosts=$ret_code2->fetchAll();
594 594
                 //echo "rule grp :\n";print_r($grouphosts);echo "\n";
595
-                foreach ( $grouphosts as $host)
595
+                foreach ($grouphosts as $host)
596 596
                 {
597 597
                     //echo $host['ip4']."\n";
598
-                    if ($host['ip4']==$ip || $host['ip6']==$ip)
598
+                    if ($host['ip4'] == $ip || $host['ip6'] == $ip)
599 599
                     {
600 600
                         //echo "Rule added \n";
601 601
                         $rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
         $db_conn=$this->trapsDB->db_connect_trap();
619 619
         $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
620 620
         if ($db_conn->query($sql) === false) {
621
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
621
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
622 622
         }
623 623
     }
624 624
     
@@ -630,23 +630,23 @@  discard block
 block discarded – undo
630 630
      * @param string $display
631 631
      * @returnn bool true is service check was sent without error
632 632
      */
633
-    public function serviceCheckResult($host,$service,$state,$display)
633
+    public function serviceCheckResult($host, $service, $state, $display)
634 634
     {
635 635
         if ($this->apiUse === false)
636 636
         {
637
-            $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
638
-                $host.';' .$service .';' . $state . ';'.$display;
639
-                $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
637
+            $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
638
+                $host.';'.$service.';'.$state.';'.$display;
639
+                $this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
640 640
                 
641 641
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
642
-                exec('echo "'.$send.'" > ' .$this->icinga2cmd);
642
+                exec('echo "'.$send.'" > '.$this->icinga2cmd);
643 643
                 return true;
644 644
         }
645 645
         else
646 646
         {
647 647
             // Get perfdata if found
648 648
             $matches=array();
649
-            if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1)
649
+            if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1)
650 650
             {
651 651
                 $display=$matches[1];
652 652
                 $perfdata=$matches[2];
@@ -656,17 +656,17 @@  discard block
 block discarded – undo
656 656
                 $perfdata='';
657 657
             }
658 658
             
659
-            $api = $this->getAPI();
659
+            $api=$this->getAPI();
660 660
             $api->setCredentials($this->apiUsername, $this->apiPassword);
661
-            list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata);
661
+            list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata);
662 662
             if ($retcode == false)
663 663
             {
664
-                $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
664
+                $this->logging->log("Error sending result : ".$retmessage, WARN, '');
665 665
                 return false;
666 666
             }
667 667
             else
668 668
             {
669
-                $this->logging->log( "Sent result : " .$retmessage,INFO );
669
+                $this->logging->log("Sent result : ".$retmessage, INFO);
670 670
                 return true;
671 671
             }
672 672
         }
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
     
675 675
     public function getHostByIP($ip)
676 676
     {
677
-        $api = $this->getAPI();
677
+        $api=$this->getAPI();
678 678
         $api->setCredentials($this->apiUsername, $this->apiPassword);
679 679
         return $api->getHostByIP($ip);
680 680
     }
@@ -687,35 +687,35 @@  discard block
 block discarded – undo
687 687
     protected function applyDisplay($display)
688 688
     {
689 689
         $matches=array();
690
-        while (preg_match('/_OID\(([0-9\.\*]+)\)/',$display,$matches) == 1)
690
+        while (preg_match('/_OID\(([0-9\.\*]+)\)/', $display, $matches) == 1)
691 691
         {
692 692
             $oid=$matches[1];
693 693
             $found=0;
694 694
             // Test and transform regexp
695
-            $oidR = $this->ruleClass->regexp_eval($oid);
695
+            $oidR=$this->ruleClass->regexp_eval($oid);
696 696
             
697
-            foreach($this->trapDataExt as $val)
697
+            foreach ($this->trapDataExt as $val)
698 698
             {
699
-                if (preg_match("/^$oidR$/",$val->oid) == 1)
699
+                if (preg_match("/^$oidR$/", $val->oid) == 1)
700 700
                 {
701
-                    $val->value=preg_replace('/"/','',$val->value);
701
+                    $val->value=preg_replace('/"/', '', $val->value);
702 702
                     $rep=0;
703
-                    $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
704
-                    if ($rep==0)
703
+                    $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
704
+                    if ($rep == 0)
705 705
                     {
706
-                        $this->logging->log("Error in display",WARN,'');
706
+                        $this->logging->log("Error in display", WARN, '');
707 707
                         return $display;
708 708
                     }
709 709
                     $found=1;
710 710
                     break;
711 711
                 }
712 712
             }
713
-            if ($found==0)
713
+            if ($found == 0)
714 714
             {
715
-                $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
716
-                if ($rep==0)
715
+                $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
716
+                if ($rep == 0)
717 717
                 {
718
-                    $this->logging->log("Error in display",WARN,'');
718
+                    $this->logging->log("Error in display", WARN, '');
719 719
                     return $display;
720 720
                 }
721 721
             }
@@ -727,11 +727,11 @@  discard block
 block discarded – undo
727 727
      */
728 728
     public function applyRules()
729 729
     {
730
-        $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']);
730
+        $rules=$this->getRules($this->trapData['source_ip'], $this->trapData['trap_oid']);
731 731
         
732
-        if ($rules===false || count($rules)==0)
732
+        if ($rules === false || count($rules) == 0)
733 733
         {
734
-            $this->logging->log('No rules found for this trap',INFO );
734
+            $this->logging->log('No rules found for this trap', INFO);
735 735
             $this->trapData['status']='unknown';
736 736
             $this->trapToDb=true;
737 737
             return;
@@ -746,59 +746,59 @@  discard block
 block discarded – undo
746 746
             $service_name=$rule['service_name'];
747 747
             
748 748
             $display=$this->applyDisplay($rule['display']);
749
-            $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', ';
749
+            $this->trapAction=($this->trapAction == null) ? '' : $this->trapAction.', ';
750 750
             try
751 751
             {
752
-                $this->logging->log('Rule to eval : '.$rule['rule'],INFO );
753
-                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ;
752
+                $this->logging->log('Rule to eval : '.$rule['rule'], INFO);
753
+                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt);
754 754
                 //->eval_rule($rule['rule']);
755 755
                 
756 756
                 if ($evalr == true)
757 757
                 {
758 758
                     //$this->logging->log('rules OOK: '.print_r($rule),INFO );
759 759
                     $action=$rule['action_match'];
760
-                    $this->logging->log('action OK : '.$action,INFO );
760
+                    $this->logging->log('action OK : '.$action, INFO);
761 761
                     if ($action >= 0)
762 762
                     {
763
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
763
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
764 764
                         {
765 765
                             $this->trapAction.='Error sending status : check cmd/API';
766 766
                         }
767 767
                         else
768 768
                         {
769
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
769
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
770 770
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
771 771
                         }
772 772
                     }
773 773
                     else
774 774
                     {
775
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
775
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
776 776
                     }
777
-                    $this->trapToDb=($action==-2)?false:true;
777
+                    $this->trapToDb=($action == -2) ?false:true;
778 778
                 }
779 779
                 else
780 780
                 {
781 781
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
782 782
                     
783 783
                     $action=$rule['action_nomatch'];
784
-                    $this->logging->log('action NOK : '.$action,INFO );
784
+                    $this->logging->log('action NOK : '.$action, INFO);
785 785
                     if ($action >= 0)
786 786
                     {
787
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
787
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
788 788
                         {
789 789
                             $this->trapAction.='Error sending status : check cmd/API';
790 790
                         }
791 791
                         else
792 792
                         {
793
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
793
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
794 794
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
795 795
                         }
796 796
                     }
797 797
                     else
798 798
                     {
799
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
799
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
800 800
                     }
801
-                    $this->trapToDb=($action==-2)?false:true;
801
+                    $this->trapToDb=($action == -2) ?false:true;
802 802
                 }
803 803
                 // Put name in source_name
804 804
                 if (!isset($this->trapData['source_name']))
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
                 }
808 808
                 else
809 809
                 {
810
-                    if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name']))
810
+                    if (!preg_match('/'.$rule['host_name'].'/', $this->trapData['source_name']))
811 811
                     { // only add if not present
812 812
                         $this->trapData['source_name'].=','.$rule['host_name'];
813 813
                     }
@@ -815,13 +815,13 @@  discard block
 block discarded – undo
815 815
             }
816 816
             catch (Exception $e)
817 817
             {
818
-                $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
818
+                $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
819 819
                 $this->trapAction.=' ERR : '.$e->getMessage();
820 820
                 $this->trapData['status']='error';
821 821
             }
822 822
             
823 823
         }
824
-        if ($this->trapData['status']=='error')
824
+        if ($this->trapData['status'] == 'error')
825 825
         {
826 826
             $this->trapToDb=true; // Always put errors in DB for the use can see
827 827
         }
@@ -837,13 +837,13 @@  discard block
 block discarded – undo
837 837
     public function add_rule_final($time)
838 838
     {
839 839
         $db_conn=$this->trapsDB->db_connect_trap();
840
-        if ($this->trapAction==null)
840
+        if ($this->trapAction == null)
841 841
         {
842 842
             $this->trapAction='No action';
843 843
         }
844 844
         $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."'  WHERE (id = '".$this->trapId."');";
845 845
         if ($db_conn->query($sql) === false) {
846
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
846
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
847 847
         }
848 848
     }
849 849
     
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
     WHERE s.current_state != 0;";
867 867
         $db_conn=$this->trapsDB->db_connect_ido();
868 868
         if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
869
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
869
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
870 870
             return 0;
871 871
         }
872 872
         $services=$services_db->fetchAll();
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
         $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;";
876 876
         $db_conn2=$this->trapsDB->db_connect_trap();
877 877
         if (($rules_db=$db_conn2->query($sql_query)) === false) {
878
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
878
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
879 879
             return 0;
880 880
         }
881 881
         $rules=$rules_db->fetchAll();
@@ -891,13 +891,13 @@  discard block
 block discarded – undo
891 891
                     $service['host_name'] == $rule['host_name'] &&
892 892
                     ($service['last_check'] + $rule['revert_ok']) < $now)
893 893
                 {
894
-                    $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
894
+                    $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
895 895
                     $numreset++;
896 896
                 }
897 897
             }
898 898
         }
899 899
         echo "\n";
900
-        echo $numreset . " service(s) reset to OK\n";
900
+        echo $numreset." service(s) reset to OK\n";
901 901
         return 0;
902 902
         
903 903
     }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/TrapConfig.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -36,15 +36,15 @@  discard block
 block discarded – undo
36 36
      * @param string $message warning message if not found
37 37
      * @return boolean true if found, or false
38 38
      */
39
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
39
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=WARN, $message=null)
40 40
     {
41 41
         if (!isset($option_array[$option_category][$option_name]))
42 42
         {
43 43
             if ($message === null)
44 44
             {
45
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
45
+                $message='No '.$option_name.' in config file: '.$this->trapModuleConfig;
46 46
             }
47
-            $this->getLogging()->log($message,$log_level);
47
+            $this->getLogging()->log($message, $log_level);
48 48
             return false;
49 49
         }
50 50
         else
@@ -62,24 +62,24 @@  discard block
 block discarded – undo
62 62
         // Database options
63 63
         if ($this->logSetup === false) // Only if logging was no setup in constructor
64 64
         {
65
-            $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
66
-            $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
67
-            $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
65
+            $this->getDBConfigIfSet('log_level', $this->getLogging()->debugLevel);
66
+            $this->getDBConfigIfSet('log_destination', $this->getLogging()->outputMode);
67
+            $this->getDBConfigIfSet('log_file', $this->getLogging()->outputFile);
68 68
         }
69 69
         
70
-        $tmpVal = -1; // Get boolean coded in database as 1/0
70
+        $tmpVal=-1; // Get boolean coded in database as 1/0
71 71
         $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal);
72
-        if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
72
+        if ($tmpVal != -1) $this->useSnmpTrapAddess=($tmpVal == 1) ? TRUE : FALSE;
73 73
         
74 74
         $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps
75
-        $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
75
+        $this->snmpTrapAddressOID=preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
76 76
     }
77 77
         
78 78
     /** Set $variable to value if $element found in database config table
79 79
      * @param string $element
80 80
      * @param string $variable
81 81
      */
82
-    protected function getDBConfigIfSet($element,&$variable)
82
+    protected function getDBConfigIfSet($element, &$variable)
83 83
     {
84 84
         $value=$this->getDBConfig($element);
85 85
         if ($value != null) $variable=$value;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         $db_conn=$this->trapsDB->db_connect_trap();
96 96
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
97 97
         if (($ret_code=$db_conn->query($sql)) === false) {
98
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
98
+            $this->logging->log('No result in query : '.$sql, WARN, '');
99 99
             return null;
100 100
         }
101 101
         $value=$ret_code->fetch();
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
     {
115 115
         
116 116
         $nodeStatus='';
117
-        $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
117
+        $this->getOptionIfSet($trapConfig, 'config', 'node', $nodeStatus);
118 118
         if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
119 119
         {
120
-            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
120
+            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER', WARN);
121 121
             $this->getTrapApi()->setStatusMaster();
122 122
         }
123 123
         else 
@@ -125,36 +125,36 @@  discard block
 block discarded – undo
125 125
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
126 126
             {
127 127
                 // Get options to connect to API
128
-                $IP = $port = $user =  $pass = null;
129
-                $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
130
-                $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
131
-                $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
132
-                $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
128
+                $IP=$port=$user=$pass=null;
129
+                $this->getOptionIfSet($trapConfig, 'config', 'masterIP', $IP, ERROR);
130
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPort', $port, ERROR);
131
+                $this->getOptionIfSet($trapConfig, 'config', 'masterUser', $user, ERROR);
132
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPass', $pass, ERROR);
133 133
                 $this->getTrapApi()->setParams($IP, $port, $user, $pass);
134 134
                 return;
135 135
             }
136 136
         }
137 137
         
138 138
         // Snmptranslate binary path
139
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
139
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
140 140
         
141 141
         // mibs path
142
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
142
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
143 143
         
144 144
         // icinga2cmd path
145
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
145
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
146 146
         
147 147
         // table prefix
148
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
148
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix);
149 149
         
150 150
         // API options
151
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
151
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname))
152 152
         {
153 153
             $this->apiUse=true;
154 154
             // Get API options or throw exception as not configured correctly
155
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
156
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
157
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
155
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort, ERROR);
156
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername, ERROR);
157
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword, ERROR);
158 158
         }
159 159
     }
160 160
     
@@ -165,43 +165,43 @@  discard block
 block discarded – undo
165 165
     protected function setupDatabase($trapConfig)
166 166
     {
167 167
         // Trap database
168
-        if (!array_key_exists('database',$trapConfig['config']))
168
+        if (!array_key_exists('database', $trapConfig['config']))
169 169
         {
170
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
170
+            $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, '');
171 171
             return;
172 172
         }
173 173
         $dbTrapName=$trapConfig['config']['database'];
174
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
174
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
175 175
         
176
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
176
+        if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false)
177 177
         {
178
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
178
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, '');
179 179
             return;
180 180
         }
181
-        if (!array_key_exists($dbTrapName,$dbConfig))
181
+        if (!array_key_exists($dbTrapName, $dbConfig))
182 182
         {
183
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
183
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
184 184
             return;
185 185
         }
186 186
         
187
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
187
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix);
188 188
         
189
-        $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG );
189
+        $this->logging->log("API Use : ".print_r($this->apiUse, true), DEBUG);
190 190
         
191 191
         //TODO enable this again when API queries are all done :
192 192
         //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
193 193
         
194 194
         // IDO Database
195
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
195
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
196 196
         {
197
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
197
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
198 198
         }
199 199
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
200 200
         
201
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
202
-        if (!array_key_exists($dbIdoName,$dbConfig))
201
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
202
+        if (!array_key_exists($dbIdoName, $dbConfig))
203 203
         {
204
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
204
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
205 205
             return;
206 206
         }
207 207
         
Please login to merge, or discard this patch.