@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @param string $rule |
| 17 | 17 | * @param int $item |
| 18 | 18 | */ |
| 19 | - abstract public function evaluation($rule,&$item); |
|
| 19 | + abstract public function evaluation($rule, &$item); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Get full number |
@@ -24,20 +24,20 @@ discard block |
||
| 24 | 24 | * @param int $item current eval position |
| 25 | 25 | * @return array<int,string> |
| 26 | 26 | */ |
| 27 | - private function get_number(string $rule,int &$item) |
|
| 27 | + private function get_number(string $rule, int &$item) |
|
| 28 | 28 | { |
| 29 | - $item2=$item+1; |
|
| 29 | + $item2=$item + 1; |
|
| 30 | 30 | while ( |
| 31 | - ($item2!=strlen($rule)) |
|
| 32 | - && (preg_match('/[\-0-9\.]/',$rule[$item2]))) |
|
| 31 | + ($item2 != strlen($rule)) |
|
| 32 | + && (preg_match('/[\-0-9\.]/', $rule[$item2]))) |
|
| 33 | 33 | { |
| 34 | - $item2++ ; |
|
| 34 | + $item2++; |
|
| 35 | 35 | } |
| 36 | - $val=substr($rule,$item,$item2-$item); |
|
| 36 | + $val=substr($rule, $item, $item2 - $item); |
|
| 37 | 37 | $item=$item2; |
| 38 | 38 | //echo "number ".$val."\n"; |
| 39 | 39 | |
| 40 | - return array(0,$val); |
|
| 40 | + return array(0, $val); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -46,14 +46,14 @@ discard block |
||
| 46 | 46 | * @param int $item current eval position |
| 47 | 47 | * @return array<int,string> |
| 48 | 48 | */ |
| 49 | - private function get_string(string $rule,int &$item) |
|
| 49 | + private function get_string(string $rule, int &$item) |
|
| 50 | 50 | { |
| 51 | 51 | $item++; |
| 52 | - $item2=$this->eval_getNext($rule,$item,'"'); |
|
| 53 | - $val=substr($rule,$item,$item2-$item-1); |
|
| 52 | + $item2=$this->eval_getNext($rule, $item, '"'); |
|
| 53 | + $val=substr($rule, $item, $item2 - $item - 1); |
|
| 54 | 54 | $item=$item2; |
| 55 | 55 | //echo "string : ".$val."\n"; |
| 56 | - return array(1,$val); |
|
| 56 | + return array(1, $val); |
|
| 57 | 57 | |
| 58 | 58 | } |
| 59 | 59 | |
@@ -65,18 +65,18 @@ discard block |
||
| 65 | 65 | * @throws Exception |
| 66 | 66 | * @return string : everything inside parenthesis |
| 67 | 67 | */ |
| 68 | - private function parse_parenthesis(string $rule,int &$item) : string |
|
| 68 | + private function parse_parenthesis(string $rule, int &$item) : string |
|
| 69 | 69 | { |
| 70 | 70 | $item++; |
| 71 | 71 | $start=$item; |
| 72 | 72 | $parenthesisCount=0; |
| 73 | 73 | while (($item < strlen($rule)) // Not end of string AND |
| 74 | - && ( ($rule[$item] != ')' ) || $parenthesisCount > 0) ) // Closing ')' or embeded () |
|
| 74 | + && (($rule[$item] != ')') || $parenthesisCount > 0)) // Closing ')' or embeded () |
|
| 75 | 75 | { |
| 76 | - if ($rule[$item] == '"' ) |
|
| 76 | + if ($rule[$item] == '"') |
|
| 77 | 77 | { // pass through string |
| 78 | 78 | $item++; |
| 79 | - $item=$this->eval_getNext($rule,$item,'"'); |
|
| 79 | + $item=$this->eval_getNext($rule, $item, '"'); |
|
| 80 | 80 | continue; |
| 81 | 81 | } |
| 82 | 82 | if ($rule[$item] == '(') |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | $item++; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if ($item==strlen($rule)) {throw new Exception("no closing () in ".$rule ." at " .$item);} |
|
| 94 | - $val=substr($rule,$start,$item-$start); |
|
| 93 | + if ($item == strlen($rule)) {throw new Exception("no closing () in ".$rule." at ".$item); } |
|
| 94 | + $val=substr($rule, $start, $item - $start); |
|
| 95 | 95 | $item++; |
| 96 | 96 | return $val; |
| 97 | 97 | } |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | * @param int $item |
| 103 | 103 | * @return array<int,string> |
| 104 | 104 | */ |
| 105 | - private function get_group(string $rule,int &$item) : array |
|
| 105 | + private function get_group(string $rule, int &$item) : array |
|
| 106 | 106 | { |
| 107 | 107 | // gets eveything inside parenthesis |
| 108 | 108 | $val=$this->parse_parenthesis($rule, $item); |
| 109 | 109 | // Returns boolean with evaluation of all inside parenthesis |
| 110 | 110 | $start=0; |
| 111 | - return array(2,$this->evaluation($val,$start)); |
|
| 111 | + return array(2, $this->evaluation($val, $start)); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -117,25 +117,25 @@ discard block |
||
| 117 | 117 | * @throws Exception |
| 118 | 118 | * @return array<int,string> |
| 119 | 119 | */ |
| 120 | - private function get_function(string $rule,int &$item) : array |
|
| 120 | + private function get_function(string $rule, int &$item) : array |
|
| 121 | 121 | { |
| 122 | 122 | // function is : __function(param1,param2...) |
| 123 | 123 | $start=$item; |
| 124 | - while (($item < strlen($rule)) && ($rule[$item] != '(' )) // Not end of string AND not opening '(' |
|
| 124 | + while (($item < strlen($rule)) && ($rule[$item] != '(')) // Not end of string AND not opening '(' |
|
| 125 | 125 | { |
| 126 | 126 | $item++; |
| 127 | 127 | } |
| 128 | - if ($item==strlen($rule)) {throw new Exception("no opening () for function in ".$rule ." at " .$item);} |
|
| 128 | + if ($item == strlen($rule)) {throw new Exception("no opening () for function in ".$rule." at ".$item); } |
|
| 129 | 129 | |
| 130 | 130 | // get parameters between parenthesis |
| 131 | 131 | |
| 132 | 132 | $this->parse_parenthesis($rule, $item); |
| 133 | 133 | |
| 134 | - $val=substr($rule,$start,$item-$start); |
|
| 134 | + $val=substr($rule, $start, $item - $start); |
|
| 135 | 135 | |
| 136 | - $this->logging->log('got function ' . $val,DEBUG); |
|
| 136 | + $this->logging->log('got function '.$val, DEBUG); |
|
| 137 | 137 | |
| 138 | - return array(2,$this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
| 138 | + return array(2, $this->trapClass->pluginClass->evaluateFunctionString($val)); |
|
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | |
@@ -146,18 +146,18 @@ discard block |
||
| 146 | 146 | * @throws Exception |
| 147 | 147 | * @return int Position after next token |
| 148 | 148 | */ |
| 149 | - protected function eval_getNext(string $rule,int $item,string $tok) |
|
| 149 | + protected function eval_getNext(string $rule, int $item, string $tok) |
|
| 150 | 150 | { |
| 151 | 151 | while ( |
| 152 | - ($rule[$item] != $tok ) |
|
| 152 | + ($rule[$item] != $tok) |
|
| 153 | 153 | && ($item < strlen($rule))) |
| 154 | 154 | { |
| 155 | 155 | $item++; |
| 156 | 156 | } |
| 157 | - if ($item==strlen($rule)) { |
|
| 158 | - throw new Exception("closing '".$tok."' not found in ".$rule ." at " .$item); |
|
| 157 | + if ($item == strlen($rule)) { |
|
| 158 | + throw new Exception("closing '".$tok."' not found in ".$rule." at ".$item); |
|
| 159 | 159 | } |
| 160 | - return $item+1; |
|
| 160 | + return $item + 1; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** get negate (!) and return true if found - and pass it with item++ - |
@@ -165,9 +165,9 @@ discard block |
||
| 165 | 165 | * @param int $item |
| 166 | 166 | * @return boolean |
| 167 | 167 | */ |
| 168 | - private function check_negate_first(string $rule,int &$item) |
|
| 168 | + private function check_negate_first(string $rule, int &$item) |
|
| 169 | 169 | { |
| 170 | - if ( $rule[$item] == '!') // If '!' found, negate next expression. |
|
| 170 | + if ($rule[$item] == '!') // If '!' found, negate next expression. |
|
| 171 | 171 | { |
| 172 | 172 | $item++; |
| 173 | 173 | return true; |
@@ -189,17 +189,17 @@ discard block |
||
| 189 | 189 | $rule2=''; |
| 190 | 190 | while ($item < strlen($rule)) |
| 191 | 191 | { |
| 192 | - if ($rule[$item]==' ') { $item++; continue; } |
|
| 193 | - if ($rule[$item]=='"') |
|
| 192 | + if ($rule[$item] == ' ') { $item++; continue; } |
|
| 193 | + if ($rule[$item] == '"') |
|
| 194 | 194 | { |
| 195 | 195 | $rule2.=$rule[$item]; |
| 196 | 196 | $item++; |
| 197 | - while (($item < strlen($rule)) && ($rule[$item]!='"') ) |
|
| 197 | + while (($item < strlen($rule)) && ($rule[$item] != '"')) |
|
| 198 | 198 | { |
| 199 | 199 | $rule2.=$rule[$item]; |
| 200 | 200 | $item++; |
| 201 | 201 | } |
| 202 | - if ($item == strlen ($rule)) throw new Exception("closing '\"' not found in ".$rule ." at " .$item); |
|
| 202 | + if ($item == strlen($rule)) throw new Exception("closing '\"' not found in ".$rule." at ".$item); |
|
| 203 | 203 | $rule2.=$rule[$item]; |
| 204 | 204 | $item++; |
| 205 | 205 | continue; |
@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | * @param string $message warning message if not found |
| 29 | 29 | * @return boolean true if found, or false |
| 30 | 30 | */ |
| 31 | - protected function getOptionIfSet($option_array,$option_category,$option_name, &$option_var, $log_level = 2, $message = null) |
|
| 31 | + protected function getOptionIfSet($option_array, $option_category, $option_name, &$option_var, $log_level=2, $message=null) |
|
| 32 | 32 | { |
| 33 | 33 | if (!isset($option_array[$option_category][$option_name])) |
| 34 | 34 | { |
| 35 | 35 | if ($message === null) |
| 36 | 36 | { |
| 37 | - $message='No ' . $option_name . ' in config file: '. $this->trapModuleConfig; |
|
| 37 | + $message='No '.$option_name.' in config file: '.$this->trapModuleConfig; |
|
| 38 | 38 | } |
| 39 | - $this->getLogging()->log($message,$log_level); |
|
| 39 | + $this->getLogging()->log($message, $log_level); |
|
| 40 | 40 | return false; |
| 41 | 41 | } |
| 42 | 42 | else |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | // Database options |
| 55 | 55 | if ($this->logSetup === false) // Only if logging was no setup in constructor |
| 56 | 56 | { |
| 57 | - $this->getDBConfigIfSet('log_level',$this->getLogging()->debugLevel); |
|
| 58 | - $this->getDBConfigIfSet('log_destination',$this->getLogging()->outputMode); |
|
| 59 | - $this->getDBConfigIfSet('log_file',$this->getLogging()->outputFile); |
|
| 57 | + $this->getDBConfigIfSet('log_level', $this->getLogging()->debugLevel); |
|
| 58 | + $this->getDBConfigIfSet('log_destination', $this->getLogging()->outputMode); |
|
| 59 | + $this->getDBConfigIfSet('log_file', $this->getLogging()->outputFile); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @param string $element |
| 65 | 65 | * @param string $variable |
| 66 | 66 | */ |
| 67 | - protected function getDBConfigIfSet($element,&$variable) |
|
| 67 | + protected function getDBConfigIfSet($element, &$variable) |
|
| 68 | 68 | { |
| 69 | 69 | $value=$this->getDBConfig($element); |
| 70 | 70 | if ($value != null) $variable=$value; |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 81 | 81 | $sql='SELECT value from '.$this->dbPrefix.'db_config WHERE ( name=\''.$element.'\' )'; |
| 82 | 82 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 83 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
| 83 | + $this->logging->log('No result in query : '.$sql, WARN, ''); |
|
| 84 | 84 | return null; |
| 85 | 85 | } |
| 86 | 86 | $value=$ret_code->fetch(); |
@@ -99,24 +99,24 @@ discard block |
||
| 99 | 99 | { |
| 100 | 100 | |
| 101 | 101 | // Snmptranslate binary path |
| 102 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate', $this->snmptranslate); |
|
| 102 | + $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate', $this->snmptranslate); |
|
| 103 | 103 | |
| 104 | 104 | // mibs path |
| 105 | - $this->getOptionIfSet($trapConfig,'config','snmptranslate_dirs', $this->snmptranslate_dirs); |
|
| 105 | + $this->getOptionIfSet($trapConfig, 'config', 'snmptranslate_dirs', $this->snmptranslate_dirs); |
|
| 106 | 106 | |
| 107 | 107 | // icinga2cmd path |
| 108 | - $this->getOptionIfSet($trapConfig,'config','icingacmd', $this->icinga2cmd); |
|
| 108 | + $this->getOptionIfSet($trapConfig, 'config', 'icingacmd', $this->icinga2cmd); |
|
| 109 | 109 | |
| 110 | 110 | // table prefix |
| 111 | - $this->getOptionIfSet($trapConfig,'config','database_prefix', $this->dbPrefix); |
|
| 111 | + $this->getOptionIfSet($trapConfig, 'config', 'database_prefix', $this->dbPrefix); |
|
| 112 | 112 | |
| 113 | 113 | // API options |
| 114 | - if ($this->getOptionIfSet($trapConfig,'config','icingaAPI_host', $this->apiHostname)) |
|
| 114 | + if ($this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_host', $this->apiHostname)) |
|
| 115 | 115 | { |
| 116 | 116 | $this->apiUse=true; |
| 117 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_port', $this->apiPort); |
|
| 118 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_user', $this->apiUsername); |
|
| 119 | - $this->getOptionIfSet($trapConfig,'config','icingaAPI_password', $this->apiPassword); |
|
| 117 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_port', $this->apiPort); |
|
| 118 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_user', $this->apiUsername); |
|
| 119 | + $this->getOptionIfSet($trapConfig, 'config', 'icingaAPI_password', $this->apiPassword); |
|
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
@@ -127,40 +127,40 @@ discard block |
||
| 127 | 127 | protected function setupDatabase($trapConfig) |
| 128 | 128 | { |
| 129 | 129 | // Trap database |
| 130 | - if (!array_key_exists('database',$trapConfig['config'])) |
|
| 130 | + if (!array_key_exists('database', $trapConfig['config'])) |
|
| 131 | 131 | { |
| 132 | - $this->logging->log("No database in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 132 | + $this->logging->log("No database in config file: ".$this->trapModuleConfig, ERROR, ''); |
|
| 133 | 133 | return; |
| 134 | 134 | } |
| 135 | 135 | $dbTrapName=$trapConfig['config']['database']; |
| 136 | - $this->logging->log("Found database in config file: ".$dbTrapName,INFO ); |
|
| 136 | + $this->logging->log("Found database in config file: ".$dbTrapName, INFO); |
|
| 137 | 137 | |
| 138 | - if ( ($dbConfig=parse_ini_file($this->icingaweb2Ressources,true)) === false) |
|
| 138 | + if (($dbConfig=parse_ini_file($this->icingaweb2Ressources, true)) === false) |
|
| 139 | 139 | { |
| 140 | - $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources,ERROR,''); |
|
| 140 | + $this->logging->log("Error reading ini file : ".$this->icingaweb2Ressources, ERROR, ''); |
|
| 141 | 141 | return; |
| 142 | 142 | } |
| 143 | - if (!array_key_exists($dbTrapName,$dbConfig)) |
|
| 143 | + if (!array_key_exists($dbTrapName, $dbConfig)) |
|
| 144 | 144 | { |
| 145 | - $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 145 | + $this->logging->log("No database '.$dbTrapName.' in config file: ".$this->icingaweb2Ressources, ERROR, ''); |
|
| 146 | 146 | return; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $this->trapsDB = new Database($this->logging,$dbConfig[$dbTrapName],$this->dbPrefix); |
|
| 149 | + $this->trapsDB=new Database($this->logging, $dbConfig[$dbTrapName], $this->dbPrefix); |
|
| 150 | 150 | |
| 151 | 151 | if ($this->apiUse === true) return; // In case of API use, no IDO is necessary |
| 152 | 152 | |
| 153 | 153 | // IDO Database |
| 154 | - if (!array_key_exists('IDOdatabase',$trapConfig['config'])) |
|
| 154 | + if (!array_key_exists('IDOdatabase', $trapConfig['config'])) |
|
| 155 | 155 | { |
| 156 | - $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig,ERROR,''); |
|
| 156 | + $this->logging->log("No IDOdatabase in config file: ".$this->trapModuleConfig, ERROR, ''); |
|
| 157 | 157 | } |
| 158 | 158 | $dbIdoName=$trapConfig['config']['IDOdatabase']; |
| 159 | 159 | |
| 160 | - $this->logging->log("Found IDO database in config file: ".$dbIdoName,INFO ); |
|
| 161 | - if (!array_key_exists($dbIdoName,$dbConfig)) |
|
| 160 | + $this->logging->log("Found IDO database in config file: ".$dbIdoName, INFO); |
|
| 161 | + if (!array_key_exists($dbIdoName, $dbConfig)) |
|
| 162 | 162 | { |
| 163 | - $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources,ERROR,''); |
|
| 163 | + $this->logging->log("No database '.$dbIdoName.' in config file: ".$this->icingaweb2Ressources, ERROR, ''); |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -52,13 +52,13 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | // Logs |
| 54 | 54 | /** @var Logging Logging class. */ |
| 55 | - public $logging; //< Logging class. |
|
| 55 | + public $logging; //< Logging class. |
|
| 56 | 56 | /** @var bool true if log was setup in constructor */ |
| 57 | - protected $logSetup; //< bool true if log was setup in constructor |
|
| 57 | + protected $logSetup; //< bool true if log was setup in constructor |
|
| 58 | 58 | |
| 59 | 59 | // Databases |
| 60 | 60 | /** @var Database $trapsDB Database class*/ |
| 61 | - public $trapsDB = null; |
|
| 61 | + public $trapsDB=null; |
|
| 62 | 62 | |
| 63 | 63 | // Trap received data |
| 64 | 64 | protected $receivingHost; |
@@ -74,15 +74,15 @@ discard block |
||
| 74 | 74 | protected $trapToDb=true; |
| 75 | 75 | |
| 76 | 76 | /** @var Mib mib class */ |
| 77 | - public $mibClass = null; |
|
| 77 | + public $mibClass=null; |
|
| 78 | 78 | |
| 79 | 79 | /** @var Rule rule class */ |
| 80 | - public $ruleClass = null; |
|
| 80 | + public $ruleClass=null; |
|
| 81 | 81 | |
| 82 | 82 | /** @var Plugins plugins manager **/ |
| 83 | - public $pluginClass = null; |
|
| 83 | + public $pluginClass=null; |
|
| 84 | 84 | |
| 85 | - function __construct($etcDir='/etc/icingaweb2',$baseLogLevel=null,$baseLogMode='syslog',$baseLogFile='') |
|
| 85 | + function __construct($etcDir='/etc/icingaweb2', $baseLogLevel=null, $baseLogMode='syslog', $baseLogFile='') |
|
| 86 | 86 | { |
| 87 | 87 | // Paths of ini files |
| 88 | 88 | $this->icingaweb2Etc=$etcDir; |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | $this->icingaweb2Ressources=$this->icingaweb2Etc."/resources.ini"; |
| 91 | 91 | |
| 92 | 92 | //************* Setup logging |
| 93 | - $this->logging = new Logging(); |
|
| 93 | + $this->logging=new Logging(); |
|
| 94 | 94 | if ($baseLogLevel != null) |
| 95 | 95 | { |
| 96 | - $this->logging->setLogging($baseLogLevel, $baseLogMode,$baseLogFile); |
|
| 96 | + $this->logging->setLogging($baseLogLevel, $baseLogMode, $baseLogFile); |
|
| 97 | 97 | $this->logSetup=true; |
| 98 | 98 | } |
| 99 | 99 | else |
@@ -103,14 +103,14 @@ discard block |
||
| 103 | 103 | $this->logging->log('Loggin started', INFO); |
| 104 | 104 | |
| 105 | 105 | //*************** Get options from ini files |
| 106 | - if (! is_file($this->trapModuleConfig)) |
|
| 106 | + if (!is_file($this->trapModuleConfig)) |
|
| 107 | 107 | { |
| 108 | 108 | throw new Exception("Ini file ".$this->trapModuleConfig." does not exists"); |
| 109 | 109 | } |
| 110 | - $trapConfig=parse_ini_file($this->trapModuleConfig,true); |
|
| 110 | + $trapConfig=parse_ini_file($this->trapModuleConfig, true); |
|
| 111 | 111 | if ($trapConfig == false) |
| 112 | 112 | { |
| 113 | - $this->logging->log("Error reading ini file : ".$this->trapModuleConfig,ERROR,'syslog'); |
|
| 113 | + $this->logging->log("Error reading ini file : ".$this->trapModuleConfig, ERROR, 'syslog'); |
|
| 114 | 114 | throw new Exception("Error reading ini file : ".$this->trapModuleConfig); |
| 115 | 115 | } |
| 116 | 116 | $this->getMainOptions($trapConfig); // Get main options from ini file |
@@ -124,10 +124,10 @@ discard block |
||
| 124 | 124 | if ($this->apiUse === true) $this->getAPI(); // Setup API |
| 125 | 125 | |
| 126 | 126 | //*************** Setup MIB |
| 127 | - $this->mibClass = new Mib($this->logging,$this->trapsDB,$this->snmptranslate,$this->snmptranslate_dirs); // Create Mib class |
|
| 127 | + $this->mibClass=new Mib($this->logging, $this->trapsDB, $this->snmptranslate, $this->snmptranslate_dirs); // Create Mib class |
|
| 128 | 128 | |
| 129 | 129 | //*************** Setup Rule |
| 130 | - $this->ruleClass = new Rule($this); //< Create Rule class |
|
| 130 | + $this->ruleClass=new Rule($this); //< Create Rule class |
|
| 131 | 131 | |
| 132 | 132 | $this->trapData=array( // TODO : put this in a reset function (DAEMON_MODE) |
| 133 | 133 | 'source_ip' => 'unknown', |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | |
| 140 | 140 | //*************** Setup Plugins |
| 141 | 141 | //Create plugin class. Plugins are not loaded here, but by calling registerAllPlugins |
| 142 | - $this->pluginClass = new Plugins($this); |
|
| 142 | + $this->pluginClass=new Plugins($this); |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | 145 | } |
@@ -162,15 +162,15 @@ discard block |
||
| 162 | 162 | * @param string $destination file/syslog/display |
| 163 | 163 | * @return void |
| 164 | 164 | **/ |
| 165 | - public function trapLog( $message, $level, $destination ='') // OBSOLETE |
|
| 165 | + public function trapLog($message, $level, $destination='') // OBSOLETE |
|
| 166 | 166 | { |
| 167 | 167 | // TODO : replace ref with $this->logging->log |
| 168 | 168 | $this->logging->log($message, $level, $destination); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - public function setLogging($debugLvl,$outputType,$outputOption=null) // OBSOLETE |
|
| 171 | + public function setLogging($debugLvl, $outputType, $outputOption=null) // OBSOLETE |
|
| 172 | 172 | { |
| 173 | - $this->logging->setLogging($debugLvl, $outputType,$outputOption); |
|
| 173 | + $this->logging->setLogging($debugLvl, $outputType, $outputOption); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | { |
| 182 | 182 | if ($this->icinga2api == null) |
| 183 | 183 | { |
| 184 | - $this->icinga2api = new Icinga2API($this->apiHostname,$this->apiPort); |
|
| 184 | + $this->icinga2api=new Icinga2API($this->apiHostname, $this->apiPort); |
|
| 185 | 185 | } |
| 186 | 186 | return $this->icinga2api; |
| 187 | 187 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | if ($input_stream === false) |
| 201 | 201 | { |
| 202 | 202 | $this->writeTrapErrorToDB("Error reading trap (code 1/Stdin)"); |
| 203 | - $this->logging->log("Error reading stdin !",ERROR,''); |
|
| 203 | + $this->logging->log("Error reading stdin !", ERROR, ''); |
|
| 204 | 204 | return null; // note : exception thrown by logging |
| 205 | 205 | } |
| 206 | 206 | |
@@ -209,21 +209,21 @@ discard block |
||
| 209 | 209 | if ($this->receivingHost === false) |
| 210 | 210 | { |
| 211 | 211 | $this->writeTrapErrorToDB("Error reading trap (code 1/Line Host)"); |
| 212 | - $this->logging->log("Error reading Host !",ERROR,''); |
|
| 212 | + $this->logging->log("Error reading Host !", ERROR, ''); |
|
| 213 | 213 | } |
| 214 | 214 | // line 2 IP:port=>IP:port |
| 215 | 215 | $IP=chop(fgets($input_stream)); |
| 216 | 216 | if ($IP === false) |
| 217 | 217 | { |
| 218 | 218 | $this->writeTrapErrorToDB("Error reading trap (code 1/Line IP)"); |
| 219 | - $this->logging->log("Error reading IP !",ERROR,''); |
|
| 219 | + $this->logging->log("Error reading IP !", ERROR, ''); |
|
| 220 | 220 | } |
| 221 | 221 | $matches=array(); |
| 222 | - $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/',$IP,$matches); |
|
| 223 | - if ($ret_code===0 || $ret_code===false) |
|
| 222 | + $ret_code=preg_match('/.DP: \[(.*)\]:(.*)->\[(.*)\]:(.*)/', $IP, $matches); |
|
| 223 | + if ($ret_code === 0 || $ret_code === false) |
|
| 224 | 224 | { |
| 225 | 225 | $this->writeTrapErrorToDB("Error parsing trap (code 2/IP)"); |
| 226 | - $this->logging->log('Error parsing IP : '.$IP,ERROR,''); |
|
| 226 | + $this->logging->log('Error parsing IP : '.$IP, ERROR, ''); |
|
| 227 | 227 | } |
| 228 | 228 | else |
| 229 | 229 | { |
@@ -233,34 +233,34 @@ discard block |
||
| 233 | 233 | $this->trapData['destination_port']=$matches[4]; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - while (($vars=fgets($input_stream)) !==false) |
|
| 236 | + while (($vars=fgets($input_stream)) !== false) |
|
| 237 | 237 | { |
| 238 | 238 | $vars=chop($vars); |
| 239 | - $ret_code=preg_match('/^([^ ]+) (.*)$/',$vars,$matches); |
|
| 240 | - if ($ret_code===0 || $ret_code===false) |
|
| 239 | + $ret_code=preg_match('/^([^ ]+) (.*)$/', $vars, $matches); |
|
| 240 | + if ($ret_code === 0 || $ret_code === false) |
|
| 241 | 241 | { |
| 242 | - $this->logging->log('No match on trap data : '.$vars,WARN,''); |
|
| 242 | + $this->logging->log('No match on trap data : '.$vars, WARN, ''); |
|
| 243 | 243 | } |
| 244 | 244 | else |
| 245 | 245 | { |
| 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')) |
|
| 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 | 249 | } |
| 250 | 250 | else |
| 251 | 251 | { |
| 252 | - $object= new stdClass; |
|
| 253 | - $object->oid =$matches[1]; |
|
| 254 | - $object->value = $matches[2]; |
|
| 255 | - array_push($this->trapDataExt,$object); |
|
| 252 | + $object=new stdClass; |
|
| 253 | + $object->oid=$matches[1]; |
|
| 254 | + $object->value=$matches[2]; |
|
| 255 | + array_push($this->trapDataExt, $object); |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - if ($this->trapData['trap_oid']=='unknown') |
|
| 260 | + if ($this->trapData['trap_oid'] == 'unknown') |
|
| 261 | 261 | { |
| 262 | - $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)",$this->trapData['source_ip']); |
|
| 263 | - $this->logging->log('no trap oid found',ERROR,''); |
|
| 262 | + $this->writeTrapErrorToDB("No trap oid found : check snmptrapd configuration (code 3/OID)", $this->trapData['source_ip']); |
|
| 263 | + $this->logging->log('no trap oid found', ERROR, ''); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Translate oids. |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
| 285 | - $this->trapData['status']= 'waiting'; |
|
| 285 | + $this->trapData['status']='waiting'; |
|
| 286 | 286 | |
| 287 | 287 | return $this->trapData; |
| 288 | 288 | } |
@@ -298,40 +298,40 @@ discard block |
||
| 298 | 298 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 299 | 299 | |
| 300 | 300 | $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid.'\';'; |
| 301 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
| 301 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
| 302 | 302 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 303 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
| 303 | + $this->logging->log('No result in query : '.$sql, ERROR, ''); |
|
| 304 | 304 | } |
| 305 | 305 | $name=$ret_code->fetch(); |
| 306 | 306 | if ($name['name'] != null) |
| 307 | 307 | { |
| 308 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
| 308 | + return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | // Also check if it is an instance of OID |
| 312 | - $oid_instance=preg_replace('/\.[0-9]+$/','',$oid); |
|
| 312 | + $oid_instance=preg_replace('/\.[0-9]+$/', '', $oid); |
|
| 313 | 313 | |
| 314 | 314 | $sql='SELECT mib,name from '.$this->dbPrefix.'mib_cache WHERE oid=\''.$oid_instance.'\';'; |
| 315 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
| 315 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
| 316 | 316 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 317 | - $this->logging->log('No result in query : ' . $sql,ERROR,''); |
|
| 317 | + $this->logging->log('No result in query : '.$sql, ERROR, ''); |
|
| 318 | 318 | } |
| 319 | 319 | $name=$ret_code->fetch(); |
| 320 | 320 | if ($name['name'] != null) |
| 321 | 321 | { |
| 322 | - return array('trap_name_mib'=>$name['mib'],'trap_name'=>$name['name']); |
|
| 322 | + return array('trap_name_mib'=>$name['mib'], 'trap_name'=>$name['name']); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | // Try to get oid name from snmptranslate |
| 326 | - $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
|
| 326 | + $translate=exec($this->snmptranslate.' -m ALL -M +'.$this->snmptranslate_dirs. |
|
| 327 | 327 | ' '.$oid); |
| 328 | 328 | $matches=array(); |
| 329 | - $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
|
| 330 | - if ($ret_code===0 || $ret_code === false) { |
|
| 329 | + $ret_code=preg_match('/(.*)::(.*)/', $translate, $matches); |
|
| 330 | + if ($ret_code === 0 || $ret_code === false) { |
|
| 331 | 331 | return NULL; |
| 332 | 332 | } else { |
| 333 | - $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid,INFO); |
|
| 334 | - return array('trap_name_mib'=>$matches[1],'trap_name'=>$matches[2]); |
|
| 333 | + $this->logging->log('Found name with snmptrapd and not in DB for oid='.$oid, INFO); |
|
| 334 | + return array('trap_name_mib'=>$matches[1], 'trap_name'=>$matches[2]); |
|
| 335 | 335 | } |
| 336 | 336 | } |
| 337 | 337 | |
@@ -342,90 +342,90 @@ discard block |
||
| 342 | 342 | **/ |
| 343 | 343 | public function eraseOldTraps($days=0) |
| 344 | 344 | { |
| 345 | - if ($days==0) |
|
| 345 | + if ($days == 0) |
|
| 346 | 346 | { |
| 347 | 347 | if (($days=$this->getDBConfig('db_remove_days')) == null) |
| 348 | 348 | { |
| 349 | - $this->logging->log('No days specified & no db value : no tap erase' ,WARN,''); |
|
| 349 | + $this->logging->log('No days specified & no db value : no tap erase', WARN, ''); |
|
| 350 | 350 | return; |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 354 | - $daysago = strtotime("-".$days." day"); |
|
| 355 | - $sql= 'delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s",$daysago).'\';'; |
|
| 354 | + $daysago=strtotime("-".$days." day"); |
|
| 355 | + $sql='delete from '.$this->dbPrefix.'received where date_received < \''.date("Y-m-d H:i:s", $daysago).'\';'; |
|
| 356 | 356 | if ($db_conn->query($sql) === false) { |
| 357 | - $this->logging->log('Error erasing traps : '.$sql,ERROR,''); |
|
| 357 | + $this->logging->log('Error erasing traps : '.$sql, ERROR, ''); |
|
| 358 | 358 | } |
| 359 | - $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql,INFO); |
|
| 359 | + $this->logging->log('Erased traps older than '.$days.' day(s) : '.$sql, INFO); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** Write error to received trap database |
| 363 | 363 | */ |
| 364 | - public function writeTrapErrorToDB($message,$sourceIP=null,$trapoid=null) |
|
| 364 | + public function writeTrapErrorToDB($message, $sourceIP=null, $trapoid=null) |
|
| 365 | 365 | { |
| 366 | 366 | |
| 367 | 367 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 368 | 368 | |
| 369 | 369 | // add date time |
| 370 | - $insert_col ='date_received,status'; |
|
| 371 | - $insert_val = "'" . date("Y-m-d H:i:s")."','error'"; |
|
| 370 | + $insert_col='date_received,status'; |
|
| 371 | + $insert_val="'".date("Y-m-d H:i:s")."','error'"; |
|
| 372 | 372 | |
| 373 | - if ($sourceIP !=null) |
|
| 373 | + if ($sourceIP != null) |
|
| 374 | 374 | { |
| 375 | - $insert_col .=',source_ip'; |
|
| 376 | - $insert_val .=",'". $sourceIP ."'"; |
|
| 375 | + $insert_col.=',source_ip'; |
|
| 376 | + $insert_val.=",'".$sourceIP."'"; |
|
| 377 | 377 | } |
| 378 | - if ($trapoid !=null) |
|
| 378 | + if ($trapoid != null) |
|
| 379 | 379 | { |
| 380 | - $insert_col .=',trap_oid'; |
|
| 381 | - $insert_val .=",'". $trapoid ."'"; |
|
| 380 | + $insert_col.=',trap_oid'; |
|
| 381 | + $insert_val.=",'".$trapoid."'"; |
|
| 382 | 382 | } |
| 383 | - $insert_col .=',status_detail'; |
|
| 384 | - $insert_val .=",'". $message ."'"; |
|
| 383 | + $insert_col.=',status_detail'; |
|
| 384 | + $insert_val.=",'".$message."'"; |
|
| 385 | 385 | |
| 386 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
| 386 | + $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')'; |
|
| 387 | 387 | |
| 388 | 388 | switch ($this->trapsDB->trapDBType) |
| 389 | 389 | { |
| 390 | 390 | case 'pgsql': |
| 391 | - $sql .= ' RETURNING id;'; |
|
| 392 | - $this->logging->log('sql : '.$sql,INFO); |
|
| 391 | + $sql.=' RETURNING id;'; |
|
| 392 | + $this->logging->log('sql : '.$sql, INFO); |
|
| 393 | 393 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 394 | - $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
| 394 | + $this->logging->log('Error SQL insert : '.$sql, 1, ''); |
|
| 395 | 395 | } |
| 396 | - $this->logging->log('SQL insertion OK',INFO ); |
|
| 396 | + $this->logging->log('SQL insertion OK', INFO); |
|
| 397 | 397 | // Get last id to insert oid/values in secondary table |
| 398 | 398 | if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
| 399 | 399 | |
| 400 | - $this->logging->log('Erreur recuperation id',1,''); |
|
| 400 | + $this->logging->log('Erreur recuperation id', 1, ''); |
|
| 401 | 401 | } |
| 402 | - if (! isset($inserted_id_ret['id'])) { |
|
| 403 | - $this->logging->log('Error getting id',1,''); |
|
| 402 | + if (!isset($inserted_id_ret['id'])) { |
|
| 403 | + $this->logging->log('Error getting id', 1, ''); |
|
| 404 | 404 | } |
| 405 | 405 | $this->trapId=$inserted_id_ret['id']; |
| 406 | 406 | break; |
| 407 | 407 | case 'mysql': |
| 408 | - $sql .= ';'; |
|
| 409 | - $this->logging->log('sql : '.$sql,INFO ); |
|
| 408 | + $sql.=';'; |
|
| 409 | + $this->logging->log('sql : '.$sql, INFO); |
|
| 410 | 410 | if ($db_conn->query($sql) === false) { |
| 411 | - $this->logging->log('Error SQL insert : '.$sql,1,''); |
|
| 411 | + $this->logging->log('Error SQL insert : '.$sql, 1, ''); |
|
| 412 | 412 | } |
| 413 | - $this->logging->log('SQL insertion OK',INFO ); |
|
| 413 | + $this->logging->log('SQL insertion OK', INFO); |
|
| 414 | 414 | // Get last id to insert oid/values in secondary table |
| 415 | 415 | $sql='SELECT LAST_INSERT_ID();'; |
| 416 | 416 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 417 | - $this->logging->log('Erreur recuperation id',1,''); |
|
| 417 | + $this->logging->log('Erreur recuperation id', 1, ''); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | $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"); |
|
| 421 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 422 | 422 | $this->trapId=$inserted_id; |
| 423 | 423 | break; |
| 424 | 424 | default: |
| 425 | - $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,1,''); |
|
| 425 | + $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, 1, ''); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - $this->logging->log('id found: '. $this->trapId,INFO ); |
|
| 428 | + $this->logging->log('id found: '.$this->trapId, INFO); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** Write trap data to trap database |
@@ -442,86 +442,86 @@ discard block |
||
| 442 | 442 | $insert_col=''; |
| 443 | 443 | $insert_val=''; |
| 444 | 444 | // add date time |
| 445 | - $this->trapData['date_received'] = date("Y-m-d H:i:s"); |
|
| 445 | + $this->trapData['date_received']=date("Y-m-d H:i:s"); |
|
| 446 | 446 | |
| 447 | 447 | $firstcol=1; |
| 448 | 448 | foreach ($this->trapData as $col => $val) |
| 449 | 449 | { |
| 450 | - if ($firstcol==0) |
|
| 450 | + if ($firstcol == 0) |
|
| 451 | 451 | { |
| 452 | - $insert_col .=','; |
|
| 453 | - $insert_val .=','; |
|
| 452 | + $insert_col.=','; |
|
| 453 | + $insert_val.=','; |
|
| 454 | 454 | } |
| 455 | - $insert_col .= $col ; |
|
| 456 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
| 455 | + $insert_col.=$col; |
|
| 456 | + $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val); |
|
| 457 | 457 | $firstcol=0; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received (' . $insert_col . ') VALUES ('.$insert_val.')'; |
|
| 460 | + $sql='INSERT INTO '.$this->dbPrefix.'received ('.$insert_col.') VALUES ('.$insert_val.')'; |
|
| 461 | 461 | switch ($this->trapsDB->trapDBType) |
| 462 | 462 | { |
| 463 | 463 | case 'pgsql': |
| 464 | - $sql .= ' RETURNING id;'; |
|
| 465 | - $this->logging->log('sql : '.$sql,INFO ); |
|
| 464 | + $sql.=' RETURNING id;'; |
|
| 465 | + $this->logging->log('sql : '.$sql, INFO); |
|
| 466 | 466 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 467 | - $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
| 467 | + $this->logging->log('Error SQL insert : '.$sql, ERROR, ''); |
|
| 468 | 468 | } |
| 469 | - $this->logging->log('SQL insertion OK',INFO ); |
|
| 469 | + $this->logging->log('SQL insertion OK', INFO); |
|
| 470 | 470 | // Get last id to insert oid/values in secondary table |
| 471 | 471 | if (($inserted_id_ret=$ret_code->fetch(PDO::FETCH_ASSOC)) === false) { |
| 472 | 472 | |
| 473 | - $this->logging->log('Erreur recuperation id',ERROR,''); |
|
| 473 | + $this->logging->log('Erreur recuperation id', ERROR, ''); |
|
| 474 | 474 | } |
| 475 | - if (! isset($inserted_id_ret['id'])) { |
|
| 476 | - $this->logging->log('Error getting id',ERROR,''); |
|
| 475 | + if (!isset($inserted_id_ret['id'])) { |
|
| 476 | + $this->logging->log('Error getting id', ERROR, ''); |
|
| 477 | 477 | } |
| 478 | 478 | $this->trapId=$inserted_id_ret['id']; |
| 479 | 479 | break; |
| 480 | 480 | case 'mysql': |
| 481 | - $sql .= ';'; |
|
| 482 | - $this->logging->log('sql : '.$sql,INFO ); |
|
| 481 | + $sql.=';'; |
|
| 482 | + $this->logging->log('sql : '.$sql, INFO); |
|
| 483 | 483 | if ($db_conn->query($sql) === false) { |
| 484 | - $this->logging->log('Error SQL insert : '.$sql,ERROR,''); |
|
| 484 | + $this->logging->log('Error SQL insert : '.$sql, ERROR, ''); |
|
| 485 | 485 | } |
| 486 | - $this->logging->log('SQL insertion OK',INFO ); |
|
| 486 | + $this->logging->log('SQL insertion OK', INFO); |
|
| 487 | 487 | // Get last id to insert oid/values in secondary table |
| 488 | 488 | $sql='SELECT LAST_INSERT_ID();'; |
| 489 | 489 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 490 | - $this->logging->log('Erreur recuperation id',ERROR,''); |
|
| 490 | + $this->logging->log('Erreur recuperation id', ERROR, ''); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | $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"); |
|
| 494 | + if ($inserted_id == false) throw new Exception("Weird SQL error : last_insert_id returned false : open issue"); |
|
| 495 | 495 | $this->trapId=$inserted_id; |
| 496 | 496 | break; |
| 497 | 497 | default: |
| 498 | - $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType,ERROR,''); |
|
| 498 | + $this->logging->log('Error SQL type unknown : '.$this->trapsDB->trapDBType, ERROR, ''); |
|
| 499 | 499 | } |
| 500 | - $this->logging->log('id found: '.$this->trapId,INFO ); |
|
| 500 | + $this->logging->log('id found: '.$this->trapId, INFO); |
|
| 501 | 501 | |
| 502 | 502 | // Fill trap extended data table |
| 503 | 503 | foreach ($this->trapDataExt as $value) { |
| 504 | 504 | // TODO : detect if trap value is encoded and decode it to UTF-8 for database |
| 505 | 505 | $firstcol=1; |
| 506 | - $value->trap_id = $this->trapId; |
|
| 506 | + $value->trap_id=$this->trapId; |
|
| 507 | 507 | $insert_col=''; |
| 508 | 508 | $insert_val=''; |
| 509 | 509 | foreach ($value as $col => $val) |
| 510 | 510 | { |
| 511 | - if ($firstcol==0) |
|
| 511 | + if ($firstcol == 0) |
|
| 512 | 512 | { |
| 513 | - $insert_col .=','; |
|
| 514 | - $insert_val .=','; |
|
| 513 | + $insert_col.=','; |
|
| 514 | + $insert_val.=','; |
|
| 515 | 515 | } |
| 516 | - $insert_col .= $col; |
|
| 517 | - $insert_val .= ($val==null)? 'NULL' : $db_conn->quote($val); |
|
| 516 | + $insert_col.=$col; |
|
| 517 | + $insert_val.=($val == null) ? 'NULL' : $db_conn->quote($val); |
|
| 518 | 518 | $firstcol=0; |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | - $sql= 'INSERT INTO '.$this->dbPrefix.'received_data (' . $insert_col . ') VALUES ('.$insert_val.');'; |
|
| 521 | + $sql='INSERT INTO '.$this->dbPrefix.'received_data ('.$insert_col.') VALUES ('.$insert_val.');'; |
|
| 522 | 522 | |
| 523 | 523 | if ($db_conn->query($sql) === false) { |
| 524 | - $this->logging->log('Erreur insertion data : ' . $sql,WARN,''); |
|
| 524 | + $this->logging->log('Erreur insertion data : '.$sql, WARN, ''); |
|
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -531,14 +531,14 @@ discard block |
||
| 531 | 531 | * @param $oid string oid in numeric |
| 532 | 532 | * @return mixed|boolean : PDO object or false |
| 533 | 533 | */ |
| 534 | - protected function getRules($ip,$oid) |
|
| 534 | + protected function getRules($ip, $oid) |
|
| 535 | 535 | { |
| 536 | 536 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 537 | 537 | // fetch rules based on IP in rule and OID |
| 538 | 538 | $sql='SELECT * from '.$this->dbPrefix.'rules WHERE trap_oid=\''.$oid.'\' '; |
| 539 | - $this->logging->log('SQL query : '.$sql,DEBUG ); |
|
| 539 | + $this->logging->log('SQL query : '.$sql, DEBUG); |
|
| 540 | 540 | if (($ret_code=$db_conn->query($sql)) === false) { |
| 541 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
| 541 | + $this->logging->log('No result in query : '.$sql, WARN, ''); |
|
| 542 | 542 | return false; |
| 543 | 543 | } |
| 544 | 544 | $rules_all=$ret_code->fetchAll(); |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | $rule_ret_key=0; |
| 548 | 548 | foreach ($rules_all as $key => $rule) |
| 549 | 549 | { |
| 550 | - if ($rule['ip4']==$ip || $rule['ip6']==$ip) |
|
| 550 | + if ($rule['ip4'] == $ip || $rule['ip6'] == $ip) |
|
| 551 | 551 | { |
| 552 | 552 | $rules_ret[$rule_ret_key]=$rules_all[$key]; |
| 553 | 553 | //TODO : get host name by API (and check if correct in rule). |
@@ -555,7 +555,7 @@ discard block |
||
| 555 | 555 | continue; |
| 556 | 556 | } |
| 557 | 557 | // TODO : get hosts IP by API |
| 558 | - if (isset($rule['host_group_name']) && $rule['host_group_name']!=null) |
|
| 558 | + if (isset($rule['host_group_name']) && $rule['host_group_name'] != null) |
|
| 559 | 559 | { // get ips of group members by oid |
| 560 | 560 | $db_conn2=$this->trapsDB->db_connect_ido(); |
| 561 | 561 | $sql="SELECT m.host_object_id, a.address as ip4, a.address6 as ip6, b.name1 as host_name |
@@ -566,15 +566,15 @@ discard block |
||
| 566 | 566 | LEFT JOIN icinga_objects as b ON b.object_id = a.host_object_id |
| 567 | 567 | WHERE o.name1='".$rule['host_group_name']."';"; |
| 568 | 568 | if (($ret_code2=$db_conn2->query($sql)) === false) { |
| 569 | - $this->logging->log('No result in query : ' . $sql,WARN,''); |
|
| 569 | + $this->logging->log('No result in query : '.$sql, WARN, ''); |
|
| 570 | 570 | continue; |
| 571 | 571 | } |
| 572 | 572 | $grouphosts=$ret_code2->fetchAll(); |
| 573 | 573 | //echo "rule grp :\n";print_r($grouphosts);echo "\n"; |
| 574 | - foreach ( $grouphosts as $host) |
|
| 574 | + foreach ($grouphosts as $host) |
|
| 575 | 575 | { |
| 576 | 576 | //echo $host['ip4']."\n"; |
| 577 | - if ($host['ip4']==$ip || $host['ip6']==$ip) |
|
| 577 | + if ($host['ip4'] == $ip || $host['ip6'] == $ip) |
|
| 578 | 578 | { |
| 579 | 579 | //echo "Rule added \n"; |
| 580 | 580 | $rules_ret[$rule_ret_key]=$rules_all[$key]; |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 598 | 598 | $sql="UPDATE ".$this->dbPrefix."rules SET num_match = '".$set."' WHERE (id = '".$id."');"; |
| 599 | 599 | if ($db_conn->query($sql) === false) { |
| 600 | - $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
| 600 | + $this->logging->log('Error in update query : '.$sql, WARN, ''); |
|
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | 603 | |
@@ -609,23 +609,23 @@ discard block |
||
| 609 | 609 | * @param string $display |
| 610 | 610 | * @returnn bool true is service check was sent without error |
| 611 | 611 | */ |
| 612 | - public function serviceCheckResult($host,$service,$state,$display) |
|
| 612 | + public function serviceCheckResult($host, $service, $state, $display) |
|
| 613 | 613 | { |
| 614 | 614 | if ($this->apiUse === false) |
| 615 | 615 | { |
| 616 | - $send = '[' . date('U') .'] PROCESS_SERVICE_CHECK_RESULT;' . |
|
| 617 | - $host.';' .$service .';' . $state . ';'.$display; |
|
| 618 | - $this->logging->log( $send." : to : " .$this->icinga2cmd,INFO ); |
|
| 616 | + $send='['.date('U').'] PROCESS_SERVICE_CHECK_RESULT;'. |
|
| 617 | + $host.';'.$service.';'.$state.';'.$display; |
|
| 618 | + $this->logging->log($send." : to : ".$this->icinga2cmd, INFO); |
|
| 619 | 619 | |
| 620 | 620 | // TODO : file_put_contents & fopen (,'w' or 'a') does not work. See why. Or not as using API will be by default.... |
| 621 | - exec('echo "'.$send.'" > ' .$this->icinga2cmd); |
|
| 621 | + exec('echo "'.$send.'" > '.$this->icinga2cmd); |
|
| 622 | 622 | return true; |
| 623 | 623 | } |
| 624 | 624 | else |
| 625 | 625 | { |
| 626 | 626 | // Get perfdata if found |
| 627 | 627 | $matches=array(); |
| 628 | - if (preg_match('/(.*)\|(.*)/',$display,$matches) == 1) |
|
| 628 | + if (preg_match('/(.*)\|(.*)/', $display, $matches) == 1) |
|
| 629 | 629 | { |
| 630 | 630 | $display=$matches[1]; |
| 631 | 631 | $perfdata=$matches[2]; |
@@ -635,17 +635,17 @@ discard block |
||
| 635 | 635 | $perfdata=''; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - $api = $this->getAPI(); |
|
| 638 | + $api=$this->getAPI(); |
|
| 639 | 639 | $api->setCredentials($this->apiUsername, $this->apiPassword); |
| 640 | - list($retcode,$retmessage)=$api->serviceCheckResult($host,$service,$state,$display,$perfdata); |
|
| 640 | + list($retcode, $retmessage)=$api->serviceCheckResult($host, $service, $state, $display, $perfdata); |
|
| 641 | 641 | if ($retcode == false) |
| 642 | 642 | { |
| 643 | - $this->logging->log( "Error sending result : " .$retmessage,WARN,''); |
|
| 643 | + $this->logging->log("Error sending result : ".$retmessage, WARN, ''); |
|
| 644 | 644 | return false; |
| 645 | 645 | } |
| 646 | 646 | else |
| 647 | 647 | { |
| 648 | - $this->logging->log( "Sent result : " .$retmessage,INFO ); |
|
| 648 | + $this->logging->log("Sent result : ".$retmessage, INFO); |
|
| 649 | 649 | return true; |
| 650 | 650 | } |
| 651 | 651 | } |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | |
| 654 | 654 | public function getHostByIP($ip) |
| 655 | 655 | { |
| 656 | - $api = $this->getAPI(); |
|
| 656 | + $api=$this->getAPI(); |
|
| 657 | 657 | $api->setCredentials($this->apiUsername, $this->apiPassword); |
| 658 | 658 | return $api->getHostByIP($ip); |
| 659 | 659 | } |
@@ -666,35 +666,35 @@ discard block |
||
| 666 | 666 | protected function applyDisplay($display) |
| 667 | 667 | { |
| 668 | 668 | $matches=array(); |
| 669 | - while (preg_match('/_OID\(([0-9\.\*]+)\)/',$display,$matches) == 1) |
|
| 669 | + while (preg_match('/_OID\(([0-9\.\*]+)\)/', $display, $matches) == 1) |
|
| 670 | 670 | { |
| 671 | 671 | $oid=$matches[1]; |
| 672 | 672 | $found=0; |
| 673 | 673 | // Test and transform regexp |
| 674 | - $oidR = $this->ruleClass->regexp_eval($oid); |
|
| 674 | + $oidR=$this->ruleClass->regexp_eval($oid); |
|
| 675 | 675 | |
| 676 | - foreach($this->trapDataExt as $val) |
|
| 676 | + foreach ($this->trapDataExt as $val) |
|
| 677 | 677 | { |
| 678 | - if (preg_match("/^$oidR$/",$val->oid) == 1) |
|
| 678 | + if (preg_match("/^$oidR$/", $val->oid) == 1) |
|
| 679 | 679 | { |
| 680 | - $val->value=preg_replace('/"/','',$val->value); |
|
| 680 | + $val->value=preg_replace('/"/', '', $val->value); |
|
| 681 | 681 | $rep=0; |
| 682 | - $display=preg_replace('/_OID\('.$oid.'\)/',$val->value,$display,-1,$rep); |
|
| 683 | - if ($rep==0) |
|
| 682 | + $display=preg_replace('/_OID\('.$oid.'\)/', $val->value, $display, -1, $rep); |
|
| 683 | + if ($rep == 0) |
|
| 684 | 684 | { |
| 685 | - $this->logging->log("Error in display",WARN,''); |
|
| 685 | + $this->logging->log("Error in display", WARN, ''); |
|
| 686 | 686 | return $display; |
| 687 | 687 | } |
| 688 | 688 | $found=1; |
| 689 | 689 | break; |
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | - if ($found==0) |
|
| 692 | + if ($found == 0) |
|
| 693 | 693 | { |
| 694 | - $display=preg_replace('/_OID\('.$oid.'\)/','<not in trap>',$display,-1,$rep); |
|
| 695 | - if ($rep==0) |
|
| 694 | + $display=preg_replace('/_OID\('.$oid.'\)/', '<not in trap>', $display, -1, $rep); |
|
| 695 | + if ($rep == 0) |
|
| 696 | 696 | { |
| 697 | - $this->logging->log("Error in display",WARN,''); |
|
| 697 | + $this->logging->log("Error in display", WARN, ''); |
|
| 698 | 698 | return $display; |
| 699 | 699 | } |
| 700 | 700 | } |
@@ -706,11 +706,11 @@ discard block |
||
| 706 | 706 | */ |
| 707 | 707 | public function applyRules() |
| 708 | 708 | { |
| 709 | - $rules = $this->getRules($this->trapData['source_ip'],$this->trapData['trap_oid']); |
|
| 709 | + $rules=$this->getRules($this->trapData['source_ip'], $this->trapData['trap_oid']); |
|
| 710 | 710 | |
| 711 | - if ($rules===false || count($rules)==0) |
|
| 711 | + if ($rules === false || count($rules) == 0) |
|
| 712 | 712 | { |
| 713 | - $this->logging->log('No rules found for this trap',INFO ); |
|
| 713 | + $this->logging->log('No rules found for this trap', INFO); |
|
| 714 | 714 | $this->trapData['status']='unknown'; |
| 715 | 715 | $this->trapToDb=true; |
| 716 | 716 | return; |
@@ -725,59 +725,59 @@ discard block |
||
| 725 | 725 | $service_name=$rule['service_name']; |
| 726 | 726 | |
| 727 | 727 | $display=$this->applyDisplay($rule['display']); |
| 728 | - $this->trapAction = ($this->trapAction==null)? '' : $this->trapAction . ', '; |
|
| 728 | + $this->trapAction=($this->trapAction == null) ? '' : $this->trapAction.', '; |
|
| 729 | 729 | try |
| 730 | 730 | { |
| 731 | - $this->logging->log('Rule to eval : '.$rule['rule'],INFO ); |
|
| 732 | - $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt) ; |
|
| 731 | + $this->logging->log('Rule to eval : '.$rule['rule'], INFO); |
|
| 732 | + $evalr=$this->ruleClass->eval_rule($rule['rule'], $this->trapDataExt); |
|
| 733 | 733 | //->eval_rule($rule['rule']); |
| 734 | 734 | |
| 735 | 735 | if ($evalr == true) |
| 736 | 736 | { |
| 737 | 737 | //$this->logging->log('rules OOK: '.print_r($rule),INFO ); |
| 738 | 738 | $action=$rule['action_match']; |
| 739 | - $this->logging->log('action OK : '.$action,INFO ); |
|
| 739 | + $this->logging->log('action OK : '.$action, INFO); |
|
| 740 | 740 | if ($action >= 0) |
| 741 | 741 | { |
| 742 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display) == false) |
|
| 742 | + if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false) |
|
| 743 | 743 | { |
| 744 | 744 | $this->trapAction.='Error sending status : check cmd/API'; |
| 745 | 745 | } |
| 746 | 746 | else |
| 747 | 747 | { |
| 748 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
| 748 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
| 749 | 749 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 750 | 750 | } |
| 751 | 751 | } |
| 752 | 752 | else |
| 753 | 753 | { |
| 754 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
| 754 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
| 755 | 755 | } |
| 756 | - $this->trapToDb=($action==-2)?false:true; |
|
| 756 | + $this->trapToDb=($action == -2) ?false:true; |
|
| 757 | 757 | } |
| 758 | 758 | else |
| 759 | 759 | { |
| 760 | 760 | //$this->logging->log('rules KOO : '.print_r($rule),INFO ); |
| 761 | 761 | |
| 762 | 762 | $action=$rule['action_nomatch']; |
| 763 | - $this->logging->log('action NOK : '.$action,INFO ); |
|
| 763 | + $this->logging->log('action NOK : '.$action, INFO); |
|
| 764 | 764 | if ($action >= 0) |
| 765 | 765 | { |
| 766 | - if ($this->serviceCheckResult($host_name,$service_name,$action,$display)==false) |
|
| 766 | + if ($this->serviceCheckResult($host_name, $service_name, $action, $display) == false) |
|
| 767 | 767 | { |
| 768 | 768 | $this->trapAction.='Error sending status : check cmd/API'; |
| 769 | 769 | } |
| 770 | 770 | else |
| 771 | 771 | { |
| 772 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
| 772 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
| 773 | 773 | $this->trapAction.='Status '.$action.' to '.$host_name.'/'.$service_name; |
| 774 | 774 | } |
| 775 | 775 | } |
| 776 | 776 | else |
| 777 | 777 | { |
| 778 | - $this->add_rule_match($rule['id'],$rule['num_match']+1); |
|
| 778 | + $this->add_rule_match($rule['id'], $rule['num_match'] + 1); |
|
| 779 | 779 | } |
| 780 | - $this->trapToDb=($action==-2)?false:true; |
|
| 780 | + $this->trapToDb=($action == -2) ?false:true; |
|
| 781 | 781 | } |
| 782 | 782 | // Put name in source_name |
| 783 | 783 | if (!isset($this->trapData['source_name'])) |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | } |
| 787 | 787 | else |
| 788 | 788 | { |
| 789 | - if (!preg_match('/'.$rule['host_name'].'/',$this->trapData['source_name'])) |
|
| 789 | + if (!preg_match('/'.$rule['host_name'].'/', $this->trapData['source_name'])) |
|
| 790 | 790 | { // only add if not present |
| 791 | 791 | $this->trapData['source_name'].=','.$rule['host_name']; |
| 792 | 792 | } |
@@ -794,13 +794,13 @@ discard block |
||
| 794 | 794 | } |
| 795 | 795 | catch (Exception $e) |
| 796 | 796 | { |
| 797 | - $this->logging->log('Error in rule eval : '.$e->getMessage(),WARN,''); |
|
| 797 | + $this->logging->log('Error in rule eval : '.$e->getMessage(), WARN, ''); |
|
| 798 | 798 | $this->trapAction.=' ERR : '.$e->getMessage(); |
| 799 | 799 | $this->trapData['status']='error'; |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | } |
| 803 | - if ($this->trapData['status']=='error') |
|
| 803 | + if ($this->trapData['status'] == 'error') |
|
| 804 | 804 | { |
| 805 | 805 | $this->trapToDb=true; // Always put errors in DB for the use can see |
| 806 | 806 | } |
@@ -816,13 +816,13 @@ discard block |
||
| 816 | 816 | public function add_rule_final($time) |
| 817 | 817 | { |
| 818 | 818 | $db_conn=$this->trapsDB->db_connect_trap(); |
| 819 | - if ($this->trapAction==null) |
|
| 819 | + if ($this->trapAction == null) |
|
| 820 | 820 | { |
| 821 | 821 | $this->trapAction='No action'; |
| 822 | 822 | } |
| 823 | 823 | $sql="UPDATE ".$this->dbPrefix."received SET process_time = '".$time."' , status_detail='".$this->trapAction."' WHERE (id = '".$this->trapId."');"; |
| 824 | 824 | if ($db_conn->query($sql) === false) { |
| 825 | - $this->logging->log('Error in update query : ' . $sql,WARN,''); |
|
| 825 | + $this->logging->log('Error in update query : '.$sql, WARN, ''); |
|
| 826 | 826 | } |
| 827 | 827 | } |
| 828 | 828 | |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | WHERE s.current_state != 0;"; |
| 846 | 846 | $db_conn=$this->trapsDB->db_connect_ido(); |
| 847 | 847 | if (($services_db=$db_conn->query($sql_query)) === false) { // set err to 1 to throw exception. |
| 848 | - $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
| 848 | + $this->logging->log('No result in query : '.$sql_query, ERROR, ''); |
|
| 849 | 849 | return 0; |
| 850 | 850 | } |
| 851 | 851 | $services=$services_db->fetchAll(); |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | $sql_query="SELECT host_name, service_name, revert_ok FROM ".$this->dbPrefix."rules where revert_ok != 0;"; |
| 855 | 855 | $db_conn2=$this->trapsDB->db_connect_trap(); |
| 856 | 856 | if (($rules_db=$db_conn2->query($sql_query)) === false) { |
| 857 | - $this->logging->log('No result in query : ' . $sql_query,ERROR,''); |
|
| 857 | + $this->logging->log('No result in query : '.$sql_query, ERROR, ''); |
|
| 858 | 858 | return 0; |
| 859 | 859 | } |
| 860 | 860 | $rules=$rules_db->fetchAll(); |
@@ -870,13 +870,13 @@ discard block |
||
| 870 | 870 | $service['host_name'] == $rule['host_name'] && |
| 871 | 871 | ($service['last_check'] + $rule['revert_ok']) < $now) |
| 872 | 872 | { |
| 873 | - $this->serviceCheckResult($service['host_name'],$service['service_name'],0,'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
| 873 | + $this->serviceCheckResult($service['host_name'], $service['service_name'], 0, 'Reset service to OK after '.$rule['revert_ok'].' seconds'); |
|
| 874 | 874 | $numreset++; |
| 875 | 875 | } |
| 876 | 876 | } |
| 877 | 877 | } |
| 878 | 878 | echo "\n"; |
| 879 | - echo $numreset . " service(s) reset to OK\n"; |
|
| 879 | + echo $numreset." service(s) reset to OK\n"; |
|
| 880 | 880 | return 0; |
| 881 | 881 | |
| 882 | 882 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | use Trapdirector\Trap; |
| 5 | 5 | |
| 6 | 6 | // start |
| 7 | -$time1 = microtime(true); |
|
| 7 | +$time1=microtime(true); |
|
| 8 | 8 | |
| 9 | 9 | require_once ('trap_class.php'); |
| 10 | 10 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | try |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - $trap = new Trap($icingaweb2Etc); |
|
| 20 | + $trap=new Trap($icingaweb2Etc); |
|
| 21 | 21 | //$Trap = new Trap($icingaweb2Etc,4,'display'); // For debug |
| 22 | 22 | //$Trap = new Trap($icingaweb2Etc,4,'syslog'); // For debug |
| 23 | 23 | //$Trap->setLogging(4,'syslog'); |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | { |
| 39 | 39 | if ($trap == null) |
| 40 | 40 | { // Exception in trap creation : log in display & syslog |
| 41 | - $logging = new Logging(); |
|
| 42 | - $logging->log("Caught exception creating Trap class",2); |
|
| 41 | + $logging=new Logging(); |
|
| 42 | + $logging->log("Caught exception creating Trap class", 2); |
|
| 43 | 43 | } |
| 44 | 44 | else |
| 45 | 45 | { |
| 46 | - $trap->logging->log("Exception : ". $e->getMessage(),2,0); |
|
| 46 | + $trap->logging->log("Exception : ".$e->getMessage(), 2, 0); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | |
@@ -38,39 +38,39 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function updateAction() |
| 40 | 40 | { |
| 41 | - $background = $this->params->get('pid', null); |
|
| 42 | - $logLevel= $this->params->has('verb') ? 4 : 2; |
|
| 43 | - if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
| 44 | - $forceCheck=$this->params->has('force-check')?True:False; |
|
| 41 | + $background=$this->params->get('pid', null); |
|
| 42 | + $logLevel=$this->params->has('verb') ? 4 : 2; |
|
| 43 | + if ($this->params->has('force-check')) { echo "Not implemented"; return; } |
|
| 44 | + $forceCheck=$this->params->has('force-check') ?True:False; |
|
| 45 | 45 | $pid=1; |
| 46 | 46 | if ($background != null) |
| 47 | 47 | { |
| 48 | - $file=@fopen($background,'w'); |
|
| 48 | + $file=@fopen($background, 'w'); |
|
| 49 | 49 | if ($file == false) |
| 50 | 50 | { |
| 51 | 51 | echo 'Error : cannot open pid file '.$background; |
| 52 | 52 | return 1; |
| 53 | 53 | } |
| 54 | - $pid = pcntl_fork(); |
|
| 54 | + $pid=pcntl_fork(); |
|
| 55 | 55 | if ($pid == -1) { |
| 56 | 56 | echo 'Error : Cannot fork process'; |
| 57 | 57 | return 1; |
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
| 61 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
| 61 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
| 62 | 62 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 63 | - $trap = new Trap($icingaweb2_etc); |
|
| 63 | + $trap=new Trap($icingaweb2_etc); |
|
| 64 | 64 | if ($pid == 1) |
| 65 | 65 | { |
| 66 | - $trap->setLogging($logLevel,'display'); |
|
| 66 | + $trap->setLogging($logLevel, 'display'); |
|
| 67 | 67 | } |
| 68 | 68 | else |
| 69 | 69 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
| 70 | 70 | if ($pid != 0) |
| 71 | 71 | { |
| 72 | 72 | // father process |
| 73 | - fwrite($file,$pid); |
|
| 73 | + fwrite($file, $pid); |
|
| 74 | 74 | fclose($file); |
| 75 | 75 | echo "OK : process $pid in bckground"; |
| 76 | 76 | return 0; |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | fclose(STDERR); |
| 85 | 85 | try |
| 86 | 86 | { |
| 87 | - $trap->mibClass->update_mib_database(false,$forceCheck); |
|
| 87 | + $trap->mibClass->update_mib_database(false, $forceCheck); |
|
| 88 | 88 | } |
| 89 | 89 | catch (Exception $e) |
| 90 | 90 | { |
| 91 | - $trap->logging->log('Error in updating : ' . $e->getMessage(),2); |
|
| 91 | + $trap->logging->log('Error in updating : '.$e->getMessage(), 2); |
|
| 92 | 92 | } |
| 93 | 93 | unlink($background); |
| 94 | 94 | return 0; |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | echo "Update main mib database : \n"; |
| 102 | 102 | echo "# (trap found) C (trap already processed) . (every 2 seconds) : \n"; |
| 103 | - $trap->mibClass->update_mib_database(true,$forceCheck); |
|
| 103 | + $trap->mibClass->update_mib_database(true, $forceCheck); |
|
| 104 | 104 | echo "Done\n"; |
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | catch (Exception $e) |
| 108 | 108 | { |
| 109 | - echo 'Error in updating : ' . $e->getMessage(); |
|
| 109 | + echo 'Error in updating : '.$e->getMessage(); |
|
| 110 | 110 | } |
| 111 | 111 | if ($pid != 1) |
| 112 | 112 | { |
@@ -134,23 +134,23 @@ discard block |
||
| 134 | 134 | return; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $Config = new TrapModuleConfig($db_prefix); |
|
| 137 | + $Config=new TrapModuleConfig($db_prefix); |
|
| 138 | 138 | |
| 139 | 139 | try |
| 140 | 140 | { |
| 141 | 141 | |
| 142 | 142 | $dbresource=$this->Config()->get('config', 'database'); |
| 143 | 143 | echo "DB name : $dbresource\n"; |
| 144 | - $db = IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
| 144 | + $db=IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
| 145 | 145 | |
| 146 | - $query = $db->delete( |
|
| 146 | + $query=$db->delete( |
|
| 147 | 147 | $Config->getMIBCacheTableName(), |
| 148 | 148 | 'id>0'); |
| 149 | - echo 'Deleted '. $query . " traps and objects\n"; |
|
| 149 | + echo 'Deleted '.$query." traps and objects\n"; |
|
| 150 | 150 | } |
| 151 | 151 | catch (Exception $e) |
| 152 | 152 | { |
| 153 | - echo 'Error in DB : ' . $e->getMessage(); |
|
| 153 | + echo 'Error in DB : '.$e->getMessage(); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | |