Passed
Push — master ( a5cb6b...ce1111 )
by Patrick
02:05
created
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Braces   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -92,8 +92,7 @@  discard block
 block discarded – undo
92 92
         {
93 93
             $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
94 94
             $this->logSetup=true;
95
-        }
96
-        else
95
+        } else
97 96
         {
98 97
             $this->logSetup=false;
99 98
         }
@@ -118,7 +117,10 @@  discard block
 block discarded – undo
118 117
         $this->getDatabaseOptions(); // Get options in database
119 118
         
120 119
         //*************** Setup API
121
-        if ($this->apiUse === true) $this->getAPI(); // Setup API
120
+        if ($this->apiUse === true) {
121
+        	$this->getAPI();
122
+        }
123
+        // Setup API
122 124
         
123 125
         //*************** Setup MIB
124 126
         $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
@@ -161,8 +163,7 @@  discard block
 block discarded – undo
161 163
             }
162 164
             $this->logging->log($message,$log_level);
163 165
             return false;
164
-        }
165
-        else
166
+        } else
166 167
         {
167 168
             $option_var=$option_array[$option_category][$option_name];
168 169
             return true;
@@ -226,7 +227,10 @@  discard block
 block discarded – undo
226 227
         
227 228
         $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
228 229
         
229
-        if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
230
+        if ($this->apiUse === true) {
231
+        	return;
232
+        }
233
+        // In case of API use, no IDO is necessary
230 234
         
231 235
         // IDO Database
232 236
         if (!array_key_exists('IDOdatabase',$trapConfig['config']))
@@ -251,9 +255,11 @@  discard block
 block discarded – undo
251 255
     protected function getDatabaseOptions()
252 256
     {
253 257
         // Database options
254
-        if ($this->logSetup === false) // Only if logging was no setup in constructor
258
+        if ($this->logSetup === false) {
259
+        	// Only if logging was no setup in constructor
255 260
         {
256 261
             $this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
262
+        }
257 263
             $this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
258 264
             $this->getDBConfigIfSet('log_file',$this->logging->outputFile);
259 265
         }
@@ -266,7 +272,9 @@  discard block
 block discarded – undo
266 272
     protected function getDBConfigIfSet($element,&$variable)
267 273
     {
268 274
         $value=$this->getDBConfig($element);
269
-        if ($value != null) $variable=$value;
275
+        if ($value != null) {
276
+        	$variable=$value;
277
+        }
270 278
     }
271 279
     
272 280
     /**
@@ -358,8 +366,7 @@  discard block
 block discarded – undo
358 366
         {
359 367
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
360 368
             $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
361
-        }
362
-        else
369
+        } else
363 370
         {
364 371
             $this->trapData['source_ip']=$matches[1];
365 372
             $this->trapData['destination_ip']=$matches[3];
@@ -374,14 +381,12 @@  discard block
 block discarded – undo
374 381
             if ($ret_code===0 || $ret_code===false)
375 382
             {
376 383
                 $this->logging->log('No match on trap data : '.$vars,WARN,'');
377
-            }
378
-            else
384
+            } else
379 385
             {
380 386
                 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'))
381 387
                 {
382 388
                     $this->trapData['trap_oid']=$matches[2];
383
-                }
384
-                else
389
+                } else
385 390
                 {
386 391
                     $object= new stdClass;
387 392
                     $object->oid =$matches[1];
@@ -552,7 +557,9 @@  discard block
 block discarded – undo
552 557
                 }
553 558
                 
554 559
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
555
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
560
+                if ($inserted_id==false) {
561
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
562
+                }
556 563
                 $this->trapId=$inserted_id;
557 564
                 break;
558 565
             default:
@@ -568,7 +575,9 @@  discard block
 block discarded – undo
568 575
     {
569 576
         
570 577
         // If action is ignore -> don't send t DB
571
-        if ($this->trapToDb === false) return;
578
+        if ($this->trapToDb === false) {
579
+        	return;
580
+        }
572 581
         
573 582
         
574 583
         $db_conn=$this->trapsDB->db_connect_trap();
@@ -625,7 +634,9 @@  discard block
 block discarded – undo
625 634
                 }
626 635
                 
627 636
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
628
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
637
+                if ($inserted_id==false) {
638
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
639
+                }
629 640
                 $this->trapId=$inserted_id;
630 641
                 break;
631 642
             default:
@@ -754,8 +765,7 @@  discard block
 block discarded – undo
754 765
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
755 766
                 exec('echo "'.$send.'" > ' .$this->icinga2cmd);
756 767
                 return true;
757
-        }
758
-        else
768
+        } else
759 769
         {
760 770
             // Get perfdata if found
761 771
             $matches=array();
@@ -763,8 +773,7 @@  discard block
 block discarded – undo
763 773
             {
764 774
                 $display=$matches[1];
765 775
                 $perfdata=$matches[2];
766
-            }
767
-            else
776
+            } else
768 777
             {
769 778
                 $perfdata='';
770 779
             }
@@ -776,8 +785,7 @@  discard block
 block discarded – undo
776 785
             {
777 786
                 $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
778 787
                 return false;
779
-            }
780
-            else
788
+            } else
781 789
             {
782 790
                 $this->logging->log( "Sent result : " .$retmessage,INFO );
783 791
                 return true;
@@ -873,20 +881,17 @@  discard block
 block discarded – undo
873 881
                         if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
874 882
                         {
875 883
                             $this->trapAction.='Error sending status : check cmd/API';
876
-                        }
877
-                        else
884
+                        } else
878 885
                         {
879 886
                             $this->add_rule_match($rule['id'],$rule['num_match']+1);
880 887
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
881 888
                         }
882
-                    }
883
-                    else
889
+                    } else
884 890
                     {
885 891
                         $this->add_rule_match($rule['id'],$rule['num_match']+1);
886 892
                     }
887 893
                     $this->trapToDb=($action==-2)?false:true;
888
-                }
889
-                else
894
+                } else
890 895
                 {
891 896
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
892 897
                     
@@ -897,14 +902,12 @@  discard block
 block discarded – undo
897 902
                         if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
898 903
                         {
899 904
                             $this->trapAction.='Error sending status : check cmd/API';
900
-                        }
901
-                        else
905
+                        } else
902 906
                         {
903 907
                             $this->add_rule_match($rule['id'],$rule['num_match']+1);
904 908
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
905 909
                         }
906
-                    }
907
-                    else
910
+                    } else
908 911
                     {
909 912
                         $this->add_rule_match($rule['id'],$rule['num_match']+1);
910 913
                     }
@@ -914,16 +917,14 @@  discard block
 block discarded – undo
914 917
                 if (!isset($this->trapData['source_name']))
915 918
                 {
916 919
                     $this->trapData['source_name']=$rule['host_name'];
917
-                }
918
-                else
920
+                } else
919 921
                 {
920 922
                     if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name']))
921 923
                     { // only add if not present
922 924
                         $this->trapData['source_name'].=','.$rule['host_name'];
923 925
                     }
924 926
                 }
925
-            }
926
-            catch (Exception $e)
927
+            } catch (Exception $e)
927 928
             {
928 929
                 $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
929 930
                 $this->trapAction.=' ERR : '.$e->getMessage();
@@ -934,8 +935,7 @@  discard block
 block discarded – undo
934 935
         if ($this->trapData['status']=='error')
935 936
         {
936 937
             $this->trapToDb=true; // Always put errors in DB for the use can see
937
-        }
938
-        else
938
+        } else
939 939
         {
940 940
             $this->trapData['status']='done';
941 941
         }
Please login to merge, or discard this patch.