@@ -15,183 +15,183 @@ |
||
| 15 | 15 | trait TrapConfig |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** @return \Trapdirector\Logging */ |
|
| 19 | - abstract public function getLogging(); |
|
| 20 | - /** @return \Trapdirector\TrapApi */ |
|
| 21 | - abstract public function getTrapApi(); |
|
| 18 | + /** @return \Trapdirector\Logging */ |
|
| 19 | + abstract public function getLogging(); |
|
| 20 | + /** @return \Trapdirector\TrapApi */ |
|
| 21 | + abstract public function getTrapApi(); |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Get option from array of ini file, send message if empty |
|
| 25 | - * @param string $option_array Array of ini file |
|
| 26 | - * @param string $option_category category in ini file |
|
| 27 | - * @param string $option_name name of option in category |
|
| 28 | - * @param mixed $option_var variable to fill if found, left untouched if not found |
|
| 29 | - * @param integer $log_level default 2 (warning) |
|
| 30 | - * @param string $message warning message if not found |
|
| 31 | - * @return boolean true if found, or false |
|
| 32 | - */ |
|
| 33 | - protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null) |
|
| 34 | - { |
|
| 35 | - if (!isset($option_array[$option_category][$option_name])) |
|
| 36 | - { |
|
| 37 | - if ($message === null) |
|
| 38 | - { |
|
| 39 | - $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig; |
|
| 40 | - } |
|
| 41 | - $this->getLogging()->log($message,$log_level); |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 44 | - else |
|
| 45 | - { |
|
| 46 | - $option_var=$option_array[$option_category][$option_name]; |
|
| 47 | - return true; |
|
| 48 | - } |
|
| 49 | - } |
|
| 23 | + /** |
|
| 24 | + * Get option from array of ini file, send message if empty |
|
| 25 | + * @param string $option_array Array of ini file |
|
| 26 | + * @param string $option_category category in ini file |
|
| 27 | + * @param string $option_name name of option in category |
|
| 28 | + * @param mixed $option_var variable to fill if found, left untouched if not found |
|
| 29 | + * @param integer $log_level default 2 (warning) |
|
| 30 | + * @param string $message warning message if not found |
|
| 31 | + * @return boolean true if found, or false |
|
| 32 | + */ |
|
| 33 | + protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null) |
|
| 34 | + { |
|
| 35 | + if (!isset($option_array[$option_category][$option_name])) |
|
| 36 | + { |
|
| 37 | + if ($message === null) |
|
| 38 | + { |
|
| 39 | + $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig; |
|
| 40 | + } |
|
| 41 | + $this->getLogging()->log($message,$log_level); |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | + else |
|
| 45 | + { |
|
| 46 | + $option_var=$option_array[$option_category][$option_name]; |
|
| 47 | + return true; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Get options in database |
|
| 53 | - */ |
|
| 54 | - protected function getDatabaseOptions() |
|
| 55 | - { |
|
| 56 | - // Database options |
|
| 57 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
| 58 | - { |
|
| 59 | - $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
|
| 60 | - $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
|
| 61 | - $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
|
| 62 | - } |
|
| 63 | - } |
|
| 51 | + /** |
|
| 52 | + * Get options in database |
|
| 53 | + */ |
|
| 54 | + protected function getDatabaseOptions() |
|
| 55 | + { |
|
| 56 | + // Database options |
|
| 57 | + if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
| 58 | + { |
|
| 59 | + $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
|
| 60 | + $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
|
| 61 | + $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** Set $variable to value if $element found in database config table |
|
| 66 | - * @param string $element |
|
| 67 | - * @param string $variable |
|
| 68 | - */ |
|
| 69 | - protected function getDBConfigIfSet($element,&$variable) |
|
| 70 | - { |
|
| 71 | - $value=$this->getDBConfig($element); |
|
| 72 | - if ($value != null) $variable=$value; |
|
| 73 | - } |
|
| 65 | + /** Set $variable to value if $element found in database config table |
|
| 66 | + * @param string $element |
|
| 67 | + * @param string $variable |
|
| 68 | + */ |
|
| 69 | + protected function getDBConfigIfSet($element,&$variable) |
|
| 70 | + { |
|
| 71 | + $value=$this->getDBConfig($element); |
|
| 72 | + if ($value != null) $variable=$value; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Get data from db_config |
|
| 77 | - * @param $element string name of param |
|
| 78 | - * @return mixed : value (or null) |
|
| 79 | - */ |
|
| 80 | - protected function getDBConfig($element) // TODO : put this in DB class |
|
| 81 | - { |
|
| 82 | - $db_conn=$this->trapsDB->db_connect_trap(); |
|
| 83 | - $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )'; |
|
| 84 | - if (($ret_code=$db_conn->query($sql)) === false) { |
|
| 85 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
| 86 | - return null; |
|
| 87 | - } |
|
| 88 | - $value=$ret_code->fetch(); |
|
| 89 | - if ($value != null && isset($value['value'])) |
|
| 90 | - { |
|
| 91 | - return $value['value']; |
|
| 92 | - } |
|
| 93 | - return null; |
|
| 94 | - } |
|
| 75 | + /** |
|
| 76 | + * Get data from db_config |
|
| 77 | + * @param $element string name of param |
|
| 78 | + * @return mixed : value (or null) |
|
| 79 | + */ |
|
| 80 | + protected function getDBConfig($element) // TODO : put this in DB class |
|
| 81 | + { |
|
| 82 | + $db_conn=$this->trapsDB->db_connect_trap(); |
|
| 83 | + $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )'; |
|
| 84 | + if (($ret_code=$db_conn->query($sql)) === false) { |
|
| 85 | + $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
| 86 | + return null; |
|
| 87 | + } |
|
| 88 | + $value=$ret_code->fetch(); |
|
| 89 | + if ($value != null && isset($value['value'])) |
|
| 90 | + { |
|
| 91 | + return $value['value']; |
|
| 92 | + } |
|
| 93 | + return null; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Get options from ini file |
|
| 98 | - * @param array $trap_config : ini file array |
|
| 99 | - */ |
|
| 100 | - protected function getMainOptions($trapConfig) |
|
| 101 | - { |
|
| 96 | + /** |
|
| 97 | + * Get options from ini file |
|
| 98 | + * @param array $trap_config : ini file array |
|
| 99 | + */ |
|
| 100 | + protected function getMainOptions($trapConfig) |
|
| 101 | + { |
|
| 102 | 102 | |
| 103 | - $nodeStatus=''; |
|
| 104 | - $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus); |
|
| 105 | - if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE) |
|
| 106 | - { |
|
| 107 | - $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
|
| 108 | - $this->getTrapApi()->setStatusMaster(); |
|
| 109 | - } |
|
| 110 | - else |
|
| 111 | - { |
|
| 112 | - if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
|
| 113 | - { |
|
| 114 | - // Get options to connect to API |
|
| 115 | - $IP = $port = $user = $pass = null; |
|
| 116 | - $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR); |
|
| 117 | - $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR); |
|
| 118 | - $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR); |
|
| 119 | - $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR); |
|
| 120 | - $this->getTrapApi()->setParams($IP, $port, $user, $pass); |
|
| 121 | - return; |
|
| 122 | - } |
|
| 123 | - } |
|
| 103 | + $nodeStatus=''; |
|
| 104 | + $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus); |
|
| 105 | + if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE) |
|
| 106 | + { |
|
| 107 | + $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
|
| 108 | + $this->getTrapApi()->setStatusMaster(); |
|
| 109 | + } |
|
| 110 | + else |
|
| 111 | + { |
|
| 112 | + if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
|
| 113 | + { |
|
| 114 | + // Get options to connect to API |
|
| 115 | + $IP = $port = $user = $pass = null; |
|
| 116 | + $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR); |
|
| 117 | + $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR); |
|
| 118 | + $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR); |
|
| 119 | + $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR); |
|
| 120 | + $this->getTrapApi()->setParams($IP, $port, $user, $pass); |
|
| 121 | + return; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - // Snmptranslate binary path |
|
| 126 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate); |
|
| 125 | + // Snmptranslate binary path |
|
| 126 | + $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate); |
|
| 127 | 127 | |
| 128 | - // mibs path |
|
| 129 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
| 128 | + // mibs path |
|
| 129 | + $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
| 130 | 130 | |
| 131 | - // icinga2cmd path |
|
| 132 | - $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd); |
|
| 131 | + // icinga2cmd path |
|
| 132 | + $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd); |
|
| 133 | 133 | |
| 134 | - // table prefix |
|
| 135 | - $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix); |
|
| 134 | + // table prefix |
|
| 135 | + $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix); |
|
| 136 | 136 | |
| 137 | - // API options |
|
| 138 | - if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname)) |
|
| 139 | - { |
|
| 140 | - $this->apiUse=true; |
|
| 141 | - // Get API options or throw exception as not configured correctly |
|
| 142 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR); |
|
| 143 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR); |
|
| 144 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR); |
|
| 145 | - } |
|
| 146 | - } |
|
| 137 | + // API options |
|
| 138 | + if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname)) |
|
| 139 | + { |
|
| 140 | + $this->apiUse=true; |
|
| 141 | + // Get API options or throw exception as not configured correctly |
|
| 142 | + $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR); |
|
| 143 | + $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR); |
|
| 144 | + $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Create and setup database class for trap & ido (if no api) db |
|
| 150 | - * @param array $trap_config : ini file array |
|
| 151 | - */ |
|
| 152 | - protected function setupDatabase($trapConfig) |
|
| 153 | - { |
|
| 154 | - // Trap database |
|
| 155 | - if (!array_key_exists('database',$trapConfig['config'])) |
|
| 156 | - { |
|
| 157 | - $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - $dbTrapName=$trapConfig['config']['database']; |
|
| 161 | - $this->logging->log("Found database in config file: ".$dbTrapName,INFO ); |
|
| 148 | + /** |
|
| 149 | + * Create and setup database class for trap & ido (if no api) db |
|
| 150 | + * @param array $trap_config : ini file array |
|
| 151 | + */ |
|
| 152 | + protected function setupDatabase($trapConfig) |
|
| 153 | + { |
|
| 154 | + // Trap database |
|
| 155 | + if (!array_key_exists('database',$trapConfig['config'])) |
|
| 156 | + { |
|
| 157 | + $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + $dbTrapName=$trapConfig['config']['database']; |
|
| 161 | + $this->logging->log("Found database in config file: ".$dbTrapName,INFO ); |
|
| 162 | 162 | |
| 163 | - if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false) |
|
| 164 | - { |
|
| 165 | - $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,''); |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - if (!array_key_exists($dbTrapName,$dbConfig)) |
|
| 169 | - { |
|
| 170 | - $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 171 | - return; |
|
| 172 | - } |
|
| 163 | + if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false) |
|
| 164 | + { |
|
| 165 | + $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,''); |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + if (!array_key_exists($dbTrapName,$dbConfig)) |
|
| 169 | + { |
|
| 170 | + $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 171 | + return; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
|
| 174 | + $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
|
| 175 | 175 | |
| 176 | - //TODO enable this again when API queries are all done : $this->logging->log("API Use : ".print_r($this->apiUse,true),INFO ); |
|
| 176 | + //TODO enable this again when API queries are all done : $this->logging->log("API Use : ".print_r($this->apiUse,true),INFO ); |
|
| 177 | 177 | |
| 178 | - if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
|
| 178 | + if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
|
| 179 | 179 | |
| 180 | - // IDO Database |
|
| 181 | - if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
| 182 | - { |
|
| 183 | - $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 184 | - } |
|
| 185 | - $dbIdoName=$trapConfig['config']['IDOdatabase']; |
|
| 180 | + // IDO Database |
|
| 181 | + if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
| 182 | + { |
|
| 183 | + $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 184 | + } |
|
| 185 | + $dbIdoName=$trapConfig['config']['IDOdatabase']; |
|
| 186 | 186 | |
| 187 | - $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
| 188 | - if (!array_key_exists($dbIdoName,$dbConfig)) |
|
| 189 | - { |
|
| 190 | - $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 191 | - return; |
|
| 192 | - } |
|
| 187 | + $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
| 188 | + if (!array_key_exists($dbIdoName,$dbConfig)) |
|
| 189 | + { |
|
| 190 | + $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - $this->trapsDB->setupIDO($dbConfig[$dbIdoName]); |
|
| 195 | - } |
|
| 194 | + $this->trapsDB->setupIDO($dbConfig[$dbIdoName]); |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | 197 | } |
| 198 | 198 | \ No newline at end of file |
@@ -30,15 +30,15 @@ discard block |
||
| 30 | 30 | * @param string $message warning message if not found |
| 31 | 31 | * @return boolean true if found, or false |
| 32 | 32 | */ |
| 33 | - protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = WARN, $message = null) |
|
| 33 | + protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=WARN, $message=null) |
|
| 34 | 34 | { |
| 35 | 35 | if (!isset($option_array[$option_category][$option_name])) |
| 36 | 36 | { |
| 37 | 37 | if ($message === null) |
| 38 | 38 | { |
| 39 | - $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig; |
|
| 39 | + $message='No '.$option_name.' in config file: '.$this->trapModuleConfig; |
|
| 40 | 40 | } |
| 41 | - $this->getLogging()->log($message,$log_level); |
|
| 41 | + $this->getLogging()->log($message, $log_level); |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | else |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | // Database options |
| 57 | 57 | if ($this->logSetup === false) // Only if logging was no setup in constructor |
| 58 | 58 | { |
| 59 | - $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
|
| 60 | - $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
|
| 61 | - $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
|
| 59 | + $this->getDBConfigIfSet('log_level', $this->getLogging()->debugLevel); |
|
| 60 | + $this->getDBConfigIfSet('log_destination', $this->getLogging()->outputMode); |
|
| 61 | + $this->getDBConfigIfSet('log_file', $this->getLogging()->outputFile); |
|
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @param string $element |
| 67 | 67 | * @param string $variable |
| 68 | 68 | */ |
| 69 | - protected function getDBConfigIfSet($element,&$variable) |
|
| 69 | + protected function getDBConfigIfSet($element, &$variable) |
|
| 70 | 70 | { |
| 71 | 71 | $value=$this->getDBConfig($element); |
| 72 | 72 | if ($value != null) $variable=$value; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 83 | 83 | $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )'; |
| 84 | 84 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 85 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
| 85 | + $this->logging->log('No result in query : '.$sql, WARN, ''); |
|
| 86 | 86 | return null; |
| 87 | 87 | } |
| 88 | 88 | $value=$ret_code->fetch(); |
@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | { |
| 102 | 102 | |
| 103 | 103 | $nodeStatus=''; |
| 104 | - $this->getOptionIfSet($trapConfig,'config','node', $nodeStatus); |
|
| 104 | + $this->getOptionIfSet($trapConfig, 'config', 'node', $nodeStatus); |
|
| 105 | 105 | if ($this->getTrapApi()->setStatus($nodeStatus) === FALSE) |
| 106 | 106 | { |
| 107 | - $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
|
| 107 | + $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER', WARN); |
|
| 108 | 108 | $this->getTrapApi()->setStatusMaster(); |
| 109 | 109 | } |
| 110 | 110 | else |
@@ -112,36 +112,36 @@ discard block |
||
| 112 | 112 | if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
| 113 | 113 | { |
| 114 | 114 | // Get options to connect to API |
| 115 | - $IP = $port = $user = $pass = null; |
|
| 116 | - $this->getOptionIfSet($trapConfig,'config','masterIP', $IP, ERROR); |
|
| 117 | - $this->getOptionIfSet($trapConfig,'config','masterPort', $port, ERROR); |
|
| 118 | - $this->getOptionIfSet($trapConfig,'config','masterUser', $user, ERROR); |
|
| 119 | - $this->getOptionIfSet($trapConfig,'config','masterPass', $pass, ERROR); |
|
| 115 | + $IP=$port=$user=$pass=null; |
|
| 116 | + $this->getOptionIfSet($trapConfig, 'config', 'masterIP', $IP, ERROR); |
|
| 117 | + $this->getOptionIfSet($trapConfig, 'config', 'masterPort', $port, ERROR); |
|
| 118 | + $this->getOptionIfSet($trapConfig, 'config', 'masterUser', $user, ERROR); |
|
| 119 | + $this->getOptionIfSet($trapConfig, 'config', 'masterPass', $pass, ERROR); |
|
| 120 | 120 | $this->getTrapApi()->setParams($IP, $port, $user, $pass); |
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Snmptranslate binary path |
| 126 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate); |
|
| 126 | + $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate); |
|
| 127 | 127 | |
| 128 | 128 | // mibs path |
| 129 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
| 129 | + $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs); |
|
| 130 | 130 | |
| 131 | 131 | // icinga2cmd path |
| 132 | - $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd); |
|
| 132 | + $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd); |
|
| 133 | 133 | |
| 134 | 134 | // table prefix |
| 135 | - $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix); |
|
| 135 | + $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix); |
|
| 136 | 136 | |
| 137 | 137 | // API options |
| 138 | - if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname)) |
|
| 138 | + if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname)) |
|
| 139 | 139 | { |
| 140 | 140 | $this->apiUse=true; |
| 141 | 141 | // Get API options or throw exception as not configured correctly |
| 142 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort,ERROR); |
|
| 143 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername,ERROR); |
|
| 144 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword,ERROR); |
|
| 142 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort, ERROR); |
|
| 143 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername, ERROR); |
|
| 144 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword, ERROR); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | |
@@ -152,42 +152,42 @@ discard block |
||
| 152 | 152 | protected function setupDatabase($trapConfig) |
| 153 | 153 | { |
| 154 | 154 | // Trap database |
| 155 | - if (!array_key_exists('database',$trapConfig['config'])) |
|
| 155 | + if (!array_key_exists('database', $trapConfig['config'])) |
|
| 156 | 156 | { |
| 157 | - $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 157 | + $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, ''); |
|
| 158 | 158 | return; |
| 159 | 159 | } |
| 160 | 160 | $dbTrapName=$trapConfig['config']['database']; |
| 161 | - $this->logging->log("Found database in config file: ".$dbTrapName,INFO ); |
|
| 161 | + $this->logging->log("Found database in config file: ".$dbTrapName, INFO); |
|
| 162 | 162 | |
| 163 | - if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false) |
|
| 163 | + if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false) |
|
| 164 | 164 | { |
| 165 | - $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,''); |
|
| 165 | + $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, ''); |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | - if (!array_key_exists($dbTrapName,$dbConfig)) |
|
| 168 | + if (!array_key_exists($dbTrapName, $dbConfig)) |
|
| 169 | 169 | { |
| 170 | - $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 170 | + $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, ''); |
|
| 171 | 171 | return; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
|
| 174 | + $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix); |
|
| 175 | 175 | |
| 176 | 176 | //TODO enable this again when API queries are all done : $this->logging->log("API Use : ".print_r($this->apiUse,true),INFO ); |
| 177 | 177 | |
| 178 | 178 | if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
| 179 | 179 | |
| 180 | 180 | // IDO Database |
| 181 | - if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
| 181 | + if (!array_key_exists('IDOdatabase', $trapConfig['config'])) |
|
| 182 | 182 | { |
| 183 | - $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 183 | + $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, ''); |
|
| 184 | 184 | } |
| 185 | 185 | $dbIdoName=$trapConfig['config']['IDOdatabase']; |
| 186 | 186 | |
| 187 | - $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
| 188 | - if (!array_key_exists($dbIdoName,$dbConfig)) |
|
| 187 | + $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO); |
|
| 188 | + if (!array_key_exists($dbIdoName, $dbConfig)) |
|
| 189 | 189 | { |
| 190 | - $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 190 | + $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, ''); |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
@@ -40,8 +40,7 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | $this->getLogging()->log($message,$log_level); |
| 42 | 42 | return false; |
| 43 | - } |
|
| 44 | - else |
|
| 43 | + } else |
|
| 45 | 44 | { |
| 46 | 45 | $option_var=$option_array[$option_category][$option_name]; |
| 47 | 46 | return true; |
@@ -54,9 +53,11 @@ discard block |
||
| 54 | 53 | protected function getDatabaseOptions() |
| 55 | 54 | { |
| 56 | 55 | // Database options |
| 57 | - if ($this->logSetup === false) // Only if logging was no setup in constructor |
|
| 56 | + if ($this->logSetup === false) { |
|
| 57 | + // Only if logging was no setup in constructor |
|
| 58 | 58 | { |
| 59 | 59 | $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
| 60 | + } |
|
| 60 | 61 | $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
| 61 | 62 | $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
| 62 | 63 | } |
@@ -69,7 +70,9 @@ discard block |
||
| 69 | 70 | protected function getDBConfigIfSet($element,&$variable) |
| 70 | 71 | { |
| 71 | 72 | $value=$this->getDBConfig($element); |
| 72 | - if ($value != null) $variable=$value; |
|
| 73 | + if ($value != null) { |
|
| 74 | + $variable=$value; |
|
| 75 | + } |
|
| 73 | 76 | } |
| 74 | 77 | |
| 75 | 78 | /** |
@@ -106,8 +109,7 @@ discard block |
||
| 106 | 109 | { |
| 107 | 110 | $this->getLogging()->log('Unknown node status '.$nodeStatus.' : setting to MASTER',WARN); |
| 108 | 111 | $this->getTrapApi()->setStatusMaster(); |
| 109 | - } |
|
| 110 | - else |
|
| 112 | + } else |
|
| 111 | 113 | { |
| 112 | 114 | if ($this->getTrapApi()->getStatus() != TrapApi::MASTER) |
| 113 | 115 | { |
@@ -175,7 +177,10 @@ discard block |
||
| 175 | 177 | |
| 176 | 178 | //TODO enable this again when API queries are all done : $this->logging->log("API Use : ".print_r($this->apiUse,true),INFO ); |
| 177 | 179 | |
| 178 | - if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
|
| 180 | + if ($this->apiUse === true) { |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | + // In case of API use, no IDO is necessary |
|
| 179 | 184 | |
| 180 | 185 | // IDO Database |
| 181 | 186 | if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |