@@ -10,22 +10,22 @@ |
||
10 | 10 | 'url' => 'settings' |
11 | 11 | )); |
12 | 12 | |
13 | -$section = $this->menuSection(N_('Traps'),array ( |
|
13 | +$section=$this->menuSection(N_('Traps'), array( |
|
14 | 14 | 'icon' => 'filter', |
15 | 15 | 'url' => 'trapdirector' |
16 | 16 | )); |
17 | 17 | |
18 | -$section->add(N_('Status & Mibs'),array( |
|
18 | +$section->add(N_('Status & Mibs'), array( |
|
19 | 19 | 'url' => 'trapdirector/status/', |
20 | 20 | 'permission' => 'trapdirector/view' |
21 | 21 | )); |
22 | 22 | |
23 | -$section->add(N_('Received'),array( |
|
23 | +$section->add(N_('Received'), array( |
|
24 | 24 | 'url' => 'trapdirector/received/', |
25 | 25 | 'permission' => 'trapdirector/view' |
26 | 26 | )); |
27 | 27 | |
28 | -$section->add(N_('Handlers'),array( |
|
28 | +$section->add(N_('Handlers'), array( |
|
29 | 29 | 'url' => 'trapdirector/handler/', |
30 | 30 | 'permission' => 'trapdirector/config' |
31 | 31 | )); |
@@ -24,21 +24,21 @@ |
||
24 | 24 | public function dbAction() |
25 | 25 | { |
26 | 26 | $db_prefix=$this->Config()->get('config', 'database_prefix'); |
27 | - $Config = new TrapModuleConfig($db_prefix); |
|
27 | + $Config=new TrapModuleConfig($db_prefix); |
|
28 | 28 | |
29 | 29 | try |
30 | 30 | { |
31 | 31 | |
32 | 32 | $dbresource=$this->Config()->get('config', 'database'); |
33 | - printf("DB name : %s\n",$dbresource); |
|
34 | - $dataBase = IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
33 | + printf("DB name : %s\n", $dbresource); |
|
34 | + $dataBase=IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
35 | 35 | |
36 | - $query = $dataBase->select()->from($Config->getTrapTableName(),array('COUNT(*)')); |
|
37 | - printf("Number of traps : %s\n", $dataBase->fetchOne($query) ); |
|
38 | - $query = $dataBase->select()->from($Config->getTrapDataTableName(),array('COUNT(*)')); |
|
39 | - printf("Number of trap objects : %s\n", $dataBase->fetchOne($query) ); |
|
40 | - $query = $dataBase->select()->from($Config->getTrapRuleName(),array('COUNT(*)')); |
|
41 | - printf("Number of rules : %s\n", $dataBase->fetchOne($query) ); |
|
36 | + $query=$dataBase->select()->from($Config->getTrapTableName(), array('COUNT(*)')); |
|
37 | + printf("Number of traps : %s\n", $dataBase->fetchOne($query)); |
|
38 | + $query=$dataBase->select()->from($Config->getTrapDataTableName(), array('COUNT(*)')); |
|
39 | + printf("Number of trap objects : %s\n", $dataBase->fetchOne($query)); |
|
40 | + $query=$dataBase->select()->from($Config->getTrapRuleName(), array('COUNT(*)')); |
|
41 | + printf("Number of rules : %s\n", $dataBase->fetchOne($query)); |
|
42 | 42 | |
43 | 43 | } |
44 | 44 | catch (Exception $e) |
@@ -30,16 +30,16 @@ discard block |
||
30 | 30 | public function rotateAction() |
31 | 31 | { |
32 | 32 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
33 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
33 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
34 | 34 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
35 | 35 | $debug_level=2; |
36 | - $trap = new Trap($icingaweb2_etc); |
|
37 | - $trap->setLogging($debug_level,'display'); |
|
36 | + $trap=new Trap($icingaweb2_etc); |
|
37 | + $trap->setLogging($debug_level, 'display'); |
|
38 | 38 | try |
39 | 39 | { |
40 | - $days = $this->params->get('days', '<default>'); |
|
40 | + $days=$this->params->get('days', '<default>'); |
|
41 | 41 | echo $this->screen->colorize("Deleting traps older than $days days\n", 'lightblue'); |
42 | - if ($days=='<default>') |
|
42 | + if ($days == '<default>') |
|
43 | 43 | { |
44 | 44 | $trap->eraseOldTraps(); |
45 | 45 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | } |
52 | 52 | catch (Exception $e) |
53 | 53 | { |
54 | - echo 'Error in updating : ' . $e->getMessage(); |
|
54 | + echo 'Error in updating : '.$e->getMessage(); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | public function resetOKAction() |
67 | 67 | { |
68 | 68 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
69 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
69 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
70 | 70 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
71 | 71 | $debug_level=2; |
72 | - $trap = new Trap($icingaweb2_etc); |
|
73 | - $trap->setLogging($debug_level,'display'); |
|
72 | + $trap=new Trap($icingaweb2_etc); |
|
73 | + $trap->setLogging($debug_level, 'display'); |
|
74 | 74 | try |
75 | 75 | { |
76 | 76 | $trap->reset_services(); |
77 | 77 | } |
78 | 78 | catch (Exception $e) |
79 | 79 | { |
80 | - echo 'ERROR : '. $e->getMessage(); |
|
80 | + echo 'ERROR : '.$e->getMessage(); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | $this->setName('form_config_traps'); |
19 | 19 | $this->setSubmitLabel($this->translate('Save Changes')); |
20 | 20 | } |
21 | - public function setPaths($module_base_path,$icinga_base_path) |
|
21 | + public function setPaths($module_base_path, $icinga_base_path) |
|
22 | 22 | { |
23 | 23 | $this->module_base_path=$module_base_path; |
24 | 24 | $this->icinga_base_path=$icinga_base_path; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ); |
83 | 83 | $retval=0; |
84 | 84 | $output=array(); |
85 | - $snmptranslate=exec('which snmptranslate',$output,$retval); |
|
85 | + $snmptranslate=exec('which snmptranslate', $output, $retval); |
|
86 | 86 | if ($retval != 0) |
87 | 87 | { |
88 | 88 | $snmptranslate='/usr/bin/snmptranslate'; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | } |
173 | 173 | |
174 | 174 | |
175 | - public function render(Zend_View_Interface $view = NULL) |
|
175 | + public function render(Zend_View_Interface $view=NULL) |
|
176 | 176 | { |
177 | 177 | |
178 | 178 |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | } |
56 | 56 | // Test Database |
57 | 57 | $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
58 | - 0 => array('Database configuration OK','',''), |
|
59 | - 1 => array('Database set in config.ini','No database in config.ini',''), |
|
60 | - 2 => array('Database exists in Icingaweb2 config','Database does not exist in Icingaweb2 : ', |
|
58 | + 0 => array('Database configuration OK', '', ''), |
|
59 | + 1 => array('Database set in config.ini', 'No database in config.ini', ''), |
|
60 | + 2 => array('Database exists in Icingaweb2 config', 'Database does not exist in Icingaweb2 : ', |
|
61 | 61 | Url::fromPath('config/resource')), |
62 | - 3 => array('Database credentials OK','Database does not exist/invalid credentials/no schema : ', |
|
62 | + 3 => array('Database credentials OK', 'Database does not exist/invalid credentials/no schema : ', |
|
63 | 63 | Url::fromPath('trapdirector/settings/createschema')), |
64 | - 4 => array('Schema is set','Schema is not set for ', |
|
64 | + 4 => array('Schema is set', 'Schema is not set for ', |
|
65 | 65 | Url::fromPath('trapdirector/settings/createschema')), |
66 | - 5 => array('Schema is up to date','Schema is outdated :', |
|
66 | + 5 => array('Schema is up to date', 'Schema is outdated :', |
|
67 | 67 | Url::fromPath('trapdirector/settings/updateschema')), |
68 | 68 | ); |
69 | 69 | |
@@ -74,13 +74,13 @@ discard block |
||
74 | 74 | { |
75 | 75 | case 2: |
76 | 76 | case 4: |
77 | - $db_message[$dberror[0]][1] .= $dberror[1]; |
|
77 | + $db_message[$dberror[0]][1].=$dberror[1]; |
|
78 | 78 | break; |
79 | 79 | case 3: |
80 | - $db_message[$dberror[0]][1] .= $dberror[1] . ', Message : ' . $dberror[2]; |
|
80 | + $db_message[$dberror[0]][1].=$dberror[1].', Message : '.$dberror[2]; |
|
81 | 81 | break; |
82 | 82 | case 5: |
83 | - $db_message[$dberror[0]][1] .= ' version '. $dberror[1] . ', version needed : ' .$dberror[2]; |
|
83 | + $db_message[$dberror[0]][1].=' version '.$dberror[1].', version needed : '.$dberror[2]; |
|
84 | 84 | break; |
85 | 85 | case 0: |
86 | 86 | case 1: |
@@ -92,18 +92,18 @@ discard block |
||
92 | 92 | |
93 | 93 | $dberror=$this->getIdoDb(true); // Get IDO DB in test mode |
94 | 94 | $this->view->ido_db_error=$dberror[0]; |
95 | - $this->view->ido_message='IDO Database : ' . $dberror[1]; |
|
95 | + $this->view->ido_message='IDO Database : '.$dberror[1]; |
|
96 | 96 | |
97 | 97 | //********* Test API |
98 | 98 | if ($this->Config()->get('config', 'icingaAPI_host') != '') |
99 | 99 | { |
100 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
100 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'), $this->Config()->get('config', 'icingaAPI_port')); |
|
101 | 101 | $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
102 | 102 | try { |
103 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
103 | + list($this->view->apimessageError, $this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
104 | 104 | //$this->view->apimessageError=false; |
105 | 105 | } catch (RuntimeException $e) { |
106 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
106 | + $this->view->apimessage='API config : '.$e->getMessage(); |
|
107 | 107 | $this->view->apimessageError=true; |
108 | 108 | } |
109 | 109 | } |
@@ -114,18 +114,18 @@ discard block |
||
114 | 114 | } |
115 | 115 | |
116 | 116 | //*********** Test snmptrapd alive and options |
117 | - list ($this->view->snmptrapdError, $this->view->snmptrapdMessage) = $this->checkSnmpTrapd(); |
|
117 | + list ($this->view->snmptrapdError, $this->view->snmptrapdMessage)=$this->checkSnmpTrapd(); |
|
118 | 118 | |
119 | 119 | // List DB in $ressources |
120 | - $resources = array(); |
|
121 | - $allowed = array('mysql', 'pgsql'); |
|
120 | + $resources=array(); |
|
121 | + $allowed=array('mysql', 'pgsql'); |
|
122 | 122 | foreach (ResourceFactory::getResourceConfigs() as $name => $resource) { |
123 | 123 | if ($resource->get('type') === 'db' && in_array($resource->get('db'), $allowed)) { |
124 | - $resources[$name] = $name; |
|
124 | + $resources[$name]=$name; |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
|
128 | + $this->view->tabs=$this->Module()->getConfigTabs()->activate('config'); |
|
129 | 129 | |
130 | 130 | // Check standard Icingaweb2 path |
131 | 131 | $this->view->icingaEtcWarn=0; |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | { |
135 | 135 | $output=array(); |
136 | 136 | |
137 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output); |
|
137 | + exec('cat '.$this->module->getBaseDir().'/bin/trap_in.php | grep "\$icingaweb2_etc=" ', $output); |
|
138 | 138 | |
139 | - if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
139 | + if (!preg_match('#"'.$icingaweb2_etc.'"#', $output[0])) |
|
140 | 140 | { |
141 | 141 | $this->view->icingaEtcWarn=1; |
142 | 142 | $this->view->icingaweb2_etc=$icingaweb2_etc; |
@@ -144,23 +144,23 @@ discard block |
||
144 | 144 | } |
145 | 145 | |
146 | 146 | // Setup path for mini documentation |
147 | - $this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
|
147 | + $this->view->traps_in_config=PHP_BINARY.' '.$this->Module()->getBaseDir().'/bin/trap_in.php'; |
|
148 | 148 | |
149 | - $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
|
149 | + $this->view->installer=$this->Module()->getBaseDir().'/bin/installer.sh ' |
|
150 | 150 | . ' -c all ' |
151 | - . ' -d ' . $this->Module()->getBaseDir() |
|
152 | - . ' -p ' . PHP_BINARY |
|
153 | - . ' -a ' . exec('whoami') |
|
154 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
151 | + . ' -d '.$this->Module()->getBaseDir() |
|
152 | + . ' -p '.PHP_BINARY |
|
153 | + . ' -a '.exec('whoami') |
|
154 | + . ' -w '.Icinga::app()->getConfigDir(); |
|
155 | 155 | |
156 | 156 | // ******************* configuration form setup******************* |
157 | - $this->view->form = $form = new TrapsConfigForm(); |
|
157 | + $this->view->form=$form=new TrapsConfigForm(); |
|
158 | 158 | |
159 | 159 | // set default paths; |
160 | - $this->view->form->setPaths($this->Module()->getBaseDir(),Icinga::app()->getConfigDir()); |
|
160 | + $this->view->form->setPaths($this->Module()->getBaseDir(), Icinga::app()->getConfigDir()); |
|
161 | 161 | |
162 | 162 | // set default ido database |
163 | - $this->view->form->setDefaultIDODB($this->Config()->module('monitoring','backends')->get('icinga','resource')); |
|
163 | + $this->view->form->setDefaultIDODB($this->Config()->module('monitoring', 'backends')->get('icinga', 'resource')); |
|
164 | 164 | |
165 | 165 | // Make form handle request. |
166 | 166 | $form->setIniConfig($this->Config()) |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | public function createschemaAction() |
173 | 173 | { |
174 | 174 | $this->checkModuleConfigPermission(); |
175 | - $this->getTabs()->add('create_schema',array( |
|
175 | + $this->getTabs()->add('create_schema', array( |
|
176 | 176 | 'active' => true, |
177 | 177 | 'label' => $this->translate('Create Schema'), |
178 | 178 | 'url' => Url::fromRequest() |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $dbName=$this->Config()->get('config', 'database'); |
194 | 194 | |
195 | 195 | try { |
196 | - $dbResource = ResourceFactory::getResourceConfig($dbName); |
|
196 | + $dbResource=ResourceFactory::getResourceConfig($dbName); |
|
197 | 197 | $dbType=$dbResource->get('db'); |
198 | 198 | switch ($dbType) { |
199 | 199 | case 'mysql': |
@@ -205,34 +205,34 @@ discard block |
||
205 | 205 | default: |
206 | 206 | throw new ConfigurationError('Unsuported database : '.$dbType); |
207 | 207 | } |
208 | - } catch (ConfigurationError $e ) |
|
208 | + } catch (ConfigurationError $e) |
|
209 | 209 | { |
210 | - printf("Database configuration error : %s",$e->getMessage()); |
|
210 | + printf("Database configuration error : %s", $e->getMessage()); |
|
211 | 211 | return; |
212 | 212 | } |
213 | 213 | printf('<pre>'); |
214 | - require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
|
214 | + require_once $this->Module()->getBaseDir().'/bin/trap_class.php'; |
|
215 | 215 | |
216 | 216 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
217 | 217 | $debug_level=4; |
218 | - $Trap = new Trap($icingaweb2_etc); |
|
219 | - $Trap->setLogging($debug_level,'display'); |
|
218 | + $Trap=new Trap($icingaweb2_etc); |
|
219 | + $Trap->setLogging($debug_level, 'display'); |
|
220 | 220 | |
221 | 221 | $prefix=$this->Config()->get('config', 'database_prefix'); |
222 | 222 | // schema file : <path>/SQL/schema_v<verion>.<dbtype> |
223 | - $schema=$this->Module()->getBaseDir() . |
|
224 | - '/SQL/schema_v'. $this->getModuleConfig()->getDbCurVersion() . '.' . $dbFileExt; |
|
223 | + $schema=$this->Module()->getBaseDir(). |
|
224 | + '/SQL/schema_v'.$this->getModuleConfig()->getDbCurVersion().'.'.$dbFileExt; |
|
225 | 225 | |
226 | - $Trap->create_schema($schema,$prefix); |
|
226 | + $Trap->create_schema($schema, $prefix); |
|
227 | 227 | echo '</pre>'; |
228 | 228 | } |
229 | - echo '<br><br>Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a>'; |
|
229 | + echo '<br><br>Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a>'; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | public function updateschemaAction() |
233 | 233 | { |
234 | 234 | $this->checkModuleConfigPermission(); |
235 | - $this->getTabs()->add('get',array( |
|
235 | + $this->getTabs()->add('get', array( |
|
236 | 236 | 'active' => true, |
237 | 237 | 'label' => $this->translate('Update Schema'), |
238 | 238 | 'url' => Url::fromRequest() |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | $dberror=$this->getDb(true); // Get DB in test mode |
243 | 243 | |
244 | - echo 'Return to <a href="' . Url::fromPath('trapdirector/settings') .'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
244 | + echo 'Return to <a href="'.Url::fromPath('trapdirector/settings').'" class="link-button icon-wrench"> settings page </a><br><br>'; |
|
245 | 245 | |
246 | 246 | if ($dberror[0] == 0) |
247 | 247 | { |
@@ -254,40 +254,40 @@ discard block |
||
254 | 254 | return; |
255 | 255 | } |
256 | 256 | // setup |
257 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
257 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
258 | 258 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
259 | 259 | $debug_level=4; |
260 | - $Trap = new Trap($icingaweb2_etc); |
|
260 | + $Trap=new Trap($icingaweb2_etc); |
|
261 | 261 | |
262 | 262 | |
263 | 263 | $prefix=$this->Config()->get('config', 'database_prefix'); |
264 | - $updateSchema=$this->Module()->getBaseDir() . '/SQL/'; |
|
264 | + $updateSchema=$this->Module()->getBaseDir().'/SQL/'; |
|
265 | 265 | |
266 | 266 | $target_version=$dberror[2]; |
267 | 267 | |
268 | 268 | if ($this->params->get('msgok') == null) { |
269 | 269 | // Check for messages and display if any |
270 | 270 | echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
271 | - $Trap->setLogging(2,'syslog'); |
|
272 | - $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true); |
|
271 | + $Trap->setLogging(2, 'syslog'); |
|
272 | + $message=$Trap->update_schema($updateSchema, $target_version, $prefix, true); |
|
273 | 273 | if ($message != '') |
274 | 274 | { |
275 | 275 | echo 'Note :<br><pre>'; |
276 | 276 | echo $message; |
277 | 277 | echo '</pre>'; |
278 | 278 | echo '<br>'; |
279 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
279 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="'.Url::fromPath('trapdirector/settings/updateschema').'?msgok=1">Click here to update</a>'; |
|
280 | 280 | echo '<br>'; |
281 | 281 | return; |
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | - $Trap->setLogging($debug_level,'display'); |
|
285 | + $Trap->setLogging($debug_level, 'display'); |
|
286 | 286 | |
287 | - echo 'Updating schema to '. $target_version . ': <br>'; |
|
287 | + echo 'Updating schema to '.$target_version.': <br>'; |
|
288 | 288 | echo '<pre>'; |
289 | 289 | |
290 | - $Trap->update_schema($updateSchema,$target_version,$prefix); |
|
290 | + $Trap->update_schema($updateSchema, $target_version, $prefix); |
|
291 | 291 | echo '</pre>'; |
292 | 292 | } |
293 | 293 | |
@@ -295,26 +295,26 @@ discard block |
||
295 | 295 | { |
296 | 296 | $psOutput=array(); |
297 | 297 | // First check is someone is listening to port 162. As not root, we can't have pid... |
298 | - exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
298 | + exec('netstat -an |grep -E "udp.*:162"', $psOutput); |
|
299 | 299 | if (count($psOutput) == 0) |
300 | 300 | { |
301 | - return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
301 | + return array(1, 'Port UDP/162 is not open : snmptrapd must not be started'); |
|
302 | 302 | } |
303 | 303 | $psOutput=array(); |
304 | - exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
304 | + exec('ps fax |grep snmptrapd |grep -v grep', $psOutput); |
|
305 | 305 | if (count($psOutput) == 0) |
306 | 306 | { |
307 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
307 | + return array(1, "UDP/162 : OK, but no snmptrapd process (?)"); |
|
308 | 308 | } |
309 | 309 | // Assume there is only one line... TODO : see if there is a better way to do this |
310 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
311 | - if (!preg_match('/-n/',$line)) |
|
312 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
313 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
314 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
315 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
316 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
310 | + $line=preg_replace('/^.*snmptrapd /', '', $psOutput[0]); |
|
311 | + if (!preg_match('/-n/', $line)) |
|
312 | + return array(1, 'snmptrapd has no -n option : '.$line); |
|
313 | + if (!preg_match('/-O[^ ]*n/', $line)) |
|
314 | + return array(1, 'snmptrapd has no -On option : '.$line); |
|
315 | + if (!preg_match('/-O[^ ]*e/', $line)) |
|
316 | + return array(1, 'snmptrapd has no -Oe option : '.$line); |
|
317 | 317 | |
318 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
318 | + return array(0, 'snmptrapd listening to UDP/162, options : '.$line); |
|
319 | 319 | } |
320 | 320 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | public function indexAction() |
14 | 14 | { |
15 | - $this->getTabs()->add('get',array( |
|
15 | + $this->getTabs()->add('get', array( |
|
16 | 16 | 'active' => true, |
17 | 17 | 'label' => $this->translate('Error'), |
18 | 18 | 'url' => Url::fromRequest() |
@@ -36,39 +36,39 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function updateAction() |
38 | 38 | { |
39 | - $background = $this->params->get('pid', null); |
|
40 | - $logLevel= $this->params->has('verb') ? 4 : 2; |
|
41 | - if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
|
42 | - $forceCheck=$this->params->has('force-check')?True:False; |
|
39 | + $background=$this->params->get('pid', null); |
|
40 | + $logLevel=$this->params->has('verb') ? 4 : 2; |
|
41 | + if ($this->params->has('force-check')) { echo "Not implemented"; return; } |
|
42 | + $forceCheck=$this->params->has('force-check') ?True:False; |
|
43 | 43 | $pid=1; |
44 | 44 | if ($background != null) |
45 | 45 | { |
46 | - $file=@fopen($background,'w'); |
|
46 | + $file=@fopen($background, 'w'); |
|
47 | 47 | if ($file == false) |
48 | 48 | { |
49 | 49 | echo 'Error : cannot open pid file '.$background; |
50 | 50 | return 1; |
51 | 51 | } |
52 | - $pid = pcntl_fork(); |
|
52 | + $pid=pcntl_fork(); |
|
53 | 53 | if ($pid == -1) { |
54 | 54 | echo 'Error : Cannot fork process'; |
55 | 55 | return 1; |
56 | 56 | } |
57 | 57 | } |
58 | 58 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
59 | - require_once($module->getBaseDir() .'/bin/trap_class.php'); |
|
59 | + require_once($module->getBaseDir().'/bin/trap_class.php'); |
|
60 | 60 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
61 | - $trap = new Trap($icingaweb2_etc); |
|
61 | + $trap=new Trap($icingaweb2_etc); |
|
62 | 62 | if ($pid == 1) |
63 | 63 | { |
64 | - $trap->setLogging($logLevel,'display'); |
|
64 | + $trap->setLogging($logLevel, 'display'); |
|
65 | 65 | } |
66 | 66 | else |
67 | 67 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
68 | 68 | if ($pid != 0) |
69 | 69 | { |
70 | 70 | // father process |
71 | - fwrite($file,$pid); |
|
71 | + fwrite($file, $pid); |
|
72 | 72 | fclose($file); |
73 | 73 | echo "OK : process $pid in bckground"; |
74 | 74 | return 0; |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | fclose(STDERR); |
83 | 83 | try |
84 | 84 | { |
85 | - $trap->update_mib_database(false,$forceCheck); |
|
85 | + $trap->update_mib_database(false, $forceCheck); |
|
86 | 86 | } |
87 | 87 | catch (Exception $e) |
88 | 88 | { |
89 | - $trap->trapLog('Error in updating : ' . $e->getMessage(),2); |
|
89 | + $trap->trapLog('Error in updating : '.$e->getMessage(), 2); |
|
90 | 90 | } |
91 | 91 | unlink($background); |
92 | 92 | return 0; |
@@ -98,13 +98,13 @@ discard block |
||
98 | 98 | { |
99 | 99 | echo "Update main mib database : \n"; |
100 | 100 | echo "# (trap found) C (trap already processed) . (every 2 seconds) : \n"; |
101 | - $trap->update_mib_database(true,$forceCheck); |
|
101 | + $trap->update_mib_database(true, $forceCheck); |
|
102 | 102 | echo "Done\n"; |
103 | 103 | |
104 | 104 | } |
105 | 105 | catch (Exception $e) |
106 | 106 | { |
107 | - echo 'Error in updating : ' . $e->getMessage(); |
|
107 | + echo 'Error in updating : '.$e->getMessage(); |
|
108 | 108 | } |
109 | 109 | if ($pid != 1) |
110 | 110 | { |
@@ -128,26 +128,26 @@ discard block |
||
128 | 128 | echo "Not implemented"; |
129 | 129 | // TODO : implement |
130 | 130 | return; |
131 | - $Config = new TrapModuleConfig($db_prefix); |
|
131 | + $Config=new TrapModuleConfig($db_prefix); |
|
132 | 132 | |
133 | 133 | try |
134 | 134 | { |
135 | 135 | |
136 | 136 | $dbresource=$this->Config()->get('config', 'database'); |
137 | 137 | echo "DB name : $dbresource\n"; |
138 | - $db = IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
138 | + $db=IcingaDbConnection::fromResourceName($dbresource)->getConnection(); |
|
139 | 139 | |
140 | - $query = $db->select()->from($Config->getTrapTableName(),array('COUNT(*)')); |
|
141 | - echo "Number of traps : " . $db->fetchOne($query) ."\n"; |
|
142 | - $query = $db->select()->from($Config->getTrapDataTableName(),array('COUNT(*)')); |
|
143 | - echo "Number of trap objects : " . $db->fetchOne($query) ."\n"; |
|
144 | - $query = $db->select()->from($Config->getTrapRuleName(),array('COUNT(*)')); |
|
145 | - echo "Number of rules : " . $db->fetchOne($query) ."\n"; |
|
140 | + $query=$db->select()->from($Config->getTrapTableName(), array('COUNT(*)')); |
|
141 | + echo "Number of traps : ".$db->fetchOne($query)."\n"; |
|
142 | + $query=$db->select()->from($Config->getTrapDataTableName(), array('COUNT(*)')); |
|
143 | + echo "Number of trap objects : ".$db->fetchOne($query)."\n"; |
|
144 | + $query=$db->select()->from($Config->getTrapRuleName(), array('COUNT(*)')); |
|
145 | + echo "Number of rules : ".$db->fetchOne($query)."\n"; |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | catch (Exception $e) |
149 | 149 | { |
150 | - echo 'Error in DB : ' . $e->getMessage(); |
|
150 | + echo 'Error in DB : '.$e->getMessage(); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | // Filters |
36 | 36 | |
37 | 37 | protected $filter; |
38 | - protected $enforcedFilters = array(); |
|
39 | - protected $searchColumns = array(); |
|
38 | + protected $enforcedFilters=array(); |
|
39 | + protected $searchColumns=array(); |
|
40 | 40 | |
41 | 41 | |
42 | 42 | // Must return titles in array ( id => display_name ) |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | // ****************** Day header |
45 | 45 | protected function renderDayIfNew($timestamp) |
46 | 46 | { |
47 | - $view = $this->getView(); |
|
47 | + $view=$this->getView(); |
|
48 | 48 | |
49 | 49 | // Check for date local format |
50 | 50 | if (in_array(setlocale(LC_ALL, 0), array('en_US.UTF-8', 'C'))) { |
51 | - $day = date('l, jS F Y', (int) $timestamp); |
|
51 | + $day=date('l, jS F Y', (int) $timestamp); |
|
52 | 52 | } else { |
53 | - $day = strftime('%A, %e. %B, %Y', (int) $timestamp); |
|
53 | + $day=strftime('%A, %e. %B, %Y', (int) $timestamp); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | if ($this->lastDay === $day) { |
@@ -58,25 +58,25 @@ discard block |
||
58 | 58 | } |
59 | 59 | |
60 | 60 | if ($this->lastDay === null) { |
61 | - $htm = "<thead>\n <tr>\n"; |
|
61 | + $htm="<thead>\n <tr>\n"; |
|
62 | 62 | } else { |
63 | - $htm = "</tbody>\n<thead>\n <tr>\n"; |
|
63 | + $htm="</tbody>\n<thead>\n <tr>\n"; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | if ($this->columnCount === null) { |
67 | - $this->columnCount = count($this->getTitles()); |
|
67 | + $this->columnCount=count($this->getTitles()); |
|
68 | 68 | } |
69 | 69 | |
70 | - $htm .= '<th colspan="' . $this->columnCount . '">' . $view->escape($day) . '</th>' . "\n"; |
|
70 | + $htm.='<th colspan="'.$this->columnCount.'">'.$view->escape($day).'</th>'."\n"; |
|
71 | 71 | if ($this->lastDay === null) { |
72 | - $htm .= " </tr>\n"; |
|
72 | + $htm.=" </tr>\n"; |
|
73 | 73 | } else { |
74 | - $htm .= " </tr>\n</thead>\n"; |
|
74 | + $htm.=" </tr>\n</thead>\n"; |
|
75 | 75 | } |
76 | 76 | |
77 | - $this->lastDay = $day; |
|
77 | + $this->lastDay=$day; |
|
78 | 78 | |
79 | - return $htm . "<tbody>\n"; |
|
79 | + return $htm."<tbody>\n"; |
|
80 | 80 | } |
81 | 81 | // ****************** Render table in html |
82 | 82 | public function __toString() |
@@ -89,28 +89,28 @@ discard block |
||
89 | 89 | // ****************** Static config set |
90 | 90 | public function setConfig($conf) |
91 | 91 | { |
92 | - $this->moduleConfig = $conf; |
|
92 | + $this->moduleConfig=$conf; |
|
93 | 93 | } |
94 | 94 | // ****************** View get/set |
95 | 95 | protected function getView() |
96 | 96 | { |
97 | 97 | if ($this->view === null) { |
98 | - $this->view = Icinga::app()->getViewRenderer()->view; |
|
98 | + $this->view=Icinga::app()->getViewRenderer()->view; |
|
99 | 99 | } |
100 | 100 | return $this->view; |
101 | 101 | } |
102 | 102 | |
103 | 103 | public function setView($view) |
104 | 104 | { |
105 | - $this->view = $view; |
|
105 | + $this->view=$view; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | // Limits |
109 | 109 | |
110 | - public function limit($count = null, $offset = null) |
|
110 | + public function limit($count=null, $offset=null) |
|
111 | 111 | { |
112 | - $this->limit = $count; |
|
113 | - $this->offset = $offset; |
|
112 | + $this->limit=$count; |
|
113 | + $this->offset=$offset; |
|
114 | 114 | |
115 | 115 | return $this; |
116 | 116 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | public function getPaginator() |
141 | 141 | { |
142 | - $paginator = new Paginator(); |
|
142 | + $paginator=new Paginator(); |
|
143 | 143 | $paginator->setQuery($this); |
144 | 144 | |
145 | 145 | return $paginator; |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | public function setConnection(Selectable $connection) |
151 | 151 | { |
152 | - $this->connection = $connection; |
|
152 | + $this->connection=$connection; |
|
153 | 153 | return $this; |
154 | 154 | } |
155 | 155 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | $db=$this->db(); |
169 | 169 | |
170 | - $query = $this->getBaseQuery(); |
|
170 | + $query=$this->getBaseQuery(); |
|
171 | 171 | |
172 | 172 | if ($this->hasLimit() || $this->hasOffset()) { |
173 | 173 | $query->limit($this->getLimit(), $this->getOffset()); |
@@ -189,20 +189,20 @@ discard block |
||
189 | 189 | |
190 | 190 | public function setFilter($filter) |
191 | 191 | { |
192 | - $this->filter = $filter; |
|
192 | + $this->filter=$filter; |
|
193 | 193 | return $this; |
194 | 194 | } |
195 | 195 | |
196 | 196 | public function getFilterEditor(Request $request) |
197 | 197 | { |
198 | - $filterEditor = Widget::create('filterEditor') |
|
198 | + $filterEditor=Widget::create('filterEditor') |
|
199 | 199 | ->setColumns(array_keys($this->getColumns())) |
200 | 200 | ->setSearchColumns(array_keys($this->getSearchColumns())) |
201 | 201 | ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
202 | 202 | ->ignoreParams('page') |
203 | 203 | ->handleRequest($request); |
204 | 204 | |
205 | - $filter = $filterEditor->getFilter(); |
|
205 | + $filter=$filterEditor->getFilter(); |
|
206 | 206 | $this->setFilter($filter); |
207 | 207 | |
208 | 208 | return $filterEditor; |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | // Filters |
33 | 33 | |
34 | 34 | protected $filter; |
35 | - protected $enforcedFilters = array(); |
|
36 | - protected $searchColumns = array(); |
|
35 | + protected $enforcedFilters=array(); |
|
36 | + protected $searchColumns=array(); |
|
37 | 37 | |
38 | 38 | protected function getTitles() { |
39 | 39 | return $this->moduleConfig->getHandlerListTitles(); |
@@ -53,34 +53,34 @@ discard block |
||
53 | 53 | public function render() |
54 | 54 | { |
55 | 55 | $data=$this->getTable(); |
56 | - $view = $this->getView(); |
|
57 | - $this->columnCount = count($this->getTitles()); |
|
56 | + $view=$this->getView(); |
|
57 | + $this->columnCount=count($this->getTitles()); |
|
58 | 58 | $this->lastDay=null; |
59 | 59 | // Table start |
60 | - $htm = '<table class="simple common-table table-row-selectable">'; |
|
60 | + $htm='<table class="simple common-table table-row-selectable">'; |
|
61 | 61 | |
62 | 62 | // Titles |
63 | - $htm .= "<thead>\n <tr>\n"; |
|
64 | - $titles = $this->getTitles(); |
|
63 | + $htm.="<thead>\n <tr>\n"; |
|
64 | + $titles=$this->getTitles(); |
|
65 | 65 | foreach ($titles as $title) |
66 | 66 | { |
67 | - $htm .= ' <th>' . $view->escape($view->translate($title)) . "</th>\n"; |
|
67 | + $htm.=' <th>'.$view->escape($view->translate($title))."</th>\n"; |
|
68 | 68 | } |
69 | - $htm .= " </tr>\n</thead>\n"; |
|
69 | + $htm.=" </tr>\n</thead>\n"; |
|
70 | 70 | |
71 | 71 | // Rows |
72 | - $htm .= "<tbody>\n"; |
|
72 | + $htm.="<tbody>\n"; |
|
73 | 73 | |
74 | 74 | foreach ($data as $row) |
75 | 75 | { |
76 | - $firstCol = true; |
|
76 | + $firstCol=true; |
|
77 | 77 | // Put date header |
78 | 78 | //$htm .= $this->renderDayIfNew($row->timestamp); |
79 | 79 | |
80 | 80 | |
81 | 81 | // Render row |
82 | - $htm .= '<tr '.' >'; |
|
83 | - foreach ( $titles as $rowkey => $title) |
|
82 | + $htm.='<tr '.' >'; |
|
83 | + foreach ($titles as $rowkey => $title) |
|
84 | 84 | { |
85 | 85 | // Check missing value |
86 | 86 | if (property_exists($row, $rowkey)) |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | break; |
94 | 94 | case 'trap_oid': // try to traslate oids. |
95 | 95 | |
96 | - if ($this->doTranslate==true) |
|
96 | + if ($this->doTranslate == true) |
|
97 | 97 | { |
98 | 98 | $oidName=$this->MIB->translateOID($row->$rowkey); |
99 | 99 | if (isset($oidName['name'])) |
@@ -102,52 +102,52 @@ discard block |
||
102 | 102 | } |
103 | 103 | else |
104 | 104 | { |
105 | - $val = $row->$rowkey; |
|
105 | + $val=$row->$rowkey; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | else |
109 | 109 | { |
110 | - $val = $row->$rowkey; |
|
110 | + $val=$row->$rowkey; |
|
111 | 111 | } |
112 | 112 | break; |
113 | 113 | case 'host_name': // switch to hostgroup if name is null |
114 | 114 | if ($row->$rowkey == null) |
115 | 115 | { |
116 | - $val = $row->host_group_name; |
|
116 | + $val=$row->host_group_name; |
|
117 | 117 | } |
118 | 118 | else |
119 | 119 | { |
120 | - $val = $row->$rowkey; |
|
120 | + $val=$row->$rowkey; |
|
121 | 121 | } |
122 | 122 | break; |
123 | 123 | default: |
124 | - $val = $row->$rowkey; |
|
124 | + $val=$row->$rowkey; |
|
125 | 125 | } |
126 | - if ($rowkey == 'trap_oid' && $this->doTranslate==true) |
|
126 | + if ($rowkey == 'trap_oid' && $this->doTranslate == true) |
|
127 | 127 | { |
128 | 128 | |
129 | 129 | } |
130 | 130 | } else { |
131 | - $val = '-'; |
|
131 | + $val='-'; |
|
132 | 132 | } |
133 | 133 | if ($firstCol == true) { // Put link in first column for trap detail. |
134 | - $htm .= '<td>' |
|
134 | + $htm.='<td>' |
|
135 | 135 | . $view->qlink( |
136 | 136 | $view->escape($val), |
137 | 137 | Url::fromPath( |
138 | - $this->moduleConfig->urlPath() . '/handler/add', |
|
138 | + $this->moduleConfig->urlPath().'/handler/add', |
|
139 | 139 | array('ruleid' => $row->id) |
140 | 140 | ) |
141 | 141 | ) |
142 | 142 | . '</td>'; |
143 | 143 | } else { |
144 | - $htm .= '<td>' . $view->escape($val) . '</td>'; |
|
144 | + $htm.='<td>'.$view->escape($val).'</td>'; |
|
145 | 145 | } |
146 | 146 | $firstCol=false; |
147 | 147 | } |
148 | - $htm .= "<tr>\n"; |
|
148 | + $htm.="<tr>\n"; |
|
149 | 149 | } |
150 | - $htm .= "</tbody></table>\n"; |
|
150 | + $htm.="</tbody></table>\n"; |
|
151 | 151 | //$htm .= "Filter : " . $this->filter."<br>\n"; |
152 | 152 | return $htm; |
153 | 153 | |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | |
156 | 156 | public function count() |
157 | 157 | { |
158 | - $db = $this->connection()->getConnection(); |
|
159 | - $query = clone($this->getBaseQuery()); |
|
158 | + $db=$this->connection()->getConnection(); |
|
159 | + $query=clone($this->getBaseQuery()); |
|
160 | 160 | $query->reset('order')->columns(array('COUNT(*)')); |
161 | 161 | $this->applyFiltersToQuery($query); |
162 | 162 | |
163 | 163 | $db=$this->db(); |
164 | 164 | |
165 | - $query = $db->select()->from( |
|
165 | + $query=$db->select()->from( |
|
166 | 166 | $this->moduleConfig->getTrapRuleName(), |
167 | 167 | array('COUNT(*)') |
168 | 168 | ); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | public function getPaginator() |
174 | 174 | { |
175 | - $paginator = new Paginator(); |
|
175 | + $paginator=new Paginator(); |
|
176 | 176 | $paginator->setQuery($this); |
177 | 177 | |
178 | 178 | return $paginator; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | { |
185 | 185 | $db=$this->db(); |
186 | 186 | |
187 | - $query = $this->getBaseQuery(); |
|
187 | + $query=$this->getBaseQuery(); |
|
188 | 188 | |
189 | 189 | if ($this->hasLimit() || $this->hasOffset()) { |
190 | 190 | $query->limit($this->getLimit(), $this->getOffset()); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | { |
198 | 198 | $db=$this->db(); |
199 | 199 | |
200 | - $query = $db->select()->from( |
|
200 | + $query=$db->select()->from( |
|
201 | 201 | $this->moduleConfig->getTrapRuleName(), |
202 | 202 | $this->moduleConfig->getHandlerListDisplayColumns() |
203 | 203 | )->order('host_name DESC,trap_oid DESC'); |
@@ -219,20 +219,20 @@ discard block |
||
219 | 219 | |
220 | 220 | public function setFilter($filter) |
221 | 221 | { |
222 | - $this->filter = $filter; |
|
222 | + $this->filter=$filter; |
|
223 | 223 | return $this; |
224 | 224 | } |
225 | 225 | |
226 | 226 | public function getFilterEditor(Request $request) |
227 | 227 | { |
228 | - $filterEditor = Widget::create('filterEditor') |
|
228 | + $filterEditor=Widget::create('filterEditor') |
|
229 | 229 | ->setColumns(array_keys($this->getColumns())) |
230 | 230 | ->setSearchColumns(array_keys($this->getSearchColumns())) |
231 | 231 | ->preserveParams('limit', 'sort', 'dir', 'view', 'backend') |
232 | 232 | ->ignoreParams('page') |
233 | 233 | ->handleRequest($request); |
234 | 234 | |
235 | - $filter = $filterEditor->getFilter(); |
|
235 | + $filter=$filterEditor->getFilter(); |
|
236 | 236 | $this->setFilter($filter); |
237 | 237 | |
238 | 238 | return $filterEditor; |