@@ -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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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->getUIDatabase()->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,20 +235,20 @@ 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 | $days=intval($days); |
240 | 240 | |
241 | - $action = $this->checkPostVar($postData, 'action', 'save|execute'); |
|
241 | + $action=$this->checkPostVar($postData, 'action', 'save|execute'); |
|
242 | 242 | |
243 | 243 | if ($action == 'save') |
244 | 244 | { |
245 | 245 | try |
246 | 246 | { |
247 | - $this->getUIDatabase()->setDBConfigValue('db_remove_days',$days); |
|
247 | + $this->getUIDatabase()->setDBConfigValue('db_remove_days', $days); |
|
248 | 248 | } |
249 | 249 | catch (Exception $e) |
250 | 250 | { |
251 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
251 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | $this->_helper->json(array('status'=>'OK')); |
@@ -258,16 +258,16 @@ discard block |
||
258 | 258 | { |
259 | 259 | try |
260 | 260 | { |
261 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
261 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
262 | 262 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
263 | 263 | $debug_level=4; |
264 | - $trap = new Trap($icingaweb2_etc); |
|
265 | - $trap->setLogging($debug_level,'syslog'); |
|
264 | + $trap=new Trap($icingaweb2_etc); |
|
265 | + $trap->setLogging($debug_level, 'syslog'); |
|
266 | 266 | $trap->eraseOldTraps($days); |
267 | 267 | } |
268 | 268 | catch (Exception $e) |
269 | 269 | { |
270 | - $this->_helper->json(array('status'=>'execute error : '.$e->getMessage() )); |
|
270 | + $this->_helper->json(array('status'=>'execute error : '.$e->getMessage())); |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | $this->_helper->json(array('status'=>'OK')); |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | { |
286 | 286 | $postData=$this->getRequest()->getPost(); |
287 | 287 | |
288 | - $destination = $this->checkPostVar($postData, 'destination', '.*'); |
|
288 | + $destination=$this->checkPostVar($postData, 'destination', '.*'); |
|
289 | 289 | $logDest=$this->getModuleConfig()->getLogDestinations(); |
290 | 290 | if (!isset($logDest[$destination])) |
291 | 291 | { |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | if (isset($postData['file'])) |
297 | 297 | { |
298 | 298 | $file=$postData['file']; |
299 | - $fileHandler=@fopen($file,'w'); |
|
299 | + $fileHandler=@fopen($file, 'w'); |
|
300 | 300 | if ($fileHandler == false) |
301 | 301 | { // File os note writabe / cannot create |
302 | 302 | $this->_helper->json(array('status'=>'File not writable : '.$file)); |
@@ -316,17 +316,17 @@ discard block |
||
316 | 316 | } |
317 | 317 | } |
318 | 318 | |
319 | - $level = $this->checkPostVar($postData, 'level', '[0-9]'); |
|
319 | + $level=$this->checkPostVar($postData, 'level', '[0-9]'); |
|
320 | 320 | |
321 | 321 | try |
322 | 322 | { |
323 | - $this->getUIDatabase()->setDBConfigValue('log_destination',$destination); |
|
324 | - $this->getUIDatabase()->setDBConfigValue('log_file',$file); |
|
325 | - $this->getUIDatabase()->setDBConfigValue('log_level',$level); |
|
323 | + $this->getUIDatabase()->setDBConfigValue('log_destination', $destination); |
|
324 | + $this->getUIDatabase()->setDBConfigValue('log_file', $file); |
|
325 | + $this->getUIDatabase()->setDBConfigValue('log_level', $level); |
|
326 | 326 | } |
327 | 327 | catch (Exception $e) |
328 | 328 | { |
329 | - $this->_helper->json(array('status'=>'Save error : '.$e->getMessage() )); |
|
329 | + $this->_helper->json(array('status'=>'Save error : '.$e->getMessage())); |
|
330 | 330 | return; |
331 | 331 | } |
332 | 332 | $this->_helper->json(array('status'=>'OK')); |
@@ -344,29 +344,29 @@ discard block |
||
344 | 344 | |
345 | 345 | $postData=$this->getRequest()->getPost(); |
346 | 346 | |
347 | - $rule = $this->checkPostVar($postData, 'rule', '.*'); |
|
347 | + $rule=$this->checkPostVar($postData, 'rule', '.*'); |
|
348 | 348 | |
349 | - $action = $this->checkPostVar($postData, 'action', 'evaluate'); |
|
349 | + $action=$this->checkPostVar($postData, 'action', 'evaluate'); |
|
350 | 350 | |
351 | 351 | if ($action == 'evaluate') |
352 | 352 | { |
353 | 353 | try |
354 | 354 | { |
355 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
355 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
356 | 356 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
357 | - $trap = new Trap($icingaweb2_etc); |
|
357 | + $trap=new Trap($icingaweb2_etc); |
|
358 | 358 | // Cleanup spaces before eval |
359 | 359 | $rule=$trap->ruleClass->eval_cleanup($rule); |
360 | 360 | // Eval |
361 | 361 | $item=0; |
362 | - $rule=$trap->ruleClass->evaluation($rule,$item); |
|
362 | + $rule=$trap->ruleClass->evaluation($rule, $item); |
|
363 | 363 | } |
364 | 364 | catch (Exception $e) |
365 | 365 | { |
366 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
366 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage())); |
|
367 | 367 | return; |
368 | 368 | } |
369 | - $return=($rule==true)?'true':'false'; |
|
369 | + $return=($rule == true) ? 'true' : 'false'; |
|
370 | 370 | $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
371 | 371 | } |
372 | 372 | |
@@ -381,15 +381,15 @@ discard block |
||
381 | 381 | { |
382 | 382 | $postData=$this->getRequest()->getPost(); |
383 | 383 | |
384 | - $pluginName = $this->checkPostVar($postData, 'name', '.*'); |
|
384 | + $pluginName=$this->checkPostVar($postData, 'name', '.*'); |
|
385 | 385 | |
386 | - $action = $this->checkPostVar($postData, 'action', 'enable|disable'); |
|
386 | + $action=$this->checkPostVar($postData, 'action', 'enable|disable'); |
|
387 | 387 | |
388 | 388 | try |
389 | 389 | { |
390 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
390 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
391 | 391 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
392 | - $trap = new Trap($icingaweb2_etc); |
|
392 | + $trap=new Trap($icingaweb2_etc); |
|
393 | 393 | // Enable plugin. |
394 | 394 | $action=($action == 'enable') ? true : false; |
395 | 395 | $retVal=$trap->pluginClass->enablePlugin($pluginName, $action); |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | } |
398 | 398 | catch (Exception $e) |
399 | 399 | { |
400 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
400 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
401 | 401 | return; |
402 | 402 | } |
403 | 403 | if ($retVal === true) |
@@ -419,45 +419,45 @@ discard block |
||
419 | 419 | { |
420 | 420 | $postData=$this->getRequest()->getPost(); |
421 | 421 | |
422 | - $functionString = $this->checkPostVar($postData, 'function', '.*'); |
|
422 | + $functionString=$this->checkPostVar($postData, 'function', '.*'); |
|
423 | 423 | |
424 | 424 | $this->checkPostVar($postData, 'action', 'evaluate'); |
425 | 425 | |
426 | 426 | // Only one action possible for now, no tests on action. |
427 | 427 | try |
428 | 428 | { |
429 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
429 | + require_once($this->Module()->getBaseDir().'/bin/trap_class.php'); |
|
430 | 430 | $icingaweb2Etc=$this->Config()->get('config', 'icingaweb2_etc'); |
431 | - $trap = new Trap($icingaweb2Etc); |
|
431 | + $trap=new Trap($icingaweb2Etc); |
|
432 | 432 | // load all plugins in case tested function is not enabled. |
433 | 433 | $trap->pluginClass->registerAllPlugins(false); |
434 | 434 | // Clean all spaces |
435 | - $functionString = $trap->ruleClass->eval_cleanup($functionString); |
|
435 | + $functionString=$trap->ruleClass->eval_cleanup($functionString); |
|
436 | 436 | // Eval functions |
437 | - $result = $trap->pluginClass->evaluateFunctionString($functionString); |
|
437 | + $result=$trap->pluginClass->evaluateFunctionString($functionString); |
|
438 | 438 | } |
439 | 439 | catch (Exception $e) |
440 | 440 | { |
441 | - $this->_helper->json(array('status'=>'Action error : '.$e->getMessage() )); |
|
441 | + $this->_helper->json(array('status'=>'Action error : '.$e->getMessage())); |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | - $result = ($result === true)?'True':'False'; |
|
446 | - $this->_helper->json(array('status'=>'OK','message' => $result)); |
|
445 | + $result=($result === true) ? 'True' : 'False'; |
|
446 | + $this->_helper->json(array('status'=>'OK', 'message' => $result)); |
|
447 | 447 | } |
448 | 448 | |
449 | 449 | /************** Utilities **********************/ |
450 | 450 | |
451 | - private function checkPostVar(array $postData,string $postVar, string $validRegexp) : string |
|
451 | + private function checkPostVar(array $postData, string $postVar, string $validRegexp) : string |
|
452 | 452 | { |
453 | 453 | if (!isset ($postData[$postVar])) |
454 | 454 | { |
455 | - $this->_helper->json(array('status'=>'No ' . $postVar)); |
|
455 | + $this->_helper->json(array('status'=>'No '.$postVar)); |
|
456 | 456 | return ''; |
457 | 457 | } |
458 | 458 | if (preg_match('/'.$validRegexp.'/', $postData[$postVar]) != 1) |
459 | 459 | { |
460 | - $this->_helper->json(array('status'=>'Unknown ' . $postVar . ' value '.$postData[$postVar])); |
|
460 | + $this->_helper->json(array('status'=>'Unknown '.$postVar.' value '.$postData[$postVar])); |
|
461 | 461 | return ''; |
462 | 462 | } |
463 | 463 | return $postData[$postVar]; |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | $this->checkReadPermission(); |
24 | 24 | $this->prepareTabs()->activate('status'); |
25 | 25 | |
26 | - $dbConn = $this->getUIDatabase()->getDb(); |
|
26 | + $dbConn=$this->getUIDatabase()->getDb(); |
|
27 | 27 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
28 | 28 | |
29 | 29 | $this->getHandlerListTable()->setConnection($dbConn); |
30 | 30 | $this->getHandlerListTable()->setMibloader($this->getMIB()); |
31 | 31 | // Apply pagination limits |
32 | - $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(),$this->getModuleConfig()->itemListDisplay()); |
|
32 | + $this->view->table=$this->applyPaginationLimits($this->getHandlerListTable(), $this->getModuleConfig()->itemListDisplay()); |
|
33 | 33 | |
34 | 34 | // Set Filter |
35 | - $this->view->filterEditor = $this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
35 | + $this->view->filterEditor=$this->getHandlerListTable()->getFilterEditor($this->getRequest()); |
|
36 | 36 | |
37 | 37 | //$this->displayExitError('Handler/indexAction','Not implemented'); |
38 | 38 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function testruleAction() |
43 | 43 | { |
44 | 44 | $this->checkReadPermission(); |
45 | - $this->getTabs()->add('get',array( |
|
45 | + $this->getTabs()->add('get', array( |
|
46 | 46 | 'active' => true, |
47 | 47 | 'label' => $this->translate('Test Rule'), |
48 | 48 | 'url' => Url::fromRequest() |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | |
52 | 52 | if ($this->params->get('rule') !== null) |
53 | 53 | { |
54 | - $this->view->rule= $this->params->get('rule'); |
|
54 | + $this->view->rule=$this->params->get('rule'); |
|
55 | 55 | } |
56 | 56 | else |
57 | 57 | { |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | } |
111 | 111 | catch (Exception $e) |
112 | 112 | { |
113 | - $this->displayExitError('Add handler : get host by IP/Name ',$e->getMessage()); |
|
113 | + $this->displayExitError('Add handler : get host by IP/Name ', $e->getMessage()); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
117 | 117 | // if one unique host found -> put id text input |
118 | - if (count($hosts)==1) { |
|
118 | + if (count($hosts) == 1) { |
|
119 | 119 | $this->view->hostname=$hosts[0]->name; |
120 | 120 | //$hostid=$hosts[0]->id; |
121 | 121 | // Tell JS to get services when page is loaded |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | } |
125 | 125 | else |
126 | 126 | { |
127 | - foreach($hosts as $key=>$val) |
|
127 | + foreach ($hosts as $key=>$val) |
|
128 | 128 | { |
129 | - array_push($this->view->hostlist,$hosts[$key]->name); |
|
129 | + array_push($this->view->hostlist, $hosts[$key]->name); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -165,18 +165,18 @@ discard block |
||
165 | 165 | $currentObjectTypeEnum |
166 | 166 | ); |
167 | 167 | $oid_index++; |
168 | - array_push($this->view->objectList,$currentObject); |
|
168 | + array_push($this->view->objectList, $currentObject); |
|
169 | 169 | // set currrent object to null in allObjects |
170 | 170 | if (isset($allObjects[$val->oid])) |
171 | 171 | { |
172 | 172 | $allObjects[$val->oid]=null; |
173 | 173 | } |
174 | 174 | } |
175 | - if ($allObjects!=null) // in case trap doesn't have objects or is not resolved |
|
175 | + if ($allObjects != null) // in case trap doesn't have objects or is not resolved |
|
176 | 176 | { |
177 | 177 | foreach ($allObjects as $key => $val) |
178 | 178 | { |
179 | - if ($val==null) { continue; } |
|
179 | + if ($val == null) { continue; } |
|
180 | 180 | array_push($this->view->objectList, array( |
181 | 181 | $oid_index, |
182 | 182 | $key, |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | // Check if hostname still exists |
205 | 205 | $host_get=$this->getUIDatabase()->getHostByName($this->view->hostname); |
206 | 206 | |
207 | - if (count($host_get)==0) |
|
207 | + if (count($host_get) == 0) |
|
208 | 208 | { |
209 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
209 | + $this->view->warning_message='Host '.$this->view->hostname.' doesn\'t exists anymore'; |
|
210 | 210 | $this->view->serviceGet=false; |
211 | 211 | } |
212 | 212 | else |
@@ -214,10 +214,10 @@ discard block |
||
214 | 214 | // Tell JS to get services when page is loaded |
215 | 215 | $this->view->serviceGet=true; |
216 | 216 | // get service id for form to set : |
217 | - $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
218 | - if (count($serviceID) ==0) |
|
217 | + $serviceID=$this->getUIDatabase()->getServiceIDByName($this->view->hostname, $ruleDetail->service_name); |
|
218 | + if (count($serviceID) == 0) |
|
219 | 219 | { |
220 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
220 | + $this->view->warning_message=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
221 | 221 | } |
222 | 222 | else |
223 | 223 | { |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | { |
235 | 235 | // Check if groupe exists |
236 | 236 | $group_get=$this->getUIDatabase()->getHostGroupByName($this->view->hostgroupname); |
237 | - if (count($group_get)==0) |
|
237 | + if (count($group_get) == 0) |
|
238 | 238 | { |
239 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
239 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname.' doesn\'t exists anymore'; |
|
240 | 240 | $this->view->serviceGroupGet=false; |
241 | 241 | } |
242 | 242 | else |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | |
255 | 255 | // Tell JS to get services when page is loaded |
256 | 256 | $this->view->serviceGroupGet=true; |
257 | - if ($foundGrpService==0) |
|
257 | + if ($foundGrpService == 0) |
|
258 | 258 | { |
259 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
259 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name.' doesn\'t exists anymore'; |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | } |
@@ -274,12 +274,12 @@ discard block |
||
274 | 274 | $index=1; |
275 | 275 | // check in display & rule for : OID(<oid>) |
276 | 276 | $matches=array(); |
277 | - while ( preg_match('/_OID\(([\.0-9\*]+)\)/',$display,$matches) || |
|
278 | - preg_match('/_OID\(([\.0-9\*]+)\)/',$rule,$matches)) |
|
277 | + while (preg_match('/_OID\(([\.0-9\*]+)\)/', $display, $matches) || |
|
278 | + preg_match('/_OID\(([\.0-9\*]+)\)/', $rule, $matches)) |
|
279 | 279 | { |
280 | 280 | $curOid=$matches[1]; |
281 | 281 | |
282 | - if ( (preg_match('/\*/',$curOid) == 0 ) |
|
282 | + if ((preg_match('/\*/', $curOid) == 0) |
|
283 | 283 | && ($object=$this->getMIB()->translateOID($curOid)) != null) |
284 | 284 | { |
285 | 285 | array_push($curObjectList, array( |
@@ -304,9 +304,9 @@ discard block |
||
304 | 304 | 'not found' |
305 | 305 | )); |
306 | 306 | } |
307 | - $curOid = preg_replace('/\*/','\*',$curOid); |
|
308 | - $display=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$display); |
|
309 | - $rule=preg_replace('/_OID\('.$curOid.'\)/','\$'.$index.'\$',$rule); |
|
307 | + $curOid=preg_replace('/\*/', '\*', $curOid); |
|
308 | + $display=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $display); |
|
309 | + $rule=preg_replace('/_OID\('.$curOid.'\)/', '\$'.$index.'\$', $rule); |
|
310 | 310 | $index++; |
311 | 311 | } |
312 | 312 | return $curObjectList; |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | { |
321 | 321 | $this->checkConfigPermission(); |
322 | 322 | // set up tab |
323 | - $this->getTabs()->add('get',array( |
|
323 | + $this->getTabs()->add('get', array( |
|
324 | 324 | 'active' => true, |
325 | 325 | 'label' => $this->translate('Add handler'), |
326 | 326 | 'url' => Url::fromRequest() |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | //$this->view->trapvalues=false; // Set to true to display 'value' colum in objects |
335 | 335 | |
336 | - if (($trapid = $this->params->get('fromid')) !== null) { |
|
336 | + if (($trapid=$this->params->get('fromid')) !== null) { |
|
337 | 337 | /********** Setup from existing trap ***************/ |
338 | 338 | $this->add_from_existing($trapid); |
339 | 339 | return; |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | $this->view->setRuleMatch=$ruleDetail->action_match; |
354 | 354 | $this->view->setRuleNoMatch=$ruleDetail->action_nomatch; |
355 | 355 | $this->view->hostgroupname=$ruleDetail->host_group_name; |
356 | - $this->view->modified=gmdate("Y-m-d\TH:i:s\Z",$ruleDetail->modified); |
|
356 | + $this->view->modified=gmdate("Y-m-d\TH:i:s\Z", $ruleDetail->modified); |
|
357 | 357 | $this->view->modifier=$ruleDetail->modifier; |
358 | 358 | |
359 | 359 | // Warning message if host/service don't exists anymore |
@@ -405,26 +405,26 @@ discard block |
||
405 | 405 | |
406 | 406 | $params=array( |
407 | 407 | // id (also db) => array('post' => post id, 'val' => default val, 'db' => send to table) |
408 | - 'hostgroup' => array('post' => 'hostgroup','db'=>false), |
|
409 | - 'db_rule' => array('post' => 'db_rule','db'=>false), |
|
410 | - 'hostid' => array('post' => 'hostid','db'=>false), |
|
411 | - 'host_name' => array('post' => 'hostname','val' => null,'db'=>true), |
|
412 | - 'host_group_name'=> array('post' => null,'val' => null,'db'=>true), |
|
413 | - 'serviceid' => array('post' => 'serviceid','db'=>false), |
|
414 | - 'service_name' => array('post' => 'serviceName','db'=>true), |
|
415 | - 'trap_oid' => array('post' => 'oid','db'=>true), |
|
416 | - 'revert_ok' => array('post' => 'revertOK','val' => 0,'db'=>true), |
|
417 | - 'display' => array('post' => 'display','val' => '','db'=>true), |
|
418 | - 'rule' => array('post' => 'rule','val' => '','db'=>true), |
|
419 | - 'action_match' => array('post' => 'ruleMatch','val' => -1,'db'=>true), |
|
420 | - 'action_nomatch'=> array('post' => 'ruleNoMatch','val' => -1,'db'=>true), |
|
421 | - 'ip4' => array('post' => null,'val' => null,'db'=>true), |
|
422 | - 'ip6' => array('post' => null,'val' => null,'db'=>true), |
|
423 | - 'action_form' => array('post' => 'action_form','db'=>false) |
|
408 | + 'hostgroup' => array('post' => 'hostgroup', 'db'=>false), |
|
409 | + 'db_rule' => array('post' => 'db_rule', 'db'=>false), |
|
410 | + 'hostid' => array('post' => 'hostid', 'db'=>false), |
|
411 | + 'host_name' => array('post' => 'hostname', 'val' => null, 'db'=>true), |
|
412 | + 'host_group_name'=> array('post' => null, 'val' => null, 'db'=>true), |
|
413 | + 'serviceid' => array('post' => 'serviceid', 'db'=>false), |
|
414 | + 'service_name' => array('post' => 'serviceName', 'db'=>true), |
|
415 | + 'trap_oid' => array('post' => 'oid', 'db'=>true), |
|
416 | + 'revert_ok' => array('post' => 'revertOK', 'val' => 0, 'db'=>true), |
|
417 | + 'display' => array('post' => 'display', 'val' => '', 'db'=>true), |
|
418 | + 'rule' => array('post' => 'rule', 'val' => '', 'db'=>true), |
|
419 | + 'action_match' => array('post' => 'ruleMatch', 'val' => -1, 'db'=>true), |
|
420 | + 'action_nomatch'=> array('post' => 'ruleNoMatch', 'val' => -1, 'db'=>true), |
|
421 | + 'ip4' => array('post' => null, 'val' => null, 'db'=>true), |
|
422 | + 'ip6' => array('post' => null, 'val' => null, 'db'=>true), |
|
423 | + 'action_form' => array('post' => 'action_form', 'db'=>false) |
|
424 | 424 | ); |
425 | 425 | |
426 | 426 | if (isset($postData[$params['action_form']['post']]) |
427 | - && $postData[$params['action_form']['post']] == 'delete' ) |
|
427 | + && $postData[$params['action_form']['post']] == 'delete') |
|
428 | 428 | { |
429 | 429 | try |
430 | 430 | { |
@@ -444,16 +444,16 @@ discard block |
||
444 | 444 | } |
445 | 445 | foreach (array_keys($params) as $key) |
446 | 446 | { |
447 | - if ($params[$key]['post']==null) continue; // data not sent in post vars |
|
448 | - if (! isset($postData[$params[$key]['post']])) |
|
447 | + if ($params[$key]['post'] == null) continue; // data not sent in post vars |
|
448 | + if (!isset($postData[$params[$key]['post']])) |
|
449 | 449 | { |
450 | 450 | // should not happen as the js checks data |
451 | - $this->_helper->json(array('status'=>'No ' . $key)); |
|
451 | + $this->_helper->json(array('status'=>'No '.$key)); |
|
452 | 452 | } |
453 | 453 | else |
454 | 454 | { |
455 | 455 | $data=$postData[$params[$key]['post']]; |
456 | - if ($data!=null && $data !="") |
|
456 | + if ($data != null && $data != "") |
|
457 | 457 | { |
458 | 458 | $params[$key]['val']=$postData[$params[$key]['post']]; |
459 | 459 | } |
@@ -462,8 +462,8 @@ discard block |
||
462 | 462 | |
463 | 463 | try |
464 | 464 | { |
465 | - $isHostGroup=($params['hostgroup']['val'] == 1)?true:false; |
|
466 | - if (! $isHostGroup ) |
|
465 | + $isHostGroup=($params['hostgroup']['val'] == 1) ?true:false; |
|
466 | + if (!$isHostGroup) |
|
467 | 467 | { // checks if selection by host |
468 | 468 | $hostAddr=$this->getUIDatabase()->getHostInfoByID($params['hostid']['val']); |
469 | 469 | $params['ip4']['val']=$hostAddr->ip4; |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | } |
477 | 477 | if (!is_numeric($params['serviceid']['val'])) |
478 | 478 | { |
479 | - $this->_helper->json(array('status'=>"Invalid service id ". $params['serviceid']['val'])); |
|
479 | + $this->_helper->json(array('status'=>"Invalid service id ".$params['serviceid']['val'])); |
|
480 | 480 | return; |
481 | 481 | } |
482 | 482 | $serviceName=$this->getUIDatabase()->getObjectNameByid($params['serviceid']['val']); |
@@ -495,25 +495,25 @@ discard block |
||
495 | 495 | return; |
496 | 496 | } |
497 | 497 | // Put param in correct column (group_name) |
498 | - $params['host_group_name']['val'] = $params['host_name']['val']; |
|
498 | + $params['host_group_name']['val']=$params['host_name']['val']; |
|
499 | 499 | $params['host_name']['val']=null; |
500 | 500 | } |
501 | 501 | $dbparams=array(); |
502 | 502 | foreach ($params as $key=>$val) |
503 | 503 | { |
504 | - if ($val['db']==true ) |
|
504 | + if ($val['db'] == true) |
|
505 | 505 | { |
506 | - $dbparams[$key] = $val['val']; |
|
506 | + $dbparams[$key]=$val['val']; |
|
507 | 507 | } |
508 | 508 | } |
509 | 509 | // echo '<br>'; print_r($dbparams);echo '<br>'; |
510 | - if ($params['db_rule']['val'] == -1 ) |
|
510 | + if ($params['db_rule']['val'] == -1) |
|
511 | 511 | { |
512 | 512 | $ruleID=$this->getUIDatabase()->addHandlerRule($dbparams); |
513 | 513 | } |
514 | 514 | else |
515 | 515 | { |
516 | - $this->getUIDatabase()->updateHandlerRule($dbparams,$params['db_rule']['val']); |
|
516 | + $this->getUIDatabase()->updateHandlerRule($dbparams, $params['db_rule']['val']); |
|
517 | 517 | $ruleID=$params['db_rule']['val']; |
518 | 518 | } |
519 | 519 | } |
@@ -532,10 +532,10 @@ discard block |
||
532 | 532 | */ |
533 | 533 | protected function getTrapDetail($trapid) |
534 | 534 | { |
535 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
535 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
536 | 536 | $queryArray=$this->getModuleConfig()->trapDetailQuery(); |
537 | 537 | |
538 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
538 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
539 | 539 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
540 | 540 | // *************** Get main data |
541 | 541 | // extract columns and titles; |
@@ -545,19 +545,19 @@ discard block |
||
545 | 545 | } |
546 | 546 | try |
547 | 547 | { |
548 | - $query = $dbConn->select() |
|
549 | - ->from($this->getModuleConfig()->getTrapTableName(),$elmts) |
|
550 | - ->where('id=?',$trapid); |
|
548 | + $query=$dbConn->select() |
|
549 | + ->from($this->getModuleConfig()->getTrapTableName(), $elmts) |
|
550 | + ->where('id=?', $trapid); |
|
551 | 551 | $trapDetail=$dbConn->fetchRow($query); |
552 | - if ( $trapDetail == null ) |
|
552 | + if ($trapDetail == null) |
|
553 | 553 | { |
554 | - $trapDetail = 'NULL'; |
|
554 | + $trapDetail='NULL'; |
|
555 | 555 | throw new Exception('No traps was found with id = '.$trapid); |
556 | 556 | } |
557 | 557 | } |
558 | 558 | catch (Exception $e) |
559 | 559 | { |
560 | - $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail,true),$e->getMessage()); |
|
560 | + $this->displayExitError('Add handler : get trap detail returning : '.print_r($trapDetail, true), $e->getMessage()); |
|
561 | 561 | return; |
562 | 562 | } |
563 | 563 | |
@@ -571,10 +571,10 @@ discard block |
||
571 | 571 | */ |
572 | 572 | protected function getTrapobjects($trapid) |
573 | 573 | { |
574 | - if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
|
574 | + if (!preg_match('/^[0-9]+$/', $trapid)) { throw new Exception('Invalid id'); } |
|
575 | 575 | $queryArrayData=$this->getModuleConfig()->trapDataDetailQuery(); |
576 | 576 | |
577 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
577 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
578 | 578 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
579 | 579 | // *************** Get object data |
580 | 580 | // extract columns and titles; |
@@ -584,15 +584,15 @@ discard block |
||
584 | 584 | } |
585 | 585 | try |
586 | 586 | { |
587 | - $query = $dbConn->select() |
|
588 | - ->from($this->moduleConfig->getTrapDataTableName(),$data_elmts) |
|
589 | - ->where('trap_id=?',$trapid); |
|
587 | + $query=$dbConn->select() |
|
588 | + ->from($this->moduleConfig->getTrapDataTableName(), $data_elmts) |
|
589 | + ->where('trap_id=?', $trapid); |
|
590 | 590 | $trapDetail=$dbConn->fetchAll($query); |
591 | 591 | // if ( $trapDetail == null ) throw new Exception('No traps was found with id = '.$trapid); |
592 | 592 | } |
593 | 593 | catch (Exception $e) |
594 | 594 | { |
595 | - $this->displayExitError('Add handler : get trap data detail : ',$e->getMessage()); |
|
595 | + $this->displayExitError('Add handler : get trap data detail : ', $e->getMessage()); |
|
596 | 596 | return array(); |
597 | 597 | } |
598 | 598 | |
@@ -606,24 +606,24 @@ discard block |
||
606 | 606 | */ |
607 | 607 | protected function getRuleDetail($ruleid) |
608 | 608 | { |
609 | - if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
|
609 | + if (!preg_match('/^[0-9]+$/', $ruleid)) { throw new Exception('Invalid id'); } |
|
610 | 610 | $queryArray=$this->getModuleConfig()->ruleDetailQuery(); |
611 | 611 | |
612 | - $dbConn = $this->getUIDatabase()->getDbConn(); |
|
612 | + $dbConn=$this->getUIDatabase()->getDbConn(); |
|
613 | 613 | if ($dbConn === null) throw new \ErrorException('uncatched db error'); |
614 | 614 | // *************** Get main data |
615 | 615 | try |
616 | 616 | { |
617 | - $query = $dbConn->select() |
|
618 | - ->from($this->getModuleConfig()->getTrapRuleName(),$queryArray) |
|
619 | - ->where('id=?',$ruleid); |
|
617 | + $query=$dbConn->select() |
|
618 | + ->from($this->getModuleConfig()->getTrapRuleName(), $queryArray) |
|
619 | + ->where('id=?', $ruleid); |
|
620 | 620 | $ruleDetail=$dbConn->fetchRow($query); |
621 | - if ( $ruleDetail == null ) throw new Exception('No rule was found with id = '.$ruleid); |
|
621 | + if ($ruleDetail == null) throw new Exception('No rule was found with id = '.$ruleid); |
|
622 | 622 | } |
623 | 623 | catch (Exception $e) |
624 | 624 | { |
625 | - $this->displayExitError('Update handler : get rule detail',$e->getMessage()); |
|
626 | - throw new Exception('Error : ' . $e->getMessage()); |
|
625 | + $this->displayExitError('Update handler : get rule detail', $e->getMessage()); |
|
626 | + throw new Exception('Error : '.$e->getMessage()); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | return $ruleDetail; |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | { |
637 | 637 | return $this->getTabs()->add('status', array( |
638 | 638 | 'label' => $this->translate('Traps'), |
639 | - 'url' => $this->getModuleConfig()->urlPath() . '/handler') |
|
639 | + 'url' => $this->getModuleConfig()->urlPath().'/handler') |
|
640 | 640 | ); |
641 | 641 | } |
642 | 642 |
@@ -5,18 +5,18 @@ discard block |
||
5 | 5 | |
6 | 6 | require_once 'bin/trap_class.php'; |
7 | 7 | |
8 | -$options = getopt("r:d:"); |
|
8 | +$options=getopt("r:d:"); |
|
9 | 9 | |
10 | -$icingaweb2Etc=(array_key_exists('d',$options))?$options['d']:"/etc/icingaweb2"; |
|
10 | +$icingaweb2Etc=(array_key_exists('d', $options)) ? $options['d'] : "/etc/icingaweb2"; |
|
11 | 11 | |
12 | -$debugLevel=4;// 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
12 | +$debugLevel=4; // 0=No output 1=critical 2=warning 3=trace 4=ALL |
|
13 | 13 | |
14 | -$trap = new trap($icingaweb2Etc); |
|
15 | -$trap->setLogging($debugLevel,'display'); |
|
14 | +$trap=new trap($icingaweb2Etc); |
|
15 | +$trap->setLogging($debugLevel, 'display'); |
|
16 | 16 | |
17 | -$input=array_key_exists('r',$options); |
|
17 | +$input=array_key_exists('r', $options); |
|
18 | 18 | |
19 | -if (! $input) { |
|
19 | +if (!$input) { |
|
20 | 20 | $inputStream=fopen('php://stdin', 'r'); |
21 | 21 | if ($inputStream === false) |
22 | 22 | { |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | $rule=$trap->ruleClass->eval_cleanup($rule); |
32 | 32 | //echo 'After cleanup : #'.$rule."#\n"; |
33 | 33 | $item=0; |
34 | - $val = $trap->ruleClass->evaluation($rule,$item); |
|
35 | - if ($val==true) { printf( "true"); } else { printf( "false");} |
|
34 | + $val=$trap->ruleClass->evaluation($rule, $item); |
|
35 | + if ($val == true) { printf("true"); } else { printf("false"); } |
|
36 | 36 | printf("\n"); |
37 | 37 | } |
38 | -catch (Exception $e) { printf("%s\n",$e->getMessage()); exit(1);} |
|
38 | +catch (Exception $e) { printf("%s\n", $e->getMessage()); exit(1); } |
|
39 | 39 | |
40 | 40 | exit(0); |
@@ -8,19 +8,19 @@ discard block |
||
8 | 8 | |
9 | 9 | class Icinga2API |
10 | 10 | { |
11 | - protected $version = 'v1'; //< icinga2 api version |
|
11 | + protected $version='v1'; //< icinga2 api version |
|
12 | 12 | |
13 | - protected $host; //< icinga2 host name or IP |
|
14 | - protected $port; //< icinga2 api port |
|
13 | + protected $host; //< icinga2 host name or IP |
|
14 | + protected $port; //< icinga2 api port |
|
15 | 15 | |
16 | - protected $user; //< user name |
|
17 | - protected $pass; //< user password |
|
18 | - protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED) |
|
19 | - protected $authmethod='pass'; //< Authentication : 'pass' or 'cert' |
|
16 | + protected $user; //< user name |
|
17 | + protected $pass; //< user password |
|
18 | + protected $usercert; //< user key for certificate auth (NOT IMPLEMENTED) |
|
19 | + protected $authmethod='pass'; //< Authentication : 'pass' or 'cert' |
|
20 | 20 | |
21 | 21 | protected $curl; |
22 | 22 | // http://php.net/manual/de/function.json-last-error.php#119985 |
23 | - protected $errorReference = [ |
|
23 | + protected $errorReference=[ |
|
24 | 24 | JSON_ERROR_NONE => 'No error has occurred.', |
25 | 25 | JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded.', |
26 | 26 | JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON.', |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded.', |
32 | 32 | JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given.', |
33 | 33 | ]; |
34 | - const JSON_UNKNOWN_ERROR = 'Unknown error.'; |
|
34 | + const JSON_UNKNOWN_ERROR='Unknown error.'; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Creates Icinga2API object |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param string $host host name or IP |
40 | 40 | * @param number $port API port |
41 | 41 | */ |
42 | - public function __construct($host, $port = 5665) |
|
42 | + public function __construct($host, $port=5665) |
|
43 | 43 | { |
44 | 44 | $this->host=$host; |
45 | 45 | $this->port=$port; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param string $user |
50 | 50 | * @param string $pass |
51 | 51 | */ |
52 | - public function setCredentials($user,$pass) |
|
52 | + public function setCredentials($user, $pass) |
|
53 | 53 | { |
54 | 54 | $this->user=$user; |
55 | 55 | $this->pass=$pass; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param string $user |
62 | 62 | * @param string $usercert |
63 | 63 | */ |
64 | - public function setCredentialskey($user,$usercert) |
|
64 | + public function setCredentialskey($user, $usercert) |
|
65 | 65 | { |
66 | 66 | $this->user=$user; |
67 | 67 | $this->usercert=$usercert; |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | if (property_exists($result, 'results') && property_exists($result->results[0], 'permissions')) |
86 | 86 | { |
87 | 87 | |
88 | - foreach ( $permissions as $mustPermission) |
|
88 | + foreach ($permissions as $mustPermission) |
|
89 | 89 | { |
90 | 90 | $curPermOK=0; |
91 | - foreach ( $result->results[0]->permissions as $curPermission) |
|
91 | + foreach ($result->results[0]->permissions as $curPermission) |
|
92 | 92 | { |
93 | - $curPermission=preg_replace('/\*/','.*',$curPermission); // put * as .* to created a regexp |
|
94 | - if (preg_match('#'.$curPermission.'#',$mustPermission)) |
|
93 | + $curPermission=preg_replace('/\*/', '.*', $curPermission); // put * as .* to created a regexp |
|
94 | + if (preg_match('#'.$curPermission.'#', $mustPermission)) |
|
95 | 95 | { |
96 | 96 | $curPermOK=1; |
97 | 97 | break; |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | } |
107 | 107 | if ($permOk == 0) |
108 | 108 | { |
109 | - return array(true,'API connection OK, but missing permission : '.$permMissing); |
|
109 | + return array(true, 'API connection OK, but missing permission : '.$permMissing); |
|
110 | 110 | } |
111 | - return array(false,'API connection OK'); |
|
111 | + return array(false, 'API connection OK'); |
|
112 | 112 | |
113 | 113 | } |
114 | - return array(true,'API connection OK, but cannot get permissions'); |
|
114 | + return array(true, 'API connection OK, but cannot get permissions'); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function curl() { |
128 | 128 | if ($this->curl === null) { |
129 | - $this->curl = curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
129 | + $this->curl=curl_init(sprintf('https://%s:%d', $this->host, $this->port)); |
|
130 | 130 | if ($this->curl === false) { |
131 | 131 | throw new Exception('CURL INIT ERROR'); |
132 | 132 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param string $perfdata : performance data as string |
144 | 144 | * @return array (status = true (oK) or false (nok), string message) |
145 | 145 | */ |
146 | - public function serviceCheckResult($host,$service,$state,$display,$perfdata='') |
|
146 | + public function serviceCheckResult($host, $service, $state, $display, $perfdata='') |
|
147 | 147 | { |
148 | 148 | //Send a POST request to the URL endpoint /v1/actions/process-check-result |
149 | 149 | //actions/process-check-result?service=example.localdomain!passive-ping6 |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | { |
163 | 163 | return array(false, $e->getMessage()); |
164 | 164 | } |
165 | - if (property_exists($result,'error') ) |
|
165 | + if (property_exists($result, 'error')) |
|
166 | 166 | { |
167 | - if (property_exists($result,'status')) |
|
167 | + if (property_exists($result, 'status')) |
|
168 | 168 | { |
169 | 169 | $message=$result->status; |
170 | 170 | } |
@@ -172,21 +172,21 @@ discard block |
||
172 | 172 | { |
173 | 173 | $message="Unkown status"; |
174 | 174 | } |
175 | - return array(false , 'Ret code ' .$result->error.' : '.$message); |
|
175 | + return array(false, 'Ret code '.$result->error.' : '.$message); |
|
176 | 176 | } |
177 | 177 | if (property_exists($result, 'results')) |
178 | 178 | { |
179 | 179 | if (isset($result->results[0])) |
180 | 180 | { |
181 | - return array(true,'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
181 | + return array(true, 'code '.$result->results[0]->code.' : '.$result->results[0]->status); |
|
182 | 182 | } |
183 | 183 | else |
184 | 184 | { |
185 | - return array(false,'Service not found'); |
|
185 | + return array(false, 'Service not found'); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |
189 | - return array(false,'Unkown result, open issue with this : '.print_r($result,true)); |
|
189 | + return array(false, 'Unkown result, open issue with this : '.print_r($result, true)); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $url='objects/hosts'; |
208 | 208 | $body=array( |
209 | 209 | "filter" => 'host.address=="'.$ip.'" || host.address6=="'.$ip.'"', |
210 | - "attrs" => array('__name','name','display_name') |
|
210 | + "attrs" => array('__name', 'name', 'display_name') |
|
211 | 211 | ); |
212 | 212 | try |
213 | 213 | { |
@@ -217,24 +217,24 @@ discard block |
||
217 | 217 | throw new Exception($e->getMessage()); |
218 | 218 | } |
219 | 219 | |
220 | - if (property_exists($result,'error') ) |
|
220 | + if (property_exists($result, 'error')) |
|
221 | 221 | { |
222 | - if (property_exists($result,'status')) |
|
222 | + if (property_exists($result, 'status')) |
|
223 | 223 | { |
224 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
224 | + throw new Exception('Ret code '.$result->error.' : '.$result->status); |
|
225 | 225 | } |
226 | 226 | else |
227 | 227 | { |
228 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
228 | + throw new Exception('Ret code '.$result->error.' : Unkown status'); |
|
229 | 229 | } |
230 | 230 | } |
231 | 231 | if (property_exists($result, 'results')) |
232 | 232 | { |
233 | 233 | $numHost=0; |
234 | 234 | $hostArray=array(); |
235 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
235 | + while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs')) |
|
236 | 236 | { |
237 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
237 | + $hostArray[$numHost]=$result->results[$numHost]->attrs; |
|
238 | 238 | $numHost++; |
239 | 239 | } |
240 | 240 | return $hostArray; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | $url='objects/hosts'; |
254 | 254 | $body=array( |
255 | 255 | "filter" => '\"'.$hostGroup.'\" in host.groups', |
256 | - "attrs" => array('address','address','name') |
|
256 | + "attrs" => array('address', 'address', 'name') |
|
257 | 257 | ); |
258 | 258 | try |
259 | 259 | { |
@@ -263,25 +263,25 @@ discard block |
||
263 | 263 | throw new Exception($e->getMessage()); |
264 | 264 | } |
265 | 265 | |
266 | - if (property_exists($result,'error') ) |
|
266 | + if (property_exists($result, 'error')) |
|
267 | 267 | { |
268 | - if (property_exists($result,'status')) |
|
268 | + if (property_exists($result, 'status')) |
|
269 | 269 | { |
270 | - throw new Exception('Ret code ' .$result->error.' : ' . $result->status); |
|
270 | + throw new Exception('Ret code '.$result->error.' : '.$result->status); |
|
271 | 271 | } |
272 | 272 | else |
273 | 273 | { |
274 | - throw new Exception('Ret code ' .$result->error.' : Unkown status'); |
|
274 | + throw new Exception('Ret code '.$result->error.' : Unkown status'); |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | if (property_exists($result, 'results')) |
278 | 278 | { |
279 | 279 | $numHost=0; |
280 | 280 | $hostArray=array(); |
281 | - while (isset($result->results[$numHost]) && property_exists ($result->results[$numHost],'attrs')) |
|
281 | + while (isset($result->results[$numHost]) && property_exists($result->results[$numHost], 'attrs')) |
|
282 | 282 | { |
283 | - $hostArray[$numHost] = $result->results[$numHost]->attrs; |
|
284 | - $hostArray[$numHost]->name = $result->results[$numHost]->name; |
|
283 | + $hostArray[$numHost]=$result->results[$numHost]->attrs; |
|
284 | + $hostArray[$numHost]->name=$result->results[$numHost]->name; |
|
285 | 285 | $numHost++; |
286 | 286 | } |
287 | 287 | return $hostArray; |
@@ -299,23 +299,23 @@ discard block |
||
299 | 299 | * @return array |
300 | 300 | */ |
301 | 301 | public function request($method, $url, $headers, $body) { |
302 | - $auth = sprintf('%s:%s', $this->user, $this->pass); |
|
303 | - $curlHeaders = array("Accept: application/json"); |
|
302 | + $auth=sprintf('%s:%s', $this->user, $this->pass); |
|
303 | + $curlHeaders=array("Accept: application/json"); |
|
304 | 304 | if ($body !== null) { |
305 | - $body = json_encode($body); |
|
305 | + $body=json_encode($body); |
|
306 | 306 | array_push($curlHeaders, 'Content-Type: application/json'); |
307 | 307 | //array_push($curlHeaders, 'X-HTTP-Method-Override: GET'); |
308 | 308 | } |
309 | 309 | //var_dump($body); |
310 | 310 | //var_dump($this->url($url)); |
311 | 311 | if ($headers !== null) { |
312 | - $curlFinalHeaders = array_merge($curlHeaders, $headers); |
|
312 | + $curlFinalHeaders=array_merge($curlHeaders, $headers); |
|
313 | 313 | } else |
314 | 314 | { |
315 | 315 | $curlFinalHeaders=$curlHeaders; |
316 | 316 | } |
317 | - $curl = $this->curl(); |
|
318 | - $opts = array( |
|
317 | + $curl=$this->curl(); |
|
318 | + $opts=array( |
|
319 | 319 | CURLOPT_URL => $this->url($url), |
320 | 320 | CURLOPT_HTTPHEADER => $curlFinalHeaders, |
321 | 321 | CURLOPT_USERPWD => $auth, |
@@ -326,14 +326,14 @@ discard block |
||
326 | 326 | CURLOPT_SSL_VERIFYPEER => false, |
327 | 327 | ); |
328 | 328 | if ($body !== null) { |
329 | - $opts[CURLOPT_POSTFIELDS] = $body; |
|
329 | + $opts[CURLOPT_POSTFIELDS]=$body; |
|
330 | 330 | } |
331 | 331 | curl_setopt_array($curl, $opts); |
332 | - $res = curl_exec($curl); |
|
332 | + $res=curl_exec($curl); |
|
333 | 333 | if ($res === false) { |
334 | - throw new Exception('CURL ERROR: ' . curl_error($curl)); |
|
334 | + throw new Exception('CURL ERROR: '.curl_error($curl)); |
|
335 | 335 | } |
336 | - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
336 | + $statusCode=curl_getinfo($curl, CURLINFO_HTTP_CODE); |
|
337 | 337 | if ($statusCode === 401) { |
338 | 338 | throw new Exception('Unable to authenticate, please check your API credentials'); |
339 | 339 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * @return array json decoded |
348 | 348 | */ |
349 | 349 | protected function fromJsonResult($json) { |
350 | - $result = @json_decode($json); |
|
350 | + $result=@json_decode($json); |
|
351 | 351 | //var_dump($json); |
352 | 352 | if ($result === null) { |
353 | 353 | throw new Exception('Parsing JSON failed: '.$this->getLastJsonErrorMessage(json_last_error())); |