Passed
Push — master ( b100fb...491d6e )
by Patrick
01:48
created
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Braces   +26 added lines, -30 removed lines patch added patch discarded remove patch
@@ -98,8 +98,7 @@  discard block
 block discarded – undo
98 98
         {
99 99
             $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
100 100
             $this->logSetup=true;
101
-        }
102
-        else
101
+        } else
103 102
         {
104 103
             $this->logSetup=false;
105 104
         }
@@ -129,7 +128,10 @@  discard block
 block discarded – undo
129 128
         $this->getDatabaseOptions(); // Get options in database
130 129
         
131 130
         //*************** Setup API
132
-        if ($this->apiUse === true) $this->getAPI(); // Setup API
131
+        if ($this->apiUse === true) {
132
+        	$this->getAPI();
133
+        }
134
+        // Setup API
133 135
         
134 136
         //*************** Setup MIB
135 137
         $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
@@ -238,8 +240,7 @@  discard block
 block discarded – undo
238 240
         {
239 241
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
240 242
             $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
241
-        }
242
-        else
243
+        } else
243 244
         {
244 245
             $this->trapData['source_ip']=$matches[1];
245 246
             $this->trapData['destination_ip']=$matches[3];
@@ -439,7 +440,9 @@  discard block
 block discarded – undo
439 440
                 }
440 441
                 
441 442
                 $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");
443
+                if ($inserted_id==false) {
444
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
445
+                }
443 446
                 $this->trapId=$inserted_id;
444 447
                 break;
445 448
             default:
@@ -455,7 +458,9 @@  discard block
 block discarded – undo
455 458
     {
456 459
         
457 460
         // If action is ignore -> don't send t DB
458
-        if ($this->trapToDb === false) return;
461
+        if ($this->trapToDb === false) {
462
+        	return;
463
+        }
459 464
         
460 465
         
461 466
         $db_conn=$this->trapsDB->db_connect_trap();
@@ -512,7 +517,9 @@  discard block
 block discarded – undo
512 517
                 }
513 518
                 
514 519
                 $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");
520
+                if ($inserted_id==false) {
521
+                	throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
522
+                }
516 523
                 $this->trapId=$inserted_id;
517 524
                 break;
518 525
             default:
@@ -641,8 +648,7 @@  discard block
 block discarded – undo
641 648
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
642 649
                 exec('echo "'.$send.'" > ' .$this->icinga2cmd);
643 650
                 return true;
644
-        }
645
-        else
651
+        } else
646 652
         {
647 653
             // Get perfdata if found
648 654
             $matches=array();
@@ -650,8 +656,7 @@  discard block
 block discarded – undo
650 656
             {
651 657
                 $display=$matches[1];
652 658
                 $perfdata=$matches[2];
653
-            }
654
-            else
659
+            } else
655 660
             {
656 661
                 $perfdata='';
657 662
             }
@@ -663,8 +668,7 @@  discard block
 block discarded – undo
663 668
             {
664 669
                 $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
665 670
                 return false;
666
-            }
667
-            else
671
+            } else
668 672
             {
669 673
                 $this->logging->log( "Sent result : " .$retmessage,INFO );
670 674
                 return true;
@@ -763,20 +767,17 @@  discard block
 block discarded – undo
763 767
                         if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
764 768
                         {
765 769
                             $this->trapAction.='Error sending status : check cmd/API';
766
-                        }
767
-                        else
770
+                        } else
768 771
                         {
769 772
                             $this->add_rule_match($rule['id'],$rule['num_match']+1);
770 773
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
771 774
                         }
772
-                    }
773
-                    else
775
+                    } else
774 776
                     {
775 777
                         $this->add_rule_match($rule['id'],$rule['num_match']+1);
776 778
                     }
777 779
                     $this->trapToDb=($action==-2)?false:true;
778
-                }
779
-                else
780
+                } else
780 781
                 {
781 782
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
782 783
                     
@@ -787,14 +788,12 @@  discard block
 block discarded – undo
787 788
                         if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
788 789
                         {
789 790
                             $this->trapAction.='Error sending status : check cmd/API';
790
-                        }
791
-                        else
791
+                        } else
792 792
                         {
793 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
-                    }
797
-                    else
796
+                    } else
798 797
                     {
799 798
                         $this->add_rule_match($rule['id'],$rule['num_match']+1);
800 799
                     }
@@ -804,16 +803,14 @@  discard block
 block discarded – undo
804 803
                 if (!isset($this->trapData['source_name']))
805 804
                 {
806 805
                     $this->trapData['source_name']=$rule['host_name'];
807
-                }
808
-                else
806
+                } else
809 807
                 {
810 808
                     if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name']))
811 809
                     { // only add if not present
812 810
                         $this->trapData['source_name'].=','.$rule['host_name'];
813 811
                     }
814 812
                 }
815
-            }
816
-            catch (Exception $e)
813
+            } catch (Exception $e)
817 814
             {
818 815
                 $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
819 816
                 $this->trapAction.=' ERR : '.$e->getMessage();
@@ -824,8 +821,7 @@  discard block
 block discarded – undo
824 821
         if ($this->trapData['status']=='error')
825 822
         {
826 823
             $this->trapToDb=true; // Always put errors in DB for the use can see
827
-        }
828
-        else
824
+        } else
829 825
         {
830 826
             $this->trapData['status']='done';
831 827
         }
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/TrapConfig.php 1 patch
Braces   +11 added lines, -7 removed lines patch added patch discarded remove patch
@@ -46,8 +46,7 @@  discard block
 block discarded – undo
46 46
             }
47 47
             $this->getLogging()->log($message,$log_level);
48 48
             return false;
49
-        }
50
-        else
49
+        } else
51 50
         {
52 51
             $option_var=$option_array[$option_category][$option_name];
53 52
             return true;
@@ -60,16 +59,20 @@  discard block
 block discarded – undo
60 59
     protected function getDatabaseOptions()
61 60
     {
62 61
         // Database options
63
-        if ($this->logSetup === false) // Only if logging was no setup in constructor
62
+        if ($this->logSetup === false) {
63
+        	// Only if logging was no setup in constructor
64 64
         {
65 65
             $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
66
+        }
66 67
             $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
67 68
             $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
68 69
         }
69 70
         
70 71
         $tmpVal = -1; // Get boolean coded in database as 1/0
71 72
         $this->getDBConfigIfSet('use_SnmpTrapAddess', $tmpVal);
72
-        if ($tmpVal != -1) $this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
73
+        if ($tmpVal != -1) {
74
+        	$this->useSnmpTrapAddess = ($tmpVal == 1) ? TRUE : FALSE;
75
+        }
73 76
         
74 77
         $this->getDBConfigIfSet('SnmpTrapAddess_oid', $this->snmpTrapAddressOID); // Get oid then replace '.' with '\.' to use in regexp whrn reading traps
75 78
         $this->snmpTrapAddressOID = preg_replace('/\./', '\\.', $this->snmpTrapAddressOID);
@@ -82,7 +85,9 @@  discard block
 block discarded – undo
82 85
     protected function getDBConfigIfSet($element,&$variable)
83 86
     {
84 87
         $value=$this->getDBConfig($element);
85
-        if ($value != null) $variable=$value;
88
+        if ($value != null) {
89
+        	$variable=$value;
90
+        }
86 91
     }
87 92
     
88 93
     /**
@@ -119,8 +124,7 @@  discard block
 block discarded – undo
119 124
         {
120 125
             $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
121 126
             $this->getTrapApi()->setStatusMaster();
122
-        }
123
-        else 
127
+        } else 
124 128
         {
125 129
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
126 130
             {
Please login to merge, or discard this patch.