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