@@ -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 | } |