@@ -38,8 +38,7 @@ discard block |
||
| 38 | 38 | } |
| 39 | 39 | $this->getLogging()->log($message,$log_level); |
| 40 | 40 | return false; |
| 41 | - } |
|
| 42 | - else |
|
| 41 | + } else |
|
| 43 | 42 | { |
| 44 | 43 | $option_var=$option_array[$option_category][$option_name]; |
| 45 | 44 | return true; |
@@ -52,9 +51,11 @@ discard block |
||
| 52 | 51 | protected function getDatabaseOptions() |
| 53 | 52 | { |
| 54 | 53 | // Database options |
| 55 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
| 54 | + if ($this->logSetup === false) { |
|
| 55 | + // Only if logging was no setup in constructor |
|
| 56 | 56 | { |
| 57 | 57 | $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
| 58 | + } |
|
| 58 | 59 | $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
| 59 | 60 | $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
| 60 | 61 | } |
@@ -67,7 +68,9 @@ discard block |
||
| 67 | 68 | protected function getDBConfigIfSet($element,&$variable) |
| 68 | 69 | { |
| 69 | 70 | $value=$this->getDBConfig($element); |
| 70 | - if ($value != null) $variable=$value; |
|
| 71 | + if ($value != null) { |
|
| 72 | + $variable=$value; |
|
| 73 | + } |
|
| 71 | 74 | } |
| 72 | 75 | |
| 73 | 76 | /** |
@@ -148,7 +151,10 @@ discard block |
||
| 148 | 151 | |
| 149 | 152 | $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
| 150 | 153 | |
| 151 | - if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
|
| 154 | + if ($this->apiUse === true) { |
|
| 155 | + return; |
|
| 156 | + } |
|
| 157 | + // In case of API use, no IDO is necessary |
|
| 152 | 158 | |
| 153 | 159 | // IDO Database |
| 154 | 160 | if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
@@ -95,8 +95,7 @@ discard block |
||
| 95 | 95 | { |
| 96 | 96 | $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
| 97 | 97 | $this->logSetup=true; |
| 98 | - } |
|
| 99 | - else |
|
| 98 | + } else |
|
| 100 | 99 | { |
| 101 | 100 | $this->logSetup=false; |
| 102 | 101 | } |
@@ -121,7 +120,10 @@ discard block |
||
| 121 | 120 | $this->getDatabaseOptions(); // Get options in database |
| 122 | 121 | |
| 123 | 122 | //*************** Setup API |
| 124 | - if ($this->apiUse === true) $this->getAPI(); // Setup API |
|
| 123 | + if ($this->apiUse === true) { |
|
| 124 | + $this->getAPI(); |
|
| 125 | + } |
|
| 126 | + // Setup API |
|
| 125 | 127 | |
| 126 | 128 | //*************** Setup MIB |
| 127 | 129 | $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
@@ -224,8 +226,7 @@ discard block |
||
| 224 | 226 | { |
| 225 | 227 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
| 226 | 228 | $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
| 227 | - } |
|
| 228 | - else |
|
| 229 | + } else |
|
| 229 | 230 | { |
| 230 | 231 | $this->trapData['source_ip']=$matches[1]; |
| 231 | 232 | $this->trapData['destination_ip']=$matches[3]; |
@@ -240,14 +241,12 @@ discard block |
||
| 240 | 241 | if ($ret_code===0 || $ret_code===false) |
| 241 | 242 | { |
| 242 | 243 | $this->logging->log('No match on trap data : '.$vars,WARN,''); |
| 243 | - } |
|
| 244 | - else |
|
| 244 | + } else |
|
| 245 | 245 | { |
| 246 | 246 | 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')) |
| 247 | 247 | { |
| 248 | 248 | $this->trapData['trap_oid']=$matches[2]; |
| 249 | - } |
|
| 250 | - else |
|
| 249 | + } else |
|
| 251 | 250 | { |
| 252 | 251 | $object= new stdClass; |
| 253 | 252 | $object->oid =$matches[1]; |
@@ -418,7 +417,9 @@ discard block |
||
| 418 | 417 | } |
| 419 | 418 | |
| 420 | 419 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 421 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 420 | + if ($inserted_id==false) { |
|
| 421 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 422 | + } |
|
| 422 | 423 | $this->trapId=$inserted_id; |
| 423 | 424 | break; |
| 424 | 425 | default: |
@@ -434,7 +435,9 @@ discard block |
||
| 434 | 435 | { |
| 435 | 436 | |
| 436 | 437 | // If action is ignore -> don't send t DB |
| 437 | - if ($this->trapToDb === false) return; |
|
| 438 | + if ($this->trapToDb === false) { |
|
| 439 | + return; |
|
| 440 | + } |
|
| 438 | 441 | |
| 439 | 442 | |
| 440 | 443 | $db_conn=$this->trapsDB->db_connect_trap(); |
@@ -491,7 +494,9 @@ discard block |
||
| 491 | 494 | } |
| 492 | 495 | |
| 493 | 496 | $inserted_id=$ret_code->fetch(PDO::FETCH_ASSOC)['LAST_INSERT_ID()']; |
| 494 | - if ($inserted_id==false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 497 | + if ($inserted_id==false) { |
|
| 498 | + throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 499 | + } |
|
| 495 | 500 | $this->trapId=$inserted_id; |
| 496 | 501 | break; |
| 497 | 502 | default: |
@@ -620,8 +625,7 @@ discard block |
||
| 620 | 625 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
| 621 | 626 | exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
| 622 | 627 | return true; |
| 623 | - } |
|
| 624 | - else |
|
| 628 | + } else |
|
| 625 | 629 | { |
| 626 | 630 | // Get perfdata if found |
| 627 | 631 | $matches=array(); |
@@ -629,8 +633,7 @@ discard block |
||
| 629 | 633 | { |
| 630 | 634 | $display=$matches[1]; |
| 631 | 635 | $perfdata=$matches[2]; |
| 632 | - } |
|
| 633 | - else |
|
| 636 | + } else |
|
| 634 | 637 | { |
| 635 | 638 | $perfdata=''; |
| 636 | 639 | } |
@@ -642,8 +645,7 @@ discard block |
||
| 642 | 645 | { |
| 643 | 646 | $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
| 644 | 647 | return false; |
| 645 | - } |
|
| 646 | - else |
|
| 648 | + } else |
|
| 647 | 649 | { |
| 648 | 650 | $this->logging->log( "Sent result : " .$retmessage,INFO ); |
| 649 | 651 | return true; |
@@ -742,20 +744,17 @@ discard block |
||
| 742 | 744 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
| 743 | 745 | { |
| 744 | 746 | $this->trapAction.='Error sending status : check cmd/API'; |
| 745 | - } |
|
| 746 | - else |
|
| 747 | + } else |
|
| 747 | 748 | { |
| 748 | 749 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 749 | 750 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 750 | 751 | } |
| 751 | - } |
|
| 752 | - else |
|
| 752 | + } else |
|
| 753 | 753 | { |
| 754 | 754 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 755 | 755 | } |
| 756 | 756 | $this->trapToDb=($action==-2)?false:true; |
| 757 | - } |
|
| 758 | - else |
|
| 757 | + } else |
|
| 759 | 758 | { |
| 760 | 759 | //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
| 761 | 760 | |
@@ -766,14 +765,12 @@ discard block |
||
| 766 | 765 | if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
| 767 | 766 | { |
| 768 | 767 | $this->trapAction.='Error sending status : check cmd/API'; |
| 769 | - } |
|
| 770 | - else |
|
| 768 | + } else |
|
| 771 | 769 | { |
| 772 | 770 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 773 | 771 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 774 | 772 | } |
| 775 | - } |
|
| 776 | - else |
|
| 773 | + } else |
|
| 777 | 774 | { |
| 778 | 775 | $this->add_rule_match($rule['id'],$rule['num_match']+1); |
| 779 | 776 | } |
@@ -783,16 +780,14 @@ discard block |
||
| 783 | 780 | if (!isset($this->trapData['source_name'])) |
| 784 | 781 | { |
| 785 | 782 | $this->trapData['source_name']=$rule['host_name']; |
| 786 | - } |
|
| 787 | - else |
|
| 783 | + } else |
|
| 788 | 784 | { |
| 789 | 785 | if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name'])) |
| 790 | 786 | { // only add if not present |
| 791 | 787 | $this->trapData['source_name'].=','.$rule['host_name']; |
| 792 | 788 | } |
| 793 | 789 | } |
| 794 | - } |
|
| 795 | - catch (Exception $e) |
|
| 790 | + } catch (Exception $e) |
|
| 796 | 791 | { |
| 797 | 792 | $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
| 798 | 793 | $this->trapAction.=' ERR : '.$e->getMessage(); |
@@ -803,8 +798,7 @@ discard block |
||
| 803 | 798 | if ($this->trapData['status']=='error') |
| 804 | 799 | { |
| 805 | 800 | $this->trapToDb=true; // Always put errors in DB for the use can see |
| 806 | - } |
|
| 807 | - else |
|
| 801 | + } else |
|
| 808 | 802 | { |
| 809 | 803 | $this->trapData['status']='done'; |
| 810 | 804 | } |
@@ -33,15 +33,13 @@ |
||
| 33 | 33 | |
| 34 | 34 | $trap->add_rule_final(microtime(true) - $time1); |
| 35 | 35 | |
| 36 | -} |
|
| 37 | -catch (Exception $e) |
|
| 36 | +} catch (Exception $e) |
|
| 38 | 37 | { |
| 39 | 38 | if ($trap == null) |
| 40 | 39 | { // Exception in trap creation : log in display & syslog |
| 41 | 40 | $logging = new Logging(); |
| 42 | 41 | $logging->log("Caught exception creating Trap class",2); |
| 43 | - } |
|
| 44 | - else |
|
| 42 | + } else |
|
| 45 | 43 | { |
| 46 | 44 | $trap->logging->log("Exception : ". $e->getMessage(),2,0); |
| 47 | 45 | } |
@@ -64,8 +64,7 @@ discard block |
||
| 64 | 64 | if ($pid == 1) |
| 65 | 65 | { |
| 66 | 66 | $trap->setLogging($logLevel,'display'); |
| 67 | - } |
|
| 68 | - else |
|
| 67 | + } else |
|
| 69 | 68 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
| 70 | 69 | if ($pid != 0) |
| 71 | 70 | { |
@@ -74,8 +73,7 @@ discard block |
||
| 74 | 73 | fclose($file); |
| 75 | 74 | echo "OK : process $pid in bckground"; |
| 76 | 75 | return 0; |
| 77 | - } |
|
| 78 | - else |
|
| 76 | + } else |
|
| 79 | 77 | { // son process : close all file descriptors and go to a new session |
| 80 | 78 | fclose($file); |
| 81 | 79 | // $sid = posix_setsid(); |
@@ -85,8 +83,7 @@ discard block |
||
| 85 | 83 | try |
| 86 | 84 | { |
| 87 | 85 | $trap->mibClass->update_mib_database(false,$forceCheck); |
| 88 | - } |
|
| 89 | - catch (Exception $e) |
|
| 86 | + } catch (Exception $e) |
|
| 90 | 87 | { |
| 91 | 88 | $trap->logging->log('Error in updating : ' . $e->getMessage(),2); |
| 92 | 89 | } |
@@ -103,8 +100,7 @@ discard block |
||
| 103 | 100 | $trap->mibClass->update_mib_database(true,$forceCheck); |
| 104 | 101 | echo "Done\n"; |
| 105 | 102 | |
| 106 | - } |
|
| 107 | - catch (Exception $e) |
|
| 103 | + } catch (Exception $e) |
|
| 108 | 104 | { |
| 109 | 105 | echo 'Error in updating : ' . $e->getMessage(); |
| 110 | 106 | } |
@@ -147,8 +143,7 @@ discard block |
||
| 147 | 143 | $Config->getMIBCacheTableName(), |
| 148 | 144 | 'id>0'); |
| 149 | 145 | echo 'Deleted '. $query . " traps and objects\n"; |
| 150 | - } |
|
| 151 | - catch (Exception $e) |
|
| 146 | + } catch (Exception $e) |
|
| 152 | 147 | { |
| 153 | 148 | echo 'Error in DB : ' . $e->getMessage(); |
| 154 | 149 | } |