Completed
Push — master ( 6d466f...a26422 )
by Patrick
02:41 queued 32s
created
library/Trapdirector/TrapsProcess/TrapConfig.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@  discard block
 block discarded – undo
30 30
      * @param string $message warning message if not found
31 31
      * @return boolean true if found, or false
32 32
      */
33
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null)
33
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=WARN, $message=null)
34 34
     {
35 35
         if (!isset($option_array[$option_category][$option_name]))
36 36
         {
37 37
             if ($message === null)
38 38
             {
39
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
39
+                $message='No '.$option_name.' in config file: '.$this->trapModuleConfig;
40 40
             }
41
-            $this->getLogging()->log($message,$log_level);
41
+            $this->getLogging()->log($message, $log_level);
42 42
             return false;
43 43
         }
44 44
         else
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
         // Database options
57 57
         if ($this->logSetup === false) // Only if logging was no setup in constructor
58 58
         {
59
-            $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel);
60
-            $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode);
61
-            $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile);
59
+            $this->getDBConfigIfSet('log_level', $this->getLogging()->debugLevel);
60
+            $this->getDBConfigIfSet('log_destination', $this->getLogging()->outputMode);
61
+            $this->getDBConfigIfSet('log_file', $this->getLogging()->outputFile);
62 62
         }
63 63
     }
64 64
         
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      * @param string $element
67 67
      * @param string $variable
68 68
      */
69
-    protected function getDBConfigIfSet($element,&$variable)
69
+    protected function getDBConfigIfSet($element, &$variable)
70 70
     {
71 71
         $value=$this->getDBConfig($element);
72 72
         if ($value != null) $variable=$value;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         $db_conn=$this->trapsDB->db_connect_trap();
83 83
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
84 84
         if (($ret_code=$db_conn->query($sql)) === false) {
85
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
85
+            $this->logging->log('No result in query : '.$sql, WARN, '');
86 86
             return null;
87 87
         }
88 88
         $value=$ret_code->fetch();
@@ -101,10 +101,10 @@  discard block
 block discarded – undo
101 101
     {
102 102
         
103 103
         $nodeStatus='';
104
-        $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus);
104
+        $this->getOptionIfSet($trapConfig, 'config', 'node', $nodeStatus);
105 105
         if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE)
106 106
         {
107
-            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN);
107
+            $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER', WARN);
108 108
             $this->getTrapApi()->setStatusMaster();
109 109
         }
110 110
         else 
@@ -112,36 +112,36 @@  discard block
 block discarded – undo
112 112
             if ($this->getTrapApi()->getStatus() != TrapApi::MASTER)
113 113
             {
114 114
                 // Get options to connect to API
115
-                $IP = $port = $user =  $pass = null;
116
-                $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR);
117
-                $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR);
118
-                $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR);
119
-                $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR);
115
+                $IP=$port=$user=$pass=null;
116
+                $this->getOptionIfSet($trapConfig, 'config', 'masterIP', $IP, ERROR);
117
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPort', $port, ERROR);
118
+                $this->getOptionIfSet($trapConfig, 'config', 'masterUser', $user, ERROR);
119
+                $this->getOptionIfSet($trapConfig, 'config', 'masterPass', $pass, ERROR);
120 120
                 $this->getTrapApi()->setParams($IP, $port, $user, $pass);
121 121
                 return;
122 122
             }
123 123
         }
124 124
         
125 125
         // Snmptranslate binary path
126
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
126
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
127 127
         
128 128
         // mibs path
129
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
129
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
130 130
         
131 131
         // icinga2cmd path
132
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
132
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
133 133
         
134 134
         // table prefix
135
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
135
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix);
136 136
         
137 137
         // API options
138
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
138
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname))
139 139
         {
140 140
             $this->apiUse=true;
141 141
             // Get API options or throw exception as not configured correctly
142
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR);
143
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR);
144
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR);
142
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort, ERROR);
143
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername, ERROR);
144
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword, ERROR);
145 145
         }
146 146
     }
147 147
     
@@ -152,42 +152,42 @@  discard block
 block discarded – undo
152 152
     protected function setupDatabase($trapConfig)
153 153
     {
154 154
         // Trap database
155
-        if (!array_key_exists('database',$trapConfig['config']))
155
+        if (!array_key_exists('database', $trapConfig['config']))
156 156
         {
157
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
157
+            $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, '');
158 158
             return;
159 159
         }
160 160
         $dbTrapName=$trapConfig['config']['database'];
161
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
161
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
162 162
         
163
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
163
+        if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false)
164 164
         {
165
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
165
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, '');
166 166
             return;
167 167
         }
168
-        if (!array_key_exists($dbTrapName,$dbConfig))
168
+        if (!array_key_exists($dbTrapName, $dbConfig))
169 169
         {
170
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
170
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
171 171
             return;
172 172
         }
173 173
         
174
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
174
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix);
175 175
         
176 176
         //TODO enable this again when API queries are all done :  $this->logging->log("API Use : ".print_r($this->apiUse,true),INFO );
177 177
         
178 178
         if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
179 179
         
180 180
         // IDO Database
181
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
181
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
182 182
         {
183
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
183
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
184 184
         }
185 185
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
186 186
         
187
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
188
-        if (!array_key_exists($dbIdoName,$dbConfig))
187
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
188
+        if (!array_key_exists($dbIdoName, $dbConfig))
189 189
         {
190
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
190
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
191 191
             return;
192 192
         }
193 193
         
Please login to merge, or discard this patch.