@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | |
8 | 8 | use Icinga\Module\Trapdirector\Icinga2API; |
9 | 9 | |
10 | -define("ERROR", 1);define("WARN", 2);define("INFO", 3);define("DEBUG", 4); |
|
10 | +define("ERROR", 1); define("WARN", 2); define("INFO", 3); define("DEBUG", 4); |
|
11 | 11 | |
12 | 12 | class Trap |
13 | 13 | { |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | |
32 | 32 | //**** Options from config database |
33 | 33 | // Logs |
34 | - protected $debug_level=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
34 | + protected $debug_level=2; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
35 | 35 | protected $alert_output='display'; // alert type : file, syslog, display |
36 | 36 | protected $debug_file="/tmp/trapdebug.txt"; |
37 | - protected $debug_text=array("","Error","Warning","Info","Debug"); |
|
37 | + protected $debug_text=array("", "Error", "Warning", "Info", "Debug"); |
|
38 | 38 | |
39 | 39 | //**** End options from database |
40 | 40 | |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | * @param string $message warning message if not found |
87 | 87 | * @return boolean true if found, or false |
88 | 88 | */ |
89 | - protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null) |
|
89 | + protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null) |
|
90 | 90 | { |
91 | 91 | if (!isset($option_array[$option_category][$option_name])) |
92 | 92 | { |
93 | 93 | if ($message === null) |
94 | 94 | { |
95 | - $message='No ' . $option_name . ' in config file: '. $this->trap_module_config; |
|
95 | + $message='No '.$option_name.' in config file: '.$this->trap_module_config; |
|
96 | 96 | } |
97 | - $this->trapLog($message,$log_level,'syslog'); |
|
97 | + $this->trapLog($message, $log_level, 'syslog'); |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | else |
@@ -108,40 +108,40 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function getOptions() |
110 | 110 | { |
111 | - $trap_config=parse_ini_file($this->trap_module_config,true); |
|
111 | + $trap_config=parse_ini_file($this->trap_module_config, true); |
|
112 | 112 | if ($trap_config == false) |
113 | 113 | { |
114 | - $this->trapLog("Error reading ini file : ".$this->trap_module_config,ERROR,'syslog'); |
|
114 | + $this->trapLog("Error reading ini file : ".$this->trap_module_config, ERROR, 'syslog'); |
|
115 | 115 | } |
116 | 116 | // Snmptranslate binary path |
117 | - $this->getOptionIfSet($trap_config,'config','snmptranslate', $this->snmptranslate); |
|
117 | + $this->getOptionIfSet($trap_config, 'config', 'snmptranslate', $this->snmptranslate); |
|
118 | 118 | |
119 | 119 | // mibs path |
120 | - $this->getOptionIfSet($trap_config,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
120 | + $this->getOptionIfSet($trap_config, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs); |
|
121 | 121 | |
122 | 122 | // icinga2cmd path |
123 | - $this->getOptionIfSet($trap_config,'config','icingacmd', $this->icinga2cmd); |
|
123 | + $this->getOptionIfSet($trap_config, 'config', 'icingacmd', $this->icinga2cmd); |
|
124 | 124 | |
125 | 125 | // table prefix |
126 | - $this->getOptionIfSet($trap_config,'config','database_prefix', $this->db_prefix); |
|
126 | + $this->getOptionIfSet($trap_config, 'config', 'database_prefix', $this->db_prefix); |
|
127 | 127 | |
128 | 128 | // API options |
129 | - if ($this->getOptionIfSet($trap_config,'config','icingaAPI_host', $this->api_hostname)) |
|
129 | + if ($this->getOptionIfSet($trap_config, 'config', 'icingaAPI_host', $this->api_hostname)) |
|
130 | 130 | { |
131 | 131 | $this->api_use=true; |
132 | - $this->getOptionIfSet($trap_config,'config','icingaAPI_port', $this->api_port); |
|
133 | - $this->getOptionIfSet($trap_config,'config','icingaAPI_user', $this->api_username); |
|
134 | - $this->getOptionIfSet($trap_config,'config','icingaAPI_password', $this->api_password); |
|
132 | + $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_port', $this->api_port); |
|
133 | + $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_user', $this->api_username); |
|
134 | + $this->getOptionIfSet($trap_config, 'config', 'icingaAPI_password', $this->api_password); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /***** Database options : ***/ |
138 | - $this->getDBConfigIfSet('log_level',$this->debug_level); |
|
139 | - $this->getDBConfigIfSet('log_destination',$this->alert_output); |
|
140 | - $this->getDBConfigIfSet('log_file',$this->debug_file); |
|
138 | + $this->getDBConfigIfSet('log_level', $this->debug_level); |
|
139 | + $this->getDBConfigIfSet('log_destination', $this->alert_output); |
|
140 | + $this->getDBConfigIfSet('log_file', $this->debug_file); |
|
141 | 141 | $this->getAPI(); |
142 | 142 | } |
143 | 143 | |
144 | - protected function getDBConfigIfSet($element,&$variable) |
|
144 | + protected function getDBConfigIfSet($element, &$variable) |
|
145 | 145 | { |
146 | 146 | $value=$this->getDBConfig($element); |
147 | 147 | if ($value != 'null') $variable=$value; |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | $db_conn=$this->db_connect_trap(); |
157 | 157 | $sql='SELECT value from '.$this->db_prefix.'db_config WHERE ( name=\''.$element.'\' )'; |
158 | 158 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
159 | - $this->trapLog('No result in query : ' . $sql,WARN,''); |
|
159 | + $this->trapLog('No result in query : '.$sql, WARN, ''); |
|
160 | 160 | return null; |
161 | 161 | } |
162 | 162 | $value=$ret_code->fetch(); |
@@ -173,29 +173,29 @@ discard block |
||
173 | 173 | * @param int $destination file/syslog/display |
174 | 174 | * @return void |
175 | 175 | **/ |
176 | - public function trapLog( $message, $level, $destination ='') |
|
176 | + public function trapLog($message, $level, $destination='') |
|
177 | 177 | { |
178 | 178 | if ($this->debug_level >= $level) |
179 | 179 | { |
180 | - $message = '['. date("Y/m/d H:i:s") . '] ' . |
|
181 | - '['. basename(__FILE__) . '] ['.$this->debug_text[$level].']: ' .$message . "\n"; |
|
180 | + $message='['.date("Y/m/d H:i:s").'] '. |
|
181 | + '['.basename(__FILE__).'] ['.$this->debug_text[$level].']: '.$message."\n"; |
|
182 | 182 | |
183 | - if ( $destination != '' ) $output=$destination; |
|
183 | + if ($destination != '') $output=$destination; |
|
184 | 184 | else $output=$this->alert_output; |
185 | 185 | switch ($output) |
186 | 186 | { |
187 | 187 | case 'file': |
188 | - file_put_contents ($this->debug_file, $message , FILE_APPEND); |
|
188 | + file_put_contents($this->debug_file, $message, FILE_APPEND); |
|
189 | 189 | break; |
190 | 190 | case 'syslog': |
191 | - switch($level) |
|
191 | + switch ($level) |
|
192 | 192 | { |
193 | - case 1 : $prio = LOG_ERR;break; |
|
194 | - case 2 : $prio = LOG_WARNING;break; |
|
195 | - case 3 : $prio = LOG_INFO;break; |
|
196 | - case 4 : $prio = LOG_DEBUG;break; |
|
193 | + case 1 : $prio=LOG_ERR; break; |
|
194 | + case 2 : $prio=LOG_WARNING; break; |
|
195 | + case 3 : $prio=LOG_INFO; break; |
|
196 | + case 4 : $prio=LOG_DEBUG; break; |
|
197 | 197 | } |
198 | - syslog($prio,$message); |
|
198 | + syslog($prio, $message); |
|
199 | 199 | break; |
200 | 200 | case 'display': |
201 | 201 | echo $message; |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | - public function setLogging($debug_lvl,$output_type,$output_option=null) |
|
213 | + public function setLogging($debug_lvl, $output_type, $output_option=null) |
|
214 | 214 | { |
215 | 215 | $this->debug_level=$debug_lvl; |
216 | 216 | switch ($output_type) |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $this->alert_output='display'; |
228 | 228 | break; |
229 | 229 | default : // syslog should always work.... |
230 | - $this->trapLog("Error in log output : ".$output_type,ERROR,'syslog'); |
|
230 | + $this->trapLog("Error in log output : ".$output_type, ERROR, 'syslog'); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | { |
236 | 236 | if ($this->icinga2api == null) |
237 | 237 | { |
238 | - $this->icinga2api = new Icinga2API($this->api_hostname,$this->api_port); |
|
238 | + $this->icinga2api=new Icinga2API($this->api_hostname, $this->api_port); |
|
239 | 239 | } |
240 | 240 | return $this->icinga2api; |
241 | 241 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | // select 1 failed, try to reconnect. |
255 | 255 | $this->trapDB=null; |
256 | 256 | $this->trapDB=$this->db_connect('traps'); |
257 | - $this->trapLog('Database connection lost, reconnecting',WARN,''); |
|
257 | + $this->trapLog('Database connection lost, reconnecting', WARN, ''); |
|
258 | 258 | return $this->trapDB; |
259 | 259 | } |
260 | 260 | |
@@ -281,14 +281,14 @@ discard block |
||
281 | 281 | protected function db_connect($database) { |
282 | 282 | $confarray=$this->get_database($database); |
283 | 283 | // $dsn = 'mysql:dbname=traps;host=127.0.0.1'; |
284 | - $dsn= $confarray[0].':dbname='.$confarray[2].';host='.$confarray[1]; |
|
285 | - $user = $confarray[3]; |
|
286 | - $password = $confarray[4]; |
|
287 | - $this->trapLog('DSN : '.$dsn,3); |
|
284 | + $dsn=$confarray[0].':dbname='.$confarray[2].';host='.$confarray[1]; |
|
285 | + $user=$confarray[3]; |
|
286 | + $password=$confarray[4]; |
|
287 | + $this->trapLog('DSN : '.$dsn, 3); |
|
288 | 288 | try { |
289 | - $dbh = new PDO($dsn, $user, $password); |
|
289 | + $dbh=new PDO($dsn, $user, $password); |
|
290 | 290 | } catch (PDOException $e) { |
291 | - $this->trapLog('Connection failed : ' . $e->getMessage(),ERROR,''); |
|
291 | + $this->trapLog('Connection failed : '.$e->getMessage(), ERROR, ''); |
|
292 | 292 | } |
293 | 293 | return $dbh; |
294 | 294 | } |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | **/ |
300 | 300 | protected function get_database($database) { |
301 | 301 | |
302 | - $trap_config=parse_ini_file($this->trap_module_config,true); |
|
302 | + $trap_config=parse_ini_file($this->trap_module_config, true); |
|
303 | 303 | if ($trap_config == false) |
304 | 304 | { |
305 | - $this->trapLog("Error reading ini file : ".$this->trap_module_config,ERROR,''); |
|
305 | + $this->trapLog("Error reading ini file : ".$this->trap_module_config, ERROR, ''); |
|
306 | 306 | } |
307 | 307 | if ($database == 'traps') |
308 | 308 | { |
309 | 309 | if (!isset($trap_config['config']['database'])) |
310 | 310 | { |
311 | - $this->trapLog("No Config/database in config file: ".$this->trap_module_config,ERROR,''); |
|
311 | + $this->trapLog("No Config/database in config file: ".$this->trap_module_config, ERROR, ''); |
|
312 | 312 | } |
313 | 313 | $db_name=$trap_config['config']['database']; |
314 | 314 | } |
@@ -316,34 +316,34 @@ discard block |
||
316 | 316 | { |
317 | 317 | if (!isset($trap_config['config']['IDOdatabase'])) |
318 | 318 | { |
319 | - $this->trapLog("No Config/IDOdatabase in config file: ".$this->trap_module_config,ERROR,''); |
|
319 | + $this->trapLog("No Config/IDOdatabase in config file: ".$this->trap_module_config, ERROR, ''); |
|
320 | 320 | } |
321 | 321 | $db_name=$trap_config['config']['IDOdatabase']; |
322 | 322 | } |
323 | 323 | else |
324 | 324 | { |
325 | - $this->trapLog("Unknown database type : ".$database,ERROR,''); |
|
325 | + $this->trapLog("Unknown database type : ".$database, ERROR, ''); |
|
326 | 326 | } |
327 | - $this->trapLog("Found database in config file: ".$db_name,3,''); |
|
328 | - $db_config=parse_ini_file($this->icingaweb2_ressources,true); |
|
327 | + $this->trapLog("Found database in config file: ".$db_name, 3, ''); |
|
328 | + $db_config=parse_ini_file($this->icingaweb2_ressources, true); |
|
329 | 329 | if ($db_config == false) |
330 | 330 | { |
331 | - $this->trapLog("Error reading ini file : ".$this->icingaweb2_ressources,ERROR,''); |
|
331 | + $this->trapLog("Error reading ini file : ".$this->icingaweb2_ressources, ERROR, ''); |
|
332 | 332 | } |
333 | 333 | if (!isset($db_config[$db_name])) |
334 | 334 | { |
335 | - $this->trapLog("No Config/database in config file: ".$this->icingaweb2_ressources,ERROR,''); |
|
335 | + $this->trapLog("No Config/database in config file: ".$this->icingaweb2_ressources, ERROR, ''); |
|
336 | 336 | } |
337 | 337 | $db_type=$db_config[$db_name]['db']; |
338 | 338 | $db_host=$db_config[$db_name]['host']; |
339 | 339 | $db_sql_name=$db_config[$db_name]['dbname']; |
340 | 340 | $db_user=$db_config[$db_name]['username']; |
341 | 341 | $db_pass=$db_config[$db_name]['password']; |
342 | - if ($database == 'traps') $this->trapDBType = $db_type; |
|
343 | - if ($database == 'ido') $this->idoDBType = $db_type; |
|
342 | + if ($database == 'traps') $this->trapDBType=$db_type; |
|
343 | + if ($database == 'ido') $this->idoDBType=$db_type; |
|
344 | 344 | |
345 | - $this->trapLog( "DB selected : $db_type $db_host $db_sql_name $db_user",3,''); |
|
346 | - return array($db_type,$db_host,$db_sql_name,$db_user,$db_pass); |
|
345 | + $this->trapLog("DB selected : $db_type $db_host $db_sql_name $db_user", 3, ''); |
|
346 | + return array($db_type, $db_host, $db_sql_name, $db_user, $db_pass); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** read data from stream |
@@ -355,10 +355,10 @@ discard block |
||
355 | 355 | //Read data from snmptrapd from stdin |
356 | 356 | $input_stream=fopen($stream, 'r'); |
357 | 357 | |
358 | - if ($input_stream==FALSE) |
|
358 | + if ($input_stream == FALSE) |
|
359 | 359 | { |
360 | 360 | $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)"); |
361 | - $this->trapLog("Error reading stdin !",ERROR,''); |
|
361 | + $this->trapLog("Error reading stdin !", ERROR, ''); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | // line 1 : host |
@@ -366,21 +366,21 @@ discard block |
||
366 | 366 | if ($this->receivingHost === false) |
367 | 367 | { |
368 | 368 | $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)"); |
369 | - $this->trapLog("Error reading Host !",ERROR,''); |
|
369 | + $this->trapLog("Error reading Host !", ERROR, ''); |
|
370 | 370 | } |
371 | 371 | // line 2 IP:port=>IP:port |
372 | 372 | $IP=chop(fgets($input_stream)); |
373 | 373 | if ($IP === false) |
374 | 374 | { |
375 | 375 | $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)"); |
376 | - $this->trapLog("Error reading IP !",ERROR,''); |
|
376 | + $this->trapLog("Error reading IP !", ERROR, ''); |
|
377 | 377 | } |
378 | 378 | $matches=array(); |
379 | - $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches); |
|
380 | - if ($ret_code===0 || $ret_code==false) |
|
379 | + $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches); |
|
380 | + if ($ret_code === 0 || $ret_code == false) |
|
381 | 381 | { |
382 | 382 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
383 | - $this->trapLog('Error parsing IP : '.$IP,ERROR,''); |
|
383 | + $this->trapLog('Error parsing IP : '.$IP, ERROR, ''); |
|
384 | 384 | } |
385 | 385 | else |
386 | 386 | { |
@@ -390,33 +390,33 @@ discard block |
||
390 | 390 | $this->trap_data['destination_port']=$matches[4]; |
391 | 391 | } |
392 | 392 | |
393 | - while (($vars=chop(fgets($input_stream))) !=false) |
|
393 | + while (($vars=chop(fgets($input_stream))) != false) |
|
394 | 394 | { |
395 | - $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches); |
|
396 | - if ($ret_code===0 || $ret_code===false) |
|
395 | + $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches); |
|
396 | + if ($ret_code === 0 || $ret_code === false) |
|
397 | 397 | { |
398 | - $this->trapLog('No match on trap data : '.$vars,WARN,''); |
|
398 | + $this->trapLog('No match on trap data : '.$vars, WARN, ''); |
|
399 | 399 | } |
400 | 400 | else |
401 | 401 | { |
402 | - 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')) |
|
402 | + 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')) |
|
403 | 403 | { |
404 | 404 | $this->trap_data['trap_oid']=$matches[2]; |
405 | 405 | } |
406 | 406 | else |
407 | 407 | { |
408 | - $object= new stdClass; |
|
409 | - $object->oid =$matches[1]; |
|
410 | - $object->value = $matches[2]; |
|
411 | - array_push($this->trap_data_ext,$object); |
|
408 | + $object=new stdClass; |
|
409 | + $object->oid=$matches[1]; |
|
410 | + $object->value=$matches[2]; |
|
411 | + array_push($this->trap_data_ext, $object); |
|
412 | 412 | } |
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - if ($this->trap_data['trap_oid']=='unknown') |
|
416 | + if ($this->trap_data['trap_oid'] == 'unknown') |
|
417 | 417 | { |
418 | - $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trap_data['source_ip']); |
|
419 | - $this->trapLog('no trap oid found',ERROR,''); |
|
418 | + $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trap_data['source_ip']); |
|
419 | + $this->trapLog('no trap oid found', ERROR, ''); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | // Translate oids. |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | |
441 | - $this->trap_data['status']= 'waiting'; |
|
441 | + $this->trap_data['status']='waiting'; |
|
442 | 442 | |
443 | 443 | return $this->trap_data; |
444 | 444 | } |
@@ -453,40 +453,40 @@ discard block |
||
453 | 453 | $db_conn=$this->db_connect_trap(); |
454 | 454 | |
455 | 455 | $sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid.'\';'; |
456 | - $this->trapLog('SQL query : '.$sql,4,''); |
|
456 | + $this->trapLog('SQL query : '.$sql, 4, ''); |
|
457 | 457 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
458 | - $this->trapLog('No result in query : ' . $sql,ERROR,''); |
|
458 | + $this->trapLog('No result in query : '.$sql, ERROR, ''); |
|
459 | 459 | } |
460 | 460 | $name=$ret_code->fetch(); |
461 | 461 | if ($name['name'] != null) |
462 | 462 | { |
463 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
463 | + return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | // Also check if it is an instance of OID |
467 | - $oid_instance=preg_replace('/\.[0-9]+$/','',$oid); |
|
467 | + $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid); |
|
468 | 468 | |
469 | 469 | $sql='SELECT mib,name from '.$this->db_prefix.'mib_cache WHERE oid=\''.$oid_instance.'\';'; |
470 | - $this->trapLog('SQL query : '.$sql,4,''); |
|
470 | + $this->trapLog('SQL query : '.$sql, 4, ''); |
|
471 | 471 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
472 | - $this->trapLog('No result in query : ' . $sql,ERROR,''); |
|
472 | + $this->trapLog('No result in query : '.$sql, ERROR, ''); |
|
473 | 473 | } |
474 | 474 | $name=$ret_code->fetch(); |
475 | 475 | if ($name['name'] != null) |
476 | 476 | { |
477 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
477 | + return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | // Try to get oid name from snmptranslate |
481 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
481 | + $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
482 | 482 | ' '.$oid); |
483 | 483 | $matches=array(); |
484 | - $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
|
485 | - if ($ret_code===0 || $ret_code===FALSE) { |
|
484 | + $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches); |
|
485 | + if ($ret_code === 0 || $ret_code === FALSE) { |
|
486 | 486 | return NULL; |
487 | 487 | } else { |
488 | - $this->trapLog('Found name with snmptrapd and not in DB for oid='.$oid,INFO,''); |
|
489 | - return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]); |
|
488 | + $this->trapLog('Found name with snmptrapd and not in DB for oid='.$oid, INFO, ''); |
|
489 | + return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]); |
|
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
@@ -496,26 +496,26 @@ discard block |
||
496 | 496 | **/ |
497 | 497 | public function eraseOldTraps($days=0) |
498 | 498 | { |
499 | - if ($days==0) |
|
499 | + if ($days == 0) |
|
500 | 500 | { |
501 | 501 | if (($days=$this->getDBConfig('db_remove_days')) == null) |
502 | 502 | { |
503 | - $this->trapLog('No days specified & no db value : no tap erase' ,WARN,''); |
|
503 | + $this->trapLog('No days specified & no db value : no tap erase', WARN, ''); |
|
504 | 504 | return; |
505 | 505 | } |
506 | 506 | } |
507 | 507 | $db_conn=$this->db_connect_trap(); |
508 | - $daysago = strtotime("-".$days." day"); |
|
509 | - $sql= 'delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';'; |
|
508 | + $daysago=strtotime("-".$days." day"); |
|
509 | + $sql='delete from '.$this->db_prefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';'; |
|
510 | 510 | if ($db_conn->query($sql) == FALSE) { |
511 | - $this->trapLog('Error erasing traps : '.$sql,ERROR,''); |
|
511 | + $this->trapLog('Error erasing traps : '.$sql, ERROR, ''); |
|
512 | 512 | } |
513 | - $this->trapLog('Erased traps older than '.$days.' day(s) : '.$sql,3); |
|
513 | + $this->trapLog('Erased traps older than '.$days.' day(s) : '.$sql, 3); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** Write error to received trap database |
517 | 517 | */ |
518 | - public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null) |
|
518 | + public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null) |
|
519 | 519 | { |
520 | 520 | |
521 | 521 | $db_conn=$this->db_connect_trap(); |
@@ -523,65 +523,65 @@ discard block |
||
523 | 523 | $insert_col=''; |
524 | 524 | $insert_val=''; |
525 | 525 | // add date time |
526 | - $insert_col ='date_received,status'; |
|
527 | - $insert_val = "'" . date("Y-m-d H:i:s")."','error'"; |
|
526 | + $insert_col='date_received,status'; |
|
527 | + $insert_val="'".date("Y-m-d H:i:s")."','error'"; |
|
528 | 528 | |
529 | - if ($sourceIP !=null) |
|
529 | + if ($sourceIP != null) |
|
530 | 530 | { |
531 | - $insert_col .=',source_ip'; |
|
532 | - $insert_val .=",'". $sourceIP ."'"; |
|
531 | + $insert_col.=',source_ip'; |
|
532 | + $insert_val.=",'".$sourceIP."'"; |
|
533 | 533 | } |
534 | - if ($trapoid !=null) |
|
534 | + if ($trapoid != null) |
|
535 | 535 | { |
536 | - $insert_col .=',trap_oid'; |
|
537 | - $insert_val .=",'". $trapoid ."'"; |
|
536 | + $insert_col.=',trap_oid'; |
|
537 | + $insert_val.=",'".$trapoid."'"; |
|
538 | 538 | } |
539 | - $insert_col .=',status_detail'; |
|
540 | - $insert_val .=",'". $message ."'"; |
|
539 | + $insert_col.=',status_detail'; |
|
540 | + $insert_val.=",'".$message."'"; |
|
541 | 541 | |
542 | - $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
542 | + $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')'; |
|
543 | 543 | |
544 | 544 | switch ($this->trapDBType) |
545 | 545 | { |
546 | 546 | case 'pgsql': |
547 | - $sql .= ' RETURNING id;'; |
|
548 | - $this->trapLog('sql : '.$sql,3,''); |
|
547 | + $sql.=' RETURNING id;'; |
|
548 | + $this->trapLog('sql : '.$sql, 3, ''); |
|
549 | 549 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
550 | - $this->trapLog('Error SQL insert : '.$sql,1,''); |
|
550 | + $this->trapLog('Error SQL insert : '.$sql, 1, ''); |
|
551 | 551 | } |
552 | - $this->trapLog('SQL insertion OK',3,''); |
|
552 | + $this->trapLog('SQL insertion OK', 3, ''); |
|
553 | 553 | // Get last id to insert oid/values in secondary table |
554 | 554 | if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) == FALSE) { |
555 | 555 | |
556 | - $this->trapLog('Erreur recuperation id',1,''); |
|
556 | + $this->trapLog('Erreur recuperation id', 1, ''); |
|
557 | 557 | } |
558 | - if (! isset($inserted_id_ret['id'])) { |
|
559 | - $this->trapLog('Error getting id',1,''); |
|
558 | + if (!isset($inserted_id_ret['id'])) { |
|
559 | + $this->trapLog('Error getting id', 1, ''); |
|
560 | 560 | } |
561 | 561 | $this->trap_id=$inserted_id_ret['id']; |
562 | 562 | break; |
563 | 563 | case 'mysql': |
564 | - $sql .= ';'; |
|
565 | - $this->trapLog('sql : '.$sql,3,''); |
|
564 | + $sql.=';'; |
|
565 | + $this->trapLog('sql : '.$sql, 3, ''); |
|
566 | 566 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
567 | - $this->trapLog('Error SQL insert : '.$sql,1,''); |
|
567 | + $this->trapLog('Error SQL insert : '.$sql, 1, ''); |
|
568 | 568 | } |
569 | - $this->trapLog('SQL insertion OK',3,''); |
|
569 | + $this->trapLog('SQL insertion OK', 3, ''); |
|
570 | 570 | // Get last id to insert oid/values in secondary table |
571 | 571 | $sql='SELECT LAST_INSERT_ID();'; |
572 | 572 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
573 | - $this->trapLog('Erreur recuperation id',1,''); |
|
573 | + $this->trapLog('Erreur recuperation id', 1, ''); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
577 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
577 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
578 | 578 | $this->trap_id=$inserted_id; |
579 | 579 | break; |
580 | 580 | default: |
581 | - $this->trapLog('Error SQL type : '.$this->trapDBType,1,''); |
|
581 | + $this->trapLog('Error SQL type : '.$this->trapDBType, 1, ''); |
|
582 | 582 | } |
583 | 583 | |
584 | - $this->trapLog('id found: '. $this->trap_id,3,''); |
|
584 | + $this->trapLog('id found: '.$this->trap_id, 3, ''); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** Write trap data to trap database |
@@ -598,86 +598,86 @@ discard block |
||
598 | 598 | $insert_col=''; |
599 | 599 | $insert_val=''; |
600 | 600 | // add date time |
601 | - $this->trap_data['date_received'] = date("Y-m-d H:i:s"); |
|
601 | + $this->trap_data['date_received']=date("Y-m-d H:i:s"); |
|
602 | 602 | |
603 | 603 | $firstcol=1; |
604 | 604 | foreach ($this->trap_data as $col => $val) |
605 | 605 | { |
606 | - if ($firstcol==0) |
|
606 | + if ($firstcol == 0) |
|
607 | 607 | { |
608 | - $insert_col .=','; |
|
609 | - $insert_val .=','; |
|
608 | + $insert_col.=','; |
|
609 | + $insert_val.=','; |
|
610 | 610 | } |
611 | - $insert_col .= $col ; |
|
612 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
611 | + $insert_col.=$col; |
|
612 | + $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val); |
|
613 | 613 | $firstcol=0; |
614 | 614 | } |
615 | 615 | |
616 | - $sql= 'INSERT INTO '.$this->db_prefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
616 | + $sql='INSERT INTO '.$this->db_prefix.'received ('.$insert_col.') VALUES ('.$insert_val.')'; |
|
617 | 617 | switch ($this->trapDBType) |
618 | 618 | { |
619 | 619 | case 'pgsql': |
620 | - $sql .= ' RETURNING id;'; |
|
621 | - $this->trapLog('sql : '.$sql,3,''); |
|
620 | + $sql.=' RETURNING id;'; |
|
621 | + $this->trapLog('sql : '.$sql, 3, ''); |
|
622 | 622 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
623 | - $this->trapLog('Error SQL insert : '.$sql,ERROR,''); |
|
623 | + $this->trapLog('Error SQL insert : '.$sql, ERROR, ''); |
|
624 | 624 | } |
625 | - $this->trapLog('SQL insertion OK',3,''); |
|
625 | + $this->trapLog('SQL insertion OK', 3, ''); |
|
626 | 626 | // Get last id to insert oid/values in secondary table |
627 | 627 | if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) == FALSE) { |
628 | 628 | |
629 | - $this->trapLog('Erreur recuperation id',ERROR,''); |
|
629 | + $this->trapLog('Erreur recuperation id', ERROR, ''); |
|
630 | 630 | } |
631 | - if (! isset($inserted_id_ret['id'])) { |
|
632 | - $this->trapLog('Error getting id',ERROR,''); |
|
631 | + if (!isset($inserted_id_ret['id'])) { |
|
632 | + $this->trapLog('Error getting id', ERROR, ''); |
|
633 | 633 | } |
634 | 634 | $this->trap_id=$inserted_id_ret['id']; |
635 | 635 | break; |
636 | 636 | case 'mysql': |
637 | - $sql .= ';'; |
|
638 | - $this->trapLog('sql : '.$sql,3,''); |
|
637 | + $sql.=';'; |
|
638 | + $this->trapLog('sql : '.$sql, 3, ''); |
|
639 | 639 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
640 | - $this->trapLog('Error SQL insert : '.$sql,ERROR,''); |
|
640 | + $this->trapLog('Error SQL insert : '.$sql, ERROR, ''); |
|
641 | 641 | } |
642 | - $this->trapLog('SQL insertion OK',3,''); |
|
642 | + $this->trapLog('SQL insertion OK', 3, ''); |
|
643 | 643 | // Get last id to insert oid/values in secondary table |
644 | 644 | $sql='SELECT LAST_INSERT_ID();'; |
645 | 645 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
646 | - $this->trapLog('Erreur recuperation id',ERROR,''); |
|
646 | + $this->trapLog('Erreur recuperation id', ERROR, ''); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
650 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
650 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
651 | 651 | $this->trap_id=$inserted_id; |
652 | 652 | break; |
653 | 653 | default: |
654 | - $this->trapLog('Error SQL type : '.$this->trapDBType,ERROR,''); |
|
654 | + $this->trapLog('Error SQL type : '.$this->trapDBType, ERROR, ''); |
|
655 | 655 | } |
656 | - $this->trapLog('id found: '.$this->trap_id,3,''); |
|
656 | + $this->trapLog('id found: '.$this->trap_id, 3, ''); |
|
657 | 657 | |
658 | 658 | // Fill trap extended data table |
659 | 659 | foreach ($this->trap_data_ext as $value) { |
660 | 660 | // TODO : detect if trap value is encoded and decode it to UTF-8 for database |
661 | 661 | $firstcol=1; |
662 | - $value->trap_id = $this->trap_id; |
|
662 | + $value->trap_id=$this->trap_id; |
|
663 | 663 | $insert_col=''; |
664 | 664 | $insert_val=''; |
665 | 665 | foreach ($value as $col => $val) |
666 | 666 | { |
667 | - if ($firstcol==0) |
|
667 | + if ($firstcol == 0) |
|
668 | 668 | { |
669 | - $insert_col .=','; |
|
670 | - $insert_val .=','; |
|
669 | + $insert_col.=','; |
|
670 | + $insert_val.=','; |
|
671 | 671 | } |
672 | - $insert_col .= $col; |
|
673 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
672 | + $insert_col.=$col; |
|
673 | + $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val); |
|
674 | 674 | $firstcol=0; |
675 | 675 | } |
676 | 676 | |
677 | - $sql= 'INSERT INTO '.$this->db_prefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');'; |
|
677 | + $sql='INSERT INTO '.$this->db_prefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');'; |
|
678 | 678 | |
679 | 679 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
680 | - $this->trapLog('Erreur insertion data : ' . $sql,WARN,''); |
|
680 | + $this->trapLog('Erreur insertion data : '.$sql, WARN, ''); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 | } |
@@ -687,14 +687,14 @@ discard block |
||
687 | 687 | * @param $oid string oid in numeric |
688 | 688 | * @return mixed : PDO object or false |
689 | 689 | */ |
690 | - protected function getRules($ip,$oid) |
|
690 | + protected function getRules($ip, $oid) |
|
691 | 691 | { |
692 | 692 | $db_conn=$this->db_connect_trap(); |
693 | 693 | // fetch rules based on IP in rule and OID |
694 | 694 | $sql='SELECT * from '.$this->db_prefix.'rules WHERE trap_oid=\''.$oid.'\' '; |
695 | - $this->trapLog('SQL query : '.$sql,4,''); |
|
695 | + $this->trapLog('SQL query : '.$sql, 4, ''); |
|
696 | 696 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
697 | - $this->trapLog('No result in query : ' . $sql,WARN,''); |
|
697 | + $this->trapLog('No result in query : '.$sql, WARN, ''); |
|
698 | 698 | return false; |
699 | 699 | } |
700 | 700 | $rules_all=$ret_code->fetchAll(); |
@@ -703,7 +703,7 @@ discard block |
||
703 | 703 | $rule_ret_key=0; |
704 | 704 | foreach ($rules_all as $key => $rule) |
705 | 705 | { |
706 | - if ($rule['ip4']==$ip || $rule['ip6']==$ip) |
|
706 | + if ($rule['ip4'] == $ip || $rule['ip6'] == $ip) |
|
707 | 707 | { |
708 | 708 | $rules_ret[$rule_ret_key]=$rules_all[$key]; |
709 | 709 | //TODO : get host name by API (and check if correct in rule). |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | continue; |
712 | 712 | } |
713 | 713 | // TODO : get hosts IP by API |
714 | - if (isset($rule['host_group_name']) && $rule['host_group_name']!=null) |
|
714 | + if (isset($rule['host_group_name']) && $rule['host_group_name'] != null) |
|
715 | 715 | { // get ips of group members by oid |
716 | 716 | $db_conn2=$this->db_connect_ido(); |
717 | 717 | $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name |
@@ -722,15 +722,15 @@ discard block |
||
722 | 722 | LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id |
723 | 723 | WHERE o.name1='".$rule['host_group_name']."';"; |
724 | 724 | if (($ret_code2=$db_conn2->query($sql)) == FALSE) { |
725 | - $this->trapLog('No result in query : ' . $sql,WARN,''); |
|
725 | + $this->trapLog('No result in query : '.$sql, WARN, ''); |
|
726 | 726 | continue; |
727 | 727 | } |
728 | 728 | $grouphosts=$ret_code2->fetchAll(); |
729 | 729 | //echo "rule grp :\n";print_r($grouphosts);echo "\n"; |
730 | - foreach ( $grouphosts as $host) |
|
730 | + foreach ($grouphosts as $host) |
|
731 | 731 | { |
732 | 732 | //echo $host['ip4']."\n"; |
733 | - if ($host['ip4']==$ip || $host['ip6']==$ip) |
|
733 | + if ($host['ip4'] == $ip || $host['ip6'] == $ip) |
|
734 | 734 | { |
735 | 735 | //echo "Rule added \n"; |
736 | 736 | $rules_ret[$rule_ret_key]=$rules_all[$key]; |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | $db_conn=$this->db_connect_trap(); |
754 | 754 | $sql="UPDATE ".$this->db_prefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');"; |
755 | 755 | if ($db_conn->query($sql) == FALSE) { |
756 | - $this->trapLog('Error in update query : ' . $sql,WARN,''); |
|
756 | + $this->trapLog('Error in update query : '.$sql, WARN, ''); |
|
757 | 757 | } |
758 | 758 | } |
759 | 759 | |
@@ -765,31 +765,31 @@ discard block |
||
765 | 765 | * @param string $display |
766 | 766 | * @returnn bool true is service check was sent without error |
767 | 767 | */ |
768 | - public function serviceCheckResult($host,$service,$state,$display) |
|
768 | + public function serviceCheckResult($host, $service, $state, $display) |
|
769 | 769 | { |
770 | 770 | if ($this->api_use == false) |
771 | 771 | { |
772 | - $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' . |
|
773 | - $host.';' .$service .';' . $state . ';'.$display; |
|
774 | - $this->trapLog( $send." : to : " .$this->icinga2cmd,3,''); |
|
772 | + $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'. |
|
773 | + $host.';'.$service.';'.$state.';'.$display; |
|
774 | + $this->trapLog($send." : to : ".$this->icinga2cmd, 3, ''); |
|
775 | 775 | |
776 | 776 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
777 | - exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
|
777 | + exec('echo "'.$send.'" > '.$this->icinga2cmd); |
|
778 | 778 | return true; |
779 | 779 | } |
780 | 780 | else |
781 | 781 | { |
782 | - $api = $this->getAPI(); |
|
782 | + $api=$this->getAPI(); |
|
783 | 783 | $api->setCredentials($this->api_username, $this->api_password); |
784 | - list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display); |
|
784 | + list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display); |
|
785 | 785 | if ($retcode == false) |
786 | 786 | { |
787 | - $this->trapLog( "Error sending result : " .$retmessage,WARN,''); |
|
787 | + $this->trapLog("Error sending result : ".$retmessage, WARN, ''); |
|
788 | 788 | return false; |
789 | 789 | } |
790 | 790 | else |
791 | 791 | { |
792 | - $this->trapLog( "Sent result : " .$retmessage,3,''); |
|
792 | + $this->trapLog("Sent result : ".$retmessage, 3, ''); |
|
793 | 793 | return true; |
794 | 794 | } |
795 | 795 | } |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | |
798 | 798 | public function getHostByIP($ip) |
799 | 799 | { |
800 | - $api = $this->getAPI(); |
|
800 | + $api=$this->getAPI(); |
|
801 | 801 | $api->setCredentials($this->api_username, $this->api_password); |
802 | 802 | return $api->getHostByIP($ip); |
803 | 803 | } |
@@ -810,32 +810,32 @@ discard block |
||
810 | 810 | protected function applyDisplay($display) |
811 | 811 | { |
812 | 812 | $matches=array(); |
813 | - while (preg_match('/_OID\(([0-9\.]+)\)/',$display,$matches) == 1) |
|
813 | + while (preg_match('/_OID\(([0-9\.]+)\)/', $display, $matches) == 1) |
|
814 | 814 | { |
815 | 815 | $oid=$matches[1]; |
816 | 816 | $found=0; |
817 | - foreach($this->trap_data_ext as $val) |
|
817 | + foreach ($this->trap_data_ext as $val) |
|
818 | 818 | { |
819 | 819 | if ($oid == $val->oid) |
820 | 820 | { |
821 | - $val->value=preg_replace('/"/','',$val->value); |
|
821 | + $val->value=preg_replace('/"/', '', $val->value); |
|
822 | 822 | $rep=0; |
823 | - $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep); |
|
824 | - if ($rep==0) |
|
823 | + $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep); |
|
824 | + if ($rep == 0) |
|
825 | 825 | { |
826 | - $this->trapLog("Error in display",WARN,''); |
|
826 | + $this->trapLog("Error in display", WARN, ''); |
|
827 | 827 | return $display; |
828 | 828 | } |
829 | 829 | $found=1; |
830 | 830 | break; |
831 | 831 | } |
832 | 832 | } |
833 | - if ($found==0) |
|
833 | + if ($found == 0) |
|
834 | 834 | { |
835 | - $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep); |
|
836 | - if ($rep==0) |
|
835 | + $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep); |
|
836 | + if ($rep == 0) |
|
837 | 837 | { |
838 | - $this->trapLog("Error in display",WARN,''); |
|
838 | + $this->trapLog("Error in display", WARN, ''); |
|
839 | 839 | return $display; |
840 | 840 | } |
841 | 841 | } |
@@ -845,27 +845,27 @@ discard block |
||
845 | 845 | |
846 | 846 | |
847 | 847 | /***************** Eval & tokenizer functions ****************/ |
848 | - protected function eval_getElement($rule,&$item) |
|
848 | + protected function eval_getElement($rule, &$item) |
|
849 | 849 | { |
850 | - while ($rule[$item]==' ') $item++; |
|
851 | - if (preg_match('/[0-9\.]/',$rule[$item])) |
|
850 | + while ($rule[$item] == ' ') $item++; |
|
851 | + if (preg_match('/[0-9\.]/', $rule[$item])) |
|
852 | 852 | { // number |
853 | 853 | |
854 | - $item2=$item+1; |
|
855 | - while (($item2!=strlen($rule)) && (preg_match('/[0-9\.]/',$rule[$item2]))) { $item2++ ;} |
|
856 | - $val=substr($rule,$item,$item2-$item); |
|
854 | + $item2=$item + 1; |
|
855 | + while (($item2 != strlen($rule)) && (preg_match('/[0-9\.]/', $rule[$item2]))) { $item2++; } |
|
856 | + $val=substr($rule, $item, $item2 - $item); |
|
857 | 857 | $item=$item2; |
858 | 858 | //echo "number ".$val."\n"; |
859 | - return array(0,$val); |
|
859 | + return array(0, $val); |
|
860 | 860 | } |
861 | 861 | if ($rule[$item] == '"') |
862 | 862 | { // string |
863 | 863 | $item++; |
864 | - $item2=$this->eval_getNext($rule,$item,'"'); |
|
865 | - $val=substr($rule,$item,$item2-$item-1); |
|
864 | + $item2=$this->eval_getNext($rule, $item, '"'); |
|
865 | + $val=substr($rule, $item, $item2 - $item - 1); |
|
866 | 866 | $item=$item2; |
867 | 867 | //echo "string : ".$val."\n"; |
868 | - return array(1,$val); |
|
868 | + return array(1, $val); |
|
869 | 869 | } |
870 | 870 | |
871 | 871 | if ($rule[$item] == '(') |
@@ -874,14 +874,14 @@ discard block |
||
874 | 874 | $start=$item; |
875 | 875 | $parenthesis_count=0; |
876 | 876 | while (($item < strlen($rule)) // Not end of string AND |
877 | - && ( ($rule[$item] != ')' ) || $parenthesis_count > 0) ) // Closing ')' or embeded () |
|
877 | + && (($rule[$item] != ')') || $parenthesis_count > 0)) // Closing ')' or embeded () |
|
878 | 878 | { |
879 | - if ($rule[$item] == '"' ) |
|
879 | + if ($rule[$item] == '"') |
|
880 | 880 | { // pass through string |
881 | 881 | $item++; |
882 | - $item=$this->eval_getNext($rule,$item,'"'); |
|
882 | + $item=$this->eval_getNext($rule, $item, '"'); |
|
883 | 883 | } |
884 | - else{ |
|
884 | + else { |
|
885 | 885 | if ($rule[$item] == '(') |
886 | 886 | { |
887 | 887 | $parenthesis_count++; |
@@ -894,49 +894,49 @@ discard block |
||
894 | 894 | } |
895 | 895 | } |
896 | 896 | |
897 | - if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
898 | - $val=substr($rule,$start,$item-$start); |
|
897 | + if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); } |
|
898 | + $val=substr($rule, $start, $item - $start); |
|
899 | 899 | $item++; |
900 | 900 | $start=0; |
901 | 901 | //echo "group : ".$val."\n"; |
902 | 902 | // returns evaluation of group as type 2 (boolean) |
903 | - return array(2,$this->evaluation($val,$start)); |
|
903 | + return array(2, $this->evaluation($val, $start)); |
|
904 | 904 | } |
905 | - throw new Exception("number/string not found in ".$rule ." at " .$item . ' : ' .$rule[$item]); |
|
905 | + throw new Exception("number/string not found in ".$rule." at ".$item.' : '.$rule[$item]); |
|
906 | 906 | |
907 | 907 | } |
908 | 908 | |
909 | - protected function eval_getNext($rule,$item,$tok) |
|
909 | + protected function eval_getNext($rule, $item, $tok) |
|
910 | 910 | { |
911 | - while (($rule[$item] != $tok ) && ($item < strlen($rule))) { $item++;} |
|
912 | - if ($item==strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
913 | - return $item+1; |
|
911 | + while (($rule[$item] != $tok) && ($item < strlen($rule))) { $item++; } |
|
912 | + if ($item == strlen($rule)) throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item); |
|
913 | + return $item + 1; |
|
914 | 914 | } |
915 | 915 | |
916 | - protected function eval_getOper($rule,&$item) |
|
916 | + protected function eval_getOper($rule, &$item) |
|
917 | 917 | { |
918 | - while ($rule[$item]==' ') $item++; |
|
918 | + while ($rule[$item] == ' ') $item++; |
|
919 | 919 | switch ($rule[$item]) |
920 | 920 | { |
921 | 921 | case '<': |
922 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"<=");} |
|
923 | - $item++; return array(0,"<"); |
|
922 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, "<="); } |
|
923 | + $item++; return array(0, "<"); |
|
924 | 924 | case '>': |
925 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,">=");} |
|
926 | - $item++; return array(0,">"); |
|
925 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, ">="); } |
|
926 | + $item++; return array(0, ">"); |
|
927 | 927 | case '=': |
928 | - $item++; return array(0,"="); |
|
928 | + $item++; return array(0, "="); |
|
929 | 929 | case '!': |
930 | - if ($rule[$item+1]=='=') { $item+=2; return array(0,"!=");} |
|
931 | - throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule ." at " .$item); |
|
930 | + if ($rule[$item + 1] == '=') { $item+=2; return array(0, "!="); } |
|
931 | + throw new Exception("Erreur in expr - incorrect operator '!' found in ".$rule." at ".$item); |
|
932 | 932 | case '~': |
933 | - $item++; return array(0,"~"); |
|
933 | + $item++; return array(0, "~"); |
|
934 | 934 | case '|': |
935 | - $item++; return array(1,"|"); |
|
935 | + $item++; return array(1, "|"); |
|
936 | 936 | case '&': |
937 | - $item++; return array(1,"&"); |
|
937 | + $item++; return array(1, "&"); |
|
938 | 938 | default : |
939 | - throw new Exception("Erreur in expr - operator not found in ".$rule ." at " .$item); |
|
939 | + throw new Exception("Erreur in expr - operator not found in ".$rule." at ".$item); |
|
940 | 940 | } |
941 | 941 | } |
942 | 942 | |
@@ -948,10 +948,10 @@ discard block |
||
948 | 948 | * comparison int vs strings will return null (error) |
949 | 949 | * return : bool or null on error |
950 | 950 | */ |
951 | - public function evaluation($rule,&$item) |
|
951 | + public function evaluation($rule, &$item) |
|
952 | 952 | { |
953 | 953 | //echo "Evaluation of ".substr($rule,$item)."\n"; |
954 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
954 | + if ($rule[$item] == '!') // If '!' found, negate next expression. |
|
955 | 955 | { |
956 | 956 | $negate=true; |
957 | 957 | $item++; |
@@ -961,63 +961,63 @@ discard block |
||
961 | 961 | $negate=false; |
962 | 962 | } |
963 | 963 | // First element : number, string or () |
964 | - list($type1,$val1) = $this->eval_getElement($rule,$item); |
|
964 | + list($type1, $val1)=$this->eval_getElement($rule, $item); |
|
965 | 965 | //echo "Elmt1: ".$val1."/".$type1." : ".substr($rule,$item)."\n"; |
966 | 966 | |
967 | - if ($item==strlen($rule)) // If only element, return value, but only boolean |
|
967 | + if ($item == strlen($rule)) // If only element, return value, but only boolean |
|
968 | 968 | { |
969 | 969 | if ($type1 != 2) throw new Exception("Cannot use num/string as boolean : ".$rule); |
970 | - if ($negate == true) $val1= ! $val1; |
|
970 | + if ($negate == true) $val1=!$val1; |
|
971 | 971 | return $val1; |
972 | 972 | } |
973 | 973 | |
974 | 974 | // Second element : operator |
975 | - list($typec,$comp) = $this->eval_getOper($rule,$item); |
|
975 | + list($typec, $comp)=$this->eval_getOper($rule, $item); |
|
976 | 976 | //echo "Comp : ".$comp." : ".substr($rule,$item)."\n"; |
977 | 977 | |
978 | 978 | // Third element : number, string or () |
979 | - if ( $rule[$item] == '!') // starts with a ! so evaluate whats next |
|
979 | + if ($rule[$item] == '!') // starts with a ! so evaluate whats next |
|
980 | 980 | { |
981 | 981 | $item++; |
982 | 982 | if ($typec != 1) throw new Exception("Mixing boolean and comparison : ".$rule); |
983 | - $val2= ! $this->evaluation($rule,$item); |
|
983 | + $val2=!$this->evaluation($rule, $item); |
|
984 | 984 | $type2=2; // result is a boolean |
985 | 985 | } |
986 | 986 | else |
987 | 987 | { |
988 | - list($type2,$val2) = $this->eval_getElement($rule,$item); |
|
988 | + list($type2, $val2)=$this->eval_getElement($rule, $item); |
|
989 | 989 | } |
990 | 990 | //echo "Elmt2: ".$val2."/".$type2." : ".substr($rule,$item)."\n"; |
991 | 991 | |
992 | - if ($type1!=$type2) // cannot compare different types |
|
992 | + if ($type1 != $type2) // cannot compare different types |
|
993 | 993 | { |
994 | 994 | throw new Exception("Cannot compare string & number : ".$rule); |
995 | 995 | } |
996 | - if ($typec==1 && $type1 !=2) // cannot use & or | with string/number |
|
996 | + if ($typec == 1 && $type1 != 2) // cannot use & or | with string/number |
|
997 | 997 | { |
998 | 998 | throw new Exception("Cannot use boolean operators with string & number : ".$rule); |
999 | 999 | } |
1000 | 1000 | |
1001 | - switch ($comp){ |
|
1002 | - case '<': $retVal= ($val1 < $val2); break; |
|
1003 | - case '<=': $retVal= ($val1 <= $val2); break; |
|
1004 | - case '>': $retVal= ($val1 > $val2); break; |
|
1005 | - case '>=': $retVal= ($val1 >= $val2); break; |
|
1006 | - case '=': $retVal= ($val1 == $val2); break; |
|
1007 | - case '!=': $retVal= ($val1 != $val2); break; |
|
1008 | - case '~': $retVal= (preg_match('/'.preg_replace('/"/','',$val2).'/',$val1)); break; |
|
1009 | - case '|': $retVal= ($val1 || $val2); break; |
|
1010 | - case '&': $retVal= ($val1 && $val2); break; |
|
1001 | + switch ($comp) { |
|
1002 | + case '<': $retVal=($val1 < $val2); break; |
|
1003 | + case '<=': $retVal=($val1 <= $val2); break; |
|
1004 | + case '>': $retVal=($val1 > $val2); break; |
|
1005 | + case '>=': $retVal=($val1 >= $val2); break; |
|
1006 | + case '=': $retVal=($val1 == $val2); break; |
|
1007 | + case '!=': $retVal=($val1 != $val2); break; |
|
1008 | + case '~': $retVal=(preg_match('/'.preg_replace('/"/', '', $val2).'/', $val1)); break; |
|
1009 | + case '|': $retVal=($val1 || $val2); break; |
|
1010 | + case '&': $retVal=($val1 && $val2); break; |
|
1011 | 1011 | default: throw new Exception("Error in expression - unknown comp : ".$comp); |
1012 | 1012 | } |
1013 | - if ($negate == true) $retVal = ! $retVal; // Inverse result if negate before expression |
|
1013 | + if ($negate == true) $retVal=!$retVal; // Inverse result if negate before expression |
|
1014 | 1014 | |
1015 | - if ($item==strlen($rule)) return $retVal; // End of string : return evaluation |
|
1015 | + if ($item == strlen($rule)) return $retVal; // End of string : return evaluation |
|
1016 | 1016 | // check for logical operator : |
1017 | 1017 | switch ($rule[$item]) |
1018 | 1018 | { |
1019 | - case '|': $item++; return ($retVal || $this->evaluation($rule,$item) ); break; |
|
1020 | - case '&': $item++; return ($retVal && $this->evaluation($rule,$item) ); break; |
|
1019 | + case '|': $item++; return ($retVal || $this->evaluation($rule, $item)); break; |
|
1020 | + case '&': $item++; return ($retVal && $this->evaluation($rule, $item)); break; |
|
1021 | 1021 | |
1022 | 1022 | default: throw new Exception("Erreur in expr - garbadge at end of expression : ".$rule[$item]); |
1023 | 1023 | } |
@@ -1029,17 +1029,17 @@ discard block |
||
1029 | 1029 | $rule2=''; |
1030 | 1030 | while ($item < strlen($rule)) |
1031 | 1031 | { |
1032 | - if ($rule[$item]==' ') { $item++; continue; } |
|
1033 | - if ($rule[$item]=='"') |
|
1032 | + if ($rule[$item] == ' ') { $item++; continue; } |
|
1033 | + if ($rule[$item] == '"') |
|
1034 | 1034 | { |
1035 | 1035 | $rule2.=$rule[$item]; |
1036 | 1036 | $item++; |
1037 | - while (($rule[$item]!='"') && ($item < strlen($rule))) |
|
1037 | + while (($rule[$item] != '"') && ($item < strlen($rule))) |
|
1038 | 1038 | { |
1039 | 1039 | $rule2.=$rule[$item]; |
1040 | 1040 | $item++; |
1041 | 1041 | } |
1042 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
1042 | + if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item); |
|
1043 | 1043 | $rule2.=$rule[$item]; |
1044 | 1044 | $item++; |
1045 | 1045 | continue; |
@@ -1059,12 +1059,12 @@ discard block |
||
1059 | 1059 | |
1060 | 1060 | protected function eval_rule($rule) |
1061 | 1061 | { |
1062 | - if ($rule==null || $rule == '') // Empty rule is always true |
|
1062 | + if ($rule == null || $rule == '') // Empty rule is always true |
|
1063 | 1063 | { |
1064 | 1064 | return true; |
1065 | 1065 | } |
1066 | 1066 | $matches=array(); |
1067 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$rule,$matches) == 1) |
|
1067 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/', $rule, $matches) == 1) |
|
1068 | 1068 | { |
1069 | 1069 | $oid=$matches[1]; |
1070 | 1070 | $found=0; |
@@ -1076,49 +1076,49 @@ discard block |
||
1076 | 1076 | // replace * with \* in oid for preg_replace |
1077 | 1077 | $oid=preg_replace('/\*/', '\*', $oid); |
1078 | 1078 | |
1079 | - $this->trapLog('OID in rule : '.$oid.' / '.$oidR,4,''); |
|
1079 | + $this->trapLog('OID in rule : '.$oid.' / '.$oidR, 4, ''); |
|
1080 | 1080 | |
1081 | - foreach($this->trap_data_ext as $val) |
|
1081 | + foreach ($this->trap_data_ext as $val) |
|
1082 | 1082 | { |
1083 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
1083 | + if (preg_match("/^$oidR$/", $val->oid) == 1) |
|
1084 | 1084 | { |
1085 | - if (!preg_match('/^[0-9]*\.?[0-9]+$/',$val->value)) |
|
1085 | + if (!preg_match('/^[0-9]*\.?[0-9]+$/', $val->value)) |
|
1086 | 1086 | { // If not a number, change " to ' and put " around it |
1087 | - $val->value=preg_replace('/"/',"'",$val->value); |
|
1087 | + $val->value=preg_replace('/"/', "'", $val->value); |
|
1088 | 1088 | $val->value='"'.$val->value.'"'; |
1089 | 1089 | } |
1090 | 1090 | $rep=0; |
1091 | - $rule=preg_replace('/_OID\('.$oid.'\)/',$val->value,$rule,-1,$rep); |
|
1092 | - if ($rep==0) |
|
1091 | + $rule=preg_replace('/_OID\('.$oid.'\)/', $val->value, $rule, -1, $rep); |
|
1092 | + if ($rep == 0) |
|
1093 | 1093 | { |
1094 | - $this->trapLog("Error in rule_eval",WARN,''); |
|
1094 | + $this->trapLog("Error in rule_eval", WARN, ''); |
|
1095 | 1095 | return false; |
1096 | 1096 | } |
1097 | 1097 | $found=1; |
1098 | 1098 | break; |
1099 | 1099 | } |
1100 | 1100 | } |
1101 | - if ($found==0) |
|
1101 | + if ($found == 0) |
|
1102 | 1102 | { // OID not found : throw error |
1103 | 1103 | throw new Exception('OID '.$oid.' not found in trap'); |
1104 | 1104 | } |
1105 | 1105 | } |
1106 | 1106 | $item=0; |
1107 | 1107 | $rule=$this->eval_cleanup($rule); |
1108 | - $this->trapLog('Rule after clenup: '.$rule,3,''); |
|
1108 | + $this->trapLog('Rule after clenup: '.$rule, 3, ''); |
|
1109 | 1109 | |
1110 | - return $this->evaluation($rule,$item); |
|
1110 | + return $this->evaluation($rule, $item); |
|
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | /** Match rules for current trap and do action |
1114 | 1114 | */ |
1115 | 1115 | public function applyRules() |
1116 | 1116 | { |
1117 | - $rules = $this->getRules($this->trap_data['source_ip'],$this->trap_data['trap_oid']); |
|
1117 | + $rules=$this->getRules($this->trap_data['source_ip'], $this->trap_data['trap_oid']); |
|
1118 | 1118 | |
1119 | - if ($rules==FALSE || count($rules)==0) |
|
1119 | + if ($rules == FALSE || count($rules) == 0) |
|
1120 | 1120 | { |
1121 | - $this->trapLog('No rules found for this trap',3,''); |
|
1121 | + $this->trapLog('No rules found for this trap', 3, ''); |
|
1122 | 1122 | $this->trap_data['status']='unknown'; |
1123 | 1123 | $this->trap_to_db=true; |
1124 | 1124 | return; |
@@ -1133,58 +1133,58 @@ discard block |
||
1133 | 1133 | $service_name=$rule['service_name']; |
1134 | 1134 | |
1135 | 1135 | $display=$this->applyDisplay($rule['display']); |
1136 | - $this->trap_action = ($this->trap_action==null)? '' : $this->trap_action . ', '; |
|
1136 | + $this->trap_action=($this->trap_action == null) ? '' : $this->trap_action.', '; |
|
1137 | 1137 | try |
1138 | 1138 | { |
1139 | - $this->trapLog('Rule to eval : '.$rule['rule'],3,''); |
|
1139 | + $this->trapLog('Rule to eval : '.$rule['rule'], 3, ''); |
|
1140 | 1140 | $evalr=$this->eval_rule($rule['rule']); |
1141 | 1141 | |
1142 | 1142 | if ($evalr == true) |
1143 | 1143 | { |
1144 | 1144 | //$this->trapLog('rules OOK: '.print_r($rule),3,''); |
1145 | 1145 | $action=$rule['action_match']; |
1146 | - $this->trapLog('action OK : '.$action,3,''); |
|
1146 | + $this->trapLog('action OK : '.$action, 3, ''); |
|
1147 | 1147 | if ($action >= 0) |
1148 | 1148 | { |
1149 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
|
1149 | + if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false) |
|
1150 | 1150 | { |
1151 | 1151 | $this->trap_action.='Error sending status : check cmd/API'; |
1152 | 1152 | } |
1153 | 1153 | else |
1154 | 1154 | { |
1155 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
1155 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
1156 | 1156 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
1157 | 1157 | } |
1158 | 1158 | } |
1159 | 1159 | else |
1160 | 1160 | { |
1161 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
1161 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
1162 | 1162 | } |
1163 | - $this->trap_to_db=($action==-2)?false:true; |
|
1163 | + $this->trap_to_db=($action == -2) ?false:true; |
|
1164 | 1164 | } |
1165 | 1165 | else |
1166 | 1166 | { |
1167 | 1167 | //$this->trapLog('rules KOO : '.print_r($rule),3,''); |
1168 | 1168 | |
1169 | 1169 | $action=$rule['action_nomatch']; |
1170 | - $this->trapLog('action NOK : '.$action,3,''); |
|
1170 | + $this->trapLog('action NOK : '.$action, 3, ''); |
|
1171 | 1171 | if ($action >= 0) |
1172 | 1172 | { |
1173 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
|
1173 | + if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false) |
|
1174 | 1174 | { |
1175 | 1175 | $this->trap_action.='Error sending status : check cmd/API'; |
1176 | 1176 | } |
1177 | 1177 | else |
1178 | 1178 | { |
1179 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
1179 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
1180 | 1180 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
1181 | 1181 | } |
1182 | 1182 | } |
1183 | 1183 | else |
1184 | 1184 | { |
1185 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
1185 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
1186 | 1186 | } |
1187 | - $this->trap_to_db=($action==-2)?false:true; |
|
1187 | + $this->trap_to_db=($action == -2) ?false:true; |
|
1188 | 1188 | } |
1189 | 1189 | // Put name in source_name |
1190 | 1190 | if (!isset($this->trap_data['source_name'])) |
@@ -1193,7 +1193,7 @@ discard block |
||
1193 | 1193 | } |
1194 | 1194 | else |
1195 | 1195 | { |
1196 | - if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name'])) |
|
1196 | + if (!preg_match('/'.$rule['host_name'].'/', $this->trap_data['source_name'])) |
|
1197 | 1197 | { // only add if not present |
1198 | 1198 | $this->trap_data['source_name'].=','.$rule['host_name']; |
1199 | 1199 | } |
@@ -1201,13 +1201,13 @@ discard block |
||
1201 | 1201 | } |
1202 | 1202 | catch (Exception $e) |
1203 | 1203 | { |
1204 | - $this->trapLog('Error in rule eval : '.$e->getMessage(),WARN,''); |
|
1204 | + $this->trapLog('Error in rule eval : '.$e->getMessage(), WARN, ''); |
|
1205 | 1205 | $this->trap_action.=' ERR : '.$e->getMessage(); |
1206 | 1206 | $this->trap_data['status']='error'; |
1207 | 1207 | } |
1208 | 1208 | |
1209 | 1209 | } |
1210 | - if ($this->trap_data['status']=='error') |
|
1210 | + if ($this->trap_data['status'] == 'error') |
|
1211 | 1211 | { |
1212 | 1212 | $this->trap_to_db=true; // Always put errors in DB for the use can see |
1213 | 1213 | } |
@@ -1223,13 +1223,13 @@ discard block |
||
1223 | 1223 | public function add_rule_final($time) |
1224 | 1224 | { |
1225 | 1225 | $db_conn=$this->db_connect_trap(); |
1226 | - if ($this->trap_action==null) |
|
1226 | + if ($this->trap_action == null) |
|
1227 | 1227 | { |
1228 | 1228 | $this->trap_action='No action'; |
1229 | 1229 | } |
1230 | 1230 | $sql="UPDATE ".$this->db_prefix."received SET process_time = '".$time."' , status_detail='".$this->trap_action."' WHERE (id = '".$this->trap_id."');"; |
1231 | 1231 | if ($db_conn->query($sql) == FALSE) { |
1232 | - $this->trapLog('Error in update query : ' . $sql,WARN,''); |
|
1232 | + $this->trapLog('Error in update query : '.$sql, WARN, ''); |
|
1233 | 1233 | } |
1234 | 1234 | } |
1235 | 1235 | |
@@ -1239,14 +1239,14 @@ discard block |
||
1239 | 1239 | * @param $schema_file string File to read schema from |
1240 | 1240 | * @param $table_prefix string to replace #PREFIX# in schema file by this |
1241 | 1241 | */ |
1242 | - public function create_schema($schema_file,$table_prefix) |
|
1242 | + public function create_schema($schema_file, $table_prefix) |
|
1243 | 1243 | { |
1244 | 1244 | //Read data from snmptrapd from stdin |
1245 | 1245 | $input_stream=fopen($schema_file, 'r'); |
1246 | 1246 | |
1247 | - if ($input_stream==FALSE) |
|
1247 | + if ($input_stream == FALSE) |
|
1248 | 1248 | { |
1249 | - $this->trapLog("Error reading schema !",ERROR,''); |
|
1249 | + $this->trapLog("Error reading schema !", ERROR, ''); |
|
1250 | 1250 | } |
1251 | 1251 | $newline=''; |
1252 | 1252 | $cur_table=''; |
@@ -1255,14 +1255,14 @@ discard block |
||
1255 | 1255 | |
1256 | 1256 | while (($line=fgets($input_stream)) !== false) |
1257 | 1257 | { |
1258 | - $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line)); |
|
1258 | + $newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line)); |
|
1259 | 1259 | if (preg_match('/; *$/', $newline)) |
1260 | 1260 | { |
1261 | - $sql= $newline; |
|
1261 | + $sql=$newline; |
|
1262 | 1262 | if ($db_conn->query($sql) == FALSE) { |
1263 | - $this->trapLog('Error create schema : '.$sql,ERROR,''); |
|
1263 | + $this->trapLog('Error create schema : '.$sql, ERROR, ''); |
|
1264 | 1264 | } |
1265 | - if (preg_match('/^ *CREATE TABLE ([^ ]+)/',$newline,$cur_table_array)) |
|
1265 | + if (preg_match('/^ *CREATE TABLE ([^ ]+)/', $newline, $cur_table_array)) |
|
1266 | 1266 | { |
1267 | 1267 | $cur_table='table '.$cur_table_array[1]; |
1268 | 1268 | } |
@@ -1270,19 +1270,19 @@ discard block |
||
1270 | 1270 | { |
1271 | 1271 | $cur_table='secret SQL stuff :-)'; |
1272 | 1272 | } |
1273 | - $this->trapLog('Creating : ' . $cur_table, 3,''); |
|
1273 | + $this->trapLog('Creating : '.$cur_table, 3, ''); |
|
1274 | 1274 | $newline=''; |
1275 | 1275 | } |
1276 | 1276 | } |
1277 | 1277 | |
1278 | - $sql= $newline; |
|
1278 | + $sql=$newline; |
|
1279 | 1279 | if ($sql != '') |
1280 | 1280 | { |
1281 | 1281 | if ($db_conn->query($sql) == FALSE) { |
1282 | - $this->trapLog('Error create schema : '.$sql,ERROR,''); |
|
1282 | + $this->trapLog('Error create schema : '.$sql, ERROR, ''); |
|
1283 | 1283 | } |
1284 | 1284 | } |
1285 | - $this->trapLog('Schema created',3); |
|
1285 | + $this->trapLog('Schema created', 3); |
|
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | /** |
@@ -1293,14 +1293,14 @@ discard block |
||
1293 | 1293 | * @param bool $getmsg : only get messages from version upgrades |
1294 | 1294 | * @return string : if $getmsg=true, return messages. |
1295 | 1295 | */ |
1296 | - public function update_schema($prefix,$target_version,$table_prefix,$getmsg=false) |
|
1296 | + public function update_schema($prefix, $target_version, $table_prefix, $getmsg=false) |
|
1297 | 1297 | { |
1298 | 1298 | // Get current db number |
1299 | 1299 | $db_conn=$this->db_connect_trap(); |
1300 | 1300 | $sql='SELECT id,value from '.$this->db_prefix.'db_config WHERE name=\'db_version\' '; |
1301 | - $this->trapLog('SQL query : '.$sql,4,''); |
|
1301 | + $this->trapLog('SQL query : '.$sql, 4, ''); |
|
1302 | 1302 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
1303 | - $this->trapLog('Cannot get db version. Query : ' . $sql,2,''); |
|
1303 | + $this->trapLog('Cannot get db version. Query : '.$sql, 2, ''); |
|
1304 | 1304 | return; |
1305 | 1305 | } |
1306 | 1306 | $version=$ret_code->fetchAll(); |
@@ -1309,47 +1309,47 @@ discard block |
||
1309 | 1309 | |
1310 | 1310 | if ($this->trapDBType == 'pgsql') |
1311 | 1311 | { |
1312 | - $prefix .= 'update_pgsql/schema_'; |
|
1312 | + $prefix.='update_pgsql/schema_'; |
|
1313 | 1313 | } |
1314 | 1314 | else |
1315 | 1315 | { |
1316 | - $prefix .= 'update_sql/schema_'; |
|
1316 | + $prefix.='update_sql/schema_'; |
|
1317 | 1317 | } |
1318 | 1318 | //echo "version all :\n";print_r($version);echo " \n $cur_ver \n"; |
1319 | 1319 | if ($getmsg == true) |
1320 | 1320 | { |
1321 | 1321 | $message=''; |
1322 | - $this->trapLog('getting message for upgrade',4,''); |
|
1323 | - while($cur_version<$target_version) |
|
1322 | + $this->trapLog('getting message for upgrade', 4, ''); |
|
1323 | + while ($cur_version < $target_version) |
|
1324 | 1324 | { |
1325 | 1325 | $cur_version++; |
1326 | - $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql'; |
|
1326 | + $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql'; |
|
1327 | 1327 | $input_stream=fopen($updateFile, 'r'); |
1328 | - if ($input_stream==FALSE) |
|
1328 | + if ($input_stream == FALSE) |
|
1329 | 1329 | { |
1330 | - $this->trapLog("Error reading update file ". $updateFile,2,''); |
|
1330 | + $this->trapLog("Error reading update file ".$updateFile, 2, ''); |
|
1331 | 1331 | return; |
1332 | 1332 | } |
1333 | 1333 | do { $line=fgets($input_stream); } |
1334 | - while ($line !== false && !preg_match('/#MESSAGE/',$line)); |
|
1334 | + while ($line !== false && !preg_match('/#MESSAGE/', $line)); |
|
1335 | 1335 | if ($line === false) |
1336 | 1336 | { |
1337 | - $this->trapLog("No message in file ". $updateFile,2,''); |
|
1337 | + $this->trapLog("No message in file ".$updateFile, 2, ''); |
|
1338 | 1338 | return; |
1339 | 1339 | } |
1340 | - $message .= ($cur_version-1) . '->' . $cur_version. ' : ' . preg_replace('/#MESSAGE : /','',$line)."\n"; |
|
1340 | + $message.=($cur_version - 1).'->'.$cur_version.' : '.preg_replace('/#MESSAGE : /', '', $line)."\n"; |
|
1341 | 1341 | } |
1342 | 1342 | return $message; |
1343 | 1343 | } |
1344 | - while($cur_version<$target_version) |
|
1344 | + while ($cur_version < $target_version) |
|
1345 | 1345 | { // tODO : execute pre & post scripts |
1346 | 1346 | $cur_version++; |
1347 | - $this->trapLog('Updating to version : ' .$cur_version ,3,''); |
|
1348 | - $updateFile=$prefix.'v'.($cur_version-1).'_v'.$cur_version.'.sql'; |
|
1347 | + $this->trapLog('Updating to version : '.$cur_version, 3, ''); |
|
1348 | + $updateFile=$prefix.'v'.($cur_version - 1).'_v'.$cur_version.'.sql'; |
|
1349 | 1349 | $input_stream=fopen($updateFile, 'r'); |
1350 | - if ($input_stream==FALSE) |
|
1350 | + if ($input_stream == FALSE) |
|
1351 | 1351 | { |
1352 | - $this->trapLog("Error reading update file ". $updateFile,2,''); |
|
1352 | + $this->trapLog("Error reading update file ".$updateFile, 2, ''); |
|
1353 | 1353 | return; |
1354 | 1354 | } |
1355 | 1355 | $newline=''; |
@@ -1358,24 +1358,24 @@ discard block |
||
1358 | 1358 | while (($line=fgets($input_stream)) != FALSE) |
1359 | 1359 | { |
1360 | 1360 | if (preg_match('/^#/', $line)) continue; // ignore comment lines |
1361 | - $newline.=chop(preg_replace('/#PREFIX#/',$table_prefix,$line)); |
|
1361 | + $newline.=chop(preg_replace('/#PREFIX#/', $table_prefix, $line)); |
|
1362 | 1362 | if (preg_match('/; *$/', $newline)) |
1363 | 1363 | { |
1364 | 1364 | $sql_req=$db_conn->prepare($newline); |
1365 | 1365 | if ($sql_req->execute() == FALSE) { |
1366 | - $this->trapLog('Error create schema : '.$newline,1,''); |
|
1366 | + $this->trapLog('Error create schema : '.$newline, 1, ''); |
|
1367 | 1367 | } |
1368 | 1368 | $cur_table_array=array(); |
1369 | - if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/',$newline,$cur_table_array)) |
|
1369 | + if (preg_match('/^ *([^ ]+) TABLE ([^ ]+)/', $newline, $cur_table_array)) |
|
1370 | 1370 | { |
1371 | - $cur_table=$cur_table_array[1] . ' SQL table '.$cur_table_array[2]; |
|
1371 | + $cur_table=$cur_table_array[1].' SQL table '.$cur_table_array[2]; |
|
1372 | 1372 | } |
1373 | 1373 | else |
1374 | 1374 | { |
1375 | 1375 | $cur_table='secret SQL stuff :-)'; |
1376 | 1376 | $cur_table=$newline; |
1377 | 1377 | } |
1378 | - $this->trapLog('Doing : ' . $cur_table, 3,''); |
|
1378 | + $this->trapLog('Doing : '.$cur_table, 3, ''); |
|
1379 | 1379 | |
1380 | 1380 | $newline=''; |
1381 | 1381 | } |
@@ -1388,13 +1388,13 @@ discard block |
||
1388 | 1388 | //} |
1389 | 1389 | |
1390 | 1390 | $sql='UPDATE '.$this->db_prefix.'db_config SET value='.$cur_version.' WHERE ( id = '.$db_version_id.' )'; |
1391 | - $this->trapLog('SQL query : '.$sql,4,''); |
|
1391 | + $this->trapLog('SQL query : '.$sql, 4, ''); |
|
1392 | 1392 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
1393 | - $this->trapLog('Cannot update db version. Query : ' . $sql,2,''); |
|
1393 | + $this->trapLog('Cannot update db version. Query : '.$sql, 2, ''); |
|
1394 | 1394 | return; |
1395 | 1395 | } |
1396 | 1396 | |
1397 | - $this->trapLog('Schema updated to version : '.$cur_version ,3); |
|
1397 | + $this->trapLog('Schema updated to version : '.$cur_version, 3); |
|
1398 | 1398 | } |
1399 | 1399 | } |
1400 | 1400 | |
@@ -1415,7 +1415,7 @@ discard block |
||
1415 | 1415 | WHERE s.current_state != 0;"; |
1416 | 1416 | $db_conn=$this->db_connect_ido(); |
1417 | 1417 | if (($services_db=$db_conn->query($sql_query)) == FALSE) { // set err to 1 to throw exception. |
1418 | - $this->trapLog('No result in query : ' . $sql_query,ERROR,''); |
|
1418 | + $this->trapLog('No result in query : '.$sql_query, ERROR, ''); |
|
1419 | 1419 | } |
1420 | 1420 | $services=$services_db->fetchAll(); |
1421 | 1421 | |
@@ -1423,7 +1423,7 @@ discard block |
||
1423 | 1423 | $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->db_prefix."rules where revert_ok != 0;"; |
1424 | 1424 | $db_conn2=$this->db_connect_trap(); |
1425 | 1425 | if (($rules_db=$db_conn2->query($sql_query)) == FALSE) { |
1426 | - $this->trapLog('No result in query : ' . $sql_query,ERROR,''); |
|
1426 | + $this->trapLog('No result in query : '.$sql_query, ERROR, ''); |
|
1427 | 1427 | } |
1428 | 1428 | $rules=$rules_db->fetchAll(); |
1429 | 1429 | |
@@ -1438,13 +1438,13 @@ discard block |
||
1438 | 1438 | $service['host_name'] == $rule['host_name'] && |
1439 | 1439 | ($service['last_check'] + $rule['revert_ok']) < $now) |
1440 | 1440 | { |
1441 | - $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
1441 | + $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
1442 | 1442 | $numreset++; |
1443 | 1443 | } |
1444 | 1444 | } |
1445 | 1445 | } |
1446 | 1446 | echo "\n"; |
1447 | - echo $numreset . " service(s) reset to OK\n"; |
|
1447 | + echo $numreset." service(s) reset to OK\n"; |
|
1448 | 1448 | return 0; |
1449 | 1449 | |
1450 | 1450 | } |
@@ -1465,7 +1465,7 @@ discard block |
||
1465 | 1465 | * @param string $description |
1466 | 1466 | * @return number : 0=unchanged, 1 = changed, 2=created |
1467 | 1467 | */ |
1468 | - public function update_oid($oid,$mib,$name,$type,$textConv,$dispHint,$syntax,$type_enum,$description=NULL) |
|
1468 | + public function update_oid($oid, $mib, $name, $type, $textConv, $dispHint, $syntax, $type_enum, $description=NULL) |
|
1469 | 1469 | { |
1470 | 1470 | $db_conn=$this->db_connect_trap(); |
1471 | 1471 | $description=$db_conn->quote($description); |
@@ -1475,7 +1475,7 @@ discard block |
||
1475 | 1475 | { // newly created. |
1476 | 1476 | return 0; |
1477 | 1477 | } |
1478 | - if ( $name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] || |
|
1478 | + if ($name != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['name'] || |
|
1479 | 1479 | $mib != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['mib'] || |
1480 | 1480 | $type != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['type'] //|| |
1481 | 1481 | //$textConv != $this->dbOidAll[$this->dbOidIndex[$oid]['key']]['textual_convention'] //|| |
@@ -1495,23 +1495,23 @@ discard block |
||
1495 | 1495 | ':name' => $name, |
1496 | 1496 | ':type' => $type, |
1497 | 1497 | ':mib' => $mib, |
1498 | - ':tc' => ($textConv==null)?'null':$textConv , |
|
1499 | - ':display_hint' => ($dispHint==null)?'null':$dispHint , |
|
1500 | - ':syntax' => ($syntax==null)?'null':$syntax, |
|
1501 | - ':type_enum' => ($type_enum==null)?'null':$type_enum, |
|
1502 | - ':description' => ($description==null)?'null':$description, |
|
1498 | + ':tc' => ($textConv == null) ? 'null' : $textConv, |
|
1499 | + ':display_hint' => ($dispHint == null) ? 'null' : $dispHint, |
|
1500 | + ':syntax' => ($syntax == null) ? 'null' : $syntax, |
|
1501 | + ':type_enum' => ($type_enum == null) ? 'null' : $type_enum, |
|
1502 | + ':description' => ($description == null) ? 'null' : $description, |
|
1503 | 1503 | ':id' => $this->dbOidAll[$this->dbOidIndex[$oid]['id']] |
1504 | 1504 | ); |
1505 | 1505 | |
1506 | 1506 | if ($sqlQuery->execute($sqlParam) == FALSE) { |
1507 | - $this->trapLog('Error in query : ' . $sql,ERROR,''); |
|
1507 | + $this->trapLog('Error in query : '.$sql, ERROR, ''); |
|
1508 | 1508 | } |
1509 | - $this->trapLog('Trap updated : '.$name . ' / OID : '.$oid,4,''); |
|
1509 | + $this->trapLog('Trap updated : '.$name.' / OID : '.$oid, 4, ''); |
|
1510 | 1510 | return 1; |
1511 | 1511 | } |
1512 | 1512 | else |
1513 | 1513 | { |
1514 | - $this->trapLog('Trap unchanged : '.$name . ' / OID : '.$oid,4,''); |
|
1514 | + $this->trapLog('Trap unchanged : '.$name.' / OID : '.$oid, 4, ''); |
|
1515 | 1515 | return 0; |
1516 | 1516 | } |
1517 | 1517 | } |
@@ -1521,11 +1521,11 @@ discard block |
||
1521 | 1521 | |
1522 | 1522 | $sql='INSERT INTO '.$this->db_prefix.'mib_cache '. |
1523 | 1523 | '(oid, name, type , mib, textual_convention, display_hint '. |
1524 | - ', syntax, type_enum , description ) ' . |
|
1524 | + ', syntax, type_enum , description ) '. |
|
1525 | 1525 | 'values (:oid, :name , :type ,:mib ,:tc , :display_hint'. |
1526 | 1526 | ', :syntax, :type_enum, :description )'; |
1527 | 1527 | |
1528 | - if ($this->trapDBType == 'pgsql') $sql .= 'RETURNING id'; |
|
1528 | + if ($this->trapDBType == 'pgsql') $sql.='RETURNING id'; |
|
1529 | 1529 | |
1530 | 1530 | $sqlQuery=$db_conn->prepare($sql); |
1531 | 1531 | |
@@ -1534,15 +1534,15 @@ discard block |
||
1534 | 1534 | ':name' => $name, |
1535 | 1535 | ':type' => $type, |
1536 | 1536 | ':mib' => $mib, |
1537 | - ':tc' => ($textConv==null)?'null':$textConv , |
|
1538 | - ':display_hint' => ($dispHint==null)?'null':$dispHint , |
|
1539 | - ':syntax' => ($syntax==null)?'null':$syntax, |
|
1540 | - ':type_enum' => ($type_enum==null)?'null':$type_enum, |
|
1541 | - ':description' => ($description==null)?'null':$description |
|
1537 | + ':tc' => ($textConv == null) ? 'null' : $textConv, |
|
1538 | + ':display_hint' => ($dispHint == null) ? 'null' : $dispHint, |
|
1539 | + ':syntax' => ($syntax == null) ? 'null' : $syntax, |
|
1540 | + ':type_enum' => ($type_enum == null) ? 'null' : $type_enum, |
|
1541 | + ':description' => ($description == null) ? 'null' : $description |
|
1542 | 1542 | ); |
1543 | 1543 | |
1544 | 1544 | if ($sqlQuery->execute($sqlParam) == FALSE) { |
1545 | - $this->trapLog('Error in query : ' . $sql,1,''); |
|
1545 | + $this->trapLog('Error in query : '.$sql, 1, ''); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | 1548 | switch ($this->trapDBType) |
@@ -1550,10 +1550,10 @@ discard block |
||
1550 | 1550 | case 'pgsql': |
1551 | 1551 | // Get last id to insert oid/values in secondary table |
1552 | 1552 | if (($inserted_id_ret=$sqlQuery->fetch(PDO::FETCH_ASSOC)) == FALSE) { |
1553 | - $this->trapLog('Error getting id - pgsql - ',1,''); |
|
1553 | + $this->trapLog('Error getting id - pgsql - ', 1, ''); |
|
1554 | 1554 | } |
1555 | - if (! isset($inserted_id_ret['id'])) { |
|
1556 | - $this->trapLog('Error getting id - pgsql - empty.',1,''); |
|
1555 | + if (!isset($inserted_id_ret['id'])) { |
|
1556 | + $this->trapLog('Error getting id - pgsql - empty.', 1, ''); |
|
1557 | 1557 | } |
1558 | 1558 | $this->dbOidIndex[$oid]['id']=$inserted_id_ret['id']; |
1559 | 1559 | break; |
@@ -1561,15 +1561,15 @@ discard block |
||
1561 | 1561 | // Get last id to insert oid/values in secondary table |
1562 | 1562 | $sql='SELECT LAST_INSERT_ID();'; |
1563 | 1563 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
1564 | - $this->trapLog('Erreur getting id - mysql - ',1,''); |
|
1564 | + $this->trapLog('Erreur getting id - mysql - ', 1, ''); |
|
1565 | 1565 | } |
1566 | 1566 | |
1567 | 1567 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
1568 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
1568 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
1569 | 1569 | $this->dbOidIndex[$oid]['id']=$inserted_id; |
1570 | 1570 | break; |
1571 | 1571 | default: |
1572 | - $this->trapLog('Error SQL type : '.$this->trapDBType,1,''); |
|
1572 | + $this->trapLog('Error SQL type : '.$this->trapDBType, 1, ''); |
|
1573 | 1573 | } |
1574 | 1574 | |
1575 | 1575 | // Set as newly created. |
@@ -1584,21 +1584,21 @@ discard block |
||
1584 | 1584 | * @param array $objects : array of objects name (without MIB) |
1585 | 1585 | * @param bool $check_existing : check instead of create |
1586 | 1586 | */ |
1587 | - public function trap_objects($trapOID,$trapmib,$objects,$check_existing) |
|
1587 | + public function trap_objects($trapOID, $trapmib, $objects, $check_existing) |
|
1588 | 1588 | { |
1589 | 1589 | $dbObjects=null; // cache of objects for trap in db |
1590 | 1590 | $db_conn=$this->db_connect_trap(); |
1591 | 1591 | |
1592 | 1592 | // Get id of trapmib. |
1593 | 1593 | |
1594 | - $trapId = $this->dbOidIndex[$trapOID]['id']; |
|
1594 | + $trapId=$this->dbOidIndex[$trapOID]['id']; |
|
1595 | 1595 | if ($check_existing == true) |
1596 | 1596 | { |
1597 | 1597 | // Get all objects |
1598 | 1598 | $sql='SELECT * FROM '.$this->db_prefix.'mib_cache_trap_object where trap_id='.$trapId.';'; |
1599 | - $this->trapLog('SQL query get all traps: '.$sql,4,''); |
|
1599 | + $this->trapLog('SQL query get all traps: '.$sql, 4, ''); |
|
1600 | 1600 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
1601 | - $this->trapLog('No result in query : ' . $sql,1,''); |
|
1601 | + $this->trapLog('No result in query : '.$sql, 1, ''); |
|
1602 | 1602 | } |
1603 | 1603 | $dbObjectsRaw=$ret_code->fetchAll(); |
1604 | 1604 | |
@@ -1612,39 +1612,39 @@ discard block |
||
1612 | 1612 | $match=$snmptrans=array(); |
1613 | 1613 | $retVal=0; |
1614 | 1614 | $objOid=$objTc=$objDispHint=$objSyntax=$objDesc=$objEnum=NULL; |
1615 | - $tmpdesc='';$indesc=false; |
|
1615 | + $tmpdesc=''; $indesc=false; |
|
1616 | 1616 | |
1617 | 1617 | $objMib=$trapmib; |
1618 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1619 | - ' -On -Td '.$objMib.'::'.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
1620 | - if ($retVal!=0) |
|
1618 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1619 | + ' -On -Td '.$objMib.'::'.$object.' 2>/dev/null', $snmptrans, $retVal); |
|
1620 | + if ($retVal != 0) |
|
1621 | 1621 | { |
1622 | 1622 | // Maybe not trap mib, search with IR |
1623 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1624 | - ' -IR '.$object . ' 2>/dev/null',$snmptrans,$retVal); |
|
1625 | - if ($retVal != 0 || !preg_match('/(.*)::(.*)/',$snmptrans[0],$match)) |
|
1623 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1624 | + ' -IR '.$object.' 2>/dev/null', $snmptrans, $retVal); |
|
1625 | + if ($retVal != 0 || !preg_match('/(.*)::(.*)/', $snmptrans[0], $match)) |
|
1626 | 1626 | { // Not found -> continue with warning |
1627 | - $this->trapLog('Error finding trap object : '.$trapmib.'::'.$object,2,''); |
|
1627 | + $this->trapLog('Error finding trap object : '.$trapmib.'::'.$object, 2, ''); |
|
1628 | 1628 | continue; |
1629 | 1629 | } |
1630 | 1630 | $objMib=$match[1]; |
1631 | 1631 | |
1632 | 1632 | // Do the snmptranslate again. |
1633 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1634 | - ' -On -Td '.$objMib.'::'.$object,$snmptrans,$retVal); |
|
1635 | - if ($retVal!=0) { |
|
1636 | - $this->trapLog('Error finding trap object : '.$objMib.'::'.$object,2,''); |
|
1633 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1634 | + ' -On -Td '.$objMib.'::'.$object, $snmptrans, $retVal); |
|
1635 | + if ($retVal != 0) { |
|
1636 | + $this->trapLog('Error finding trap object : '.$objMib.'::'.$object, 2, ''); |
|
1637 | 1637 | } |
1638 | 1638 | |
1639 | 1639 | } |
1640 | 1640 | foreach ($snmptrans as $line) |
1641 | 1641 | { |
1642 | - if ($indesc==true) |
|
1642 | + if ($indesc == true) |
|
1643 | 1643 | { |
1644 | - $line=preg_replace('/[\t ]+/',' ',$line); |
|
1645 | - if (preg_match('/(.*)"$/', $line,$match)) |
|
1644 | + $line=preg_replace('/[\t ]+/', ' ', $line); |
|
1645 | + if (preg_match('/(.*)"$/', $line, $match)) |
|
1646 | 1646 | { |
1647 | - $objDesc = $tmpdesc . $match[1]; |
|
1647 | + $objDesc=$tmpdesc.$match[1]; |
|
1648 | 1648 | $indesc=false; |
1649 | 1649 | } |
1650 | 1650 | $tmpdesc.=$line; |
@@ -1655,43 +1655,43 @@ discard block |
||
1655 | 1655 | $objOid=$line; |
1656 | 1656 | continue; |
1657 | 1657 | } |
1658 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/',$line,$match)) |
|
1658 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+([^{]*) \{(.*)\}/', $line, $match)) |
|
1659 | 1659 | { |
1660 | 1660 | $objSyntax=$match[1]; |
1661 | 1661 | $objEnum=$match[2]; |
1662 | 1662 | continue; |
1663 | 1663 | } |
1664 | - if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/',$line,$match)) |
|
1664 | + if (preg_match('/^[\t ]+SYNTAX[\t ]+(.*)/', $line, $match)) |
|
1665 | 1665 | { |
1666 | 1666 | $objSyntax=$match[1]; |
1667 | 1667 | continue; |
1668 | 1668 | } |
1669 | - if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/',$line,$match)) |
|
1669 | + if (preg_match('/^[\t ]+DISPLAY-HINT[\t ]+"(.*)"/', $line, $match)) |
|
1670 | 1670 | { |
1671 | 1671 | $objDispHint=$match[1]; |
1672 | 1672 | continue; |
1673 | 1673 | } |
1674 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/',$line,$match)) |
|
1674 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)"/', $line, $match)) |
|
1675 | 1675 | { |
1676 | 1676 | $objDesc=$match[1]; |
1677 | 1677 | continue; |
1678 | 1678 | } |
1679 | - if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$line,$match)) |
|
1679 | + if (preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $line, $match)) |
|
1680 | 1680 | { |
1681 | 1681 | $tmpdesc=$match[1]; |
1682 | 1682 | $indesc=true; |
1683 | 1683 | continue; |
1684 | 1684 | } |
1685 | - if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/',$line,$match)) |
|
1685 | + if (preg_match('/^[\t ]+-- TEXTUAL CONVENTION[\t ]+(.*)/', $line, $match)) |
|
1686 | 1686 | { |
1687 | 1687 | $objTc=$match[1]; |
1688 | 1688 | continue; |
1689 | 1689 | } |
1690 | 1690 | } |
1691 | - $this->trapLog("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc",4,''); |
|
1691 | + $this->trapLog("Adding trap $object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc", 4, ''); |
|
1692 | 1692 | //echo "$object : $objOid / $objSyntax / $objEnum / $objDispHint / $objTc / $objDesc\n"; |
1693 | 1693 | // Update |
1694 | - $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum,$objDesc); |
|
1694 | + $this->update_oid($objOid, $objMib, $object, '3', $objTc, $objDispHint, $objSyntax, $objEnum, $objDesc); |
|
1695 | 1695 | |
1696 | 1696 | if (isset($dbObjects[$this->dbOidIndex[$objOid]['id']])) |
1697 | 1697 | { // if link exists, continue |
@@ -1712,7 +1712,7 @@ discard block |
||
1712 | 1712 | ); |
1713 | 1713 | |
1714 | 1714 | if ($sqlQuery->execute($sqlParam) == FALSE) { |
1715 | - $this->trapLog('Error adding trap object : ' . $sql . ' / ' . $trapId . '/'. $this->dbOidIndex[$objOid]['id'] ,1,''); |
|
1715 | + $this->trapLog('Error adding trap object : '.$sql.' / '.$trapId.'/'.$this->dbOidIndex[$objOid]['id'], 1, ''); |
|
1716 | 1716 | } |
1717 | 1717 | } |
1718 | 1718 | if ($check_existing == true) |
@@ -1729,19 +1729,19 @@ discard block |
||
1729 | 1729 | * @param boolean $onlyTraps : only cache traps and objects (true) or all (false) |
1730 | 1730 | * @param string $startOID : only cache under startOID (NOT IMPLEMENTED) |
1731 | 1731 | */ |
1732 | - public function update_mib_database($display_progress=false,$check_change=false,$onlyTraps=true,$startOID='.1') |
|
1732 | + public function update_mib_database($display_progress=false, $check_change=false, $onlyTraps=true, $startOID='.1') |
|
1733 | 1733 | { |
1734 | 1734 | // Timing |
1735 | - $timeTaken = microtime(true); |
|
1735 | + $timeTaken=microtime(true); |
|
1736 | 1736 | $retVal=0; |
1737 | 1737 | // Get all mib objects from all mibs |
1738 | - $snmpCommand=$this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null'; |
|
1739 | - $this->trapLog('Getting all traps : '.$snmpCommand,4,''); |
|
1738 | + $snmpCommand=$this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs.' -On -Tto 2>/dev/null'; |
|
1739 | + $this->trapLog('Getting all traps : '.$snmpCommand, 4, ''); |
|
1740 | 1740 | unset($this->objectsAll); |
1741 | - exec($snmpCommand,$this->objectsAll,$retVal); |
|
1742 | - if ($retVal!=0) |
|
1741 | + exec($snmpCommand, $this->objectsAll, $retVal); |
|
1742 | + if ($retVal != 0) |
|
1743 | 1743 | { |
1744 | - $this->trapLog('error executing snmptranslate',ERROR,''); |
|
1744 | + $this->trapLog('error executing snmptranslate', ERROR, ''); |
|
1745 | 1745 | } |
1746 | 1746 | |
1747 | 1747 | // Get all mibs from databse to have a memory index |
@@ -1749,14 +1749,14 @@ discard block |
||
1749 | 1749 | $db_conn=$this->db_connect_trap(); |
1750 | 1750 | |
1751 | 1751 | $sql='SELECT * from '.$this->db_prefix.'mib_cache;'; |
1752 | - $this->trapLog('SQL query : '.$sql,4,''); |
|
1752 | + $this->trapLog('SQL query : '.$sql, 4, ''); |
|
1753 | 1753 | if (($ret_code=$db_conn->query($sql)) == FALSE) { |
1754 | - $this->trapLog('No result in query : ' . $sql,ERROR,''); |
|
1754 | + $this->trapLog('No result in query : '.$sql, ERROR, ''); |
|
1755 | 1755 | } |
1756 | 1756 | $this->dbOidAll=$ret_code->fetchAll(); |
1757 | 1757 | $this->dbOidIndex=array(); |
1758 | 1758 | // Create the index for db; |
1759 | - foreach($this->dbOidAll as $key=>$val) |
|
1759 | + foreach ($this->dbOidAll as $key=>$val) |
|
1760 | 1760 | { |
1761 | 1761 | $this->dbOidIndex[$val['oid']]['key']=$key; |
1762 | 1762 | $this->dbOidIndex[$val['oid']]['id']=$val['id']; |
@@ -1764,11 +1764,11 @@ discard block |
||
1764 | 1764 | |
1765 | 1765 | // Count elements to show progress |
1766 | 1766 | $numElements=count($this->objectsAll); |
1767 | - $this->trapLog('Total snmp objects returned by snmptranslate : '.$numElements,3,''); |
|
1767 | + $this->trapLog('Total snmp objects returned by snmptranslate : '.$numElements, 3, ''); |
|
1768 | 1768 | |
1769 | - $step=$basestep=$numElements/10; // output display of % done |
|
1769 | + $step=$basestep=$numElements / 10; // output display of % done |
|
1770 | 1770 | $num_step=0; |
1771 | - $timeFiveSec = microtime(true); // Used for display a '.' every <n> seconds |
|
1771 | + $timeFiveSec=microtime(true); // Used for display a '.' every <n> seconds |
|
1772 | 1772 | |
1773 | 1773 | // Create index for trap objects |
1774 | 1774 | $this->trapObjectsIndex=array(); |
@@ -1778,28 +1778,28 @@ discard block |
||
1778 | 1778 | $time_parse1N=$time_check1N=$time_check2N=$time_check3N=$time_updateN=$time_objectsN=0; |
1779 | 1779 | $time_num_traps=0; |
1780 | 1780 | |
1781 | - for ($curElement=0;$curElement < $numElements;$curElement++) |
|
1781 | + for ($curElement=0; $curElement < $numElements; $curElement++) |
|
1782 | 1782 | { |
1783 | - $time_1= microtime(true); |
|
1784 | - if ((microtime(true)-$timeFiveSec) > 2 && $display_progress) |
|
1783 | + $time_1=microtime(true); |
|
1784 | + if ((microtime(true) - $timeFiveSec) > 2 && $display_progress) |
|
1785 | 1785 | { // echo a . every 2 sec |
1786 | 1786 | echo '.'; |
1787 | - $timeFiveSec = microtime(true); |
|
1787 | + $timeFiveSec=microtime(true); |
|
1788 | 1788 | } |
1789 | - if ($curElement>$step) |
|
1789 | + if ($curElement > $step) |
|
1790 | 1790 | { // display progress |
1791 | 1791 | $num_step++; |
1792 | 1792 | $step+=$basestep; |
1793 | 1793 | if ($display_progress) |
1794 | 1794 | { |
1795 | - echo "\n" . ($num_step*10). '% : '; |
|
1795 | + echo "\n".($num_step * 10).'% : '; |
|
1796 | 1796 | } |
1797 | 1797 | } |
1798 | 1798 | // Get oid or pass if not found |
1799 | - if (!preg_match('/^\.[0-9\.]+$/',$this->objectsAll[$curElement])) |
|
1799 | + if (!preg_match('/^\.[0-9\.]+$/', $this->objectsAll[$curElement])) |
|
1800 | 1800 | { |
1801 | - $time_parse1 += microtime(true) - $time_1; |
|
1802 | - $time_parse1N ++; |
|
1801 | + $time_parse1+=microtime(true) - $time_1; |
|
1802 | + $time_parse1N++; |
|
1803 | 1803 | continue; |
1804 | 1804 | } |
1805 | 1805 | $oid=$this->objectsAll[$curElement]; |
@@ -1808,9 +1808,9 @@ discard block |
||
1808 | 1808 | $curElement++; |
1809 | 1809 | $match=$snmptrans=array(); |
1810 | 1810 | if (!preg_match('/ +([^\(]+)\(.+\) type=([0-9]+)( tc=([0-9]+))?( hint=(.+))?/', |
1811 | - $this->objectsAll[$curElement],$match)) |
|
1811 | + $this->objectsAll[$curElement], $match)) |
|
1812 | 1812 | { |
1813 | - $time_check1 += microtime(true) - $time_1; |
|
1813 | + $time_check1+=microtime(true) - $time_1; |
|
1814 | 1814 | $time_check1N++; |
1815 | 1815 | continue; |
1816 | 1816 | } |
@@ -1818,21 +1818,21 @@ discard block |
||
1818 | 1818 | $name=$match[1]; // Name |
1819 | 1819 | $type=$match[2]; // type (21=trap, 0: may be trap, else : not trap |
1820 | 1820 | |
1821 | - if ($type==0) // object type=0 : check if v1 trap |
|
1821 | + if ($type == 0) // object type=0 : check if v1 trap |
|
1822 | 1822 | { |
1823 | 1823 | // Check if next is suboid -> in that case is cannot be a trap |
1824 | - if (preg_match("/^$oid/",$this->objectsAll[$curElement+1])) |
|
1824 | + if (preg_match("/^$oid/", $this->objectsAll[$curElement + 1])) |
|
1825 | 1825 | { |
1826 | - $time_check2 += microtime(true) - $time_1; |
|
1826 | + $time_check2+=microtime(true) - $time_1; |
|
1827 | 1827 | $time_check2N++; |
1828 | 1828 | continue; |
1829 | 1829 | } |
1830 | 1830 | unset($snmptrans); |
1831 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1832 | - ' -Td '.$oid . ' | grep OBJECTS ',$snmptrans,$retVal); |
|
1833 | - if ($retVal!=0) |
|
1831 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1832 | + ' -Td '.$oid.' | grep OBJECTS ', $snmptrans, $retVal); |
|
1833 | + if ($retVal != 0) |
|
1834 | 1834 | { |
1835 | - $time_check2 += microtime(true) - $time_1; |
|
1835 | + $time_check2+=microtime(true) - $time_1; |
|
1836 | 1836 | $time_check2N++; |
1837 | 1837 | continue; |
1838 | 1838 | } |
@@ -1840,56 +1840,56 @@ discard block |
||
1840 | 1840 | // Force as trap. |
1841 | 1841 | $type=21; |
1842 | 1842 | } |
1843 | - if ($onlyTraps==true && $type!=21) // if only traps and not a trap, continue |
|
1843 | + if ($onlyTraps == true && $type != 21) // if only traps and not a trap, continue |
|
1844 | 1844 | { |
1845 | - $time_check3 += microtime(true) - $time_1; |
|
1845 | + $time_check3+=microtime(true) - $time_1; |
|
1846 | 1846 | $time_check3N++; |
1847 | 1847 | continue; |
1848 | 1848 | } |
1849 | 1849 | |
1850 | 1850 | $time_num_traps++; |
1851 | 1851 | |
1852 | - $this->trapLog('Found trap : '.$match[1] . ' / OID : '.$oid,3,''); |
|
1852 | + $this->trapLog('Found trap : '.$match[1].' / OID : '.$oid, 3, ''); |
|
1853 | 1853 | if ($display_progress) echo '#'; // echo a # when trap found |
1854 | 1854 | |
1855 | 1855 | // get trap objects & source MIB |
1856 | 1856 | unset($snmptrans); |
1857 | - exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1858 | - ' -Td '.$oid,$snmptrans,$retVal); |
|
1859 | - if ($retVal!=0) |
|
1857 | + exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
1858 | + ' -Td '.$oid, $snmptrans, $retVal); |
|
1859 | + if ($retVal != 0) |
|
1860 | 1860 | { |
1861 | - $this->trapLog('error executing snmptranslate',ERROR,''); |
|
1861 | + $this->trapLog('error executing snmptranslate', ERROR, ''); |
|
1862 | 1862 | } |
1863 | 1863 | |
1864 | - if (!preg_match('/^(.*)::/',$snmptrans[0],$match)) |
|
1864 | + if (!preg_match('/^(.*)::/', $snmptrans[0], $match)) |
|
1865 | 1865 | { |
1866 | - $this->trapLog('Error getting mib from trap '.$oid.' : ' . $snmptrans[0],1,''); |
|
1866 | + $this->trapLog('Error getting mib from trap '.$oid.' : '.$snmptrans[0], 1, ''); |
|
1867 | 1867 | } |
1868 | 1868 | $trapMib=$match[1]; |
1869 | 1869 | |
1870 | - $numLine=1;$trapDesc=''; |
|
1871 | - while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/',$snmptrans[$numLine],$match)) $numLine++; |
|
1870 | + $numLine=1; $trapDesc=''; |
|
1871 | + while (isset($snmptrans[$numLine]) && !preg_match('/^[\t ]+DESCRIPTION[\t ]+"(.*)/', $snmptrans[$numLine], $match)) $numLine++; |
|
1872 | 1872 | if (isset($snmptrans[$numLine])) |
1873 | 1873 | { |
1874 | - $snmptrans[$numLine] = preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/','',$snmptrans[$numLine]); |
|
1874 | + $snmptrans[$numLine]=preg_replace('/^[\t ]+DESCRIPTION[\t ]+"/', '', $snmptrans[$numLine]); |
|
1875 | 1875 | |
1876 | - while (isset($snmptrans[$numLine]) && !preg_match('/"/',$snmptrans[$numLine])) |
|
1876 | + while (isset($snmptrans[$numLine]) && !preg_match('/"/', $snmptrans[$numLine])) |
|
1877 | 1877 | { |
1878 | - $trapDesc.=preg_replace('/[\t ]+/',' ',$snmptrans[$numLine]); |
|
1878 | + $trapDesc.=preg_replace('/[\t ]+/', ' ', $snmptrans[$numLine]); |
|
1879 | 1879 | $numLine++; |
1880 | 1880 | } |
1881 | 1881 | if (isset($snmptrans[$numLine])) { |
1882 | - $trapDesc.=preg_replace('/".*/','',$snmptrans[$numLine]); |
|
1883 | - $trapDesc=preg_replace('/[\t ]+/',' ',$trapDesc); |
|
1882 | + $trapDesc.=preg_replace('/".*/', '', $snmptrans[$numLine]); |
|
1883 | + $trapDesc=preg_replace('/[\t ]+/', ' ', $trapDesc); |
|
1884 | 1884 | } |
1885 | 1885 | |
1886 | 1886 | } |
1887 | - $update=$this->update_oid($oid,$trapMib,$name,$type,NULL,NULL,NULL,NULL,$trapDesc); |
|
1888 | - $time_update += microtime(true) - $time_1; $time_1= microtime(true); |
|
1887 | + $update=$this->update_oid($oid, $trapMib, $name, $type, NULL, NULL, NULL, NULL, $trapDesc); |
|
1888 | + $time_update+=microtime(true) - $time_1; $time_1=microtime(true); |
|
1889 | 1889 | |
1890 | - if (($update==0) && ($check_change==false)) |
|
1890 | + if (($update == 0) && ($check_change == false)) |
|
1891 | 1891 | { // Trapd didn't change & force check disabled |
1892 | - $time_objects += microtime(true) - $time_1; |
|
1892 | + $time_objects+=microtime(true) - $time_1; |
|
1893 | 1893 | if ($display_progress) echo "C"; |
1894 | 1894 | continue; |
1895 | 1895 | } |
@@ -1897,7 +1897,7 @@ discard block |
||
1897 | 1897 | $synt=null; |
1898 | 1898 | foreach ($snmptrans as $line) |
1899 | 1899 | { |
1900 | - if (preg_match('/OBJECTS.*\{([^\}]+)\}/',$line,$match)) |
|
1900 | + if (preg_match('/OBJECTS.*\{([^\}]+)\}/', $line, $match)) |
|
1901 | 1901 | { |
1902 | 1902 | $synt=$match[1]; |
1903 | 1903 | } |
@@ -1905,30 +1905,30 @@ discard block |
||
1905 | 1905 | if ($synt == null) |
1906 | 1906 | { |
1907 | 1907 | //echo "No objects for $trapOID\n"; |
1908 | - $time_objects += microtime(true) - $time_1; |
|
1908 | + $time_objects+=microtime(true) - $time_1; |
|
1909 | 1909 | continue; |
1910 | 1910 | } |
1911 | 1911 | //echo "$synt \n"; |
1912 | 1912 | $trapObjects=array(); |
1913 | - while (preg_match('/ *([^ ,]+) *,* */',$synt,$match)) |
|
1913 | + while (preg_match('/ *([^ ,]+) *,* */', $synt, $match)) |
|
1914 | 1914 | { |
1915 | - array_push($trapObjects,$match[1]); |
|
1916 | - $synt=preg_replace('/'.$match[0].'/','',$synt); |
|
1915 | + array_push($trapObjects, $match[1]); |
|
1916 | + $synt=preg_replace('/'.$match[0].'/', '', $synt); |
|
1917 | 1917 | } |
1918 | 1918 | |
1919 | 1919 | $this->trap_objects($oid, $trapMib, $trapObjects, false); |
1920 | 1920 | |
1921 | - $time_objects += microtime(true) - $time_1; |
|
1921 | + $time_objects+=microtime(true) - $time_1; |
|
1922 | 1922 | $time_objectsN++; |
1923 | 1923 | } |
1924 | 1924 | |
1925 | 1925 | if ($display_progress) |
1926 | 1926 | { |
1927 | 1927 | echo "\nNumber of processed traps : $time_num_traps \n"; |
1928 | - echo "\nParsing : " . number_format($time_parse1+$time_check1,1) ." sec / " . ($time_parse1N+ $time_check1N) . " occurences\n"; |
|
1929 | - echo "Detecting traps : " . number_format($time_check2+$time_check3,1) . " sec / " . ($time_check2N+$time_check3N) ." occurences\n"; |
|
1930 | - echo "Trap processing ($time_updateN): ".number_format($time_update,1)." sec , "; |
|
1931 | - echo "Objects processing ($time_objectsN) : ".number_format($time_objects,1)." sec \n"; |
|
1928 | + echo "\nParsing : ".number_format($time_parse1 + $time_check1, 1)." sec / ".($time_parse1N + $time_check1N)." occurences\n"; |
|
1929 | + echo "Detecting traps : ".number_format($time_check2 + $time_check3, 1)." sec / ".($time_check2N + $time_check3N)." occurences\n"; |
|
1930 | + echo "Trap processing ($time_updateN): ".number_format($time_update, 1)." sec , "; |
|
1931 | + echo "Objects processing ($time_objectsN) : ".number_format($time_objects, 1)." sec \n"; |
|
1932 | 1932 | } |
1933 | 1933 | |
1934 | 1934 | // Timing ends |