@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | /** Get host list with filter (IP or name) : host=<filter> |
15 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
16 | - */ |
|
15 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
16 | + */ |
|
17 | 17 | public function gethostsAction() |
18 | 18 | { |
19 | 19 | $postData=$this->getRequest()->getPost(); |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | /** Get hostgroup list with filter (name) : hostgroup=<hostFilter> |
35 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
36 | - */ |
|
35 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
36 | + */ |
|
37 | 37 | public function gethostgroupsAction() |
38 | 38 | { |
39 | 39 | $postData=$this->getRequest()->getPost(); |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | /** Get service list by host name ( host=<host> ) |
55 | - * returns in JSON : |
|
56 | - * status=>OK/No services found/More than one host matches |
|
57 | - * services=>array of services (name) |
|
58 | - * hostid = host object id or -1 if not found. |
|
59 | - */ |
|
55 | + * returns in JSON : |
|
56 | + * status=>OK/No services found/More than one host matches |
|
57 | + * services=>array of services (name) |
|
58 | + * hostid = host object id or -1 if not found. |
|
59 | + */ |
|
60 | 60 | public function getservicesAction() |
61 | 61 | { |
62 | 62 | $postData=$this->getRequest()->getPost(); |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | } |
99 | 99 | |
100 | 100 | /** Get service list by host group ( name=<host> ) |
101 | - * returns in JSON : |
|
102 | - * status=>OK/No services found/More than one host matches |
|
103 | - * services=>array of services (name) |
|
104 | - * groupid = group object id or -1 if not found. |
|
105 | - */ |
|
101 | + * returns in JSON : |
|
102 | + * status=>OK/No services found/More than one host matches |
|
103 | + * services=>array of services (name) |
|
104 | + * groupid = group object id or -1 if not found. |
|
105 | + */ |
|
106 | 106 | public function gethostgroupservicesAction() |
107 | 107 | { |
108 | 108 | $postData=$this->getRequest()->getPost(); |
@@ -132,10 +132,10 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | /** Get traps from mib : entry : mib=<mib> |
135 | - * returns in JSON : |
|
136 | - * status=>OK/No mib/Error getting mibs |
|
137 | - * traps=>array of array( oid -> name) |
|
138 | - */ |
|
135 | + * returns in JSON : |
|
136 | + * status=>OK/No mib/Error getting mibs |
|
137 | + * traps=>array of array( oid -> name) |
|
138 | + */ |
|
139 | 139 | public function gettrapsAction() |
140 | 140 | { |
141 | 141 | $postData=$this->getRequest()->getPost(); |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | } |
156 | 156 | |
157 | 157 | /** Get trap objects from mib : entry : trap=<oid> |
158 | - * returns in JSON : |
|
159 | - * status=>OK/no trap/not found |
|
160 | - * objects=>array of array( oid -> name, oid->mib) |
|
161 | - */ |
|
158 | + * returns in JSON : |
|
159 | + * status=>OK/no trap/not found |
|
160 | + * objects=>array of array( oid -> name, oid->mib) |
|
161 | + */ |
|
162 | 162 | public function gettrapobjectsAction() |
163 | 163 | { |
164 | 164 | $postData=$this->getRequest()->getPost(); |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | /** Get list of all loaded mibs : entry : none |
181 | - * return : array of strings. |
|
182 | - */ |
|
181 | + * return : array of strings. |
|
182 | + */ |
|
183 | 183 | public function getmiblistAction() |
184 | 184 | { |
185 | 185 | try |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | /** Get MIB::Name from OID : entry : oid |
197 | - * status=>OK/No oid/not found |
|
198 | - * mib=>string |
|
199 | - * name=>string |
|
200 | - */ |
|
197 | + * status=>OK/No oid/not found |
|
198 | + * mib=>string |
|
199 | + * name=>string |
|
200 | + */ |
|
201 | 201 | public function translateoidAction() |
202 | 202 | { |
203 | 203 | $postData=$this->getRequest()->getPost(); |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | 'name' => $object['name'], |
219 | 219 | 'type' => $object['type'], |
220 | 220 | 'type_enum' => $object['type_enum'], |
221 | - 'description' => $object['description'] |
|
221 | + 'description' => $object['description'] |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | } |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | /** Save or execute database purge of <n> days |
229 | - * days=>int |
|
230 | - * action=>save/execute |
|
231 | - * return : status=>OK/Message error |
|
232 | - */ |
|
229 | + * days=>int |
|
230 | + * action=>save/execute |
|
231 | + * return : status=>OK/Message error |
|
232 | + */ |
|
233 | 233 | public function dbmaintenanceAction() |
234 | 234 | { |
235 | 235 | |
@@ -275,11 +275,11 @@ discard block |
||
275 | 275 | } |
276 | 276 | |
277 | 277 | /** Save log output to db |
278 | - * destination=>log destination |
|
279 | - * file=>file name |
|
280 | - * level => int |
|
281 | - * return : status=>OK/Message error |
|
282 | - */ |
|
278 | + * destination=>log destination |
|
279 | + * file=>file name |
|
280 | + * level => int |
|
281 | + * return : status=>OK/Message error |
|
282 | + */ |
|
283 | 283 | public function logdestinationAction() |
284 | 284 | { |
285 | 285 | $postData=$this->getRequest()->getPost(); |
@@ -298,8 +298,8 @@ discard block |
||
298 | 298 | $fileHandler=@fopen($file,'w'); |
299 | 299 | if ($fileHandler == false) |
300 | 300 | { // File os note writabe / cannot create |
301 | - $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
302 | - return; |
|
301 | + $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
302 | + return; |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | else |
@@ -341,33 +341,33 @@ discard block |
||
341 | 341 | public function testruleAction() |
342 | 342 | { |
343 | 343 | |
344 | - $postData=$this->getRequest()->getPost(); |
|
344 | + $postData=$this->getRequest()->getPost(); |
|
345 | 345 | |
346 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
346 | + $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
347 | 347 | |
348 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
348 | + $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
349 | 349 | |
350 | - if ($action == 'evaluate') |
|
351 | - { |
|
352 | - try |
|
353 | - { |
|
354 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
355 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
356 | - $trap = new Trap($icingaweb2_etc); |
|
357 | - // Cleanup spaces before eval |
|
358 | - $rule=$trap->ruleClass->eval_cleanup($rule); |
|
359 | - // Eval |
|
360 | - $item=0; |
|
361 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
362 | - } |
|
363 | - catch (Exception $e) |
|
364 | - { |
|
365 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
366 | - return; |
|
367 | - } |
|
368 | - $return=($rule==true)?'true':'false'; |
|
369 | - $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
370 | - } |
|
350 | + if ($action == 'evaluate') |
|
351 | + { |
|
352 | + try |
|
353 | + { |
|
354 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
355 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
356 | + $trap = new Trap($icingaweb2_etc); |
|
357 | + // Cleanup spaces before eval |
|
358 | + $rule=$trap->ruleClass->eval_cleanup($rule); |
|
359 | + // Eval |
|
360 | + $item=0; |
|
361 | + $rule=$trap->ruleClass->evaluation($rule,$item); |
|
362 | + } |
|
363 | + catch (Exception $e) |
|
364 | + { |
|
365 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
366 | + return; |
|
367 | + } |
|
368 | + $return=($rule==true)?'true':'false'; |
|
369 | + $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
370 | + } |
|
371 | 371 | |
372 | 372 | } |
373 | 373 | |
@@ -378,35 +378,35 @@ discard block |
||
378 | 378 | */ |
379 | 379 | public function pluginAction() |
380 | 380 | { |
381 | - $postData=$this->getRequest()->getPost(); |
|
381 | + $postData=$this->getRequest()->getPost(); |
|
382 | 382 | |
383 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
383 | + $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
384 | 384 | |
385 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
385 | + $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
386 | 386 | |
387 | - try |
|
388 | - { |
|
389 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
390 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
391 | - $trap = new Trap($icingaweb2_etc); |
|
392 | - // Enable plugin. |
|
393 | - $action=($action == 'enable') ? true : false; |
|
394 | - $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
387 | + try |
|
388 | + { |
|
389 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
390 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
391 | + $trap = new Trap($icingaweb2_etc); |
|
392 | + // Enable plugin. |
|
393 | + $action=($action == 'enable') ? true : false; |
|
394 | + $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
|
395 | 395 | |
396 | - } |
|
397 | - catch (Exception $e) |
|
398 | - { |
|
399 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
400 | - return; |
|
401 | - } |
|
402 | - if ($retVal === true) |
|
403 | - { |
|
404 | - $this->_helper->json(array('status'=>'OK')); |
|
405 | - } |
|
406 | - else |
|
407 | - { |
|
408 | - $this->_helper->json(array('status'=>'Error, see logs')); |
|
409 | - } |
|
396 | + } |
|
397 | + catch (Exception $e) |
|
398 | + { |
|
399 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
400 | + return; |
|
401 | + } |
|
402 | + if ($retVal === true) |
|
403 | + { |
|
404 | + $this->_helper->json(array('status'=>'OK')); |
|
405 | + } |
|
406 | + else |
|
407 | + { |
|
408 | + $this->_helper->json(array('status'=>'Error, see logs')); |
|
409 | + } |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | /** Function evaluation |
@@ -416,49 +416,49 @@ discard block |
||
416 | 416 | */ |
417 | 417 | public function functionAction() |
418 | 418 | { |
419 | - $postData=$this->getRequest()->getPost(); |
|
419 | + $postData=$this->getRequest()->getPost(); |
|
420 | 420 | |
421 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
421 | + $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
422 | 422 | |
423 | - $this->checkPostVar($postData, 'action', 'evaluate'); |
|
423 | + $this->checkPostVar($postData, 'action', 'evaluate'); |
|
424 | 424 | |
425 | - // Only one action possible for now, no tests on action. |
|
426 | - try |
|
427 | - { |
|
428 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
429 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
430 | - $trap = new Trap($icingaweb2_etc); |
|
431 | - // load all plugins in case tested function is not enabled. |
|
432 | - $trap->pluginClass->registerAllPlugins(false); |
|
433 | - // Clean all spaces |
|
434 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
435 | - // Eval functions |
|
436 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
437 | - } |
|
438 | - catch (Exception $e) |
|
439 | - { |
|
440 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
441 | - return; |
|
442 | - } |
|
425 | + // Only one action possible for now, no tests on action. |
|
426 | + try |
|
427 | + { |
|
428 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
429 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
430 | + $trap = new Trap($icingaweb2_etc); |
|
431 | + // load all plugins in case tested function is not enabled. |
|
432 | + $trap->pluginClass->registerAllPlugins(false); |
|
433 | + // Clean all spaces |
|
434 | + $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
435 | + // Eval functions |
|
436 | + $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
437 | + } |
|
438 | + catch (Exception $e) |
|
439 | + { |
|
440 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
441 | + return; |
|
442 | + } |
|
443 | 443 | |
444 | - $result = ($result === true)?'True':'False'; |
|
445 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
444 | + $result = ($result === true)?'True':'False'; |
|
445 | + $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
446 | 446 | } |
447 | 447 | |
448 | - /************** Utilities **********************/ |
|
448 | + /************** Utilities **********************/ |
|
449 | 449 | |
450 | 450 | private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
451 | 451 | { |
452 | - if (!isset ($postData[$postVar])) |
|
453 | - { |
|
454 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
455 | - return ''; |
|
456 | - } |
|
457 | - if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
458 | - { |
|
459 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
460 | - return ''; |
|
461 | - } |
|
462 | - return $postData[$postVar]; |
|
452 | + if (!isset ($postData[$postVar])) |
|
453 | + { |
|
454 | + $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
455 | + return ''; |
|
456 | + } |
|
457 | + if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
458 | + { |
|
459 | + $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
460 | + return ''; |
|
461 | + } |
|
462 | + return $postData[$postVar]; |
|
463 | 463 | } |
464 | 464 | } |