Passed
Push — master ( a5cb6b...ce1111 )
by Patrick
02:05
created
library/Trapdirector/Tables/TrapTableList.php 1 patch
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	// Filters 
22 22
 	
23 23
     protected $filter;
24
-    protected $enforcedFilters = array();
25
-    protected $searchColumns = array();
24
+    protected $enforcedFilters=array();
25
+    protected $searchColumns=array();
26 26
 	
27 27
 	protected function getTitles() {
28 28
 		// TODO : check moduleconfig is set
@@ -38,60 +38,60 @@  discard block
 block discarded – undo
38 38
 	public function render()
39 39
 	{
40 40
 		$data=$this->getTable();
41
-		$view = $this->getView();
42
-		$this->columnCount = count($this->getTitles());
41
+		$view=$this->getView();
42
+		$this->columnCount=count($this->getTitles());
43 43
 		$this->lastDay=null;
44 44
 		// Table start
45
-		$htm  = '<table class="simple common-table table-row-selectable">';
45
+		$htm='<table class="simple common-table table-row-selectable">';
46 46
 		
47 47
 		// Titles
48
-		$htm .= "<thead>\n  <tr>\n";
49
-		$titles = $this->getTitles();
48
+		$htm.="<thead>\n  <tr>\n";
49
+		$titles=$this->getTitles();
50 50
 		foreach ($titles as $title) 
51 51
 		{
52
-			$htm .= '    <th>' . $view->escape($view->translate($title)) . "</th>\n";
52
+			$htm.='    <th>'.$view->escape($view->translate($title))."</th>\n";
53 53
 		}
54
-		$htm .= "  </tr>\n</thead>\n";
54
+		$htm.="  </tr>\n</thead>\n";
55 55
 		
56 56
 		// Rows
57
-		$htm .= "<tbody>\n";
57
+		$htm.="<tbody>\n";
58 58
 		
59 59
 		foreach ($data as $row) 
60 60
 		{
61
-			$firstCol = true;
61
+			$firstCol=true;
62 62
 			// Put date header
63
-			$htm .= $this->renderDayIfNew($row->timestamp);
63
+			$htm.=$this->renderDayIfNew($row->timestamp);
64 64
 			
65 65
 			
66 66
 			// Render row
67
-			$htm .= '<tr>';
68
-			foreach ( $titles as $rowkey => $title) 
67
+			$htm.='<tr>';
68
+			foreach ($titles as $rowkey => $title) 
69 69
 			{
70 70
 				// Check missing value
71 71
 				if (property_exists($row, $rowkey)) 
72 72
 				{
73
-					$val = ($rowkey=='timestamp') ?  strftime('%T',$row->$rowkey) : $row->$rowkey;
73
+					$val=($rowkey == 'timestamp') ?  strftime('%T', $row->$rowkey) : $row->$rowkey;
74 74
 				} else {
75
-					$val = '-';
75
+					$val='-';
76 76
 				}
77 77
 				if ($firstCol == true) { // Put link in first column for trap detail.
78
-					$htm .= '<td>' 
78
+					$htm.='<td>' 
79 79
 							. $view->qlink(
80 80
 									$view->escape($val),  
81 81
 									Url::fromPath(
82
-										$this->moduleConfig->urlPath() . '/received/trapdetail', 
82
+										$this->moduleConfig->urlPath().'/received/trapdetail', 
83 83
 										array('id' => $row->id)
84 84
 									)
85 85
 							)
86 86
 							. '</td>';
87 87
 				} else {
88
-					$htm .= '<td>' . $view->escape($val) . '</td>';
88
+					$htm.='<td>'.$view->escape($val).'</td>';
89 89
 				}
90 90
 				$firstCol=false;
91 91
 			}
92
-			$htm .= "<tr>\n";
92
+			$htm.="<tr>\n";
93 93
 		}
94
-		$htm .= "</tbody></table>\n";
94
+		$htm.="</tbody></table>\n";
95 95
 		//$htm .= "Filter : " . $this->filter."<br>\n";
96 96
 		return $htm;
97 97
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     {
102 102
         $db=$this->db();
103 103
 		
104
-		$query = $db->select()->from(
104
+		$query=$db->select()->from(
105 105
             $this->moduleConfig->getTrapTableName(),
106 106
             array('COUNT(*)')
107 107
         );
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	
113 113
     public function getPaginator()
114 114
     {
115
-        $paginator = new Paginator();
115
+        $paginator=new Paginator();
116 116
         $paginator->setQuery($this);
117 117
 
118 118
         return $paginator;
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	{
125 125
 		$db=$this->db();
126 126
 		
127
-		$query = $this->getBaseQuery();
127
+		$query=$this->getBaseQuery();
128 128
 		$this->applyFiltersToQuery($query);
129 129
        if ($this->hasLimit() || $this->hasOffset()) {
130 130
             $query->limit($this->getLimit(), $this->getOffset());
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     {
138 138
 		$db=$this->db();
139 139
 		
140
-		$query = $db->select()->from(
140
+		$query=$db->select()->from(
141 141
             $this->moduleConfig->getTrapTableName(),
142 142
             $this->moduleConfig->getTrapListDisplayColumns()
143 143
         )->order('timestamp DESC');
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	protected $filter_Handler;
151 151
 	protected $filter_query='';
152 152
 	protected $filter_done='';
153
-	protected $filter_query_list=array('q','done');
153
+	protected $filter_query_list=array('q', 'done');
154 154
 	public function renderFilterHTML()
155 155
 	{
156 156
 		$htm=' <form id="filter" name="mainFilter" 
@@ -160,17 +160,17 @@  discard block
 block discarded – undo
160 160
 		$htm.='<input type="text" name="q" title="Search is simple! Try to combine multiple words" 
161 161
 		placeholder="Search..." class="search" value="'.$this->filter_query.'">';
162 162
 		$htm.='<input type="checkbox" id="checkbox_done" name="done" value="1" class="autosubmit" ';
163
-		if	($this->filter_done == 1) { $htm.=' checked ';}
163
+		if ($this->filter_done == 1) { $htm.=' checked '; }
164 164
 		$htm.='> <label for="checkbox_done">Hide processed traps</label>';
165 165
 		$htm.='</form>';
166 166
 		return $htm;
167 167
 	}
168 168
 	
169
-	public function updateFilter($handler,$filter)
169
+	public function updateFilter($handler, $filter)
170 170
 	{
171 171
 		$this->filter_Handler=$handler->remove($this->filter_query_list)->__toString();
172
-		$this->filter_query=(isset($filter['q']))?$this->filter_query=$filter['q']:'';
173
-		$this->filter_done=(isset($filter['done']))?$this->filter_done=$filter['done']:0;
172
+		$this->filter_query=(isset($filter['q'])) ? $this->filter_query=$filter['q'] : '';
173
+		$this->filter_done=(isset($filter['done'])) ? $this->filter_done=$filter['done'] : 0;
174 174
 	}
175 175
 	
176 176
     protected function getSearchColumns()
@@ -185,20 +185,20 @@  discard block
 block discarded – undo
185 185
 
186 186
     public function setFilter($filter)
187 187
     {
188
-        $this->filter = $filter;
188
+        $this->filter=$filter;
189 189
         return $this;
190 190
     }
191 191
 	
192 192
 	public function getFilterEditor(Request $request)
193 193
     {
194
-        $filterEditor = Widget::create('filterEditor')
194
+        $filterEditor=Widget::create('filterEditor')
195 195
             ->setColumns(array_keys($this->getColumns()))
196 196
             ->setSearchColumns(array_keys($this->getSearchColumns()))
197 197
             ->preserveParams('limit', 'sort', 'dir', 'view', 'backend')
198 198
             ->ignoreParams('page')
199 199
             ->handleRequest($request);
200 200
 
201
-        $filter = $filterEditor->getFilter();
201
+        $filter=$filterEditor->getFilter();
202 202
         $this->setFilter($filter);
203 203
 
204 204
         return $filterEditor;
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 		{
213 213
 			$sql.='(';
214 214
 			$first=1;
215
-			foreach($this->moduleConfig->getTrapListSearchColumns() as $column)
215
+			foreach ($this->moduleConfig->getTrapListSearchColumns() as $column)
216 216
 			{
217
-				if ($first==0) $sql.=' OR ';
217
+				if ($first == 0) $sql.=' OR ';
218 218
 				$first=0;
219 219
 				$sql.=" CAST(".$column." AS  char(100))  LIKE  '%".$this->filter_query."%' ";
220 220
 			}
Please login to merge, or discard this patch.
library/Trapdirector/TrapsProcess/Trap.php 1 patch
Spacing   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
     
50 50
     // Logs
51 51
     /** @var Logging Logging class. */
52
-    public $logging;    //< Logging class.
52
+    public $logging; //< Logging class.
53 53
     /** @var bool true if log was setup in constructor */
54
-    protected $logSetup;   //< bool true if log was setup in constructor
54
+    protected $logSetup; //< bool true if log was setup in constructor
55 55
     
56 56
     // Databases
57 57
     /** @var Database $trapsDB  Database class*/
58
-    public $trapsDB = null;
58
+    public $trapsDB=null;
59 59
     
60 60
     // Trap received data
61 61
     protected $receivingHost;
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
     protected $trapToDb=true;
72 72
     
73 73
     /** @var Mib mib class */
74
-    public $mibClass = null;
74
+    public $mibClass=null;
75 75
     
76 76
     /** @var Rule rule class */
77
-    public $ruleClass = null;
77
+    public $ruleClass=null;
78 78
     
79 79
     /** @var Plugins plugins manager **/
80
-    public $pluginClass = null;
80
+    public $pluginClass=null;
81 81
     
82
-    function __construct($etcDir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='')
82
+    function __construct($etcDir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='')
83 83
     {
84 84
         // Paths of ini files
85 85
         $this->icingaweb2Etc=$etcDir;
@@ -87,10 +87,10 @@  discard block
 block discarded – undo
87 87
         $this->icingaweb2Ressources=$this->icingaweb2Etc."/resources.ini";
88 88
         
89 89
         //************* Setup logging
90
-        $this->logging = new Logging();
90
+        $this->logging=new Logging();
91 91
         if ($baseLogLevel != null)
92 92
         {
93
-            $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile);
93
+            $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile);
94 94
             $this->logSetup=true;
95 95
         }
96 96
         else
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
         $this->logging->log('Loggin started', INFO);
101 101
         
102 102
         //*************** Get options from ini files
103
-        if (! is_file($this->trapModuleConfig))
103
+        if (!is_file($this->trapModuleConfig))
104 104
         {
105 105
             throw new Exception("Ini file ".$this->trapModuleConfig." does not exists");
106 106
         }
107
-        $trapConfig=parse_ini_file($this->trapModuleConfig,true);
107
+        $trapConfig=parse_ini_file($this->trapModuleConfig, true);
108 108
         if ($trapConfig == false)
109 109
         {
110
-            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog');
110
+            $this->logging->log("Error reading ini file : ".$this->trapModuleConfig, ERROR, 'syslog');
111 111
             throw new Exception("Error reading ini file : ".$this->trapModuleConfig);
112 112
         }
113 113
         $this->getMainOptions($trapConfig); // Get main options from ini file
@@ -121,10 +121,10 @@  discard block
 block discarded – undo
121 121
         if ($this->apiUse === true) $this->getAPI(); // Setup API
122 122
         
123 123
         //*************** Setup MIB
124
-        $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class
124
+        $this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class
125 125
         
126 126
         //*************** Setup Rule
127
-        $this->ruleClass = new Rule($this->logging); //< Create Rule class
127
+        $this->ruleClass=new Rule($this->logging); //< Create Rule class
128 128
         
129 129
         $this->trapData=array(  // TODO : put this in a reset function (DAEMON_MODE)
130 130
             'source_ip'	=> 'unknown',
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         
137 137
         //*************** Setup Plugins
138 138
         //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins
139
-        $this->pluginClass = new Plugins($this);
139
+        $this->pluginClass=new Plugins($this);
140 140
             
141 141
             
142 142
     }
@@ -151,15 +151,15 @@  discard block
 block discarded – undo
151 151
      * @param string $message warning message if not found
152 152
      * @return boolean true if found, or false
153 153
      */
154
-    protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null)
154
+    protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null)
155 155
     {
156 156
         if (!isset($option_array[$option_category][$option_name]))
157 157
         {
158 158
             if ($message === null)
159 159
             {
160
-                $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig;
160
+                $message='No '.$option_name.' in config file: '.$this->trapModuleConfig;
161 161
             }
162
-            $this->logging->log($message,$log_level);
162
+            $this->logging->log($message, $log_level);
163 163
             return false;
164 164
         }
165 165
         else
@@ -177,24 +177,24 @@  discard block
 block discarded – undo
177 177
     {
178 178
         
179 179
         // Snmptranslate binary path
180
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate);
180
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate);
181 181
         
182 182
         // mibs path
183
-        $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs);
183
+        $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs);
184 184
         
185 185
         // icinga2cmd path
186
-        $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd);
186
+        $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd);
187 187
         
188 188
         // table prefix
189
-        $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix);
189
+        $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix);
190 190
         
191 191
         // API options
192
-        if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname))
192
+        if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname))
193 193
         {
194 194
             $this->apiUse=true;
195
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort);
196
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername);
197
-            $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword);
195
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort);
196
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername);
197
+            $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword);
198 198
         }
199 199
     }
200 200
     
@@ -205,40 +205,40 @@  discard block
 block discarded – undo
205 205
     protected function setupDatabase($trapConfig)
206 206
     {
207 207
         // Trap database
208
-        if (!array_key_exists('database',$trapConfig['config']))
208
+        if (!array_key_exists('database', $trapConfig['config']))
209 209
         {
210
-            $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,'');
210
+            $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, '');
211 211
             return;
212 212
         }
213 213
         $dbTrapName=$trapConfig['config']['database'];
214
-        $this->logging->log("Found database in config file: ".$dbTrapName,INFO );
214
+        $this->logging->log("Found database in config file: ".$dbTrapName, INFO);
215 215
         
216
-        if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false)
216
+        if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false)
217 217
         {
218
-            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,'');
218
+            $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, '');
219 219
             return;
220 220
         }
221
-        if (!array_key_exists($dbTrapName,$dbConfig))
221
+        if (!array_key_exists($dbTrapName, $dbConfig))
222 222
         {
223
-            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
223
+            $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
224 224
             return;
225 225
         }
226 226
         
227
-        $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix);
227
+        $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix);
228 228
         
229 229
         if ($this->apiUse === true) return; // In case of API use, no IDO is necessary
230 230
         
231 231
         // IDO Database
232
-        if (!array_key_exists('IDOdatabase',$trapConfig['config']))
232
+        if (!array_key_exists('IDOdatabase', $trapConfig['config']))
233 233
         {
234
-            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,'');
234
+            $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, '');
235 235
         }
236 236
         $dbIdoName=$trapConfig['config']['IDOdatabase'];
237 237
         
238
-        $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO );
239
-        if (!array_key_exists($dbIdoName,$dbConfig))
238
+        $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO);
239
+        if (!array_key_exists($dbIdoName, $dbConfig))
240 240
         {
241
-            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,'');
241
+            $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, '');
242 242
             return;
243 243
         }
244 244
         
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
         // Database options
254 254
         if ($this->logSetup === false) // Only if logging was no setup in constructor
255 255
         {
256
-            $this->getDBConfigIfSet('log_level',$this->logging->debugLevel);
257
-            $this->getDBConfigIfSet('log_destination',$this->logging->outputMode);
258
-            $this->getDBConfigIfSet('log_file',$this->logging->outputFile);
256
+            $this->getDBConfigIfSet('log_level', $this->logging->debugLevel);
257
+            $this->getDBConfigIfSet('log_destination', $this->logging->outputMode);
258
+            $this->getDBConfigIfSet('log_file', $this->logging->outputFile);
259 259
         }
260 260
     }
261 261
     
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
      * @param string $element
264 264
      * @param string $variable
265 265
      */
266
-    protected function getDBConfigIfSet($element,&$variable)
266
+    protected function getDBConfigIfSet($element, &$variable)
267 267
     {
268 268
         $value=$this->getDBConfig($element);
269 269
         if ($value != null) $variable=$value;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         $db_conn=$this->trapsDB->db_connect_trap();
280 280
         $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )';
281 281
         if (($ret_code=$db_conn->query($sql)) === false) {
282
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
282
+            $this->logging->log('No result in query : '.$sql, WARN, '');
283 283
             return null;
284 284
         }
285 285
         $value=$ret_code->fetch();
@@ -296,15 +296,15 @@  discard block
 block discarded – undo
296 296
      *	@param  string $destination file/syslog/display
297 297
      *	@return void
298 298
      **/
299
-    public function trapLog( $message, $level, $destination ='') // OBSOLETE
299
+    public function trapLog($message, $level, $destination='') // OBSOLETE
300 300
     {
301 301
         // TODO : replace ref with $this->logging->log
302 302
         $this->logging->log($message, $level, $destination);
303 303
     }
304 304
     
305
-    public function setLogging($debugLvl,$outputType,$outputOption=null)  // OBSOLETE
305
+    public function setLogging($debugLvl, $outputType, $outputOption=null)  // OBSOLETE
306 306
     {
307
-        $this->logging->setLogging($debugLvl, $outputType,$outputOption);
307
+        $this->logging->setLogging($debugLvl, $outputType, $outputOption);
308 308
     }
309 309
     
310 310
     /**
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
     {
316 316
         if ($this->icinga2api == null)
317 317
         {
318
-            $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort);
318
+            $this->icinga2api=new Icinga2API($this->apiHostname, $this->apiPort);
319 319
         }
320 320
         return $this->icinga2api;
321 321
     }
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         if ($input_stream === false)
335 335
         {
336 336
             $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)");
337
-            $this->logging->log("Error reading stdin !",ERROR,'');
337
+            $this->logging->log("Error reading stdin !", ERROR, '');
338 338
             return null; // note : exception thrown by logging
339 339
         }
340 340
         
@@ -343,21 +343,21 @@  discard block
 block discarded – undo
343 343
         if ($this->receivingHost === false)
344 344
         {
345 345
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)");
346
-            $this->logging->log("Error reading Host !",ERROR,'');
346
+            $this->logging->log("Error reading Host !", ERROR, '');
347 347
         }
348 348
         // line 2 IP:port=>IP:port
349 349
         $IP=chop(fgets($input_stream));
350 350
         if ($IP === false)
351 351
         {
352 352
             $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)");
353
-            $this->logging->log("Error reading IP !",ERROR,'');
353
+            $this->logging->log("Error reading IP !", ERROR, '');
354 354
         }
355 355
         $matches=array();
356
-        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches);
357
-        if ($ret_code===0 || $ret_code===false)
356
+        $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches);
357
+        if ($ret_code === 0 || $ret_code === false)
358 358
         {
359 359
             $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)");
360
-            $this->logging->log('Error parsing IP : '.$IP,ERROR,'');
360
+            $this->logging->log('Error parsing IP : '.$IP, ERROR, '');
361 361
         }
362 362
         else
363 363
         {
@@ -367,34 +367,34 @@  discard block
 block discarded – undo
367 367
             $this->trapData['destination_port']=$matches[4];
368 368
         }
369 369
         
370
-        while (($vars=fgets($input_stream)) !==false)
370
+        while (($vars=fgets($input_stream)) !== false)
371 371
         {
372 372
             $vars=chop($vars);
373
-            $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches);
374
-            if ($ret_code===0 || $ret_code===false)
373
+            $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches);
374
+            if ($ret_code === 0 || $ret_code === false)
375 375
             {
376
-                $this->logging->log('No match on trap data : '.$vars,WARN,'');
376
+                $this->logging->log('No match on trap data : '.$vars, WARN, '');
377 377
             }
378 378
             else
379 379
             {
380
-                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'))
380
+                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 381
                 {
382 382
                     $this->trapData['trap_oid']=$matches[2];
383 383
                 }
384 384
                 else
385 385
                 {
386
-                    $object= new stdClass;
387
-                    $object->oid =$matches[1];
388
-                    $object->value = $matches[2];
389
-                    array_push($this->trapDataExt,$object);
386
+                    $object=new stdClass;
387
+                    $object->oid=$matches[1];
388
+                    $object->value=$matches[2];
389
+                    array_push($this->trapDataExt, $object);
390 390
                 }
391 391
             }
392 392
         }
393 393
         
394
-        if ($this->trapData['trap_oid']=='unknown')
394
+        if ($this->trapData['trap_oid'] == 'unknown')
395 395
         {
396
-            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']);
397
-            $this->logging->log('no trap oid found',ERROR,'');
396
+            $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trapData['source_ip']);
397
+            $this->logging->log('no trap oid found', ERROR, '');
398 398
         }
399 399
         
400 400
         // Translate oids.
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
         }
417 417
         
418 418
         
419
-        $this->trapData['status']= 'waiting';
419
+        $this->trapData['status']='waiting';
420 420
         
421 421
         return $this->trapData;
422 422
     }
@@ -432,40 +432,40 @@  discard block
 block discarded – undo
432 432
         $db_conn=$this->trapsDB->db_connect_trap();
433 433
         
434 434
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';';
435
-        $this->logging->log('SQL query : '.$sql,DEBUG );
435
+        $this->logging->log('SQL query : '.$sql, DEBUG);
436 436
         if (($ret_code=$db_conn->query($sql)) === false) {
437
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
437
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
438 438
         }
439 439
         $name=$ret_code->fetch();
440 440
         if ($name['name'] != null)
441 441
         {
442
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
442
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
443 443
         }
444 444
         
445 445
         // Also check if it is an instance of OID
446
-        $oid_instance=preg_replace('/\.[0-9]+$/','',$oid);
446
+        $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid);
447 447
         
448 448
         $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';';
449
-        $this->logging->log('SQL query : '.$sql,DEBUG );
449
+        $this->logging->log('SQL query : '.$sql, DEBUG);
450 450
         if (($ret_code=$db_conn->query($sql)) === false) {
451
-            $this->logging->log('No result in query : ' . $sql,ERROR,'');
451
+            $this->logging->log('No result in query : '.$sql, ERROR, '');
452 452
         }
453 453
         $name=$ret_code->fetch();
454 454
         if ($name['name'] != null)
455 455
         {
456
-            return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']);
456
+            return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']);
457 457
         }
458 458
         
459 459
         // Try to get oid name from snmptranslate
460
-        $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.
460
+        $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.
461 461
             ' '.$oid);
462 462
         $matches=array();
463
-        $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches);
464
-        if ($ret_code===0 || $ret_code === false) {
463
+        $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches);
464
+        if ($ret_code === 0 || $ret_code === false) {
465 465
             return NULL;
466 466
         } else {
467
-            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO);
468
-            return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]);
467
+            $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO);
468
+            return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]);
469 469
         }
470 470
     }
471 471
     
@@ -476,90 +476,90 @@  discard block
 block discarded – undo
476 476
      **/
477 477
     public function eraseOldTraps($days=0)
478 478
     {
479
-        if ($days==0)
479
+        if ($days == 0)
480 480
         {
481 481
             if (($days=$this->getDBConfig('db_remove_days')) == null)
482 482
             {
483
-                $this->logging->log('No days specified & no db value : no tap erase' ,WARN,'');
483
+                $this->logging->log('No days specified & no db value : no tap erase', WARN, '');
484 484
                 return;
485 485
             }
486 486
         }
487 487
         $db_conn=$this->trapsDB->db_connect_trap();
488
-        $daysago = strtotime("-".$days." day");
489
-        $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';';
488
+        $daysago=strtotime("-".$days." day");
489
+        $sql='delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';';
490 490
         if ($db_conn->query($sql) === false) {
491
-            $this->logging->log('Error erasing traps : '.$sql,ERROR,'');
491
+            $this->logging->log('Error erasing traps : '.$sql, ERROR, '');
492 492
         }
493
-        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO);
493
+        $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO);
494 494
     }
495 495
     
496 496
     /** Write error to received trap database
497 497
      */
498
-    public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null)
498
+    public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null)
499 499
     {
500 500
         
501 501
         $db_conn=$this->trapsDB->db_connect_trap();
502 502
         
503 503
         // add date time
504
-        $insert_col ='date_received,status';
505
-        $insert_val = "'" . date("Y-m-d H:i:s")."','error'";
504
+        $insert_col='date_received,status';
505
+        $insert_val="'".date("Y-m-d H:i:s")."','error'";
506 506
         
507
-        if ($sourceIP !=null)
507
+        if ($sourceIP != null)
508 508
         {
509
-            $insert_col .=',source_ip';
510
-            $insert_val .=",'". $sourceIP ."'";
509
+            $insert_col.=',source_ip';
510
+            $insert_val.=",'".$sourceIP."'";
511 511
         }
512
-        if ($trapoid !=null)
512
+        if ($trapoid != null)
513 513
         {
514
-            $insert_col .=',trap_oid';
515
-            $insert_val .=",'". $trapoid ."'";
514
+            $insert_col.=',trap_oid';
515
+            $insert_val.=",'".$trapoid."'";
516 516
         }
517
-        $insert_col .=',status_detail';
518
-        $insert_val .=",'". $message ."'";
517
+        $insert_col.=',status_detail';
518
+        $insert_val.=",'".$message."'";
519 519
         
520
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
520
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
521 521
         
522 522
         switch ($this->trapsDB->trapDBType)
523 523
         {
524 524
             case 'pgsql':
525
-                $sql .= ' RETURNING id;';
526
-                $this->logging->log('sql : '.$sql,INFO);
525
+                $sql.=' RETURNING id;';
526
+                $this->logging->log('sql : '.$sql, INFO);
527 527
                 if (($ret_code=$db_conn->query($sql)) === false) {
528
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
528
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
529 529
                 }
530
-                $this->logging->log('SQL insertion OK',INFO );
530
+                $this->logging->log('SQL insertion OK', INFO);
531 531
                 // Get last id to insert oid/values in secondary table
532 532
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
533 533
                     
534
-                    $this->logging->log('Erreur recuperation id',1,'');
534
+                    $this->logging->log('Erreur recuperation id', 1, '');
535 535
                 }
536
-                if (! isset($inserted_id_ret['id'])) {
537
-                    $this->logging->log('Error getting id',1,'');
536
+                if (!isset($inserted_id_ret['id'])) {
537
+                    $this->logging->log('Error getting id', 1, '');
538 538
                 }
539 539
                 $this->trapId=$inserted_id_ret['id'];
540 540
                 break;
541 541
             case 'mysql':
542
-                $sql .= ';';
543
-                $this->logging->log('sql : '.$sql,INFO );
542
+                $sql.=';';
543
+                $this->logging->log('sql : '.$sql, INFO);
544 544
                 if ($db_conn->query($sql) === false) {
545
-                    $this->logging->log('Error SQL insert : '.$sql,1,'');
545
+                    $this->logging->log('Error SQL insert : '.$sql, 1, '');
546 546
                 }
547
-                $this->logging->log('SQL insertion OK',INFO );
547
+                $this->logging->log('SQL insertion OK', INFO);
548 548
                 // Get last id to insert oid/values in secondary table
549 549
                 $sql='SELECT LAST_INSERT_ID();';
550 550
                 if (($ret_code=$db_conn->query($sql)) === false) {
551
-                    $this->logging->log('Erreur recuperation id',1,'');
551
+                    $this->logging->log('Erreur recuperation id', 1, '');
552 552
                 }
553 553
                 
554 554
                 $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");
555
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
556 556
                 $this->trapId=$inserted_id;
557 557
                 break;
558 558
             default:
559
-                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType,1,'');
559
+                $this->logging->log('Error SQL type unknown  : '.$this->trapsDB->trapDBType, 1, '');
560 560
         }
561 561
         
562
-        $this->logging->log('id found: '. $this->trapId,INFO );
562
+        $this->logging->log('id found: '.$this->trapId, INFO);
563 563
     }
564 564
     
565 565
     /** Write trap data to trap database
@@ -576,86 +576,86 @@  discard block
 block discarded – undo
576 576
         $insert_col='';
577 577
         $insert_val='';
578 578
         // add date time
579
-        $this->trapData['date_received'] = date("Y-m-d H:i:s");
579
+        $this->trapData['date_received']=date("Y-m-d H:i:s");
580 580
         
581 581
         $firstcol=1;
582 582
         foreach ($this->trapData as $col => $val)
583 583
         {
584
-            if ($firstcol==0)
584
+            if ($firstcol == 0)
585 585
             {
586
-                $insert_col .=',';
587
-                $insert_val .=',';
586
+                $insert_col.=',';
587
+                $insert_val.=',';
588 588
             }
589
-            $insert_col .= $col ;
590
-            $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
589
+            $insert_col.=$col;
590
+            $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
591 591
             $firstcol=0;
592 592
         }
593 593
         
594
-        $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')';
594
+        $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')';
595 595
         switch ($this->trapsDB->trapDBType)
596 596
         {
597 597
             case 'pgsql':
598
-                $sql .= ' RETURNING id;';
599
-                $this->logging->log('sql : '.$sql,INFO );
598
+                $sql.=' RETURNING id;';
599
+                $this->logging->log('sql : '.$sql, INFO);
600 600
                 if (($ret_code=$db_conn->query($sql)) === false) {
601
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
601
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
602 602
                 }
603
-                $this->logging->log('SQL insertion OK',INFO );
603
+                $this->logging->log('SQL insertion OK', INFO);
604 604
                 // Get last id to insert oid/values in secondary table
605 605
                 if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) {
606 606
                     
607
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
607
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
608 608
                 }
609
-                if (! isset($inserted_id_ret['id'])) {
610
-                    $this->logging->log('Error getting id',ERROR,'');
609
+                if (!isset($inserted_id_ret['id'])) {
610
+                    $this->logging->log('Error getting id', ERROR, '');
611 611
                 }
612 612
                 $this->trapId=$inserted_id_ret['id'];
613 613
                 break;
614 614
             case 'mysql':
615
-                $sql .= ';';
616
-                $this->logging->log('sql : '.$sql,INFO );
615
+                $sql.=';';
616
+                $this->logging->log('sql : '.$sql, INFO);
617 617
                 if ($db_conn->query($sql) === false) {
618
-                    $this->logging->log('Error SQL insert : '.$sql,ERROR,'');
618
+                    $this->logging->log('Error SQL insert : '.$sql, ERROR, '');
619 619
                 }
620
-                $this->logging->log('SQL insertion OK',INFO );
620
+                $this->logging->log('SQL insertion OK', INFO);
621 621
                 // Get last id to insert oid/values in secondary table
622 622
                 $sql='SELECT LAST_INSERT_ID();';
623 623
                 if (($ret_code=$db_conn->query($sql)) === false) {
624
-                    $this->logging->log('Erreur recuperation id',ERROR,'');
624
+                    $this->logging->log('Erreur recuperation id', ERROR, '');
625 625
                 }
626 626
                 
627 627
                 $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");
628
+                if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue");
629 629
                 $this->trapId=$inserted_id;
630 630
                 break;
631 631
             default:
632
-                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,'');
632
+                $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, '');
633 633
         }
634
-        $this->logging->log('id found: '.$this->trapId,INFO );
634
+        $this->logging->log('id found: '.$this->trapId, INFO);
635 635
         
636 636
         // Fill trap extended data table
637 637
         foreach ($this->trapDataExt as $value) {
638 638
             // TODO : detect if trap value is encoded and decode it to UTF-8 for database
639 639
             $firstcol=1;
640
-            $value->trap_id = $this->trapId;
640
+            $value->trap_id=$this->trapId;
641 641
             $insert_col='';
642 642
             $insert_val='';
643 643
             foreach ($value as $col => $val)
644 644
             {
645
-                if ($firstcol==0)
645
+                if ($firstcol == 0)
646 646
                 {
647
-                    $insert_col .=',';
648
-                    $insert_val .=',';
647
+                    $insert_col.=',';
648
+                    $insert_val.=',';
649 649
                 }
650
-                $insert_col .= $col;
651
-                $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val);
650
+                $insert_col.=$col;
651
+                $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val);
652 652
                 $firstcol=0;
653 653
             }
654 654
             
655
-            $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');';
655
+            $sql='INSERT INTO '.$this->dbPrefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');';
656 656
             
657 657
             if ($db_conn->query($sql) === false) {
658
-                $this->logging->log('Erreur insertion data : ' . $sql,WARN,'');
658
+                $this->logging->log('Erreur insertion data : '.$sql, WARN, '');
659 659
             }
660 660
         }
661 661
     }
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
      *	@param $oid string oid in numeric
666 666
      *	@return mixed|boolean : PDO object or false
667 667
      */
668
-    protected function getRules($ip,$oid)
668
+    protected function getRules($ip, $oid)
669 669
     {
670 670
         $db_conn=$this->trapsDB->db_connect_trap();
671 671
         // fetch rules based on IP in rule and OID
672 672
         $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' ';
673
-        $this->logging->log('SQL query : '.$sql,DEBUG );
673
+        $this->logging->log('SQL query : '.$sql, DEBUG);
674 674
         if (($ret_code=$db_conn->query($sql)) === false) {
675
-            $this->logging->log('No result in query : ' . $sql,WARN,'');
675
+            $this->logging->log('No result in query : '.$sql, WARN, '');
676 676
             return false;
677 677
         }
678 678
         $rules_all=$ret_code->fetchAll();
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
         $rule_ret_key=0;
682 682
         foreach ($rules_all as $key => $rule)
683 683
         {
684
-            if ($rule['ip4']==$ip || $rule['ip6']==$ip)
684
+            if ($rule['ip4'] == $ip || $rule['ip6'] == $ip)
685 685
             {
686 686
                 $rules_ret[$rule_ret_key]=$rules_all[$key];
687 687
                 //TODO : get host name by API (and check if correct in rule).
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
                 continue;
690 690
             }
691 691
             // TODO : get hosts IP by API
692
-            if (isset($rule['host_group_name']) && $rule['host_group_name']!=null)
692
+            if (isset($rule['host_group_name']) && $rule['host_group_name'] != null)
693 693
             { // get ips of group members by oid
694 694
                 $db_conn2=$this->trapsDB->db_connect_ido();
695 695
                 $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name
@@ -700,15 +700,15 @@  discard block
 block discarded – undo
700 700
 						LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id
701 701
 						WHERE o.name1='".$rule['host_group_name']."';";
702 702
                 if (($ret_code2=$db_conn2->query($sql)) === false) {
703
-                    $this->logging->log('No result in query : ' . $sql,WARN,'');
703
+                    $this->logging->log('No result in query : '.$sql, WARN, '');
704 704
                     continue;
705 705
                 }
706 706
                 $grouphosts=$ret_code2->fetchAll();
707 707
                 //echo "rule grp :\n";print_r($grouphosts);echo "\n";
708
-                foreach ( $grouphosts as $host)
708
+                foreach ($grouphosts as $host)
709 709
                 {
710 710
                     //echo $host['ip4']."\n";
711
-                    if ($host['ip4']==$ip || $host['ip6']==$ip)
711
+                    if ($host['ip4'] == $ip || $host['ip6'] == $ip)
712 712
                     {
713 713
                         //echo "Rule added \n";
714 714
                         $rules_ret[$rule_ret_key]=$rules_all[$key];
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
         $db_conn=$this->trapsDB->db_connect_trap();
732 732
         $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');";
733 733
         if ($db_conn->query($sql) === false) {
734
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
734
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
735 735
         }
736 736
     }
737 737
     
@@ -743,23 +743,23 @@  discard block
 block discarded – undo
743 743
      * @param string $display
744 744
      * @returnn bool true is service check was sent without error
745 745
      */
746
-    public function serviceCheckResult($host,$service,$state,$display)
746
+    public function serviceCheckResult($host, $service, $state, $display)
747 747
     {
748 748
         if ($this->apiUse === false)
749 749
         {
750
-            $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' .
751
-                $host.';' .$service .';' . $state . ';'.$display;
752
-                $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO );
750
+            $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'.
751
+                $host.';'.$service.';'.$state.';'.$display;
752
+                $this->logging->log($send." : to : ".$this->icinga2cmd, INFO);
753 753
                 
754 754
                 // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default....
755
-                exec('echo "'.$send.'" > ' .$this->icinga2cmd);
755
+                exec('echo "'.$send.'" > '.$this->icinga2cmd);
756 756
                 return true;
757 757
         }
758 758
         else
759 759
         {
760 760
             // Get perfdata if found
761 761
             $matches=array();
762
-            if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1)
762
+            if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1)
763 763
             {
764 764
                 $display=$matches[1];
765 765
                 $perfdata=$matches[2];
@@ -769,17 +769,17 @@  discard block
 block discarded – undo
769 769
                 $perfdata='';
770 770
             }
771 771
             
772
-            $api = $this->getAPI();
772
+            $api=$this->getAPI();
773 773
             $api->setCredentials($this->apiUsername, $this->apiPassword);
774
-            list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata);
774
+            list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata);
775 775
             if ($retcode == false)
776 776
             {
777
-                $this->logging->log( "Error sending result : " .$retmessage,WARN,'');
777
+                $this->logging->log("Error sending result : ".$retmessage, WARN, '');
778 778
                 return false;
779 779
             }
780 780
             else
781 781
             {
782
-                $this->logging->log( "Sent result : " .$retmessage,INFO );
782
+                $this->logging->log("Sent result : ".$retmessage, INFO);
783 783
                 return true;
784 784
             }
785 785
         }
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
     
788 788
     public function getHostByIP($ip)
789 789
     {
790
-        $api = $this->getAPI();
790
+        $api=$this->getAPI();
791 791
         $api->setCredentials($this->apiUsername, $this->apiPassword);
792 792
         return $api->getHostByIP($ip);
793 793
     }
@@ -800,32 +800,32 @@  discard block
 block discarded – undo
800 800
     protected function applyDisplay($display)
801 801
     {
802 802
         $matches=array();
803
-        while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1)
803
+        while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1)
804 804
         {
805 805
             $oid=$matches[1];
806 806
             $found=0;
807
-            foreach($this->trapDataExt as $val)
807
+            foreach ($this->trapDataExt as $val)
808 808
             {
809 809
                 if ($oid == $val->oid)
810 810
                 {
811
-                    $val->value=preg_replace('/"/','',$val->value);
811
+                    $val->value=preg_replace('/"/', '', $val->value);
812 812
                     $rep=0;
813
-                    $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep);
814
-                    if ($rep==0)
813
+                    $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep);
814
+                    if ($rep == 0)
815 815
                     {
816
-                        $this->logging->log("Error in display",WARN,'');
816
+                        $this->logging->log("Error in display", WARN, '');
817 817
                         return $display;
818 818
                     }
819 819
                     $found=1;
820 820
                     break;
821 821
                 }
822 822
             }
823
-            if ($found==0)
823
+            if ($found == 0)
824 824
             {
825
-                $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep);
826
-                if ($rep==0)
825
+                $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep);
826
+                if ($rep == 0)
827 827
                 {
828
-                    $this->logging->log("Error in display",WARN,'');
828
+                    $this->logging->log("Error in display", WARN, '');
829 829
                     return $display;
830 830
                 }
831 831
             }
@@ -837,11 +837,11 @@  discard block
 block discarded – undo
837 837
      */
838 838
     public function applyRules()
839 839
     {
840
-        $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']);
840
+        $rules=$this->getRules($this->trapData['source_ip'], $this->trapData['trap_oid']);
841 841
         
842
-        if ($rules===false || count($rules)==0)
842
+        if ($rules === false || count($rules) == 0)
843 843
         {
844
-            $this->logging->log('No rules found for this trap',INFO );
844
+            $this->logging->log('No rules found for this trap', INFO);
845 845
             $this->trapData['status']='unknown';
846 846
             $this->trapToDb=true;
847 847
             return;
@@ -856,59 +856,59 @@  discard block
 block discarded – undo
856 856
             $service_name=$rule['service_name'];
857 857
             
858 858
             $display=$this->applyDisplay($rule['display']);
859
-            $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', ';
859
+            $this->trapAction=($this->trapAction == null) ? '' : $this->trapAction.', ';
860 860
             try
861 861
             {
862
-                $this->logging->log('Rule to eval : '.$rule['rule'],INFO );
863
-                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ;
862
+                $this->logging->log('Rule to eval : '.$rule['rule'], INFO);
863
+                $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt);
864 864
                 //->eval_rule($rule['rule']);
865 865
                 
866 866
                 if ($evalr == true)
867 867
                 {
868 868
                     //$this->logging->log('rules OOK: '.print_r($rule),INFO );
869 869
                     $action=$rule['action_match'];
870
-                    $this->logging->log('action OK : '.$action,INFO );
870
+                    $this->logging->log('action OK : '.$action, INFO);
871 871
                     if ($action >= 0)
872 872
                     {
873
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false)
873
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
874 874
                         {
875 875
                             $this->trapAction.='Error sending status : check cmd/API';
876 876
                         }
877 877
                         else
878 878
                         {
879
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
879
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
880 880
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
881 881
                         }
882 882
                     }
883 883
                     else
884 884
                     {
885
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
885
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
886 886
                     }
887
-                    $this->trapToDb=($action==-2)?false:true;
887
+                    $this->trapToDb=($action == -2) ?false:true;
888 888
                 }
889 889
                 else
890 890
                 {
891 891
                     //$this->logging->log('rules KOO : '.print_r($rule),INFO );
892 892
                     
893 893
                     $action=$rule['action_nomatch'];
894
-                    $this->logging->log('action NOK : '.$action,INFO );
894
+                    $this->logging->log('action NOK : '.$action, INFO);
895 895
                     if ($action >= 0)
896 896
                     {
897
-                        if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false)
897
+                        if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false)
898 898
                         {
899 899
                             $this->trapAction.='Error sending status : check cmd/API';
900 900
                         }
901 901
                         else
902 902
                         {
903
-                            $this->add_rule_match($rule['id'],$rule['num_match']+1);
903
+                            $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
904 904
                             $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name;
905 905
                         }
906 906
                     }
907 907
                     else
908 908
                     {
909
-                        $this->add_rule_match($rule['id'],$rule['num_match']+1);
909
+                        $this->add_rule_match($rule['id'], $rule['num_match'] + 1);
910 910
                     }
911
-                    $this->trapToDb=($action==-2)?false:true;
911
+                    $this->trapToDb=($action == -2) ?false:true;
912 912
                 }
913 913
                 // Put name in source_name
914 914
                 if (!isset($this->trapData['source_name']))
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
                 }
918 918
                 else
919 919
                 {
920
-                    if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name']))
920
+                    if (!preg_match('/'.$rule['host_name'].'/', $this->trapData['source_name']))
921 921
                     { // only add if not present
922 922
                         $this->trapData['source_name'].=','.$rule['host_name'];
923 923
                     }
@@ -925,13 +925,13 @@  discard block
 block discarded – undo
925 925
             }
926 926
             catch (Exception $e)
927 927
             {
928
-                $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,'');
928
+                $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, '');
929 929
                 $this->trapAction.=' ERR : '.$e->getMessage();
930 930
                 $this->trapData['status']='error';
931 931
             }
932 932
             
933 933
         }
934
-        if ($this->trapData['status']=='error')
934
+        if ($this->trapData['status'] == 'error')
935 935
         {
936 936
             $this->trapToDb=true; // Always put errors in DB for the use can see
937 937
         }
@@ -947,13 +947,13 @@  discard block
 block discarded – undo
947 947
     public function add_rule_final($time)
948 948
     {
949 949
         $db_conn=$this->trapsDB->db_connect_trap();
950
-        if ($this->trapAction==null)
950
+        if ($this->trapAction == null)
951 951
         {
952 952
             $this->trapAction='No action';
953 953
         }
954 954
         $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."'  WHERE (id = '".$this->trapId."');";
955 955
         if ($db_conn->query($sql) === false) {
956
-            $this->logging->log('Error in update query : ' . $sql,WARN,'');
956
+            $this->logging->log('Error in update query : '.$sql, WARN, '');
957 957
         }
958 958
     }
959 959
     
@@ -976,7 +976,7 @@  discard block
 block discarded – undo
976 976
     WHERE s.current_state != 0;";
977 977
         $db_conn=$this->trapsDB->db_connect_ido();
978 978
         if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception.
979
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
979
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
980 980
             return 0;
981 981
         }
982 982
         $services=$services_db->fetchAll();
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
         $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;";
986 986
         $db_conn2=$this->trapsDB->db_connect_trap();
987 987
         if (($rules_db=$db_conn2->query($sql_query)) === false) {
988
-            $this->logging->log('No result in query : ' . $sql_query,ERROR,'');
988
+            $this->logging->log('No result in query : '.$sql_query, ERROR, '');
989 989
             return 0;
990 990
         }
991 991
         $rules=$rules_db->fetchAll();
@@ -1001,13 +1001,13 @@  discard block
 block discarded – undo
1001 1001
                     $service['host_name'] == $rule['host_name'] &&
1002 1002
                     ($service['last_check'] + $rule['revert_ok']) < $now)
1003 1003
                 {
1004
-                    $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds');
1004
+                    $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds');
1005 1005
                     $numreset++;
1006 1006
                 }
1007 1007
             }
1008 1008
         }
1009 1009
         echo "\n";
1010
-        echo $numreset . " service(s) reset to OK\n";
1010
+        echo $numreset." service(s) reset to OK\n";
1011 1011
         return 0;
1012 1012
         
1013 1013
     }
Please login to merge, or discard this patch.