Passed
Push — master ( 185cb1...b3870e )
by Patrick
01:50
created
bin/trap_in.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use Trapdirector\Trap;
5 5
 
6 6
 // start
7
-$time1 = microtime(true);
7
+$time1=microtime(true);
8 8
 
9 9
 require_once ('trap_class.php');
10 10
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 {
19 19
     //$Trap = new Trap($icingaweb2_etc);
20 20
     //$Trap = new Trap($icingaweb2_etc,4,'display'); // For debug
21
-    $Trap = new Trap($icingaweb2_etc,4,'syslog'); // For debug
21
+    $Trap=new Trap($icingaweb2_etc, 4, 'syslog'); // For debug
22 22
     //$Trap->setLogging(4,'syslog'); 
23 23
     
24 24
     // TODO : tranfer this to reset_trap cli command
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 {
38 38
     if ($Trap == null)
39 39
     {  // Exception in trap creation : log in display & syslog
40
-        $logging = new Logging();
41
-        $logging->log("Caught exception creating Trap class",2);
40
+        $logging=new Logging();
41
+        $logging->log("Caught exception creating Trap class", 2);
42 42
     }
43 43
     else
44 44
     {
45
-	   $Trap->trapLog("Exception : ". $e->getMessage(),2,0);
45
+	   $Trap->trapLog("Exception : ".$e->getMessage(), 2, 0);
46 46
     }
47 47
 }
48 48
 
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Spacing   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
     
31 31
     // Logs
32 32
     /** @var Logging Logging class. */
33
-    protected $logging;    //< Logging class.
33
+    protected $logging; //< Logging class.
34 34
     /** @var bool true if log was setup in constructor */
35
-    protected $logSetup;   //< bool true if log was setup in constructor
35
+    protected $logSetup; //< bool true if log was setup in constructor
36 36
     
37 37
     // Databases
38 38
     public $trapsDB; //< Database class
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     /** @var Rule rule class */
53 53
     public $ruleClass;
54 54
     
55
-    function __construct($etc_dir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
55
+    function __construct($etc_dir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
56 56
     {
57 57
         // Paths of ini files
58 58
         $this->icingaweb2_etc=$etc_dir;
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
         $this->icingaweb2_ressources=$this->icingaweb2_etc."/resources.ini";
61 61
         
62 62
         // Setup logging
63
-        $this->logging = new Logging();
63
+        $this->logging=new Logging();
64 64
         if ($baseLogLevel != null)
65 65
         {
66
-            $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
66
+            $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
67 67
             $this->logSetup=true;
68 68
         }
69 69
         else
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
             $this->logging->log('Loggin started', INFO);
72 72
             
73 73
             // Get options from ini files
74
-            if (! is_file($this->trap_module_config))
74
+            if (!is_file($this->trap_module_config))
75 75
             {
76 76
                 throw new Exception("Ini file ".$this->trap_module_config." does not exists");
77 77
             }
78
-            $trapConfig=parse_ini_file($this->trap_module_config,true);
78
+            $trapConfig=parse_ini_file($this->trap_module_config, true);
79 79
             if ($trapConfig == false)
80 80
             {
81
-                $this->logging->log("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog');
81
+                $this->logging->log("Error reading ini file : ".$this->trap_module_config, ERROR, 'syslog');
82 82
                 throw new Exception("Error reading ini file : ".$this->trap_module_config);
83 83
             }
84 84
             $this->getMainOptions($trapConfig); // Get main options from ini file
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
             $this->getDatabaseOptions(); // Get options in database
88 88
             if ($this->api_use === true) $this->getAPI(); // Setup API
89 89
             
90
-            $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
90
+            $this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class
91 91
             
92
-            $this->ruleClass = new Rule($this->logging); //< Create Rule class
92
+            $this->ruleClass=new Rule($this->logging); //< Create Rule class
93 93
             
94 94
             $this->trap_data=array(
95 95
                 'source_ip'	=> 'unknown',
@@ -111,15 +111,15 @@  discard block
 block discarded – undo
111 111
      * @param string $message warning message if not found
112 112
      * @return boolean true if found, or false
113 113
      */
114
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
114
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
115 115
     {
116 116
         if (!isset($option_array[$option_category][$option_name]))
117 117
         {
118 118
             if ($message === null)
119 119
             {
120
-                $message='No ' . $option_name . ' in config file: '. $this->trap_module_config;
120
+                $message='No '.$option_name.' in config file: '.$this->trap_module_config;
121 121
             }
122
-            $this->logging->log($message,$log_level);
122
+            $this->logging->log($message, $log_level);
123 123
             return false;
124 124
         }
125 125
         else
@@ -137,24 +137,24 @@  discard block
 block discarded – undo
137 137
     {
138 138
         
139 139
         // Snmptranslate binary path
140
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
140
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
141 141
         
142 142
         // mibs path
143
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
143
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
144 144
         
145 145
         // icinga2cmd path
146
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
146
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
147 147
         
148 148
         // table prefix
149
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->db_prefix);
149
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->db_prefix);
150 150
         
151 151
         // API options
152
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->api_hostname))
152
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->api_hostname))
153 153
         {
154 154
             $this->api_use=true;
155
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->api_port);
156
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->api_username);
157
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->api_password);
155
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->api_port);
156
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->api_username);
157
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->api_password);
158 158
         }
159 159
     }
160 160
     
@@ -165,40 +165,40 @@  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->trap_module_config,ERROR,'');
170
+            $this->logging->log("No database in config file: ".$this->trap_module_config, 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->icingaweb2_ressources,true)) === false)
176
+        if (($dbConfig=parse_ini_file($this->icingaweb2_ressources, true)) === false)
177 177
         {
178
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,'');
178
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2_ressources, 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->icingaweb2_ressources,ERROR,'');
183
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
184 184
             return;
185 185
         }
186 186
         
187
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix);
187
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->db_prefix);
188 188
         
189 189
         if ($this->api_use === true) return; // In case of API use, no IDO is necessary
190 190
         
191 191
         // IDO Database
192
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
192
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
193 193
         {
194
-            $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config,ERROR,'');
194
+            $this->logging->log("No IDOdatabase in config file: ".$this->trap_module_config, ERROR, '');
195 195
         }
196 196
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
197 197
         
198
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
199
-        if (!array_key_exists($dbIdoName,$dbConfig))
198
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
199
+        if (!array_key_exists($dbIdoName, $dbConfig))
200 200
         {
201
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources,ERROR,'');
201
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2_ressources, ERROR, '');
202 202
             return;
203 203
         }
204 204
         
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
         // Database options
214 214
         if ($this->logSetup === false) // Only if logging was no setup in constructor
215 215
         {
216
-            $this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
217
-            $this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
218
-            $this->getDBConfigIfSet('log_file',$this->logging->outputFile);
216
+            $this->getDBConfigIfSet('log_level', $this->logging->debugLevel);
217
+            $this->getDBConfigIfSet('log_destination', $this->logging->outputMode);
218
+            $this->getDBConfigIfSet('log_file', $this->logging->outputFile);
219 219
         }
220 220
     }
221 221
     
222
-    protected function getDBConfigIfSet($element,&$variable)
222
+    protected function getDBConfigIfSet($element, &$variable)
223 223
     {
224 224
         $value=$this->getDBConfig($element);
225 225
         if ($value != 'null') $variable=$value;
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         $db_conn=$this->trapsDB->db_connect_trap();
236 236
         $sql='SELECT value from '.$this->db_prefix.'db_config WHERE ( name=\''.$element.'\' )';
237 237
         if (($ret_code=$db_conn->query($sql)) === false) {
238
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
238
+            $this->logging->log('No result in query : '.$sql, WARN, '');
239 239
             return null;
240 240
         }
241 241
         $value=$ret_code->fetch();
@@ -252,22 +252,22 @@  discard block
 block discarded – undo
252 252
      *	@param  string $destination file/syslog/display
253 253
      *	@return void
254 254
      **/
255
-    public function trapLog( $message, $level, $destination ='') // OBSOLETE
255
+    public function trapLog($message, $level, $destination='') // OBSOLETE
256 256
     {
257 257
         // TODO : replace ref with $this->logging->log
258 258
         $this->logging->log($message, $level, $destination);
259 259
     }
260 260
     
261
-    public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
261
+    public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
262 262
     {
263
-        $this->logging->setLogging($debugLvl, $outputType,$outputOption);
263
+        $this->logging->setLogging($debugLvl, $outputType, $outputOption);
264 264
     }
265 265
     
266 266
     protected function getAPI()
267 267
     {
268 268
         if ($this->icinga2api == null)
269 269
         {
270
-            $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port);
270
+            $this->icinga2api=new Icinga2API($this->api_hostname, $this->api_port);
271 271
         }
272 272
         return $this->icinga2api;
273 273
     }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
         if ($input_stream === false)
287 287
         {
288 288
             $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
289
-            $this->logging->log("Error reading stdin !",ERROR,'');
289
+            $this->logging->log("Error reading stdin !", ERROR, '');
290 290
             return null; // note : exception thrown by logging
291 291
         }
292 292
         
@@ -295,21 +295,21 @@  discard block
 block discarded – undo
295 295
         if ($this->receivingHost === false)
296 296
         {
297 297
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
298
-            $this->logging->log("Error reading Host !",ERROR,'');
298
+            $this->logging->log("Error reading Host !", ERROR, '');
299 299
         }
300 300
         // line 2 IP:port=>IP:port
301 301
         $IP=chop(fgets($input_stream));
302 302
         if ($IP === false)
303 303
         {
304 304
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
305
-            $this->logging->log("Error reading IP !",ERROR,'');
305
+            $this->logging->log("Error reading IP !", ERROR, '');
306 306
         }
307 307
         $matches=array();
308
-        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
309
-        if ($ret_code===0 || $ret_code===false)
308
+        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
309
+        if ($ret_code === 0 || $ret_code === false)
310 310
         {
311 311
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
312
-            $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
312
+            $this->logging->log('Error parsing IP : '.$IP, ERROR, '');
313 313
         }
314 314
         else
315 315
         {
@@ -319,34 +319,34 @@  discard block
 block discarded – undo
319 319
             $this->trap_data['destination_port']=$matches[4];
320 320
         }
321 321
         
322
-        while (($vars=fgets($input_stream)) !==false)
322
+        while (($vars=fgets($input_stream)) !== false)
323 323
         {
324 324
             $vars=chop($vars);
325
-            $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
326
-            if ($ret_code===0 || $ret_code===false)
325
+            $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
326
+            if ($ret_code === 0 || $ret_code === false)
327 327
             {
328
-                $this->logging->log('No match on trap data : '.$vars,WARN,'');
328
+                $this->logging->log('No match on trap data : '.$vars, WARN, '');
329 329
             }
330 330
             else
331 331
             {
332
-                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'))
332
+                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'))
333 333
                 {
334 334
                     $this->trap_data['trap_oid']=$matches[2];
335 335
                 }
336 336
                 else
337 337
                 {
338
-                    $object= new stdClass;
339
-                    $object->oid =$matches[1];
340
-                    $object->value = $matches[2];
341
-                    array_push($this->trap_data_ext,$object);
338
+                    $object=new stdClass;
339
+                    $object->oid=$matches[1];
340
+                    $object->value=$matches[2];
341
+                    array_push($this->trap_data_ext, $object);
342 342
                 }
343 343
             }
344 344
         }
345 345
         
346
-        if ($this->trap_data['trap_oid']=='unknown')
346
+        if ($this->trap_data['trap_oid'] == 'unknown')
347 347
         {
348
-            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']);
349
-            $this->logging->log('no trap oid found',ERROR,'');
348
+            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trap_data['source_ip']);
349
+            $this->logging->log('no trap oid found', ERROR, '');
350 350
         }
351 351
         
352 352
         // Translate oids.
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
         }
369 369
         
370 370
         
371
-        $this->trap_data['status']= 'waiting';
371
+        $this->trap_data['status']='waiting';
372 372
         
373 373
         return $this->trap_data;
374 374
     }
@@ -384,40 +384,40 @@  discard block
 block discarded – undo
384 384
         $db_conn=$this->trapsDB->db_connect_trap();
385 385
         
386 386
         $sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid.'\';';
387
-        $this->logging->log('SQL query : '.$sql,DEBUG );
387
+        $this->logging->log('SQL query : '.$sql, DEBUG);
388 388
         if (($ret_code=$db_conn->query($sql)) === false) {
389
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
389
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
390 390
         }
391 391
         $name=$ret_code->fetch();
392 392
         if ($name['name'] != null)
393 393
         {
394
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
394
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
395 395
         }
396 396
         
397 397
         // Also check if it is an instance of OID
398
-        $oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
398
+        $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
399 399
         
400 400
         $sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
401
-        $this->logging->log('SQL query : '.$sql,DEBUG );
401
+        $this->logging->log('SQL query : '.$sql, DEBUG);
402 402
         if (($ret_code=$db_conn->query($sql)) === false) {
403
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
403
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
404 404
         }
405 405
         $name=$ret_code->fetch();
406 406
         if ($name['name'] != null)
407 407
         {
408
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
408
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
409 409
         }
410 410
         
411 411
         // Try to get oid name from snmptranslate
412
-        $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
412
+        $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
413 413
             ' '.$oid);
414 414
         $matches=array();
415
-        $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
416
-        if ($ret_code===0 || $ret_code === false) {
415
+        $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
416
+        if ($ret_code === 0 || $ret_code === false) {
417 417
             return NULL;
418 418
         } else {
419
-            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
420
-            return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
419
+            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
420
+            return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
421 421
         }
422 422
     }
423 423
     
@@ -428,90 +428,90 @@  discard block
 block discarded – undo
428 428
      **/
429 429
     public function eraseOldTraps($days=0)
430 430
     {
431
-        if ($days==0)
431
+        if ($days == 0)
432 432
         {
433 433
             if (($days=$this->getDBConfig('db_remove_days')) == null)
434 434
             {
435
-                $this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
435
+                $this->logging->log('No days specified & no db value : no tap erase', WARN, '');
436 436
                 return;
437 437
             }
438 438
         }
439 439
         $db_conn=$this->trapsDB->db_connect_trap();
440
-        $daysago = strtotime("-".$days." day");
441
-        $sql= 'delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
440
+        $daysago=strtotime("-".$days." day");
441
+        $sql='delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
442 442
         if ($db_conn->query($sql) === false) {
443
-            $this->logging->log('Error erasing traps : '.$sql,ERROR,'');
443
+            $this->logging->log('Error erasing traps : '.$sql, ERROR, '');
444 444
         }
445
-        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
445
+        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
446 446
     }
447 447
     
448 448
     /** Write error to received trap database
449 449
      */
450
-    public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
450
+    public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
451 451
     {
452 452
         
453 453
         $db_conn=$this->trapsDB->db_connect_trap();
454 454
         
455 455
         // add date time
456
-        $insert_col ='date_received,status';
457
-        $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
456
+        $insert_col='date_received,status';
457
+        $insert_val="'".date("Y-m-d H:i:s")."','error'";
458 458
         
459
-        if ($sourceIP !=null)
459
+        if ($sourceIP != null)
460 460
         {
461
-            $insert_col .=',source_ip';
462
-            $insert_val .=",'". $sourceIP ."'";
461
+            $insert_col.=',source_ip';
462
+            $insert_val.=",'".$sourceIP."'";
463 463
         }
464
-        if ($trapoid !=null)
464
+        if ($trapoid != null)
465 465
         {
466
-            $insert_col .=',trap_oid';
467
-            $insert_val .=",'". $trapoid ."'";
466
+            $insert_col.=',trap_oid';
467
+            $insert_val.=",'".$trapoid."'";
468 468
         }
469
-        $insert_col .=',status_detail';
470
-        $insert_val .=",'". $message ."'";
469
+        $insert_col.=',status_detail';
470
+        $insert_val.=",'".$message."'";
471 471
         
472
-        $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
472
+        $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
473 473
         
474 474
         switch ($this->trapsDB->trapDBType)
475 475
         {
476 476
             case 'pgsql':
477
-                $sql .= ' RETURNING id;';
478
-                $this->logging->log('sql : '.$sql,INFO);
477
+                $sql.=' RETURNING id;';
478
+                $this->logging->log('sql : '.$sql, INFO);
479 479
                 if (($ret_code=$db_conn->query($sql)) === false) {
480
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
480
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
481 481
                 }
482
-                $this->logging->log('SQL insertion OK',INFO );
482
+                $this->logging->log('SQL insertion OK', INFO);
483 483
                 // Get last id to insert oid/values in secondary table
484 484
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
485 485
                     
486
-                    $this->logging->log('Erreur recuperation id',1,'');
486
+                    $this->logging->log('Erreur recuperation id', 1, '');
487 487
                 }
488
-                if (! isset($inserted_id_ret['id'])) {
489
-                    $this->logging->log('Error getting id',1,'');
488
+                if (!isset($inserted_id_ret['id'])) {
489
+                    $this->logging->log('Error getting id', 1, '');
490 490
                 }
491 491
                 $this->trap_id=$inserted_id_ret['id'];
492 492
                 break;
493 493
             case 'mysql':
494
-                $sql .= ';';
495
-                $this->logging->log('sql : '.$sql,INFO );
494
+                $sql.=';';
495
+                $this->logging->log('sql : '.$sql, INFO);
496 496
                 if ($db_conn->query($sql) === false) {
497
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
497
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
498 498
                 }
499
-                $this->logging->log('SQL insertion OK',INFO );
499
+                $this->logging->log('SQL insertion OK', INFO);
500 500
                 // Get last id to insert oid/values in secondary table
501 501
                 $sql='SELECT LAST_INSERT_ID();';
502 502
                 if (($ret_code=$db_conn->query($sql)) === false) {
503
-                    $this->logging->log('Erreur recuperation id',1,'');
503
+                    $this->logging->log('Erreur recuperation id', 1, '');
504 504
                 }
505 505
                 
506 506
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
507
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
507
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
508 508
                 $this->trap_id=$inserted_id;
509 509
                 break;
510 510
             default:
511
-                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
511
+                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
512 512
         }
513 513
         
514
-        $this->logging->log('id found: '. $this->trap_id,INFO );
514
+        $this->logging->log('id found: '.$this->trap_id, INFO);
515 515
     }
516 516
     
517 517
     /** Write trap data to trap database
@@ -528,86 +528,86 @@  discard block
 block discarded – undo
528 528
         $insert_col='';
529 529
         $insert_val='';
530 530
         // add date time
531
-        $this->trap_data['date_received'] = date("Y-m-d H:i:s");
531
+        $this->trap_data['date_received']=date("Y-m-d H:i:s");
532 532
         
533 533
         $firstcol=1;
534 534
         foreach ($this->trap_data as $col => $val)
535 535
         {
536
-            if ($firstcol==0)
536
+            if ($firstcol == 0)
537 537
             {
538
-                $insert_col .=',';
539
-                $insert_val .=',';
538
+                $insert_col.=',';
539
+                $insert_val.=',';
540 540
             }
541
-            $insert_col .= $col ;
542
-            $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
541
+            $insert_col.=$col;
542
+            $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
543 543
             $firstcol=0;
544 544
         }
545 545
         
546
-        $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
546
+        $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
547 547
         switch ($this->trapsDB->trapDBType)
548 548
         {
549 549
             case 'pgsql':
550
-                $sql .= ' RETURNING id;';
551
-                $this->logging->log('sql : '.$sql,INFO );
550
+                $sql.=' RETURNING id;';
551
+                $this->logging->log('sql : '.$sql, INFO);
552 552
                 if (($ret_code=$db_conn->query($sql)) === false) {
553
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
553
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
554 554
                 }
555
-                $this->logging->log('SQL insertion OK',INFO );
555
+                $this->logging->log('SQL insertion OK', INFO);
556 556
                 // Get last id to insert oid/values in secondary table
557 557
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
558 558
                     
559
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
559
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
560 560
                 }
561
-                if (! isset($inserted_id_ret['id'])) {
562
-                    $this->logging->log('Error getting id',ERROR,'');
561
+                if (!isset($inserted_id_ret['id'])) {
562
+                    $this->logging->log('Error getting id', ERROR, '');
563 563
                 }
564 564
                 $this->trap_id=$inserted_id_ret['id'];
565 565
                 break;
566 566
             case 'mysql':
567
-                $sql .= ';';
568
-                $this->logging->log('sql : '.$sql,INFO );
567
+                $sql.=';';
568
+                $this->logging->log('sql : '.$sql, INFO);
569 569
                 if ($db_conn->query($sql) === false) {
570
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
570
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
571 571
                 }
572
-                $this->logging->log('SQL insertion OK',INFO );
572
+                $this->logging->log('SQL insertion OK', INFO);
573 573
                 // Get last id to insert oid/values in secondary table
574 574
                 $sql='SELECT LAST_INSERT_ID();';
575 575
                 if (($ret_code=$db_conn->query($sql)) === false) {
576
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
576
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
577 577
                 }
578 578
                 
579 579
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
580
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
580
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
581 581
                 $this->trap_id=$inserted_id;
582 582
                 break;
583 583
             default:
584
-                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
584
+                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
585 585
         }
586
-        $this->logging->log('id found: '.$this->trap_id,INFO );
586
+        $this->logging->log('id found: '.$this->trap_id, INFO);
587 587
         
588 588
         // Fill trap extended data table
589 589
         foreach ($this->trap_data_ext as $value) {
590 590
             // TODO : detect if trap value is encoded and decode it to UTF-8 for database
591 591
             $firstcol=1;
592
-            $value->trap_id = $this->trap_id;
592
+            $value->trap_id=$this->trap_id;
593 593
             $insert_col='';
594 594
             $insert_val='';
595 595
             foreach ($value as $col => $val)
596 596
             {
597
-                if ($firstcol==0)
597
+                if ($firstcol == 0)
598 598
                 {
599
-                    $insert_col .=',';
600
-                    $insert_val .=',';
599
+                    $insert_col.=',';
600
+                    $insert_val.=',';
601 601
                 }
602
-                $insert_col .= $col;
603
-                $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
602
+                $insert_col.=$col;
603
+                $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
604 604
                 $firstcol=0;
605 605
             }
606 606
             
607
-            $sql= 'INSERT INTO '.$this->db_prefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';
607
+            $sql='INSERT INTO '.$this->db_prefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';
608 608
             
609 609
             if ($db_conn->query($sql) === false) {
610
-                $this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
610
+                $this->logging->log('Erreur insertion data : '.$sql, WARN, '');
611 611
             }
612 612
         }
613 613
     }
@@ -617,14 +617,14 @@  discard block
 block discarded – undo
617 617
      *	@param $oid string oid in numeric
618 618
      *	@return mixed|boolean : PDO object or false
619 619
      */
620
-    protected function getRules($ip,$oid)
620
+    protected function getRules($ip, $oid)
621 621
     {
622 622
         $db_conn=$this->trapsDB->db_connect_trap();
623 623
         // fetch rules based on IP in rule and OID
624 624
         $sql='SELECT * from '.$this->db_prefix.'rules WHERE trap_oid=\''.$oid.'\' ';
625
-        $this->logging->log('SQL query : '.$sql,DEBUG );
625
+        $this->logging->log('SQL query : '.$sql, DEBUG);
626 626
         if (($ret_code=$db_conn->query($sql)) === false) {
627
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
627
+            $this->logging->log('No result in query : '.$sql, WARN, '');
628 628
             return false;
629 629
         }
630 630
         $rules_all=$ret_code->fetchAll();
@@ -633,7 +633,7 @@  discard block
 block discarded – undo
633 633
         $rule_ret_key=0;
634 634
         foreach ($rules_all as $key => $rule)
635 635
         {
636
-            if ($rule['ip4']==$ip || $rule['ip6']==$ip)
636
+            if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
637 637
             {
638 638
                 $rules_ret[$rule_ret_key]=$rules_all[$key];
639 639
                 //TODO : get host name by API (and check if correct in rule).
@@ -641,7 +641,7 @@  discard block
 block discarded – undo
641 641
                 continue;
642 642
             }
643 643
             // TODO : get hosts IP by API
644
-            if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
644
+            if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
645 645
             { // get ips of group members by oid
646 646
                 $db_conn2=$this->trapsDB->db_connect_ido();
647 647
                 $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -652,15 +652,15 @@  discard block
 block discarded – undo
652 652
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
653 653
 						WHERE o.name1='".$rule['host_group_name']."';";
654 654
                 if (($ret_code2=$db_conn2->query($sql)) === false) {
655
-                    $this->logging->log('No result in query : ' . $sql,WARN,'');
655
+                    $this->logging->log('No result in query : '.$sql, WARN, '');
656 656
                     continue;
657 657
                 }
658 658
                 $grouphosts=$ret_code2->fetchAll();
659 659
                 //echo "rule grp :\n";print_r($grouphosts);echo "\n";
660
-                foreach ( $grouphosts as $host)
660
+                foreach ($grouphosts as $host)
661 661
                 {
662 662
                     //echo $host['ip4']."\n";
663
-                    if ($host['ip4']==$ip || $host['ip6']==$ip)
663
+                    if ($host['ip4'] == $ip || $host['ip6'] == $ip)
664 664
                     {
665 665
                         //echo "Rule added \n";
666 666
                         $rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
         $db_conn=$this->trapsDB->db_connect_trap();
684 684
         $sql="UPDATE ".$this->db_prefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
685 685
         if ($db_conn->query($sql) === false) {
686
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
686
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
687 687
         }
688 688
     }
689 689
     
@@ -695,23 +695,23 @@  discard block
 block discarded – undo
695 695
      * @param string $display
696 696
      * @returnn bool true is service check was sent without error
697 697
      */
698
-    public function serviceCheckResult($host,$service,$state,$display)
698
+    public function serviceCheckResult($host, $service, $state, $display)
699 699
     {
700 700
         if ($this->api_use === false)
701 701
         {
702
-            $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
703
-                $host.';' .$service .';' . $state . ';'.$display;
704
-                $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
702
+            $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
703
+                $host.';'.$service.';'.$state.';'.$display;
704
+                $this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
705 705
                 
706 706
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
707
-                exec('echo "'.$send.'" > ' .$this->icinga2cmd);
707
+                exec('echo "'.$send.'" > '.$this->icinga2cmd);
708 708
                 return true;
709 709
         }
710 710
         else
711 711
         {
712 712
             // Get perfdata if found
713 713
             $matches=array();
714
-            if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1)
714
+            if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1)
715 715
             {
716 716
                 $display=$matches[1];
717 717
                 $perfdata=$matches[2];
@@ -721,17 +721,17 @@  discard block
 block discarded – undo
721 721
                 $perfdata='';
722 722
             }
723 723
             
724
-            $api = $this->getAPI();
724
+            $api=$this->getAPI();
725 725
             $api->setCredentials($this->api_username, $this->api_password);
726
-            list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata);
726
+            list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata);
727 727
             if ($retcode == false)
728 728
             {
729
-                $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
729
+                $this->logging->log("Error sending result : ".$retmessage, WARN, '');
730 730
                 return false;
731 731
             }
732 732
             else
733 733
             {
734
-                $this->logging->log( "Sent result : " .$retmessage,INFO );
734
+                $this->logging->log("Sent result : ".$retmessage, INFO);
735 735
                 return true;
736 736
             }
737 737
         }
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
     
740 740
     public function getHostByIP($ip)
741 741
     {
742
-        $api = $this->getAPI();
742
+        $api=$this->getAPI();
743 743
         $api->setCredentials($this->api_username, $this->api_password);
744 744
         return $api->getHostByIP($ip);
745 745
     }
@@ -752,32 +752,32 @@  discard block
 block discarded – undo
752 752
     protected function applyDisplay($display)
753 753
     {
754 754
         $matches=array();
755
-        while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
755
+        while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1)
756 756
         {
757 757
             $oid=$matches[1];
758 758
             $found=0;
759
-            foreach($this->trap_data_ext as $val)
759
+            foreach ($this->trap_data_ext as $val)
760 760
             {
761 761
                 if ($oid == $val->oid)
762 762
                 {
763
-                    $val->value=preg_replace('/"/','',$val->value);
763
+                    $val->value=preg_replace('/"/', '', $val->value);
764 764
                     $rep=0;
765
-                    $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
766
-                    if ($rep==0)
765
+                    $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
766
+                    if ($rep == 0)
767 767
                     {
768
-                        $this->logging->log("Error in display",WARN,'');
768
+                        $this->logging->log("Error in display", WARN, '');
769 769
                         return $display;
770 770
                     }
771 771
                     $found=1;
772 772
                     break;
773 773
                 }
774 774
             }
775
-            if ($found==0)
775
+            if ($found == 0)
776 776
             {
777
-                $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
778
-                if ($rep==0)
777
+                $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
778
+                if ($rep == 0)
779 779
                 {
780
-                    $this->logging->log("Error in display",WARN,'');
780
+                    $this->logging->log("Error in display", WARN, '');
781 781
                     return $display;
782 782
                 }
783 783
             }
@@ -789,11 +789,11 @@  discard block
 block discarded – undo
789 789
      */
790 790
     public function applyRules()
791 791
     {
792
-        $rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']);
792
+        $rules=$this->getRules($this->trap_data['source_ip'], $this->trap_data['trap_oid']);
793 793
         
794
-        if ($rules===false || count($rules)==0)
794
+        if ($rules === false || count($rules) == 0)
795 795
         {
796
-            $this->logging->log('No rules found for this trap',INFO );
796
+            $this->logging->log('No rules found for this trap', INFO);
797 797
             $this->trap_data['status']='unknown';
798 798
             $this->trap_to_db=true;
799 799
             return;
@@ -808,59 +808,59 @@  discard block
 block discarded – undo
808 808
             $service_name=$rule['service_name'];
809 809
             
810 810
             $display=$this->applyDisplay($rule['display']);
811
-            $this->trap_action = ($this->trap_action==null)? '' : $this->trap_action . ', ';
811
+            $this->trap_action=($this->trap_action == null) ? '' : $this->trap_action.', ';
812 812
             try
813 813
             {
814
-                $this->logging->log('Rule to eval : '.$rule['rule'],INFO );
815
-                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trap_data_ext) ;
814
+                $this->logging->log('Rule to eval : '.$rule['rule'], INFO);
815
+                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trap_data_ext);
816 816
                 //->eval_rule($rule['rule']);
817 817
                 
818 818
                 if ($evalr == true)
819 819
                 {
820 820
                     //$this->logging->log('rules OOK: '.print_r($rule),INFO );
821 821
                     $action=$rule['action_match'];
822
-                    $this->logging->log('action OK : '.$action,INFO );
822
+                    $this->logging->log('action OK : '.$action, INFO);
823 823
                     if ($action >= 0)
824 824
                     {
825
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
825
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
826 826
                         {
827 827
                             $this->trap_action.='Error sending status : check cmd/API';
828 828
                         }
829 829
                         else
830 830
                         {
831
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
831
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
832 832
                             $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
833 833
                         }
834 834
                     }
835 835
                     else
836 836
                     {
837
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
837
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
838 838
                     }
839
-                    $this->trap_to_db=($action==-2)?false:true;
839
+                    $this->trap_to_db=($action == -2) ?false:true;
840 840
                 }
841 841
                 else
842 842
                 {
843 843
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
844 844
                     
845 845
                     $action=$rule['action_nomatch'];
846
-                    $this->logging->log('action NOK : '.$action,INFO );
846
+                    $this->logging->log('action NOK : '.$action, INFO);
847 847
                     if ($action >= 0)
848 848
                     {
849
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
849
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
850 850
                         {
851 851
                             $this->trap_action.='Error sending status : check cmd/API';
852 852
                         }
853 853
                         else
854 854
                         {
855
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
855
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
856 856
                             $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name;
857 857
                         }
858 858
                     }
859 859
                     else
860 860
                     {
861
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
861
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
862 862
                     }
863
-                    $this->trap_to_db=($action==-2)?false:true;
863
+                    $this->trap_to_db=($action == -2) ?false:true;
864 864
                 }
865 865
                 // Put name in source_name
866 866
                 if (!isset($this->trap_data['source_name']))
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
                 }
870 870
                 else
871 871
                 {
872
-                    if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name']))
872
+                    if (!preg_match('/'.$rule['host_name'].'/', $this->trap_data['source_name']))
873 873
                     { // only add if not present
874 874
                         $this->trap_data['source_name'].=','.$rule['host_name'];
875 875
                     }
@@ -877,13 +877,13 @@  discard block
 block discarded – undo
877 877
             }
878 878
             catch (Exception $e)
879 879
             {
880
-                $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
880
+                $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
881 881
                 $this->trap_action.=' ERR : '.$e->getMessage();
882 882
                 $this->trap_data['status']='error';
883 883
             }
884 884
             
885 885
         }
886
-        if ($this->trap_data['status']=='error')
886
+        if ($this->trap_data['status'] == 'error')
887 887
         {
888 888
             $this->trap_to_db=true; // Always put errors in DB for the use can see
889 889
         }
@@ -899,13 +899,13 @@  discard block
 block discarded – undo
899 899
     public function add_rule_final($time)
900 900
     {
901 901
         $db_conn=$this->trapsDB->db_connect_trap();
902
-        if ($this->trap_action==null)
902
+        if ($this->trap_action == null)
903 903
         {
904 904
             $this->trap_action='No action';
905 905
         }
906 906
         $sql="UPDATE ".$this->db_prefix."received SET process_time = '".$time."' , status_detail='".$this->trap_action."'  WHERE (id = '".$this->trap_id."');";
907 907
         if ($db_conn->query($sql) === false) {
908
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
908
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
909 909
         }
910 910
     }
911 911
     
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
     WHERE s.current_state != 0;";
929 929
         $db_conn=$this->trapsDB->db_connect_ido();
930 930
         if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
931
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
931
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
932 932
             return 0;
933 933
         }
934 934
         $services=$services_db->fetchAll();
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
         $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->db_prefix."rules where revert_ok != 0;";
938 938
         $db_conn2=$this->trapsDB->db_connect_trap();
939 939
         if (($rules_db=$db_conn2->query($sql_query)) === false) {
940
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
940
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
941 941
             return 0;
942 942
         }
943 943
         $rules=$rules_db->fetchAll();
@@ -953,13 +953,13 @@  discard block
 block discarded – undo
953 953
                     $service['host_name'] == $rule['host_name'] &&
954 954
                     ($service['last_check'] + $rule['revert_ok']) < $now)
955 955
                 {
956
-                    $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
956
+                    $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
957 957
                     $numreset++;
958 958
                 }
959 959
             }
960 960
         }
961 961
         echo "\n";
962
-        echo $numreset . " service(s) reset to OK\n";
962
+        echo $numreset." service(s) reset to OK\n";
963 963
         return 0;
964 964
         
965 965
     }
Please login to merge, or discard this patch.