@@ -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(); |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | $fileHandler=@fopen($file,'w'); |
304 | 304 | if ($fileHandler == false) |
305 | 305 | { // File os note writabe / cannot create |
306 | - $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
307 | - return; |
|
306 | + $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
307 | + return; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | else |
@@ -354,50 +354,50 @@ discard block |
||
354 | 354 | public function testruleAction() |
355 | 355 | { |
356 | 356 | |
357 | - $postData=$this->getRequest()->getPost(); |
|
358 | - if (isset($postData['rule'])) |
|
359 | - { |
|
360 | - $rule=$postData['rule']; |
|
361 | - } |
|
362 | - else |
|
363 | - { |
|
364 | - $this->_helper->json(array('status'=>'No Rule')); |
|
365 | - } |
|
366 | - if (isset($postData['action'])) |
|
367 | - { |
|
368 | - $action=$postData['action']; |
|
369 | - if ($action != 'evaluate') |
|
370 | - { |
|
371 | - $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
372 | - return; |
|
373 | - } |
|
374 | - } |
|
375 | - else |
|
376 | - { |
|
377 | - $this->_helper->json(array('status'=>'No action')); |
|
378 | - return; |
|
379 | - } |
|
380 | - if ($action == 'evaluate') |
|
381 | - { |
|
382 | - try |
|
383 | - { |
|
384 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
385 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
386 | - $Trap = new Trap($icingaweb2_etc); |
|
387 | - // Cleanup spaces before eval |
|
388 | - $rule=$Trap->ruleClass->eval_cleanup($rule); |
|
389 | - // Eval |
|
390 | - $item=0; |
|
391 | - $rule=$Trap->ruleClass->evaluation($rule,$item); |
|
392 | - } |
|
393 | - catch (Exception $e) |
|
394 | - { |
|
395 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
396 | - return; |
|
397 | - } |
|
398 | - $return=($rule==true)?'true':'false'; |
|
399 | - $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
400 | - } |
|
357 | + $postData=$this->getRequest()->getPost(); |
|
358 | + if (isset($postData['rule'])) |
|
359 | + { |
|
360 | + $rule=$postData['rule']; |
|
361 | + } |
|
362 | + else |
|
363 | + { |
|
364 | + $this->_helper->json(array('status'=>'No Rule')); |
|
365 | + } |
|
366 | + if (isset($postData['action'])) |
|
367 | + { |
|
368 | + $action=$postData['action']; |
|
369 | + if ($action != 'evaluate') |
|
370 | + { |
|
371 | + $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
372 | + return; |
|
373 | + } |
|
374 | + } |
|
375 | + else |
|
376 | + { |
|
377 | + $this->_helper->json(array('status'=>'No action')); |
|
378 | + return; |
|
379 | + } |
|
380 | + if ($action == 'evaluate') |
|
381 | + { |
|
382 | + try |
|
383 | + { |
|
384 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
385 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
386 | + $Trap = new Trap($icingaweb2_etc); |
|
387 | + // Cleanup spaces before eval |
|
388 | + $rule=$Trap->ruleClass->eval_cleanup($rule); |
|
389 | + // Eval |
|
390 | + $item=0; |
|
391 | + $rule=$Trap->ruleClass->evaluation($rule,$item); |
|
392 | + } |
|
393 | + catch (Exception $e) |
|
394 | + { |
|
395 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
396 | + return; |
|
397 | + } |
|
398 | + $return=($rule==true)?'true':'false'; |
|
399 | + $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
400 | + } |
|
401 | 401 | |
402 | 402 | } |
403 | 403 | |
@@ -408,53 +408,53 @@ discard block |
||
408 | 408 | */ |
409 | 409 | public function pluginAction() |
410 | 410 | { |
411 | - $postData=$this->getRequest()->getPost(); |
|
412 | - if (isset($postData['name'])) |
|
413 | - { |
|
414 | - $pluginName=$postData['name']; |
|
415 | - } |
|
416 | - else |
|
417 | - { |
|
418 | - $this->_helper->json(array('status'=>'No plugin name')); |
|
419 | - } |
|
420 | - if (isset($postData['action'])) |
|
421 | - { |
|
422 | - $action=$postData['action']; |
|
423 | - if ($action != 'enable' && $action != 'disable') |
|
424 | - { |
|
425 | - $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
426 | - return; |
|
427 | - } |
|
428 | - } |
|
429 | - else |
|
430 | - { |
|
431 | - $this->_helper->json(array('status'=>'No action')); |
|
432 | - return; |
|
433 | - } |
|
411 | + $postData=$this->getRequest()->getPost(); |
|
412 | + if (isset($postData['name'])) |
|
413 | + { |
|
414 | + $pluginName=$postData['name']; |
|
415 | + } |
|
416 | + else |
|
417 | + { |
|
418 | + $this->_helper->json(array('status'=>'No plugin name')); |
|
419 | + } |
|
420 | + if (isset($postData['action'])) |
|
421 | + { |
|
422 | + $action=$postData['action']; |
|
423 | + if ($action != 'enable' && $action != 'disable') |
|
424 | + { |
|
425 | + $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
426 | + return; |
|
427 | + } |
|
428 | + } |
|
429 | + else |
|
430 | + { |
|
431 | + $this->_helper->json(array('status'=>'No action')); |
|
432 | + return; |
|
433 | + } |
|
434 | 434 | |
435 | - try |
|
436 | - { |
|
437 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
438 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
439 | - $Trap = new Trap($icingaweb2_etc); |
|
440 | - // Enable plugin. |
|
441 | - $action=($action == 'enable') ? true : false; |
|
442 | - $retVal=$Trap->pluginClass->enablePlugin($pluginName, $action); |
|
435 | + try |
|
436 | + { |
|
437 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
438 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
439 | + $Trap = new Trap($icingaweb2_etc); |
|
440 | + // Enable plugin. |
|
441 | + $action=($action == 'enable') ? true : false; |
|
442 | + $retVal=$Trap->pluginClass->enablePlugin($pluginName, $action); |
|
443 | 443 | |
444 | - } |
|
445 | - catch (Exception $e) |
|
446 | - { |
|
447 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
448 | - return; |
|
449 | - } |
|
450 | - if ($retVal === true) |
|
451 | - { |
|
452 | - $this->_helper->json(array('status'=>'OK')); |
|
453 | - } |
|
454 | - else |
|
455 | - { |
|
456 | - $this->_helper->json(array('status'=>'Error, see logs')); |
|
457 | - } |
|
444 | + } |
|
445 | + catch (Exception $e) |
|
446 | + { |
|
447 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
448 | + return; |
|
449 | + } |
|
450 | + if ($retVal === true) |
|
451 | + { |
|
452 | + $this->_helper->json(array('status'=>'OK')); |
|
453 | + } |
|
454 | + else |
|
455 | + { |
|
456 | + $this->_helper->json(array('status'=>'Error, see logs')); |
|
457 | + } |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** Function evaluation |
@@ -464,66 +464,66 @@ discard block |
||
464 | 464 | */ |
465 | 465 | public function functionAction() |
466 | 466 | { |
467 | - $postData=$this->getRequest()->getPost(); |
|
468 | - if (isset($postData['function'])) |
|
469 | - { |
|
470 | - $functionString=$postData['function']; |
|
471 | - } |
|
472 | - else |
|
473 | - { |
|
474 | - $this->_helper->json(array('status'=>'No function name')); |
|
475 | - } |
|
476 | - if (isset($postData['action'])) |
|
477 | - { |
|
478 | - $action=$postData['action']; |
|
479 | - if ($action != 'evaluate') |
|
480 | - { |
|
481 | - $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
482 | - return; |
|
483 | - } |
|
484 | - } |
|
485 | - else |
|
486 | - { |
|
487 | - $this->_helper->json(array('status'=>'No action')); |
|
488 | - return; |
|
489 | - } |
|
467 | + $postData=$this->getRequest()->getPost(); |
|
468 | + if (isset($postData['function'])) |
|
469 | + { |
|
470 | + $functionString=$postData['function']; |
|
471 | + } |
|
472 | + else |
|
473 | + { |
|
474 | + $this->_helper->json(array('status'=>'No function name')); |
|
475 | + } |
|
476 | + if (isset($postData['action'])) |
|
477 | + { |
|
478 | + $action=$postData['action']; |
|
479 | + if ($action != 'evaluate') |
|
480 | + { |
|
481 | + $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
482 | + return; |
|
483 | + } |
|
484 | + } |
|
485 | + else |
|
486 | + { |
|
487 | + $this->_helper->json(array('status'=>'No action')); |
|
488 | + return; |
|
489 | + } |
|
490 | 490 | |
491 | - try |
|
492 | - { |
|
493 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
494 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
495 | - $Trap = new Trap($icingaweb2_etc); |
|
496 | - // load all plugins in case tested function is not enabled. |
|
497 | - $Trap->pluginClass->registerAllPlugins(false); |
|
498 | - // Clean all spaces |
|
499 | - $functionString = $Trap->ruleClass->eval_cleanup($functionString); |
|
500 | - // Eval functions |
|
501 | - $result = $Trap->pluginClass->evaluateFunctionString($functionString); |
|
502 | - } |
|
503 | - catch (Exception $e) |
|
504 | - { |
|
505 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
506 | - return; |
|
507 | - } |
|
491 | + try |
|
492 | + { |
|
493 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
494 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
495 | + $Trap = new Trap($icingaweb2_etc); |
|
496 | + // load all plugins in case tested function is not enabled. |
|
497 | + $Trap->pluginClass->registerAllPlugins(false); |
|
498 | + // Clean all spaces |
|
499 | + $functionString = $Trap->ruleClass->eval_cleanup($functionString); |
|
500 | + // Eval functions |
|
501 | + $result = $Trap->pluginClass->evaluateFunctionString($functionString); |
|
502 | + } |
|
503 | + catch (Exception $e) |
|
504 | + { |
|
505 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
506 | + return; |
|
507 | + } |
|
508 | 508 | |
509 | - $result = ($result === true)?'True':'False'; |
|
510 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
509 | + $result = ($result === true)?'True':'False'; |
|
510 | + $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
511 | 511 | } |
512 | 512 | |
513 | - /************** Utilities **********************/ |
|
513 | + /************** Utilities **********************/ |
|
514 | 514 | |
515 | 515 | private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
516 | 516 | { |
517 | - if (!isset ($postData[$postVar])) |
|
518 | - { |
|
519 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
520 | - return ''; |
|
521 | - } |
|
522 | - if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
523 | - { |
|
524 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
525 | - return ''; |
|
526 | - } |
|
527 | - return $postData[$postVar]; |
|
517 | + if (!isset ($postData[$postVar])) |
|
518 | + { |
|
519 | + $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
520 | + return ''; |
|
521 | + } |
|
522 | + if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
|
523 | + { |
|
524 | + $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
525 | + return ''; |
|
526 | + } |
|
527 | + return $postData[$postVar]; |
|
528 | 528 | } |
529 | 529 | } |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | { |
19 | 19 | $postData=$this->getRequest()->getPost(); |
20 | 20 | |
21 | - $hostFilter = $this->checkPostVar($postData, 'hostFilter', '.*'); |
|
21 | + $hostFilter=$this->checkPostVar($postData, 'hostFilter', '.*'); |
|
22 | 22 | |
23 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
23 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
24 | 24 | |
25 | 25 | $hosts=$this->getHostByIP($hostFilter); |
26 | 26 | foreach ($hosts as $val) |
27 | 27 | { |
28 | - array_push($retHosts['hosts'],$val->name); |
|
28 | + array_push($retHosts['hosts'], $val->name); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | $this->_helper->json($retHosts); |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | { |
39 | 39 | $postData=$this->getRequest()->getPost(); |
40 | 40 | |
41 | - $hostFilter = $this->checkPostVar($postData, 'hostfilter', '.*'); |
|
41 | + $hostFilter=$this->checkPostVar($postData, 'hostfilter', '.*'); |
|
42 | 42 | |
43 | - $retHosts=array('status'=>'OK','hosts' => array()); |
|
43 | + $retHosts=array('status'=>'OK', 'hosts' => array()); |
|
44 | 44 | |
45 | 45 | $hosts=$this->getHostGroupByName($hostFilter); |
46 | 46 | foreach ($hosts as $val) |
47 | 47 | { |
48 | - array_push($retHosts['hosts'],$val->name); |
|
48 | + array_push($retHosts['hosts'], $val->name); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | $this->_helper->json($retHosts); |
@@ -68,31 +68,31 @@ discard block |
||
68 | 68 | } |
69 | 69 | else |
70 | 70 | { |
71 | - $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
|
71 | + $this->_helper->json(array('status'=>'No Hosts', 'hostid' => -1)); |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $hostArray=$this->getHostByName($host); |
76 | 76 | if (count($hostArray) > 1) |
77 | 77 | { |
78 | - $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
|
78 | + $this->_helper->json(array('status'=>'More than one host matches', 'hostid' => -1)); |
|
79 | 79 | return; |
80 | 80 | } |
81 | 81 | else if (count($hostArray) == 0) |
82 | 82 | { |
83 | - $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
|
83 | + $this->_helper->json(array('status'=>'No host matches', 'hostid' => -1)); |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | $services=$this->getServicesByHostid($hostArray[0]->id); |
87 | 87 | if (count($services) < 1) |
88 | 88 | { |
89 | - $this->_helper->json(array('status'=>'No services found for host','hostid' => $hostArray[0]->id)); |
|
89 | + $this->_helper->json(array('status'=>'No services found for host', 'hostid' => $hostArray[0]->id)); |
|
90 | 90 | return; |
91 | 91 | } |
92 | - $retServices=array('status'=>'OK','services' => array(),'hostid' => $hostArray[0]->id); |
|
92 | + $retServices=array('status'=>'OK', 'services' => array(), 'hostid' => $hostArray[0]->id); |
|
93 | 93 | foreach ($services as $val) |
94 | 94 | { |
95 | - array_push($retServices['services'],array($val->id , $val->name)); |
|
95 | + array_push($retServices['services'], array($val->id, $val->name)); |
|
96 | 96 | } |
97 | 97 | $this->_helper->json($retServices); |
98 | 98 | } |
@@ -107,26 +107,26 @@ discard block |
||
107 | 107 | { |
108 | 108 | $postData=$this->getRequest()->getPost(); |
109 | 109 | |
110 | - $host = $this->checkPostVar($postData, 'host', '.*'); |
|
110 | + $host=$this->checkPostVar($postData, 'host', '.*'); |
|
111 | 111 | |
112 | 112 | $hostArray=$this->getHostGroupByName($host); |
113 | 113 | if (count($hostArray) > 1) |
114 | 114 | { |
115 | - $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
|
115 | + $this->_helper->json(array('status'=>'More than one hostgroup matches', 'hostid' => -1)); |
|
116 | 116 | return; |
117 | 117 | } |
118 | 118 | else if (count($hostArray) == 0) |
119 | 119 | { |
120 | - $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
|
120 | + $this->_helper->json(array('status'=>'No hostgroup matches', 'hostid' => -1)); |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | $services=$this->getServicesByHostGroupid($hostArray[0]->id); |
124 | 124 | if (count($services) < 1) |
125 | 125 | { |
126 | - $this->_helper->json(array('status'=>'No services found for hostgroup','hostid' => $hostArray[0]->id)); |
|
126 | + $this->_helper->json(array('status'=>'No services found for hostgroup', 'hostid' => $hostArray[0]->id)); |
|
127 | 127 | return; |
128 | 128 | } |
129 | - $retServices=array('status'=>'OK','services' => $services,'hostid' => $hostArray[0]->id); |
|
129 | + $retServices=array('status'=>'OK', 'services' => $services, 'hostid' => $hostArray[0]->id); |
|
130 | 130 | |
131 | 131 | $this->_helper->json($retServices); |
132 | 132 | } |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | { |
141 | 141 | $postData=$this->getRequest()->getPost(); |
142 | 142 | |
143 | - $mib = $this->checkPostVar($postData, 'mib', '.*'); |
|
143 | + $mib=$this->checkPostVar($postData, 'mib', '.*'); |
|
144 | 144 | |
145 | 145 | try |
146 | 146 | { |
147 | 147 | $traplist=$this->getMIB()->getTrapList($mib); |
148 | - $retTraps=array('status'=>'OK','traps' => $traplist); |
|
148 | + $retTraps=array('status'=>'OK', 'traps' => $traplist); |
|
149 | 149 | } |
150 | 150 | catch (Exception $e) |
151 | 151 | { |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | { |
164 | 164 | $postData=$this->getRequest()->getPost(); |
165 | 165 | |
166 | - $trap = $this->checkPostVar($postData, 'trap', '.*'); |
|
166 | + $trap=$this->checkPostVar($postData, 'trap', '.*'); |
|
167 | 167 | |
168 | 168 | try |
169 | 169 | { |
170 | 170 | $objectlist=$this->getMIB()->getObjectList($trap); |
171 | - $retObjects=array('status'=>'OK','objects' => $objectlist); |
|
171 | + $retObjects=array('status'=>'OK', 'objects' => $objectlist); |
|
172 | 172 | } |
173 | 173 | catch (Exception $e) |
174 | 174 | { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | { |
203 | 203 | $postData=$this->getRequest()->getPost(); |
204 | 204 | |
205 | - $oid = $this->checkPostVar($postData, 'oid', '.*'); |
|
205 | + $oid=$this->checkPostVar($postData, 'oid', '.*'); |
|
206 | 206 | |
207 | 207 | // Try to get oid name from snmptranslate |
208 | 208 | if (($object=$this->getMIB()->translateOID($oid)) == null) |
@@ -235,19 +235,19 @@ discard block |
||
235 | 235 | |
236 | 236 | $postData=$this->getRequest()->getPost(); |
237 | 237 | |
238 | - $days = $this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
238 | + $days=$this->checkPostVar($postData, 'days', '^[0-9]+$'); |
|
239 | 239 | |
240 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
240 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
241 | 241 | |
242 | 242 | if ($action == 'save') |
243 | 243 | { |
244 | 244 | try |
245 | 245 | { |
246 | - $this->setDBConfigValue('db_remove_days',$days); |
|
246 | + $this->setDBConfigValue('db_remove_days', $days); |
|
247 | 247 | } |
248 | 248 | catch (Exception $e) |
249 | 249 | { |
250 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
250 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | $this->_helper->json(array('status'=>'OK')); |
@@ -257,16 +257,16 @@ discard block |
||
257 | 257 | { |
258 | 258 | try |
259 | 259 | { |
260 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
260 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
261 | 261 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
262 | 262 | $debug_level=4; |
263 | - $Trap = new Trap($icingaweb2_etc); |
|
264 | - $Trap->setLogging($debug_level,'syslog'); |
|
263 | + $Trap=new Trap($icingaweb2_etc); |
|
264 | + $Trap->setLogging($debug_level, 'syslog'); |
|
265 | 265 | $Trap->eraseOldTraps($days); |
266 | 266 | } |
267 | 267 | catch (Exception $e) |
268 | 268 | { |
269 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
269 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
270 | 270 | return; |
271 | 271 | } |
272 | 272 | $this->_helper->json(array('status'=>'OK')); |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | if (isset($postData['file'])) |
301 | 301 | { |
302 | 302 | $file=$postData['file']; |
303 | - $fileHandler=@fopen($file,'w'); |
|
303 | + $fileHandler=@fopen($file, 'w'); |
|
304 | 304 | if ($fileHandler == false) |
305 | 305 | { // File os note writabe / cannot create |
306 | 306 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -332,13 +332,13 @@ discard block |
||
332 | 332 | |
333 | 333 | try |
334 | 334 | { |
335 | - $this->setDBConfigValue('log_destination',$destination); |
|
336 | - $this->setDBConfigValue('log_file',$file); |
|
337 | - $this->setDBConfigValue('log_level',$level); |
|
335 | + $this->setDBConfigValue('log_destination', $destination); |
|
336 | + $this->setDBConfigValue('log_file', $file); |
|
337 | + $this->setDBConfigValue('log_level', $level); |
|
338 | 338 | } |
339 | 339 | catch (Exception $e) |
340 | 340 | { |
341 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
341 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
342 | 342 | return; |
343 | 343 | } |
344 | 344 | $this->_helper->json(array('status'=>'OK')); |
@@ -381,21 +381,21 @@ discard block |
||
381 | 381 | { |
382 | 382 | try |
383 | 383 | { |
384 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
384 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
385 | 385 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
386 | - $Trap = new Trap($icingaweb2_etc); |
|
386 | + $Trap=new Trap($icingaweb2_etc); |
|
387 | 387 | // Cleanup spaces before eval |
388 | 388 | $rule=$Trap->ruleClass->eval_cleanup($rule); |
389 | 389 | // Eval |
390 | 390 | $item=0; |
391 | - $rule=$Trap->ruleClass->evaluation($rule,$item); |
|
391 | + $rule=$Trap->ruleClass->evaluation($rule, $item); |
|
392 | 392 | } |
393 | 393 | catch (Exception $e) |
394 | 394 | { |
395 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
395 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
396 | 396 | return; |
397 | 397 | } |
398 | - $return=($rule==true)?'true':'false'; |
|
398 | + $return=($rule == true) ? 'true' : 'false'; |
|
399 | 399 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
400 | 400 | } |
401 | 401 | |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | |
435 | 435 | try |
436 | 436 | { |
437 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
437 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
438 | 438 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
439 | - $Trap = new Trap($icingaweb2_etc); |
|
439 | + $Trap=new Trap($icingaweb2_etc); |
|
440 | 440 | // Enable plugin. |
441 | 441 | $action=($action == 'enable') ? true : false; |
442 | 442 | $retVal=$Trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | } |
445 | 445 | catch (Exception $e) |
446 | 446 | { |
447 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
447 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
448 | 448 | return; |
449 | 449 | } |
450 | 450 | if ($retVal === true) |
@@ -490,38 +490,38 @@ discard block |
||
490 | 490 | |
491 | 491 | try |
492 | 492 | { |
493 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
493 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
494 | 494 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
495 | - $Trap = new Trap($icingaweb2_etc); |
|
495 | + $Trap=new Trap($icingaweb2_etc); |
|
496 | 496 | // load all plugins in case tested function is not enabled. |
497 | 497 | $Trap->pluginClass->registerAllPlugins(false); |
498 | 498 | // Clean all spaces |
499 | - $functionString = $Trap->ruleClass->eval_cleanup($functionString); |
|
499 | + $functionString=$Trap->ruleClass->eval_cleanup($functionString); |
|
500 | 500 | // Eval functions |
501 | - $result = $Trap->pluginClass->evaluateFunctionString($functionString); |
|
501 | + $result=$Trap->pluginClass->evaluateFunctionString($functionString); |
|
502 | 502 | } |
503 | 503 | catch (Exception $e) |
504 | 504 | { |
505 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
505 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
506 | 506 | return; |
507 | 507 | } |
508 | 508 | |
509 | - $result = ($result === true)?'True':'False'; |
|
510 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
509 | + $result=($result === true) ? 'True' : 'False'; |
|
510 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /************** Utilities **********************/ |
514 | 514 | |
515 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
515 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
516 | 516 | { |
517 | 517 | if (!isset ($postData[$postVar])) |
518 | 518 | { |
519 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
519 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
520 | 520 | return ''; |
521 | 521 | } |
522 | 522 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
523 | 523 | { |
524 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
524 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
525 | 525 | return ''; |
526 | 526 | } |
527 | 527 | return $postData[$postVar]; |
@@ -65,8 +65,7 @@ discard block |
||
65 | 65 | if (isset($postData['host'])) |
66 | 66 | { |
67 | 67 | $host=$postData['host']; |
68 | - } |
|
69 | - else |
|
68 | + } else |
|
70 | 69 | { |
71 | 70 | $this->_helper->json(array('status'=>'No Hosts','hostid' => -1)); |
72 | 71 | return; |
@@ -77,8 +76,7 @@ discard block |
||
77 | 76 | { |
78 | 77 | $this->_helper->json(array('status'=>'More than one host matches','hostid' => -1)); |
79 | 78 | return; |
80 | - } |
|
81 | - else if (count($hostArray) == 0) |
|
79 | + } else if (count($hostArray) == 0) |
|
82 | 80 | { |
83 | 81 | $this->_helper->json(array('status'=>'No host matches','hostid' => -1)); |
84 | 82 | return; |
@@ -114,8 +112,7 @@ discard block |
||
114 | 112 | { |
115 | 113 | $this->_helper->json(array('status'=>'More than one hostgroup matches','hostid' => -1)); |
116 | 114 | return; |
117 | - } |
|
118 | - else if (count($hostArray) == 0) |
|
115 | + } else if (count($hostArray) == 0) |
|
119 | 116 | { |
120 | 117 | $this->_helper->json(array('status'=>'No hostgroup matches','hostid' => -1)); |
121 | 118 | return; |
@@ -146,8 +143,7 @@ discard block |
||
146 | 143 | { |
147 | 144 | $traplist=$this->getMIB()->getTrapList($mib); |
148 | 145 | $retTraps=array('status'=>'OK','traps' => $traplist); |
149 | - } |
|
150 | - catch (Exception $e) |
|
146 | + } catch (Exception $e) |
|
151 | 147 | { |
152 | 148 | $retTraps=array('status' => 'Error getting mibs'); |
153 | 149 | } |
@@ -169,8 +165,7 @@ discard block |
||
169 | 165 | { |
170 | 166 | $objectlist=$this->getMIB()->getObjectList($trap); |
171 | 167 | $retObjects=array('status'=>'OK','objects' => $objectlist); |
172 | - } |
|
173 | - catch (Exception $e) |
|
168 | + } catch (Exception $e) |
|
174 | 169 | { |
175 | 170 | $retObjects=array('status' => 'not found'); |
176 | 171 | } |
@@ -185,8 +180,7 @@ discard block |
||
185 | 180 | try |
186 | 181 | { |
187 | 182 | $miblist=$this->getMIB()->getMIBList(); |
188 | - } |
|
189 | - catch (Exception $e) |
|
183 | + } catch (Exception $e) |
|
190 | 184 | { |
191 | 185 | $miblist=array('Error getting mibs'); |
192 | 186 | } |
@@ -209,8 +203,7 @@ discard block |
||
209 | 203 | { |
210 | 204 | $this->_helper->json(array('status'=>'Not found')); |
211 | 205 | return; |
212 | - } |
|
213 | - else |
|
206 | + } else |
|
214 | 207 | { |
215 | 208 | $this->_helper->json( |
216 | 209 | array('status'=>'OK', |
@@ -244,8 +237,7 @@ discard block |
||
244 | 237 | try |
245 | 238 | { |
246 | 239 | $this->setDBConfigValue('db_remove_days',$days); |
247 | - } |
|
248 | - catch (Exception $e) |
|
240 | + } catch (Exception $e) |
|
249 | 241 | { |
250 | 242 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
251 | 243 | return; |
@@ -263,8 +255,7 @@ discard block |
||
263 | 255 | $Trap = new Trap($icingaweb2_etc); |
264 | 256 | $Trap->setLogging($debug_level,'syslog'); |
265 | 257 | $Trap->eraseOldTraps($days); |
266 | - } |
|
267 | - catch (Exception $e) |
|
258 | + } catch (Exception $e) |
|
268 | 259 | { |
269 | 260 | $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
270 | 261 | return; |
@@ -292,8 +283,7 @@ discard block |
||
292 | 283 | $this->_helper->json(array('status'=>'invalid destination : '.$destination)); |
293 | 284 | return; |
294 | 285 | } |
295 | - } |
|
296 | - else |
|
286 | + } else |
|
297 | 287 | { |
298 | 288 | $this->_helper->json(array('status'=>'No destination')); |
299 | 289 | } |
@@ -306,14 +296,12 @@ discard block |
||
306 | 296 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
307 | 297 | return; |
308 | 298 | } |
309 | - } |
|
310 | - else |
|
299 | + } else |
|
311 | 300 | { |
312 | 301 | if ($destination != 'file') |
313 | 302 | { |
314 | 303 | $file=null; |
315 | - } |
|
316 | - else |
|
304 | + } else |
|
317 | 305 | { |
318 | 306 | $this->_helper->json(array('status'=>'No file')); |
319 | 307 | return; |
@@ -323,8 +311,7 @@ discard block |
||
323 | 311 | if (isset($postData['level'])) |
324 | 312 | { |
325 | 313 | $level=$postData['level']; |
326 | - } |
|
327 | - else |
|
314 | + } else |
|
328 | 315 | { |
329 | 316 | $this->_helper->json(array('status'=>'No level')); |
330 | 317 | return; |
@@ -335,8 +322,7 @@ discard block |
||
335 | 322 | $this->setDBConfigValue('log_destination',$destination); |
336 | 323 | $this->setDBConfigValue('log_file',$file); |
337 | 324 | $this->setDBConfigValue('log_level',$level); |
338 | - } |
|
339 | - catch (Exception $e) |
|
325 | + } catch (Exception $e) |
|
340 | 326 | { |
341 | 327 | $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
342 | 328 | return; |
@@ -358,8 +344,7 @@ discard block |
||
358 | 344 | if (isset($postData['rule'])) |
359 | 345 | { |
360 | 346 | $rule=$postData['rule']; |
361 | - } |
|
362 | - else |
|
347 | + } else |
|
363 | 348 | { |
364 | 349 | $this->_helper->json(array('status'=>'No Rule')); |
365 | 350 | } |
@@ -371,8 +356,7 @@ discard block |
||
371 | 356 | $this->_helper->json(array('status'=>'unknown action '.$action)); |
372 | 357 | return; |
373 | 358 | } |
374 | - } |
|
375 | - else |
|
359 | + } else |
|
376 | 360 | { |
377 | 361 | $this->_helper->json(array('status'=>'No action')); |
378 | 362 | return; |
@@ -389,8 +373,7 @@ discard block |
||
389 | 373 | // Eval |
390 | 374 | $item=0; |
391 | 375 | $rule=$Trap->ruleClass->evaluation($rule,$item); |
392 | - } |
|
393 | - catch (Exception $e) |
|
376 | + } catch (Exception $e) |
|
394 | 377 | { |
395 | 378 | $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
396 | 379 | return; |
@@ -412,8 +395,7 @@ discard block |
||
412 | 395 | if (isset($postData['name'])) |
413 | 396 | { |
414 | 397 | $pluginName=$postData['name']; |
415 | - } |
|
416 | - else |
|
398 | + } else |
|
417 | 399 | { |
418 | 400 | $this->_helper->json(array('status'=>'No plugin name')); |
419 | 401 | } |
@@ -425,8 +407,7 @@ discard block |
||
425 | 407 | $this->_helper->json(array('status'=>'unknown action '.$action)); |
426 | 408 | return; |
427 | 409 | } |
428 | - } |
|
429 | - else |
|
410 | + } else |
|
430 | 411 | { |
431 | 412 | $this->_helper->json(array('status'=>'No action')); |
432 | 413 | return; |
@@ -441,8 +422,7 @@ discard block |
||
441 | 422 | $action=($action == 'enable') ? true : false; |
442 | 423 | $retVal=$Trap->pluginClass->enablePlugin($pluginName, $action); |
443 | 424 | |
444 | - } |
|
445 | - catch (Exception $e) |
|
425 | + } catch (Exception $e) |
|
446 | 426 | { |
447 | 427 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
448 | 428 | return; |
@@ -450,8 +430,7 @@ discard block |
||
450 | 430 | if ($retVal === true) |
451 | 431 | { |
452 | 432 | $this->_helper->json(array('status'=>'OK')); |
453 | - } |
|
454 | - else |
|
433 | + } else |
|
455 | 434 | { |
456 | 435 | $this->_helper->json(array('status'=>'Error, see logs')); |
457 | 436 | } |
@@ -468,8 +447,7 @@ discard block |
||
468 | 447 | if (isset($postData['function'])) |
469 | 448 | { |
470 | 449 | $functionString=$postData['function']; |
471 | - } |
|
472 | - else |
|
450 | + } else |
|
473 | 451 | { |
474 | 452 | $this->_helper->json(array('status'=>'No function name')); |
475 | 453 | } |
@@ -481,8 +459,7 @@ discard block |
||
481 | 459 | $this->_helper->json(array('status'=>'unknown action '.$action)); |
482 | 460 | return; |
483 | 461 | } |
484 | - } |
|
485 | - else |
|
462 | + } else |
|
486 | 463 | { |
487 | 464 | $this->_helper->json(array('status'=>'No action')); |
488 | 465 | return; |
@@ -499,8 +476,7 @@ discard block |
||
499 | 476 | $functionString = $Trap->ruleClass->eval_cleanup($functionString); |
500 | 477 | // Eval functions |
501 | 478 | $result = $Trap->pluginClass->evaluateFunctionString($functionString); |
502 | - } |
|
503 | - catch (Exception $e) |
|
479 | + } catch (Exception $e) |
|
504 | 480 | { |
505 | 481 | $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
506 | 482 | return; |