Completed
Push — master ( 2f676f...ba4b05 )
by Patrick
02:03
created
application/controllers/ApiController.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
         $this->_helper->layout()->disableLayout();
24 24
         $this->getResponse()->setHeader('Content-Type', 'application/json', true);
25 25
         $this->getResponse()->sendHeaders();
26
-        echo json_encode($object, $this->json_options) . "\n";
26
+        echo json_encode($object, $this->json_options)."\n";
27 27
     }
28 28
 
29 29
     protected function send_json_error($object)
@@ -31,15 +31,15 @@  discard block
 block discarded – undo
31 31
         $this->_helper->layout()->disableLayout();
32 32
         $this->getResponse()->setHeader('Content-Type', 'application/json', true);
33 33
         $this->getResponse()->sendHeaders();
34
-        echo json_encode($object, $this->json_options) . "\n";
34
+        echo json_encode($object, $this->json_options)."\n";
35 35
     }
36 36
     
37 37
 	public function indexAction()
38 38
 	{	
39 39
 		$this->checkReadPermission();
40
-		$apiObj= new RestAPI($this);
40
+		$apiObj=new RestAPI($this);
41 41
 
42
-		$modif = $apiObj->last_modified();
42
+		$modif=$apiObj->last_modified();
43 43
 		$this->send_json($modif);
44 44
 		//print_r($modif);
45 45
 		return;
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
 	public function dboptionActions()
49 49
 	{
50 50
 	    $this->checkReadPermission();
51
-	    $apiObj= new RestAPI($this);
51
+	    $apiObj=new RestAPI($this);
52 52
 	    
53
-	    $params = $this->getRequest()->getParams();
53
+	    $params=$this->getRequest()->getParams();
54 54
 	    if (isset($params['name']))
55 55
 	    {
56 56
 	        
Please login to merge, or discard this patch.
library/Trapdirector/TrapsActions/TrapDBQuery.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -34,18 +34,18 @@  discard block
 block discarded – undo
34 34
     {
35 35
         // TODO Check for rule consistency
36 36
         
37
-        $dbConn = $this->getDbConn();
37
+        $dbConn=$this->getDbConn();
38 38
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
39 39
         // Add last modified date = creation date and username
40
-        $params['created'] = new Zend_Db_Expr('NOW()');
41
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
42
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
40
+        $params['created']=new Zend_Db_Expr('NOW()');
41
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
42
+        $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername();
43 43
         
44 44
         $query=$dbConn->insert(
45 45
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
46 46
             $params
47 47
             );
48
-        if($query==false)
48
+        if ($query == false)
49 49
         {
50 50
             return null;
51 51
         }
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
      *   @param integer $ruleID : rule id in db
58 58
      *	@return array affected rows
59 59
      */
60
-    public function updateHandlerRule($params,$ruleID)
60
+    public function updateHandlerRule($params, $ruleID)
61 61
     {
62 62
         // TODO Check for rule consistency
63
-        $dbConn = $this->getDbConn();
63
+        $dbConn=$this->getDbConn();
64 64
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
65 65
         // Add last modified date = creation date and username
66
-        $params['modified'] = new 	Zend_Db_Expr('NOW()');
67
-        $params['modifier'] = $this->getTrapCtrl()->Auth()->getUser()->getUsername();
66
+        $params['modified']=new 	Zend_Db_Expr('NOW()');
67
+        $params['modifier']=$this->getTrapCtrl()->Auth()->getUser()->getUsername();
68 68
         
69 69
         $numRows=$dbConn->update(
70 70
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function deleteRule($ruleID)
81 81
     {
82
-        if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id');  }
82
+        if (!preg_match('/^[0-9]+$/', $ruleID)) { throw new Exception('Invalid id'); }
83 83
         
84
-        $dbConn = $this->getDbConn();
84
+        $dbConn=$this->getDbConn();
85 85
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
86 86
         
87 87
         $query=$dbConn->delete(
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function lastModification()
100 100
     {
101
-        $dbConn = $this->getDbConn();
101
+        $dbConn=$this->getDbConn();
102 102
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
103 103
         
104
-        $query = $dbConn->select()
104
+        $query=$dbConn->select()
105 105
         ->from(
106 106
             $this->getTrapCtrl()->getModuleConfig()->getTrapRuleName(),
107 107
             array('lastModified'=>'UNIX_TIMESTAMP(MAX(modified))'));
@@ -113,10 +113,10 @@  discard block
 block discarded – undo
113 113
      *	@param $ipAddr string source IP (v4 or v6)
114 114
      *	@param $oid string oid
115 115
      */
116
-    public function deleteTrap($ipAddr,$oid)
116
+    public function deleteTrap($ipAddr, $oid)
117 117
     {
118 118
         
119
-        $dbConn = $this->getDbConn();
119
+        $dbConn=$this->getDbConn();
120 120
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
121 121
         $condition=null;
122 122
         if ($ipAddr != null)
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
         }
126 126
         if ($oid != null)
127 127
         {
128
-            $condition=($condition===null)?'':$condition.' AND ';
128
+            $condition=($condition === null) ? '' : $condition.' AND ';
129 129
             $condition.="trap_oid='$oid'";
130 130
         }
131
-        if($condition === null) return null;
131
+        if ($condition === null) return null;
132 132
         $query=$dbConn->delete(
133 133
             $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
134 134
             $condition
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
      *	@param $ipAddr string source IP (v4 or v6)
143 143
      *	@param $oid string oid
144 144
      */
145
-    public function countTrap($ipAddr,$oid)
145
+    public function countTrap($ipAddr, $oid)
146 146
     {
147 147
         
148
-        $dbConn = $this->getDbConn();
148
+        $dbConn=$this->getDbConn();
149 149
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
150 150
         
151 151
         $condition=null;
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
         }
156 156
         if ($oid != null)
157 157
         {
158
-            $condition=($condition===null)?'':$condition.' AND ';
158
+            $condition=($condition === null) ? '' : $condition.' AND ';
159 159
             $condition.="trap_oid='$oid'";
160 160
         }
161
-        if($condition === null) return 0;
161
+        if ($condition === null) return 0;
162 162
         $query=$dbConn->select()
163 163
             ->from(
164 164
                 $this->getTrapCtrl()->getModuleConfig()->getTrapTableName(),
@@ -174,28 +174,28 @@  discard block
 block discarded – undo
174 174
     public function getDBConfigValue($element)
175 175
     {
176 176
         
177
-        $dbConn = $this->getDbConn();
177
+        $dbConn=$this->getDbConn();
178 178
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
179 179
         
180 180
         $query=$dbConn->select()
181 181
         ->from(
182 182
             $this->getTrapCtrl()->getModuleConfig()->getDbConfigTableName(),
183 183
             array('value'=>'value'))
184
-            ->where('name=?',$element);
184
+            ->where('name=?', $element);
185 185
             $returnRow=$dbConn->fetchRow($query);
186
-            if ($returnRow==null)  // value does not exists
186
+            if ($returnRow == null)  // value does not exists
187 187
             {
188 188
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
189
-                if ( ! isset($default[$element])) return null; // no default and not value
189
+                if (!isset($default[$element])) return null; // no default and not value
190 190
                 
191
-                $this->addDBConfigValue($element,$default[$element]);
191
+                $this->addDBConfigValue($element, $default[$element]);
192 192
                 return $default[$element];
193 193
             }
194 194
             if ($returnRow->value == null) // value id empty
195 195
             {
196 196
                 $default=$this->getTrapCtrl()->getModuleConfig()->getDBConfigDefaults();
197
-                if ( ! isset($default[$element])) return null; // no default and not value
198
-                $this->setDBConfigValue($element,$default[$element]);
197
+                if (!isset($default[$element])) return null; // no default and not value
198
+                $this->setDBConfigValue($element, $default[$element]);
199 199
                 return $default[$element];
200 200
             }
201 201
             return $returnRow->value;
@@ -206,10 +206,10 @@  discard block
 block discarded – undo
206 206
      *   @param string $value : value
207 207
      */
208 208
     
209
-    public function addDBConfigValue($element,$value)
209
+    public function addDBConfigValue($element, $value)
210 210
     {
211 211
         
212
-        $dbConn = $this->getDbConn();
212
+        $dbConn=$this->getDbConn();
213 213
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
214 214
         
215 215
         $query=$dbConn->insert(
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
      *	@param string $element : name of config element
227 227
      *   @param string $value : value
228 228
      */
229
-    public function setDBConfigValue($element,$value)
229
+    public function setDBConfigValue($element, $value)
230 230
     {
231 231
         
232
-        $dbConn = $this->getDbConn();
232
+        $dbConn=$this->getDbConn();
233 233
         if ($dbConn === null) throw new \ErrorException('uncatched db error');
234 234
         
235 235
         $query=$dbConn->update(
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Spacing   +172 added lines, -172 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,34 +247,34 @@  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
             }
258 258
             else
259 259
             {
260
-                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
+                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'))
261 261
                 {
262 262
                     $this->trapData['trap_oid']=$matches[2];
263 263
                 }
264 264
                 else
265 265
                 {
266
-                    $object= new stdClass;
267
-                    $object->oid =$matches[1];
268
-                    $object->value = $matches[2];
269
-                    array_push($this->trapDataExt,$object);
266
+                    $object=new stdClass;
267
+                    $object->oid=$matches[1];
268
+                    $object->value=$matches[2];
269
+                    array_push($this->trapDataExt, $object);
270 270
                 }
271 271
             }
272 272
         }
273 273
         
274
-        if ($this->trapData['trap_oid']=='unknown')
274
+        if ($this->trapData['trap_oid'] == 'unknown')
275 275
         {
276
-            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']);
277
-            $this->logging->log('no trap oid found',ERROR,'');
276
+            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trapData['source_ip']);
277
+            $this->logging->log('no trap oid found', ERROR, '');
278 278
         }
279 279
         
280 280
         // Translate oids.
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
         }
297 297
         
298 298
         
299
-        $this->trapData['status']= 'waiting';
299
+        $this->trapData['status']='waiting';
300 300
         
301 301
         return $this->trapData;
302 302
     }
@@ -312,40 +312,40 @@  discard block
 block discarded – undo
312 312
         $db_conn=$this->trapsDB->db_connect_trap();
313 313
         
314 314
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';';
315
-        $this->logging->log('SQL query : '.$sql,DEBUG );
315
+        $this->logging->log('SQL query : '.$sql, DEBUG);
316 316
         if (($ret_code=$db_conn->query($sql)) === false) {
317
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
317
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
318 318
         }
319 319
         $name=$ret_code->fetch();
320 320
         if ($name['name'] != null)
321 321
         {
322
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
322
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
323 323
         }
324 324
         
325 325
         // Also check if it is an instance of OID
326
-        $oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
326
+        $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
327 327
         
328 328
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
329
-        $this->logging->log('SQL query : '.$sql,DEBUG );
329
+        $this->logging->log('SQL query : '.$sql, DEBUG);
330 330
         if (($ret_code=$db_conn->query($sql)) === false) {
331
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
331
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
332 332
         }
333 333
         $name=$ret_code->fetch();
334 334
         if ($name['name'] != null)
335 335
         {
336
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
336
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
337 337
         }
338 338
         
339 339
         // Try to get oid name from snmptranslate
340
-        $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
340
+        $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
341 341
             ' '.$oid);
342 342
         $matches=array();
343
-        $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
344
-        if ($ret_code===0 || $ret_code === false) {
343
+        $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
344
+        if ($ret_code === 0 || $ret_code === false) {
345 345
             return NULL;
346 346
         } else {
347
-            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
348
-            return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
347
+            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
348
+            return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
349 349
         }
350 350
     }
351 351
     
@@ -356,90 +356,90 @@  discard block
 block discarded – undo
356 356
      **/
357 357
     public function eraseOldTraps($days=0)
358 358
     {
359
-        if ($days==0)
359
+        if ($days == 0)
360 360
         {
361 361
             if (($days=$this->getDBConfig('db_remove_days')) == null)
362 362
             {
363
-                $this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
363
+                $this->logging->log('No days specified & no db value : no tap erase', WARN, '');
364 364
                 return;
365 365
             }
366 366
         }
367 367
         $db_conn=$this->trapsDB->db_connect_trap();
368
-        $daysago = strtotime("-".$days." day");
369
-        $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
368
+        $daysago=strtotime("-".$days." day");
369
+        $sql='delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
370 370
         if ($db_conn->query($sql) === false) {
371
-            $this->logging->log('Error erasing traps : '.$sql,ERROR,'');
371
+            $this->logging->log('Error erasing traps : '.$sql, ERROR, '');
372 372
         }
373
-        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
373
+        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
374 374
     }
375 375
     
376 376
     /** Write error to received trap database
377 377
      */
378
-    public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
378
+    public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
379 379
     {
380 380
         
381 381
         $db_conn=$this->trapsDB->db_connect_trap();
382 382
         
383 383
         // add date time
384
-        $insert_col ='date_received,status';
385
-        $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
384
+        $insert_col='date_received,status';
385
+        $insert_val="'".date("Y-m-d H:i:s")."','error'";
386 386
         
387
-        if ($sourceIP !=null)
387
+        if ($sourceIP != null)
388 388
         {
389
-            $insert_col .=',source_ip';
390
-            $insert_val .=",'". $sourceIP ."'";
389
+            $insert_col.=',source_ip';
390
+            $insert_val.=",'".$sourceIP."'";
391 391
         }
392
-        if ($trapoid !=null)
392
+        if ($trapoid != null)
393 393
         {
394
-            $insert_col .=',trap_oid';
395
-            $insert_val .=",'". $trapoid ."'";
394
+            $insert_col.=',trap_oid';
395
+            $insert_val.=",'".$trapoid."'";
396 396
         }
397
-        $insert_col .=',status_detail';
398
-        $insert_val .=",'". $message ."'";
397
+        $insert_col.=',status_detail';
398
+        $insert_val.=",'".$message."'";
399 399
         
400
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
400
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
401 401
         
402 402
         switch ($this->trapsDB->trapDBType)
403 403
         {
404 404
             case 'pgsql':
405
-                $sql .= ' RETURNING id;';
406
-                $this->logging->log('sql : '.$sql,INFO);
405
+                $sql.=' RETURNING id;';
406
+                $this->logging->log('sql : '.$sql, INFO);
407 407
                 if (($ret_code=$db_conn->query($sql)) === false) {
408
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
408
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
409 409
                 }
410
-                $this->logging->log('SQL insertion OK',INFO );
410
+                $this->logging->log('SQL insertion OK', INFO);
411 411
                 // Get last id to insert oid/values in secondary table
412 412
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
413 413
                     
414
-                    $this->logging->log('Erreur recuperation id',1,'');
414
+                    $this->logging->log('Erreur recuperation id', 1, '');
415 415
                 }
416
-                if (! isset($inserted_id_ret['id'])) {
417
-                    $this->logging->log('Error getting id',1,'');
416
+                if (!isset($inserted_id_ret['id'])) {
417
+                    $this->logging->log('Error getting id', 1, '');
418 418
                 }
419 419
                 $this->trapId=$inserted_id_ret['id'];
420 420
                 break;
421 421
             case 'mysql':
422
-                $sql .= ';';
423
-                $this->logging->log('sql : '.$sql,INFO );
422
+                $sql.=';';
423
+                $this->logging->log('sql : '.$sql, INFO);
424 424
                 if ($db_conn->query($sql) === false) {
425
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
425
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
426 426
                 }
427
-                $this->logging->log('SQL insertion OK',INFO );
427
+                $this->logging->log('SQL insertion OK', INFO);
428 428
                 // Get last id to insert oid/values in secondary table
429 429
                 $sql='SELECT LAST_INSERT_ID();';
430 430
                 if (($ret_code=$db_conn->query($sql)) === false) {
431
-                    $this->logging->log('Erreur recuperation id',1,'');
431
+                    $this->logging->log('Erreur recuperation id', 1, '');
432 432
                 }
433 433
                 
434 434
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
435
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
435
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
436 436
                 $this->trapId=$inserted_id;
437 437
                 break;
438 438
             default:
439
-                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
439
+                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
440 440
         }
441 441
         
442
-        $this->logging->log('id found: '. $this->trapId,INFO );
442
+        $this->logging->log('id found: '.$this->trapId, INFO);
443 443
     }
444 444
     
445 445
     /** Write trap data to trap database
@@ -456,86 +456,86 @@  discard block
 block discarded – undo
456 456
         $insert_col='';
457 457
         $insert_val='';
458 458
         // add date time
459
-        $this->trapData['date_received'] = date("Y-m-d H:i:s");
459
+        $this->trapData['date_received']=date("Y-m-d H:i:s");
460 460
         
461 461
         $firstcol=1;
462 462
         foreach ($this->trapData as $col => $val)
463 463
         {
464
-            if ($firstcol==0)
464
+            if ($firstcol == 0)
465 465
             {
466
-                $insert_col .=',';
467
-                $insert_val .=',';
466
+                $insert_col.=',';
467
+                $insert_val.=',';
468 468
             }
469
-            $insert_col .= $col ;
470
-            $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
469
+            $insert_col.=$col;
470
+            $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
471 471
             $firstcol=0;
472 472
         }
473 473
         
474
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
474
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
475 475
         switch ($this->trapsDB->trapDBType)
476 476
         {
477 477
             case 'pgsql':
478
-                $sql .= ' RETURNING id;';
479
-                $this->logging->log('sql : '.$sql,INFO );
478
+                $sql.=' RETURNING id;';
479
+                $this->logging->log('sql : '.$sql, INFO);
480 480
                 if (($ret_code=$db_conn->query($sql)) === false) {
481
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
481
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
482 482
                 }
483
-                $this->logging->log('SQL insertion OK',INFO );
483
+                $this->logging->log('SQL insertion OK', INFO);
484 484
                 // Get last id to insert oid/values in secondary table
485 485
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
486 486
                     
487
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
487
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
488 488
                 }
489
-                if (! isset($inserted_id_ret['id'])) {
490
-                    $this->logging->log('Error getting id',ERROR,'');
489
+                if (!isset($inserted_id_ret['id'])) {
490
+                    $this->logging->log('Error getting id', ERROR, '');
491 491
                 }
492 492
                 $this->trapId=$inserted_id_ret['id'];
493 493
                 break;
494 494
             case 'mysql':
495
-                $sql .= ';';
496
-                $this->logging->log('sql : '.$sql,INFO );
495
+                $sql.=';';
496
+                $this->logging->log('sql : '.$sql, INFO);
497 497
                 if ($db_conn->query($sql) === false) {
498
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
498
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
499 499
                 }
500
-                $this->logging->log('SQL insertion OK',INFO );
500
+                $this->logging->log('SQL insertion OK', INFO);
501 501
                 // Get last id to insert oid/values in secondary table
502 502
                 $sql='SELECT LAST_INSERT_ID();';
503 503
                 if (($ret_code=$db_conn->query($sql)) === false) {
504
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
504
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
505 505
                 }
506 506
                 
507 507
                 $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()'];
508
-                if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
508
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
509 509
                 $this->trapId=$inserted_id;
510 510
                 break;
511 511
             default:
512
-                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
512
+                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
513 513
         }
514
-        $this->logging->log('id found: '.$this->trapId,INFO );
514
+        $this->logging->log('id found: '.$this->trapId, INFO);
515 515
         
516 516
         // Fill trap extended data table
517 517
         foreach ($this->trapDataExt as $value) {
518 518
             // TODO : detect if trap value is encoded and decode it to UTF-8 for database
519 519
             $firstcol=1;
520
-            $value->trap_id = $this->trapId;
520
+            $value->trap_id=$this->trapId;
521 521
             $insert_col='';
522 522
             $insert_val='';
523 523
             foreach ($value as $col => $val)
524 524
             {
525
-                if ($firstcol==0)
525
+                if ($firstcol == 0)
526 526
                 {
527
-                    $insert_col .=',';
528
-                    $insert_val .=',';
527
+                    $insert_col.=',';
528
+                    $insert_val.=',';
529 529
                 }
530
-                $insert_col .= $col;
531
-                $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
530
+                $insert_col.=$col;
531
+                $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
532 532
                 $firstcol=0;
533 533
             }
534 534
             
535
-            $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';
535
+            $sql='INSERT INTO '.$this->dbPrefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';
536 536
             
537 537
             if ($db_conn->query($sql) === false) {
538
-                $this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
538
+                $this->logging->log('Erreur insertion data : '.$sql, WARN, '');
539 539
             }
540 540
         }
541 541
     }
@@ -545,14 +545,14 @@  discard block
 block discarded – undo
545 545
      *	@param $oid string oid in numeric
546 546
      *	@return mixed|boolean : PDO object or false
547 547
      */
548
-    protected function getRules($ip,$oid)
548
+    protected function getRules($ip, $oid)
549 549
     {
550 550
         $db_conn=$this->trapsDB->db_connect_trap();
551 551
         // fetch rules based on IP in rule and OID
552 552
         $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' ';
553
-        $this->logging->log('SQL query : '.$sql,DEBUG );
553
+        $this->logging->log('SQL query : '.$sql, DEBUG);
554 554
         if (($ret_code=$db_conn->query($sql)) === false) {
555
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
555
+            $this->logging->log('No result in query : '.$sql, WARN, '');
556 556
             return false;
557 557
         }
558 558
         $rules_all=$ret_code->fetchAll();
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
         $rule_ret_key=0;
562 562
         foreach ($rules_all as $key => $rule)
563 563
         {
564
-            if ($rule['ip4']==$ip || $rule['ip6']==$ip)
564
+            if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
565 565
             {
566 566
                 $rules_ret[$rule_ret_key]=$rules_all[$key];
567 567
                 //TODO : get host name by API (and check if correct in rule).
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
                 continue;
570 570
             }
571 571
             // TODO : get hosts IP by API
572
-            if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
572
+            if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
573 573
             { // get ips of group members by oid
574 574
                 $db_conn2=$this->trapsDB->db_connect_ido();
575 575
                 $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -580,15 +580,15 @@  discard block
 block discarded – undo
580 580
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
581 581
 						WHERE o.name1='".$rule['host_group_name']."';";
582 582
                 if (($ret_code2=$db_conn2->query($sql)) === false) {
583
-                    $this->logging->log('No result in query : ' . $sql,WARN,'');
583
+                    $this->logging->log('No result in query : '.$sql, WARN, '');
584 584
                     continue;
585 585
                 }
586 586
                 $grouphosts=$ret_code2->fetchAll();
587 587
                 //echo "rule grp :\n";print_r($grouphosts);echo "\n";
588
-                foreach ( $grouphosts as $host)
588
+                foreach ($grouphosts as $host)
589 589
                 {
590 590
                     //echo $host['ip4']."\n";
591
-                    if ($host['ip4']==$ip || $host['ip6']==$ip)
591
+                    if ($host['ip4'] == $ip || $host['ip6'] == $ip)
592 592
                     {
593 593
                         //echo "Rule added \n";
594 594
                         $rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
         $db_conn=$this->trapsDB->db_connect_trap();
612 612
         $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
613 613
         if ($db_conn->query($sql) === false) {
614
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
614
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
615 615
         }
616 616
     }
617 617
     
@@ -623,23 +623,23 @@  discard block
 block discarded – undo
623 623
      * @param string $display
624 624
      * @returnn bool true is service check was sent without error
625 625
      */
626
-    public function serviceCheckResult($host,$service,$state,$display)
626
+    public function serviceCheckResult($host, $service, $state, $display)
627 627
     {
628 628
         if ($this->apiUse === false)
629 629
         {
630
-            $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
631
-                $host.';' .$service .';' . $state . ';'.$display;
632
-                $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
630
+            $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
631
+                $host.';'.$service.';'.$state.';'.$display;
632
+                $this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
633 633
                 
634 634
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
635
-                exec('echo "'.$send.'" > ' .$this->icinga2cmd);
635
+                exec('echo "'.$send.'" > '.$this->icinga2cmd);
636 636
                 return true;
637 637
         }
638 638
         else
639 639
         {
640 640
             // Get perfdata if found
641 641
             $matches=array();
642
-            if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1)
642
+            if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1)
643 643
             {
644 644
                 $display=$matches[1];
645 645
                 $perfdata=$matches[2];
@@ -649,17 +649,17 @@  discard block
 block discarded – undo
649 649
                 $perfdata='';
650 650
             }
651 651
             
652
-            $api = $this->getAPI();
652
+            $api=$this->getAPI();
653 653
             $api->setCredentials($this->apiUsername, $this->apiPassword);
654
-            list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata);
654
+            list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata);
655 655
             if ($retcode == false)
656 656
             {
657
-                $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
657
+                $this->logging->log("Error sending result : ".$retmessage, WARN, '');
658 658
                 return false;
659 659
             }
660 660
             else
661 661
             {
662
-                $this->logging->log( "Sent result : " .$retmessage,INFO );
662
+                $this->logging->log("Sent result : ".$retmessage, INFO);
663 663
                 return true;
664 664
             }
665 665
         }
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
     
668 668
     public function getHostByIP($ip)
669 669
     {
670
-        $api = $this->getAPI();
670
+        $api=$this->getAPI();
671 671
         $api->setCredentials($this->apiUsername, $this->apiPassword);
672 672
         return $api->getHostByIP($ip);
673 673
     }
@@ -680,35 +680,35 @@  discard block
 block discarded – undo
680 680
     protected function applyDisplay($display)
681 681
     {
682 682
         $matches=array();
683
-        while (preg_match('/_OID\(([0-9\.\*]+)\)/',$display,$matches) == 1)
683
+        while (preg_match('/_OID\(([0-9\.\*]+)\)/', $display, $matches) == 1)
684 684
         {
685 685
             $oid=$matches[1];
686 686
             $found=0;
687 687
             // Test and transform regexp
688
-            $oidR = $this->ruleClass->regexp_eval($oid);
688
+            $oidR=$this->ruleClass->regexp_eval($oid);
689 689
             
690
-            foreach($this->trapDataExt as $val)
690
+            foreach ($this->trapDataExt as $val)
691 691
             {
692
-                if (preg_match("/^$oidR$/",$val->oid) == 1)
692
+                if (preg_match("/^$oidR$/", $val->oid) == 1)
693 693
                 {
694
-                    $val->value=preg_replace('/"/','',$val->value);
694
+                    $val->value=preg_replace('/"/', '', $val->value);
695 695
                     $rep=0;
696
-                    $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
697
-                    if ($rep==0)
696
+                    $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
697
+                    if ($rep == 0)
698 698
                     {
699
-                        $this->logging->log("Error in display",WARN,'');
699
+                        $this->logging->log("Error in display", WARN, '');
700 700
                         return $display;
701 701
                     }
702 702
                     $found=1;
703 703
                     break;
704 704
                 }
705 705
             }
706
-            if ($found==0)
706
+            if ($found == 0)
707 707
             {
708
-                $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
709
-                if ($rep==0)
708
+                $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
709
+                if ($rep == 0)
710 710
                 {
711
-                    $this->logging->log("Error in display",WARN,'');
711
+                    $this->logging->log("Error in display", WARN, '');
712 712
                     return $display;
713 713
                 }
714 714
             }
@@ -720,11 +720,11 @@  discard block
 block discarded – undo
720 720
      */
721 721
     public function applyRules()
722 722
     {
723
-        $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']);
723
+        $rules=$this->getRules($this->trapData['source_ip'], $this->trapData['trap_oid']);
724 724
         
725
-        if ($rules===false || count($rules)==0)
725
+        if ($rules === false || count($rules) == 0)
726 726
         {
727
-            $this->logging->log('No rules found for this trap',INFO );
727
+            $this->logging->log('No rules found for this trap', INFO);
728 728
             $this->trapData['status']='unknown';
729 729
             $this->trapToDb=true;
730 730
             return;
@@ -739,59 +739,59 @@  discard block
 block discarded – undo
739 739
             $service_name=$rule['service_name'];
740 740
             
741 741
             $display=$this->applyDisplay($rule['display']);
742
-            $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', ';
742
+            $this->trapAction=($this->trapAction == null) ? '' : $this->trapAction.', ';
743 743
             try
744 744
             {
745
-                $this->logging->log('Rule to eval : '.$rule['rule'],INFO );
746
-                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ;
745
+                $this->logging->log('Rule to eval : '.$rule['rule'], INFO);
746
+                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt);
747 747
                 //->eval_rule($rule['rule']);
748 748
                 
749 749
                 if ($evalr == true)
750 750
                 {
751 751
                     //$this->logging->log('rules OOK: '.print_r($rule),INFO );
752 752
                     $action=$rule['action_match'];
753
-                    $this->logging->log('action OK : '.$action,INFO );
753
+                    $this->logging->log('action OK : '.$action, INFO);
754 754
                     if ($action >= 0)
755 755
                     {
756
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
756
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
757 757
                         {
758 758
                             $this->trapAction.='Error sending status : check cmd/API';
759 759
                         }
760 760
                         else
761 761
                         {
762
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
762
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
763 763
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
764 764
                         }
765 765
                     }
766 766
                     else
767 767
                     {
768
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
768
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
769 769
                     }
770
-                    $this->trapToDb=($action==-2)?false:true;
770
+                    $this->trapToDb=($action == -2) ?false:true;
771 771
                 }
772 772
                 else
773 773
                 {
774 774
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
775 775
                     
776 776
                     $action=$rule['action_nomatch'];
777
-                    $this->logging->log('action NOK : '.$action,INFO );
777
+                    $this->logging->log('action NOK : '.$action, INFO);
778 778
                     if ($action >= 0)
779 779
                     {
780
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
780
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
781 781
                         {
782 782
                             $this->trapAction.='Error sending status : check cmd/API';
783 783
                         }
784 784
                         else
785 785
                         {
786
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
786
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
787 787
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
788 788
                         }
789 789
                     }
790 790
                     else
791 791
                     {
792
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
792
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
793 793
                     }
794
-                    $this->trapToDb=($action==-2)?false:true;
794
+                    $this->trapToDb=($action == -2) ?false:true;
795 795
                 }
796 796
                 // Put name in source_name
797 797
                 if (!isset($this->trapData['source_name']))
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
                 }
801 801
                 else
802 802
                 {
803
-                    if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name']))
803
+                    if (!preg_match('/'.$rule['host_name'].'/', $this->trapData['source_name']))
804 804
                     { // only add if not present
805 805
                         $this->trapData['source_name'].=','.$rule['host_name'];
806 806
                     }
@@ -808,13 +808,13 @@  discard block
 block discarded – undo
808 808
             }
809 809
             catch (Exception $e)
810 810
             {
811
-                $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
811
+                $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
812 812
                 $this->trapAction.=' ERR : '.$e->getMessage();
813 813
                 $this->trapData['status']='error';
814 814
             }
815 815
             
816 816
         }
817
-        if ($this->trapData['status']=='error')
817
+        if ($this->trapData['status'] == 'error')
818 818
         {
819 819
             $this->trapToDb=true; // Always put errors in DB for the use can see
820 820
         }
@@ -830,13 +830,13 @@  discard block
 block discarded – undo
830 830
     public function add_rule_final($time)
831 831
     {
832 832
         $db_conn=$this->trapsDB->db_connect_trap();
833
-        if ($this->trapAction==null)
833
+        if ($this->trapAction == null)
834 834
         {
835 835
             $this->trapAction='No action';
836 836
         }
837 837
         $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."'  WHERE (id = '".$this->trapId."');";
838 838
         if ($db_conn->query($sql) === false) {
839
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
839
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
840 840
         }
841 841
     }
842 842
     
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
     WHERE s.current_state != 0;";
860 860
         $db_conn=$this->trapsDB->db_connect_ido();
861 861
         if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
862
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
862
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
863 863
             return 0;
864 864
         }
865 865
         $services=$services_db->fetchAll();
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
         $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;";
869 869
         $db_conn2=$this->trapsDB->db_connect_trap();
870 870
         if (($rules_db=$db_conn2->query($sql_query)) === false) {
871
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
871
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
872 872
             return 0;
873 873
         }
874 874
         $rules=$rules_db->fetchAll();
@@ -884,13 +884,13 @@  discard block
 block discarded – undo
884 884
                     $service['host_name'] == $rule['host_name'] &&
885 885
                     ($service['last_check'] + $rule['revert_ok']) < $now)
886 886
                 {
887
-                    $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
887
+                    $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
888 888
                     $numreset++;
889 889
                 }
890 890
             }
891 891
         }
892 892
         echo "\n";
893
-        echo $numreset . " service(s) reset to OK\n";
893
+        echo $numreset." service(s) reset to OK\n";
894 894
         return 0;
895 895
         
896 896
     }
Please login to merge, or discard this patch.
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,40 +152,40 @@  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
         if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
177 177
         
178 178
         // IDO Database
179
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
179
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
180 180
         {
181
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
181
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
182 182
         }
183 183
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
184 184
         
185
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
186
-        if (!array_key_exists($dbIdoName,$dbConfig))
185
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
186
+        if (!array_key_exists($dbIdoName, $dbConfig))
187 187
         {
188
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
188
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
189 189
             return;
190 190
         }
191 191
         
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/TrapApi.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
     public const MASTER=1;
22 22
     public const MASTERHA=2;
23 23
     public const SAT=3;
24
-    public $stateArray = array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA , 'SAT' => TrapApi::SAT  );
24
+    public $stateArray=array('MASTER' => TrapApi::MASTER, 'MASTERHA' => TrapApi::MASTERHA, 'SAT' => TrapApi::SAT);
25 25
     
26 26
     /** @var integer $whoami current server : MASTER MASTERHA or SAT */
27
-    public $whoami = TrapApi::MASTER;
27
+    public $whoami=TrapApi::MASTER;
28 28
     /** @var string $masterIP ip of master if MASTERHA or SAT  */
29 29
     public $masterIP='';
30 30
     /** @var integer $masterPort port of master if MASTERHA or SAT  */
@@ -71,21 +71,21 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function setStatus(string $status)
73 73
     {
74
-        if (! isset($this->stateArray[$status]))
74
+        if (!isset($this->stateArray[$status]))
75 75
         {
76 76
             return FALSE;
77 77
         }
78 78
         
79
-        $this->logging->log('Setting status to : ' . $status, INFO);
79
+        $this->logging->log('Setting status to : '.$status, INFO);
80 80
         
81
-        $this->whoami = $this->stateArray[$status];
81
+        $this->whoami=$this->stateArray[$status];
82 82
         
83 83
         return TRUE;
84 84
     }
85 85
  
86 86
     public function setStatusMaster()
87 87
     {
88
-        $this->whoami = TrapApi::MASTER;
88
+        $this->whoami=TrapApi::MASTER;
89 89
     }
90 90
     
91 91
     /**
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
      */
99 99
     public function setParams(string $IP, int $port, string $user, string $pass)
100 100
     {
101
-        $this->masterIP = $IP;
102
-        $this->masterPort = $port;
103
-        $this->masterUser = $user;
104
-        $this->masterPass = $pass;
101
+        $this->masterIP=$IP;
102
+        $this->masterPort=$port;
103
+        $this->masterUser=$user;
104
+        $this->masterPass=$pass;
105 105
         
106 106
         return true;
107 107
     }
Please login to merge, or discard this patch.
library/Trapdirector/Rest/RestAPI.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
         //echo json_encode($object, JSON_PRETTY_PRINT) . "\n";
36 36
     }
37 37
     
38
-    protected function sendJsonError(string $error, int $retCode = 200)
38
+    protected function sendJsonError(string $error, int $retCode=200)
39 39
     {
40 40
         //TODO
41 41
         $this->sendJson('{"Error":"'.$error.'"}');
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     {
46 46
         try 
47 47
         {
48
-            $query = $this->trapController->getUIDatabase()->lastModification();
48
+            $query=$this->trapController->getUIDatabase()->lastModification();
49 49
             return array('lastModified' => $query);
50 50
         } 
51 51
         catch (\ErrorException $e) 
Please login to merge, or discard this patch.