@@ -16,27 +16,27 @@ discard block |
||
| 16 | 16 | 'SnmpTrapAddess_oid' => '.1.3.6.1.6.3.18.1.3', // default snmpTrapAdress OID |
| 17 | 17 | ); |
| 18 | 18 | // get default values for dbconfig |
| 19 | - public function getDBConfigDefaults() { return $this->DBConfigDefaults;} |
|
| 19 | + public function getDBConfigDefaults() { return $this->DBConfigDefaults; } |
|
| 20 | 20 | /** Minimum DB version |
| 21 | 21 | * @return number |
| 22 | 22 | */ |
| 23 | - static public function getDbMinVersion() { return 2;} |
|
| 23 | + static public function getDbMinVersion() { return 2; } |
|
| 24 | 24 | /** Current DB version |
| 25 | 25 | * @return number |
| 26 | 26 | */ |
| 27 | - static public function getDbCurVersion() { return 2;} |
|
| 27 | + static public function getDbCurVersion() { return 2; } |
|
| 28 | 28 | |
| 29 | 29 | /************ Module configuration **********************/ |
| 30 | 30 | // Module base path |
| 31 | 31 | static public function urlPath() { return 'trapdirector'; } |
| 32 | - static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service" , "actions/process-check-result"); } //< api user permissions required |
|
| 32 | + static public function getapiUserPermissions() { return array("status", "objects/query/Host", "objects/query/Service", "actions/process-check-result"); } //< api user permissions required |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | /*********** Log configuration *************************/ |
| 36 | 36 | protected $logLevels=array(0=>'No output', 1=>'critical', 2=>'warning', 3=>'trace', 4=>'ALL'); |
| 37 | - public function getlogLevels() { return $this->logLevels;} |
|
| 38 | - protected $logDestinations=array('syslog'=>'syslog','file'=>'file','display'=>'display'); |
|
| 39 | - public function getLogDestinations() { return $this->logDestinations;} |
|
| 37 | + public function getlogLevels() { return $this->logLevels; } |
|
| 38 | + protected $logDestinations=array('syslog'=>'syslog', 'file'=>'file', 'display'=>'display'); |
|
| 39 | + public function getLogDestinations() { return $this->logDestinations; } |
|
| 40 | 40 | |
| 41 | 41 | function __construct($prefix) |
| 42 | 42 | { |
@@ -47,29 +47,29 @@ discard block |
||
| 47 | 47 | // DB table name of trap received list : prefix 't' |
| 48 | 48 | public function getTrapTableName() |
| 49 | 49 | { |
| 50 | - return array('t' => $this->table_prefix . 'received'); |
|
| 50 | + return array('t' => $this->table_prefix.'received'); |
|
| 51 | 51 | } |
| 52 | 52 | // DB table name of trap data list : prefix 'd' |
| 53 | 53 | public function getTrapDataTableName() |
| 54 | 54 | { |
| 55 | - return array('d' => $this->table_prefix . 'received_data'); |
|
| 55 | + return array('d' => $this->table_prefix.'received_data'); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // DB table name of rules : prefix 'r' |
| 59 | 59 | public function getTrapRuleName() |
| 60 | 60 | { |
| 61 | - return array('r' => $this->table_prefix . 'rules'); |
|
| 61 | + return array('r' => $this->table_prefix.'rules'); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | // DB table name of db config : prefix 'c' |
| 65 | 65 | public function getDbConfigTableName() |
| 66 | 66 | { |
| 67 | - return array('c' => $this->table_prefix . 'db_config'); |
|
| 67 | + return array('c' => $this->table_prefix.'db_config'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Mib cache tables |
| 71 | - public function getMIBCacheTableName() { return $this->table_prefix . 'mib_cache'; } |
|
| 72 | - public function getMIBCacheTableTrapObjName() { return $this->table_prefix . 'mib_cache_trap_object'; } |
|
| 71 | + public function getMIBCacheTableName() { return $this->table_prefix.'mib_cache'; } |
|
| 72 | + public function getMIBCacheTableTrapObjName() { return $this->table_prefix.'mib_cache_trap_object'; } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | 75 | /****************** Database queries *******************/ |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | public function getHandlerListDisplayColumns() |
| 151 | 151 | { |
| 152 | 152 | return array( |
| 153 | - 'host_name' => 'r.host_name',//'UNIX_TIMESTAMP(t.date_received)', |
|
| 153 | + 'host_name' => 'r.host_name', //'UNIX_TIMESTAMP(t.date_received)', |
|
| 154 | 154 | 'host_group_name'=> 'r.host_group_name', |
| 155 | 155 | 'source_ip' => "CASE WHEN r.ip4 IS NULL THEN r.ip6 ELSE r.ip4 END", |
| 156 | 156 | 'trap_oid' => 'r.trap_oid', |
@@ -203,32 +203,32 @@ discard block |
||
| 203 | 203 | public function trapDetailQuery() |
| 204 | 204 | { |
| 205 | 205 | return array( |
| 206 | - 'timestamp' => array('Date','UNIX_TIMESTAMP(t.date_received)'), |
|
| 207 | - 'source_ip' => array('Source IP','t.source_ip'), |
|
| 208 | - 'source_name' => array('Source name','t.source_name'), |
|
| 209 | - 'source_port' => array('Source port','t.source_port'), |
|
| 210 | - 'destination_ip' => array('Destination IP','t.destination_ip'), |
|
| 211 | - 'destination_port' => array('Destination port','t.destination_port'), |
|
| 212 | - 'trap_oid' => array('Numeric OID','t.trap_oid'), |
|
| 213 | - 'trap_name' => array('Trap name','t.trap_name'), |
|
| 214 | - 'trap_name_mib' => array('Trap MIB','t.trap_name_mib'), |
|
| 215 | - 'status' => array('Processing status','t.status'), |
|
| 216 | - 'status_detail' => array('Status details','t.status_detail'), |
|
| 217 | - 'process_time' => array('Trap processing time','t.process_time'), |
|
| 206 | + 'timestamp' => array('Date', 'UNIX_TIMESTAMP(t.date_received)'), |
|
| 207 | + 'source_ip' => array('Source IP', 't.source_ip'), |
|
| 208 | + 'source_name' => array('Source name', 't.source_name'), |
|
| 209 | + 'source_port' => array('Source port', 't.source_port'), |
|
| 210 | + 'destination_ip' => array('Destination IP', 't.destination_ip'), |
|
| 211 | + 'destination_port' => array('Destination port', 't.destination_port'), |
|
| 212 | + 'trap_oid' => array('Numeric OID', 't.trap_oid'), |
|
| 213 | + 'trap_name' => array('Trap name', 't.trap_name'), |
|
| 214 | + 'trap_name_mib' => array('Trap MIB', 't.trap_name_mib'), |
|
| 215 | + 'status' => array('Processing status', 't.status'), |
|
| 216 | + 'status_detail' => array('Status details', 't.status_detail'), |
|
| 217 | + 'process_time' => array('Trap processing time', 't.process_time'), |
|
| 218 | 218 | ); |
| 219 | 219 | } |
| 220 | 220 | // Trap detail : additional data (<key> => <title> <sql select>) |
| 221 | 221 | public function trapDataDetailQuery() |
| 222 | 222 | { |
| 223 | 223 | return array( |
| 224 | - 'oid' => array('Numeric OID','d.oid'), |
|
| 225 | - 'oid_name' => array('Text OID','d.oid_name'), |
|
| 226 | - 'oid_name_mib' => array('MIB','d.oid_name_mib'), |
|
| 227 | - 'value' => array('Value','d.value'), |
|
| 224 | + 'oid' => array('Numeric OID', 'd.oid'), |
|
| 225 | + 'oid_name' => array('Text OID', 'd.oid_name'), |
|
| 226 | + 'oid_name_mib' => array('MIB', 'd.oid_name_mib'), |
|
| 227 | + 'value' => array('Value', 'd.value'), |
|
| 228 | 228 | ); |
| 229 | 229 | } |
| 230 | 230 | // foreign key of trap data table |
| 231 | - public function trapDataFK() { return 'trap_id';} |
|
| 231 | + public function trapDataFK() { return 'trap_id'; } |
|
| 232 | 232 | |
| 233 | 233 | // Max items in a list |
| 234 | 234 | public function itemListDisplay() { return 25; } |
@@ -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,43 +152,43 @@ 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 | - $this->logging->log("API Use : ".print_r($this->apiUse,true),DEBUG ); |
|
| 176 | + $this->logging->log("API Use : ".print_r($this->apiUse, true), DEBUG); |
|
| 177 | 177 | |
| 178 | 178 | //TODO enable this again when API queries are all done : |
| 179 | 179 | //if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
| 180 | 180 | |
| 181 | 181 | // IDO Database |
| 182 | - if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
| 182 | + if (!array_key_exists('IDOdatabase', $trapConfig['config'])) |
|
| 183 | 183 | { |
| 184 | - $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 184 | + $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, ''); |
|
| 185 | 185 | } |
| 186 | 186 | $dbIdoName=$trapConfig['config']['IDOdatabase']; |
| 187 | 187 | |
| 188 | - $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
| 189 | - if (!array_key_exists($dbIdoName,$dbConfig)) |
|
| 188 | + $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO); |
|
| 189 | + if (!array_key_exists($dbIdoName, $dbConfig)) |
|
| 190 | 190 | { |
| 191 | - $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 191 | + $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, ''); |
|
| 192 | 192 | return; |
| 193 | 193 | } |
| 194 | 194 | |
@@ -21,19 +21,19 @@ discard block |
||
| 21 | 21 | /************ Trapdb ***********/ |
| 22 | 22 | try |
| 23 | 23 | { |
| 24 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
| 24 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
| 25 | 25 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
| 26 | - $query = $dbConn->select()->from( |
|
| 26 | + $query=$dbConn->select()->from( |
|
| 27 | 27 | $this->getModuleConfig()->getTrapTableName(), |
| 28 | 28 | array('COUNT(*)') |
| 29 | 29 | ); |
| 30 | 30 | $this->view->trap_count=$dbConn->fetchOne($query); |
| 31 | - $query = $dbConn->select()->from( |
|
| 31 | + $query=$dbConn->select()->from( |
|
| 32 | 32 | $this->getModuleConfig()->getTrapDataTableName(), |
| 33 | 33 | array('COUNT(*)') |
| 34 | 34 | ); |
| 35 | 35 | $this->view->trap_object_count=$dbConn->fetchOne($query); |
| 36 | - $query = $dbConn->select()->from( |
|
| 36 | + $query=$dbConn->select()->from( |
|
| 37 | 37 | $this->getModuleConfig()->getTrapRuleName(), |
| 38 | 38 | array('COUNT(*)') |
| 39 | 39 | ); |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | catch (Exception $e) |
| 46 | 46 | { |
| 47 | - $this->displayExitError('status',$e->getMessage()); |
|
| 47 | + $this->displayExitError('status', $e->getMessage()); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /*************** Log destination *******************/ |
@@ -59,20 +59,20 @@ discard block |
||
| 59 | 59 | } |
| 60 | 60 | catch (Exception $e) |
| 61 | 61 | { |
| 62 | - $this->displayExitError('status',$e->getMessage()); |
|
| 62 | + $this->displayExitError('status', $e->getMessage()); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /*************** SNMP configuration ****************/ |
| 66 | 66 | try |
| 67 | 67 | { |
| 68 | - $this->view->useSnmpTrapAddess= ( $this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1 ) ? TRUE : FALSE; |
|
| 68 | + $this->view->useSnmpTrapAddess=($this->getUIDatabase()->getDBConfigValue('use_SnmpTrapAddess') == 1) ? TRUE : FALSE; |
|
| 69 | 69 | $this->view->SnmpTrapAddressOID=$this->getUIDatabase()->getDBConfigValue('SnmpTrapAddess_oid'); |
| 70 | - $this->view->SnmpTrapAddressOIDDefault = ($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid'] ) ? TRUE : FALSE; |
|
| 70 | + $this->view->SnmpTrapAddressOIDDefault=($this->view->SnmpTrapAddressOID == $this->getModuleConfig()->getDBConfigDefaults()['SnmpTrapAddess_oid']) ? TRUE : FALSE; |
|
| 71 | 71 | |
| 72 | 72 | } |
| 73 | 73 | catch (Exception $e) |
| 74 | 74 | { |
| 75 | - $this->displayExitError('status',$e->getMessage()); |
|
| 75 | + $this->displayExitError('status', $e->getMessage()); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | } |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | if ($action == 'update_mib_db') |
| 99 | 99 | { // Do the update in background |
| 100 | 100 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
| 101 | - if (preg_match('/OK/',$return)) |
|
| 101 | + if (preg_match('/OK/', $return)) |
|
| 102 | 102 | { |
| 103 | 103 | $this->_helper->json(array('status'=>'OK')); |
| 104 | 104 | } |
@@ -107,32 +107,32 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | if ($action == 'check_update') |
| 109 | 109 | { |
| 110 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
| 110 | + $file=@fopen('/tmp/trapdirector_update.pid', 'r'); |
|
| 111 | 111 | if ($file == false) |
| 112 | 112 | { // process is dead |
| 113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
| 113 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'Cannot open file')); |
|
| 114 | 114 | return; |
| 115 | 115 | } |
| 116 | 116 | $pid=fgets($file); |
| 117 | 117 | $output=array(); |
| 118 | 118 | $retVal=0; |
| 119 | - exec('ps '.$pid,$output,$retVal); |
|
| 119 | + exec('ps '.$pid, $output, $retVal); |
|
| 120 | 120 | if ($retVal == 0) |
| 121 | 121 | { // process is alive |
| 122 | 122 | $this->_helper->json(array('status'=>'Alive and kicking')); |
| 123 | 123 | } |
| 124 | 124 | else |
| 125 | 125 | { // process is dead |
| 126 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
| 126 | + $this->_helper->json(array('status'=>'tu quoque fili', 'err'=>'no proc'.$pid)); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | - $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
|
| 129 | + $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible')); |
|
| 130 | 130 | } |
| 131 | 131 | /** Check for mib file UPLOAD */ |
| 132 | 132 | if (isset($_FILES['mibfile'])) |
| 133 | 133 | { |
| 134 | - $name=filter_var($_FILES['mibfile']['name'],FILTER_SANITIZE_STRING); |
|
| 135 | - $DirConf=explode(':',$this->Config()->get('config', 'snmptranslate_dirs')); |
|
| 134 | + $name=filter_var($_FILES['mibfile']['name'], FILTER_SANITIZE_STRING); |
|
| 135 | + $DirConf=explode(':', $this->Config()->get('config', 'snmptranslate_dirs')); |
|
| 136 | 136 | $destDir=array_shift($DirConf); |
| 137 | 137 | if (!is_dir($destDir)) |
| 138 | 138 | { |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | else |
| 148 | 148 | { |
| 149 | - $destination = $destDir .'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
| 150 | - $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'],FILTER_SANITIZE_STRING); |
|
| 151 | - if (move_uploaded_file($sourceTmpNam,$destination)===false) |
|
| 149 | + $destination=$destDir.'/'.$name; //$this->Module()->getBaseDir() . "/mibs/$name"; |
|
| 150 | + $sourceTmpNam=filter_var($_FILES['mibfile']['tmp_name'], FILTER_SANITIZE_STRING); |
|
| 151 | + if (move_uploaded_file($sourceTmpNam, $destination) === false) |
|
| 152 | 152 | { |
| 153 | 153 | $this->view->uploadStatus="ERROR, file $destination not loaded. Check file and path name or selinux violations"; |
| 154 | 154 | } |
@@ -164,13 +164,13 @@ discard block |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // snmptranslate tests |
| 167 | - $snmptranslate = $this->Config()->get('config', 'snmptranslate'); |
|
| 167 | + $snmptranslate=$this->Config()->get('config', 'snmptranslate'); |
|
| 168 | 168 | $this->view->snmptranslate_bin=$snmptranslate; |
| 169 | 169 | $this->view->snmptranslate_state='warn'; |
| 170 | - if (is_executable ( $snmptranslate )) |
|
| 170 | + if (is_executable($snmptranslate)) |
|
| 171 | 171 | { |
| 172 | - $translate=exec($snmptranslate . ' 1'); |
|
| 173 | - if (preg_match('/iso/',$translate)) |
|
| 172 | + $translate=exec($snmptranslate.' 1'); |
|
| 173 | + if (preg_match('/iso/', $translate)) |
|
| 174 | 174 | { |
| 175 | 175 | $this->view->snmptranslate='works fine'; |
| 176 | 176 | $this->view->snmptranslate_state='ok'; |
@@ -188,46 +188,46 @@ discard block |
||
| 188 | 188 | // mib database |
| 189 | 189 | |
| 190 | 190 | $this->view->mibDbCount=$this->getMIB()->countObjects(); |
| 191 | - $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null,21); |
|
| 191 | + $this->view->mibDbCountTrap=$this->getMIB()->countObjects(null, 21); |
|
| 192 | 192 | |
| 193 | 193 | // mib dirs |
| 194 | 194 | $DirConf=$this->Config()->get('config', 'snmptranslate_dirs'); |
| 195 | - $dirArray=explode(':',$DirConf); |
|
| 195 | + $dirArray=explode(':', $DirConf); |
|
| 196 | 196 | |
| 197 | 197 | // Get base directories from net-snmp-config |
| 198 | 198 | $output=$matches=array(); |
| 199 | 199 | $retVal=0; |
| 200 | - $sysDirs=exec('net-snmp-config --default-mibdirs',$output,$retVal); |
|
| 201 | - if ($retVal==0) |
|
| 200 | + $sysDirs=exec('net-snmp-config --default-mibdirs', $output, $retVal); |
|
| 201 | + if ($retVal == 0) |
|
| 202 | 202 | { |
| 203 | - $dirArray=array_merge($dirArray,explode(':',$sysDirs)); |
|
| 203 | + $dirArray=array_merge($dirArray, explode(':', $sysDirs)); |
|
| 204 | 204 | } |
| 205 | 205 | else |
| 206 | 206 | { |
| 207 | - $translateOut=exec($this->Config()->get('config', 'snmptranslate') . ' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
| 208 | - if (preg_match('/MIBDIRS.*\'([^\']+)\'/',$translateOut,$matches)) |
|
| 207 | + $translateOut=exec($this->Config()->get('config', 'snmptranslate').' -Dinit_mib .1.3 2>&1 | grep MIBDIRS'); |
|
| 208 | + if (preg_match('/MIBDIRS.*\'([^\']+)\'/', $translateOut, $matches)) |
|
| 209 | 209 | { |
| 210 | - $dirArray=array_merge($dirArray,explode(':',$matches[1])); |
|
| 210 | + $dirArray=array_merge($dirArray, explode(':', $matches[1])); |
|
| 211 | 211 | } |
| 212 | 212 | else |
| 213 | 213 | { |
| 214 | - array_push($dirArray,'Install net-snmp-config to see system directories'); |
|
| 214 | + array_push($dirArray, 'Install net-snmp-config to see system directories'); |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | $this->view->dirArray=$dirArray; |
| 219 | 219 | |
| 220 | 220 | $output=null; |
| 221 | - foreach (explode(':',$DirConf) as $mibdir) |
|
| 221 | + foreach (explode(':', $DirConf) as $mibdir) |
|
| 222 | 222 | { |
| 223 | - exec('ls '.$mibdir.' | grep -v traplist.txt',$output); |
|
| 223 | + exec('ls '.$mibdir.' | grep -v traplist.txt', $output); |
|
| 224 | 224 | } |
| 225 | 225 | //$i=0;$listFiles='';while (isset($output[$i])) $listFiles.=$output[$i++]; |
| 226 | 226 | //$this->view->fileList=explode(' ',$listFiles); |
| 227 | 227 | $this->view->fileList=$output; |
| 228 | 228 | |
| 229 | 229 | // Zend form |
| 230 | - $this->view->form= new UploadForm(); |
|
| 230 | + $this->view->form=new UploadForm(); |
|
| 231 | 231 | //$this->view->form= new Form('upload-form'); |
| 232 | 232 | |
| 233 | 233 | |
@@ -251,18 +251,18 @@ discard block |
||
| 251 | 251 | $this->view->templateForm_output=''; |
| 252 | 252 | if (isset($postData['template_name']) && isset($postData['template_revert_time'])) |
| 253 | 253 | { |
| 254 | - $template_create = 'icingacli director service create --json \'{ "check_command": "dummy", '; |
|
| 255 | - $template_create .= '"check_interval": "' .$postData['template_revert_time']. '", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", '; |
|
| 256 | - $template_create .= '"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
| 254 | + $template_create='icingacli director service create --json \'{ "check_command": "dummy", '; |
|
| 255 | + $template_create.='"check_interval": "'.$postData['template_revert_time'].'", "check_timeout": "20", "disabled": false, "enable_active_checks": true, "enable_event_handler": true, "enable_notifications": true, "enable_passive_checks": true, "enable_perfdata": true, "max_check_attempts": "1", '; |
|
| 256 | + $template_create.='"object_name": "'.$postData['template_name'].'", "object_type": "template", "retry_interval": "'.$postData['template_revert_time'].'"}\''; |
|
| 257 | 257 | $output=array(); |
| 258 | 258 | $ret_code=0; |
| 259 | - exec($template_create,$output,$ret_code); |
|
| 259 | + exec($template_create, $output, $ret_code); |
|
| 260 | 260 | if ($ret_code != 0) |
| 261 | 261 | { |
| 262 | - $this->displayExitError("Status -> Services","Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
| 262 | + $this->displayExitError("Status -> Services", "Error creating template : ".$output[0].'<br>Command was : '.$template_create); |
|
| 263 | 263 | } |
| 264 | - exec('icingacli director config deploy',$output,$ret_code); |
|
| 265 | - $this->view->templateForm_output='Template '.$postData['template_name']. ' created'; |
|
| 264 | + exec('icingacli director config deploy', $output, $ret_code); |
|
| 265 | + $this->view->templateForm_output='Template '.$postData['template_name'].' created'; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | // template creation form |
@@ -278,15 +278,15 @@ discard block |
||
| 278 | 278 | { |
| 279 | 279 | $this->prepareTabs()->activate('plugins'); |
| 280 | 280 | |
| 281 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 281 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 282 | 282 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 283 | - $Trap = new Trap($icingaweb2_etc,4); |
|
| 283 | + $Trap=new Trap($icingaweb2_etc, 4); |
|
| 284 | 284 | |
| 285 | - $this->view->pluginLoaded = htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
| 285 | + $this->view->pluginLoaded=htmlentities($Trap->pluginClass->registerAllPlugins(false)); |
|
| 286 | 286 | |
| 287 | - $enabledPlugins = $Trap->pluginClass->getEnabledPlugins(); |
|
| 287 | + $enabledPlugins=$Trap->pluginClass->getEnabledPlugins(); |
|
| 288 | 288 | |
| 289 | - $pluginList = $Trap->pluginClass->pluginList(); |
|
| 289 | + $pluginList=$Trap->pluginClass->pluginList(); |
|
| 290 | 290 | |
| 291 | 291 | // Plugin list and fill function name list |
| 292 | 292 | $functionList=array(); |
@@ -294,16 +294,16 @@ discard block |
||
| 294 | 294 | foreach ($pluginList as $plugin) |
| 295 | 295 | { |
| 296 | 296 | $pluginDetails=$Trap->pluginClass->pluginDetails($plugin); |
| 297 | - $pluginDetails->enabled = (in_array($plugin, $enabledPlugins)) ? true : false; |
|
| 298 | - $pluginDetails->catchAllTraps = ($pluginDetails->catchAllTraps === true )? 'Yes' : 'No'; |
|
| 299 | - $pluginDetails->processTraps = ($pluginDetails->processTraps === true )? 'Yes' : 'No'; |
|
| 300 | - $pluginDetails->description = htmlentities($pluginDetails->description); |
|
| 301 | - $pluginDetails->description = preg_replace('/\n/','<br>',$pluginDetails->description); |
|
| 297 | + $pluginDetails->enabled=(in_array($plugin, $enabledPlugins)) ? true : false; |
|
| 298 | + $pluginDetails->catchAllTraps=($pluginDetails->catchAllTraps === true) ? 'Yes' : 'No'; |
|
| 299 | + $pluginDetails->processTraps=($pluginDetails->processTraps === true) ? 'Yes' : 'No'; |
|
| 300 | + $pluginDetails->description=htmlentities($pluginDetails->description); |
|
| 301 | + $pluginDetails->description=preg_replace('/\n/', '<br>', $pluginDetails->description); |
|
| 302 | 302 | array_push($this->view->pluginArray, $pluginDetails); |
| 303 | 303 | // Get functions for function details |
| 304 | 304 | foreach ($pluginDetails->funcArray as $function) |
| 305 | 305 | { |
| 306 | - array_push($functionList,$function); |
|
| 306 | + array_push($functionList, $function); |
|
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | $this->view->functionList=array(); |
| 312 | 312 | foreach ($functionList as $function) |
| 313 | 313 | { |
| 314 | - $functionDetail = $Trap->pluginClass->getFunctionDetails($function); |
|
| 315 | - $functionDetail->params = htmlentities($functionDetail->params); |
|
| 316 | - $functionDetail->description = htmlentities($functionDetail->description); |
|
| 317 | - $functionDetail->description = preg_replace('/\n/','<br>',$functionDetail->description); |
|
| 314 | + $functionDetail=$Trap->pluginClass->getFunctionDetails($function); |
|
| 315 | + $functionDetail->params=htmlentities($functionDetail->params); |
|
| 316 | + $functionDetail->description=htmlentities($functionDetail->description); |
|
| 317 | + $functionDetail->description=preg_replace('/\n/', '<br>', $functionDetail->description); |
|
| 318 | 318 | array_push($this->view->functionList, $functionDetail); |
| 319 | 319 | } |
| 320 | 320 | |
@@ -324,16 +324,16 @@ discard block |
||
| 324 | 324 | { |
| 325 | 325 | return $this->getTabs()->add('status', array( |
| 326 | 326 | 'label' => $this->translate('Status'), |
| 327 | - 'url' => $this->getModuleConfig()->urlPath() . '/status') |
|
| 327 | + 'url' => $this->getModuleConfig()->urlPath().'/status') |
|
| 328 | 328 | )->add('mib', array( |
| 329 | 329 | 'label' => $this->translate('MIB Management'), |
| 330 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/mib') |
|
| 330 | + 'url' => $this->getModuleConfig()->urlPath().'/status/mib') |
|
| 331 | 331 | )->add('services', array( |
| 332 | 332 | 'label' => $this->translate('Services management'), |
| 333 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/services') |
|
| 333 | + 'url' => $this->getModuleConfig()->urlPath().'/status/services') |
|
| 334 | 334 | )->add('plugins', array( |
| 335 | 335 | 'label' => $this->translate('Plugins management'), |
| 336 | - 'url' => $this->getModuleConfig()->urlPath() . '/status/plugins') |
|
| 336 | + 'url' => $this->getModuleConfig()->urlPath().'/status/plugins') |
|
| 337 | 337 | ); |
| 338 | 338 | } |
| 339 | 339 | } |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | // TODO : see if useless |
| 342 | 342 | class UploadForm extends Form |
| 343 | 343 | { |
| 344 | - public function __construct($options = null) |
|
| 344 | + public function __construct($options=null) |
|
| 345 | 345 | { |
| 346 | 346 | parent::__construct($options); |
| 347 | 347 | $this->addElements2(); |
@@ -350,11 +350,11 @@ discard block |
||
| 350 | 350 | public function addElements2() |
| 351 | 351 | { |
| 352 | 352 | // File Input |
| 353 | - $file = new File('mib-file'); |
|
| 353 | + $file=new File('mib-file'); |
|
| 354 | 354 | $file->setLabel('Mib upload'); |
| 355 | 355 | //->setAttrib('multiple', null); |
| 356 | 356 | $this->addElement($file); |
| 357 | - $button = new Submit("upload",array('ignore'=>false)); |
|
| 358 | - $this->addElement($button);//->setIgnore(false); |
|
| 357 | + $button=new Submit("upload", array('ignore'=>false)); |
|
| 358 | + $this->addElement($button); //->setIgnore(false); |
|
| 359 | 359 | } |
| 360 | 360 | } |
@@ -18,14 +18,14 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | $postData=$this->getRequest()->getPost(); |
| 20 | 20 | |
| 21 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 21 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 22 | 22 | |
| 23 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 23 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 24 | 24 | |
| 25 | 25 | $hosts=$this->getUIDatabase()->getHostByIP($hostFilter); |
| 26 | 26 | foreach ($hosts as $val) |
| 27 | 27 | { |
| 28 | - array_push($retHosts['hosts'],$val->name); |
|
| 28 | + array_push($retHosts['hosts'], $val->name); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | $this->_helper->json($retHosts); |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | $postData=$this->getRequest()->getPost(); |
| 40 | 40 | |
| 41 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 41 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
| 42 | 42 | |
| 43 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
| 43 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
| 44 | 44 | |
| 45 | 45 | $hosts=$this->getUIDatabase()->getHostGroupByName($hostFilter); |
| 46 | 46 | foreach ($hosts as $val) |
| 47 | 47 | { |
| 48 | - array_push($retHosts['hosts'],$val->name); |
|
| 48 | + array_push($retHosts['hosts'], $val->name); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $this->_helper->json($retHosts); |
@@ -68,31 +68,31 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | else |
| 70 | 70 | { |
| 71 | - $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
|
| 71 | + $this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1)); |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | $hostArray=$this->getUIDatabase()->getHostByName($host); |
| 76 | 76 | if (count($hostArray) > 1) |
| 77 | 77 | { |
| 78 | - $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
|
| 78 | + $this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1)); |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | else if (count($hostArray) == 0) |
| 82 | 82 | { |
| 83 | - $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
|
| 83 | + $this->_helper->json(array('status'=>'No host matches', 'hostid' => -1)); |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | $services=$this->getUIDatabase()->getServicesByHostid($hostArray[0]->id); |
| 87 | 87 | if (count($services) < 1) |
| 88 | 88 | { |
| 89 | - $this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id)); |
|
| 89 | + $this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id)); |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | - $retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id); |
|
| 92 | + $retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id); |
|
| 93 | 93 | foreach ($services as $val) |
| 94 | 94 | { |
| 95 | - array_push($retServices['services'],array($val->id , $val->name)); |
|
| 95 | + array_push($retServices['services'], array($val->id, $val->name)); |
|
| 96 | 96 | } |
| 97 | 97 | $this->_helper->json($retServices); |
| 98 | 98 | } |
@@ -107,26 +107,26 @@ discard block |
||
| 107 | 107 | { |
| 108 | 108 | $postData=$this->getRequest()->getPost(); |
| 109 | 109 | |
| 110 | - $host = $this->checkPostVar($postData, 'host', '.+'); |
|
| 110 | + $host=$this->checkPostVar($postData, 'host', '.+'); |
|
| 111 | 111 | |
| 112 | 112 | $hostArray=$this->getUIDatabase()->getHostGroupByName($host); |
| 113 | 113 | if (count($hostArray) > 1) |
| 114 | 114 | { |
| 115 | - $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
|
| 115 | + $this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1)); |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | else if (count($hostArray) == 0) |
| 119 | 119 | { |
| 120 | - $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
|
| 120 | + $this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1)); |
|
| 121 | 121 | return; |
| 122 | 122 | } |
| 123 | 123 | $services=$this->getUIDatabase()->getServicesByHostGroupid($hostArray[0]->id); |
| 124 | 124 | if (count($services) < 1) |
| 125 | 125 | { |
| 126 | - $this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id)); |
|
| 126 | + $this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id)); |
|
| 127 | 127 | return; |
| 128 | 128 | } |
| 129 | - $retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id); |
|
| 129 | + $retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id); |
|
| 130 | 130 | |
| 131 | 131 | $this->_helper->json($retServices); |
| 132 | 132 | } |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | $postData=$this->getRequest()->getPost(); |
| 142 | 142 | |
| 143 | - $mib = $this->checkPostVar($postData, 'mib', '.*'); |
|
| 143 | + $mib=$this->checkPostVar($postData, 'mib', '.*'); |
|
| 144 | 144 | |
| 145 | 145 | try |
| 146 | 146 | { |
| 147 | 147 | $traplist=$this->getMIB()->getTrapList($mib); |
| 148 | - $retTraps=array('status'=>'OK','traps' => $traplist); |
|
| 148 | + $retTraps=array('status'=>'OK', 'traps' => $traplist); |
|
| 149 | 149 | } |
| 150 | 150 | catch (Exception $e) |
| 151 | 151 | { |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | { |
| 164 | 164 | $postData=$this->getRequest()->getPost(); |
| 165 | 165 | |
| 166 | - $trap = $this->checkPostVar($postData, 'trap', '.*'); |
|
| 166 | + $trap=$this->checkPostVar($postData, 'trap', '.*'); |
|
| 167 | 167 | |
| 168 | 168 | try |
| 169 | 169 | { |
| 170 | 170 | $objectlist=$this->getMIB()->getObjectList($trap); |
| 171 | - $retObjects=array('status'=>'OK','objects' => $objectlist); |
|
| 171 | + $retObjects=array('status'=>'OK', 'objects' => $objectlist); |
|
| 172 | 172 | } |
| 173 | 173 | catch (Exception $e) |
| 174 | 174 | { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | { |
| 203 | 203 | $postData=$this->getRequest()->getPost(); |
| 204 | 204 | |
| 205 | - $oid = $this->checkPostVar($postData, 'oid', '.*'); |
|
| 205 | + $oid=$this->checkPostVar($postData, 'oid', '.*'); |
|
| 206 | 206 | |
| 207 | 207 | // Try to get oid name from snmptranslate |
| 208 | 208 | if (($object=$this->getMIB()->translateOID($oid)) == null) |
@@ -235,20 +235,20 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | $postData=$this->getRequest()->getPost(); |
| 237 | 237 | |
| 238 | - $days = $this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 238 | + $days=$this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
| 239 | 239 | $days=intval($days); |
| 240 | 240 | |
| 241 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 241 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
| 242 | 242 | |
| 243 | 243 | if ($action == 'save') |
| 244 | 244 | { |
| 245 | 245 | try |
| 246 | 246 | { |
| 247 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
| 247 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days); |
|
| 248 | 248 | } |
| 249 | 249 | catch (Exception $e) |
| 250 | 250 | { |
| 251 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 251 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 252 | 252 | return; |
| 253 | 253 | } |
| 254 | 254 | $this->_helper->json(array('status'=>'OK')); |
@@ -258,16 +258,16 @@ discard block |
||
| 258 | 258 | { |
| 259 | 259 | try |
| 260 | 260 | { |
| 261 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 261 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 262 | 262 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 263 | 263 | $debug_level=4; |
| 264 | - $trap = new Trap($icingaweb2_etc); |
|
| 265 | - $trap->setLogging($debug_level,'syslog'); |
|
| 264 | + $trap=new Trap($icingaweb2_etc); |
|
| 265 | + $trap->setLogging($debug_level, 'syslog'); |
|
| 266 | 266 | $trap->eraseOldTraps($days); |
| 267 | 267 | } |
| 268 | 268 | catch (Exception $e) |
| 269 | 269 | { |
| 270 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
| 270 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
| 271 | 271 | return; |
| 272 | 272 | } |
| 273 | 273 | $this->_helper->json(array('status'=>'OK')); |
@@ -284,18 +284,18 @@ discard block |
||
| 284 | 284 | { |
| 285 | 285 | $postData=$this->getRequest()->getPost(); |
| 286 | 286 | |
| 287 | - $snmpUse = $this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
| 287 | + $snmpUse=$this->checkPostVar($postData, 'useTrapAddr', '0|1'); |
|
| 288 | 288 | |
| 289 | - $snmpOID = $this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
| 289 | + $snmpOID=$this->checkPostVar($postData, 'trapAddrOID', '^[\.0-9]+$'); |
|
| 290 | 290 | |
| 291 | 291 | try |
| 292 | 292 | { |
| 293 | - $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess',$snmpUse); |
|
| 294 | - $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid',$snmpOID); |
|
| 293 | + $this->getUIDatabase()->setDBConfigValue('use_SnmpTrapAddess', $snmpUse); |
|
| 294 | + $this->getUIDatabase()->setDBConfigValue('SnmpTrapAddess_oid', $snmpOID); |
|
| 295 | 295 | } |
| 296 | 296 | catch (Exception $e) |
| 297 | 297 | { |
| 298 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 298 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 299 | 299 | return; |
| 300 | 300 | } |
| 301 | 301 | $this->_helper->json(array('status'=>'OK')); |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | { |
| 314 | 314 | $postData=$this->getRequest()->getPost(); |
| 315 | 315 | |
| 316 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
| 316 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
| 317 | 317 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
| 318 | 318 | if (!isset($logDest[$destination])) |
| 319 | 319 | { |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | if (isset($postData['file'])) |
| 325 | 325 | { |
| 326 | 326 | $file=$postData['file']; |
| 327 | - $fileHandler=@fopen($file,'w'); |
|
| 327 | + $fileHandler=@fopen($file, 'w'); |
|
| 328 | 328 | if ($fileHandler == false) |
| 329 | 329 | { // File os note writabe / cannot create |
| 330 | 330 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -344,17 +344,17 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 347 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
| 348 | 348 | |
| 349 | 349 | try |
| 350 | 350 | { |
| 351 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
| 352 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
| 353 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
| 351 | + $this->getUIDatabase()->setDBConfigValue('log_destination', $destination); |
|
| 352 | + $this->getUIDatabase()->setDBConfigValue('log_file', $file); |
|
| 353 | + $this->getUIDatabase()->setDBConfigValue('log_level', $level); |
|
| 354 | 354 | } |
| 355 | 355 | catch (Exception $e) |
| 356 | 356 | { |
| 357 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
| 357 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
| 358 | 358 | return; |
| 359 | 359 | } |
| 360 | 360 | $this->_helper->json(array('status'=>'OK')); |
@@ -372,29 +372,29 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | $postData=$this->getRequest()->getPost(); |
| 374 | 374 | |
| 375 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
| 375 | + $rule=$this->checkPostVar($postData, 'rule', '.*'); |
|
| 376 | 376 | |
| 377 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 377 | + $action=$this->checkPostVar($postData, 'action', 'evaluate'); |
|
| 378 | 378 | |
| 379 | 379 | if ($action == 'evaluate') |
| 380 | 380 | { |
| 381 | 381 | try |
| 382 | 382 | { |
| 383 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 383 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 384 | 384 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 385 | - $trap = new Trap($icingaweb2_etc); |
|
| 385 | + $trap=new Trap($icingaweb2_etc); |
|
| 386 | 386 | // Cleanup spaces before eval |
| 387 | 387 | $rule=$trap->ruleClass->eval_cleanup($rule); |
| 388 | 388 | // Eval |
| 389 | 389 | $item=0; |
| 390 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
| 390 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
| 391 | 391 | } |
| 392 | 392 | catch (Exception $e) |
| 393 | 393 | { |
| 394 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 394 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
| 395 | 395 | return; |
| 396 | 396 | } |
| 397 | - $return=($rule==true)?'true':'false'; |
|
| 397 | + $return=($rule == true) ? 'true' : 'false'; |
|
| 398 | 398 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
| 399 | 399 | } |
| 400 | 400 | |
@@ -409,15 +409,15 @@ discard block |
||
| 409 | 409 | { |
| 410 | 410 | $postData=$this->getRequest()->getPost(); |
| 411 | 411 | |
| 412 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
| 412 | + $pluginName=$this->checkPostVar($postData, 'name', '.*'); |
|
| 413 | 413 | |
| 414 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 414 | + $action=$this->checkPostVar($postData, 'action', 'enable|disable'); |
|
| 415 | 415 | |
| 416 | 416 | try |
| 417 | 417 | { |
| 418 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 418 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 419 | 419 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 420 | - $trap = new Trap($icingaweb2_etc); |
|
| 420 | + $trap=new Trap($icingaweb2_etc); |
|
| 421 | 421 | // Enable plugin. |
| 422 | 422 | $action=($action == 'enable') ? true : false; |
| 423 | 423 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | catch (Exception $e) |
| 427 | 427 | { |
| 428 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 428 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 429 | 429 | return; |
| 430 | 430 | } |
| 431 | 431 | if ($retVal === true) |
@@ -447,45 +447,45 @@ discard block |
||
| 447 | 447 | { |
| 448 | 448 | $postData=$this->getRequest()->getPost(); |
| 449 | 449 | |
| 450 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
| 450 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
| 451 | 451 | |
| 452 | 452 | $this->checkPostVar($postData, 'action', 'evaluate'); |
| 453 | 453 | |
| 454 | 454 | // Only one action possible for now, no tests on action. |
| 455 | 455 | try |
| 456 | 456 | { |
| 457 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 457 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
| 458 | 458 | $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 459 | - $trap = new Trap($icingaweb2Etc); |
|
| 459 | + $trap=new Trap($icingaweb2Etc); |
|
| 460 | 460 | // load all plugins in case tested function is not enabled. |
| 461 | 461 | $trap->pluginClass->registerAllPlugins(false); |
| 462 | 462 | // Clean all spaces |
| 463 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
| 463 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
| 464 | 464 | // Eval functions |
| 465 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
| 465 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
| 466 | 466 | } |
| 467 | 467 | catch (Exception $e) |
| 468 | 468 | { |
| 469 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
| 469 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
| 470 | 470 | return; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - $result = ($result === true)?'True':'False'; |
|
| 474 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
| 473 | + $result=($result === true) ? 'True' : 'False'; |
|
| 474 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /************** Utilities **********************/ |
| 478 | 478 | |
| 479 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
| 479 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
| 480 | 480 | { |
| 481 | 481 | if (!isset ($postData[$postVar])) |
| 482 | 482 | { |
| 483 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
| 483 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
| 484 | 484 | return ''; |
| 485 | 485 | } |
| 486 | 486 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
| 487 | 487 | { |
| 488 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
| 488 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
| 489 | 489 | return ''; |
| 490 | 490 | } |
| 491 | 491 | return $postData[$postVar]; |