@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
| 71 | 71 | $this->logSetup=true; |
| 72 | + } else { |
|
| 73 | + $this->logSetup=false; |
|
| 72 | 74 | } |
| 73 | - else |
|
| 74 | - $this->logSetup=false; |
|
| 75 | 75 | $this->logging->log('Loggin started', INFO); |
| 76 | 76 | |
| 77 | 77 | // Get options from ini files |
@@ -84,7 +84,10 @@ discard block |
||
| 84 | 84 | $this->setupDatabase($trapConfig); // Setup database class |
| 85 | 85 | |
| 86 | 86 | $this->getDatabaseOptions(); // Get options in database |
| 87 | - if ($this->api_use === true) $this->getAPI(); // Setup API |
|
| 87 | + if ($this->api_use === true) { |
|
| 88 | + $this->getAPI(); |
|
| 89 | + } |
|
| 90 | + // Setup API |
|
| 88 | 91 | |
| 89 | 92 | $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
| 90 | 93 | |
@@ -120,8 +123,7 @@ discard block |
||
| 120 | 123 | } |
| 121 | 124 | $this->logging->log($message,$log_level,'syslog'); |
| 122 | 125 | return false; |
| 123 | - } |
|
| 124 | - else |
|
| 126 | + } else |
|
| 125 | 127 | { |
| 126 | 128 | $option_var=$option_array[$option_category][$option_name]; |
| 127 | 129 | return true; |
@@ -185,7 +187,10 @@ discard block |
||
| 185 | 187 | |
| 186 | 188 | $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->db_prefix); |
| 187 | 189 | |
| 188 | - if ($this->api_use === true) return; // In case of API use, no IDO is necessary |
|
| 190 | + if ($this->api_use === true) { |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + // In case of API use, no IDO is necessary |
|
| 189 | 194 | |
| 190 | 195 | // IDO Database |
| 191 | 196 | if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
@@ -210,9 +215,11 @@ discard block |
||
| 210 | 215 | protected function getDatabaseOptions() |
| 211 | 216 | { |
| 212 | 217 | // Database options |
| 213 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
| 218 | + if ($this->logSetup === false) { |
|
| 219 | + // Only if logging was no setup in constructor |
|
| 214 | 220 | { |
| 215 | 221 | $this->getDBConfigIfSet('log_level',$this->logging->debugLevel); |
| 222 | + } |
|
| 216 | 223 | $this->getDBConfigIfSet('log_destination',$this->logging->outputMode); |
| 217 | 224 | $this->getDBConfigIfSet('log_file',$this->logging->outputFile); |
| 218 | 225 | } |
@@ -221,7 +228,9 @@ discard block |
||
| 221 | 228 | protected function getDBConfigIfSet($element,&$variable) |
| 222 | 229 | { |
| 223 | 230 | $value=$this->getDBConfig($element); |
| 224 | - if ($value != 'null') $variable=$value; |
|
| 231 | + if ($value != 'null') { |
|
| 232 | + $variable=$value; |
|
| 233 | + } |
|
| 225 | 234 | } |
| 226 | 235 | |
| 227 | 236 | /** |
@@ -309,8 +318,7 @@ discard block |
||
| 309 | 318 | { |
| 310 | 319 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
| 311 | 320 | $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
| 312 | - } |
|
| 313 | - else |
|
| 321 | + } else |
|
| 314 | 322 | { |
| 315 | 323 | $this->trap_data['source_ip']=$matches[1]; |
| 316 | 324 | $this->trap_data['destination_ip']=$matches[3]; |
@@ -325,14 +333,12 @@ discard block |
||
| 325 | 333 | if ($ret_code===0 || $ret_code===false) |
| 326 | 334 | { |
| 327 | 335 | $this->logging->log('No match on trap data : '.$vars,WARN,''); |
| 328 | - } |
|
| 329 | - else |
|
| 336 | + } else |
|
| 330 | 337 | { |
| 331 | 338 | 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')) |
| 332 | 339 | { |
| 333 | 340 | $this->trap_data['trap_oid']=$matches[2]; |
| 334 | - } |
|
| 335 | - else |
|
| 341 | + } else |
|
| 336 | 342 | { |
| 337 | 343 | $object= new stdClass; |
| 338 | 344 | $object->oid =$matches[1]; |
@@ -503,7 +509,9 @@ discard block |
||
| 503 | 509 | } |
| 504 | 510 | |
| 505 | 511 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 506 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 512 | + if ($inserted_id==false) { |
|
| 513 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 514 | + } |
|
| 507 | 515 | $this->trap_id=$inserted_id; |
| 508 | 516 | break; |
| 509 | 517 | default: |
@@ -519,7 +527,9 @@ discard block |
||
| 519 | 527 | { |
| 520 | 528 | |
| 521 | 529 | // If action is ignore -> don't send t DB |
| 522 | - if ($this->trap_to_db === false) return; |
|
| 530 | + if ($this->trap_to_db === false) { |
|
| 531 | + return; |
|
| 532 | + } |
|
| 523 | 533 | |
| 524 | 534 | |
| 525 | 535 | $db_conn=$this->trapsDB->db_connect_trap(); |
@@ -576,7 +586,9 @@ discard block |
||
| 576 | 586 | } |
| 577 | 587 | |
| 578 | 588 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 579 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 589 | + if ($inserted_id==false) { |
|
| 590 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 591 | + } |
|
| 580 | 592 | $this->trap_id=$inserted_id; |
| 581 | 593 | break; |
| 582 | 594 | default: |
@@ -705,8 +717,7 @@ discard block |
||
| 705 | 717 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
| 706 | 718 | exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
| 707 | 719 | return true; |
| 708 | - } |
|
| 709 | - else |
|
| 720 | + } else |
|
| 710 | 721 | { |
| 711 | 722 | // Get perfdata if found |
| 712 | 723 | $matches=array(); |
@@ -714,8 +725,7 @@ discard block |
||
| 714 | 725 | { |
| 715 | 726 | $display=$matches[1]; |
| 716 | 727 | $perfdata=$matches[2]; |
| 717 | - } |
|
| 718 | - else |
|
| 728 | + } else |
|
| 719 | 729 | { |
| 720 | 730 | $perfdata=''; |
| 721 | 731 | } |
@@ -727,8 +737,7 @@ discard block |
||
| 727 | 737 | { |
| 728 | 738 | $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
| 729 | 739 | return false; |
| 730 | - } |
|
| 731 | - else |
|
| 740 | + } else |
|
| 732 | 741 | { |
| 733 | 742 | $this->logging->log( "Sent result : " .$retmessage,INFO ); |
| 734 | 743 | return true; |
@@ -824,20 +833,17 @@ discard block |
||
| 824 | 833 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
| 825 | 834 | { |
| 826 | 835 | $this->trap_action.='Error sending status : check cmd/API'; |
| 827 | - } |
|
| 828 | - else |
|
| 836 | + } else |
|
| 829 | 837 | { |
| 830 | 838 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 831 | 839 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 832 | 840 | } |
| 833 | - } |
|
| 834 | - else |
|
| 841 | + } else |
|
| 835 | 842 | { |
| 836 | 843 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 837 | 844 | } |
| 838 | 845 | $this->trap_to_db=($action==-2)?false:true; |
| 839 | - } |
|
| 840 | - else |
|
| 846 | + } else |
|
| 841 | 847 | { |
| 842 | 848 | //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
| 843 | 849 | |
@@ -848,14 +854,12 @@ discard block |
||
| 848 | 854 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
| 849 | 855 | { |
| 850 | 856 | $this->trap_action.='Error sending status : check cmd/API'; |
| 851 | - } |
|
| 852 | - else |
|
| 857 | + } else |
|
| 853 | 858 | { |
| 854 | 859 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 855 | 860 | $this->trap_action.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 856 | 861 | } |
| 857 | - } |
|
| 858 | - else |
|
| 862 | + } else |
|
| 859 | 863 | { |
| 860 | 864 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 861 | 865 | } |
@@ -865,16 +869,14 @@ discard block |
||
| 865 | 869 | if (!isset($this->trap_data['source_name'])) |
| 866 | 870 | { |
| 867 | 871 | $this->trap_data['source_name']=$rule['host_name']; |
| 868 | - } |
|
| 869 | - else |
|
| 872 | + } else |
|
| 870 | 873 | { |
| 871 | 874 | if (!preg_match('/'.$rule['host_name'].'/',$this->trap_data['source_name'])) |
| 872 | 875 | { // only add if not present |
| 873 | 876 | $this->trap_data['source_name'].=','.$rule['host_name']; |
| 874 | 877 | } |
| 875 | 878 | } |
| 876 | - } |
|
| 877 | - catch (Exception $e) |
|
| 879 | + } catch (Exception $e) |
|
| 878 | 880 | { |
| 879 | 881 | $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
| 880 | 882 | $this->trap_action.=' ERR : '.$e->getMessage(); |
@@ -885,8 +887,7 @@ discard block |
||
| 885 | 887 | if ($this->trap_data['status']=='error') |
| 886 | 888 | { |
| 887 | 889 | $this->trap_to_db=true; // Always put errors in DB for the use can see |
| 888 | - } |
|
| 889 | - else |
|
| 890 | + } else |
|
| 890 | 891 | { |
| 891 | 892 | $this->trap_data['status']='done'; |
| 892 | 893 | } |