@@ -32,8 +32,8 @@ discard block |
||
| 32 | 32 | protected $trapClass; //< Trap class for bin/trap_class.php |
| 33 | 33 | |
| 34 | 34 | /** Get instance of TrapModuleConfig class |
| 35 | - * @return TrapModuleConfig |
|
| 36 | - */ |
|
| 35 | + * @return TrapModuleConfig |
|
| 36 | + */ |
|
| 37 | 37 | public function getModuleConfig() |
| 38 | 38 | { |
| 39 | 39 | if ($this->moduleConfig == Null) |
@@ -58,12 +58,12 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | public function getTrapHostListTable() |
| 60 | 60 | { |
| 61 | - if ($this->trapTableHostList == Null) |
|
| 61 | + if ($this->trapTableHostList == Null) |
|
| 62 | 62 | { |
| 63 | - $this->trapTableHostList = new TrapTableHostList(); |
|
| 64 | - $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 65 | - } |
|
| 66 | - return $this->trapTableHostList; |
|
| 63 | + $this->trapTableHostList = new TrapTableHostList(); |
|
| 64 | + $this->trapTableHostList->setConfig($this->getModuleConfig()); |
|
| 65 | + } |
|
| 66 | + return $this->trapTableHostList; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | public function getHandlerListTable() |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** Get Database connexion |
| 80 | - * @param $DBname string DB name in resource.ini_ge |
|
| 81 | - * @param $test bool if set to true, returns error code and not database |
|
| 82 | - * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 83 | - * @return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 84 | - */ |
|
| 80 | + * @param $DBname string DB name in resource.ini_ge |
|
| 81 | + * @param $test bool if set to true, returns error code and not database |
|
| 82 | + * @param $test_version bool if set to flase, does not test database version of trapDB |
|
| 83 | + * @return array<integer,mixed>|mixed : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
| 84 | + */ |
|
| 85 | 85 | public function getDbByName($DBname,$test=false,$test_version=true) |
| 86 | 86 | { |
| 87 | 87 | try |
@@ -161,20 +161,20 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | if ( ! $dbresource ) |
| 163 | 163 | { |
| 164 | - if ($test) return array(1,'No database in config.ini'); |
|
| 165 | - $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 166 | - return null; |
|
| 164 | + if ($test) return array(1,'No database in config.ini'); |
|
| 165 | + $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
| 166 | + return null; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | try |
| 170 | 170 | { |
| 171 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 171 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 172 | 172 | } |
| 173 | 173 | catch (Exception $e) |
| 174 | 174 | { |
| 175 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 176 | - $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 177 | - return null; |
|
| 175 | + if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 176 | + $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
| 177 | + return null; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | if ($test == false) |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | try |
| 187 | 187 | { |
| 188 | - $query = $dbconn->select() |
|
| 189 | - ->from('icinga_dbversion',array('version')); |
|
| 190 | - $version=$dbconn->fetchRow($query); |
|
| 191 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 192 | - { |
|
| 193 | - return array(4,"$dbresource does not look like an IDO database"); |
|
| 194 | - } |
|
| 188 | + $query = $dbconn->select() |
|
| 189 | + ->from('icinga_dbversion',array('version')); |
|
| 190 | + $version=$dbconn->fetchRow($query); |
|
| 191 | + if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 192 | + { |
|
| 193 | + return array(4,"$dbresource does not look like an IDO database"); |
|
| 194 | + } |
|
| 195 | 195 | } |
| 196 | 196 | catch (Exception $e) |
| 197 | 197 | { |
@@ -201,15 +201,15 @@ discard block |
||
| 201 | 201 | return array(0,''); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 205 | - { |
|
| 206 | - $limit = $this->params->get('limit', $limit); |
|
| 207 | - $page = $this->params->get('page', $offset); |
|
| 204 | + protected function applyPaginationLimits(Paginatable $paginatable, $limit = 25, $offset = null) |
|
| 205 | + { |
|
| 206 | + $limit = $this->params->get('limit', $limit); |
|
| 207 | + $page = $this->params->get('page', $offset); |
|
| 208 | 208 | |
| 209 | - $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 209 | + $paginatable->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); |
|
| 210 | 210 | |
| 211 | - return $paginatable; |
|
| 212 | - } |
|
| 211 | + return $paginatable; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | 214 | public function displayExitError($source,$message) |
| 215 | 215 | { // TODO : check better ways to transmit data (with POST ?) |
@@ -218,33 +218,33 @@ discard block |
||
| 218 | 218 | |
| 219 | 219 | protected function checkReadPermission() |
| 220 | 220 | { |
| 221 | - if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 222 | - $this->displayExitError('Permissions','No permission fo view content'); |
|
| 223 | - } |
|
| 221 | + if (! $this->Auth()->hasPermission('trapdirector/view')) { |
|
| 222 | + $this->displayExitError('Permissions','No permission fo view content'); |
|
| 223 | + } |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | protected function checkConfigPermission() |
| 227 | 227 | { |
| 228 | - if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 229 | - $this->displayExitError('Permissions','No permission fo configure'); |
|
| 230 | - } |
|
| 228 | + if (! $this->Auth()->hasPermission('trapdirector/config')) { |
|
| 229 | + $this->displayExitError('Permissions','No permission fo configure'); |
|
| 230 | + } |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Check if user has write permission |
|
| 235 | - * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 236 | - * @return boolean : user has permission |
|
| 237 | - */ |
|
| 233 | + /** |
|
| 234 | + * Check if user has write permission |
|
| 235 | + * @param number $check optional : if set to 1, return true (user has permission) or false instead of displaying error page |
|
| 236 | + * @return boolean : user has permission |
|
| 237 | + */ |
|
| 238 | 238 | protected function checkModuleConfigPermission($check=0) |
| 239 | 239 | { |
| 240 | - if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 241 | - if ($check == 0) |
|
| 242 | - { |
|
| 243 | - $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 244 | - } |
|
| 245 | - return false; |
|
| 246 | - } |
|
| 247 | - return true; |
|
| 240 | + if (! $this->Auth()->hasPermission('trapdirector/module_config')) { |
|
| 241 | + if ($check == 0) |
|
| 242 | + { |
|
| 243 | + $this->displayExitError('Permissions','No permission fo configure module'); |
|
| 244 | + } |
|
| 245 | + return false; |
|
| 246 | + } |
|
| 247 | + return true; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /************************* Trap class get **********************/ |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | /************************** MIB related **************************/ |
| 265 | 265 | |
| 266 | 266 | /** Get MIBLoader class |
| 267 | - * @return MIBLoader class |
|
| 268 | - */ |
|
| 267 | + * @return MIBLoader class |
|
| 268 | + */ |
|
| 269 | 269 | protected function getMIB() |
| 270 | 270 | { |
| 271 | 271 | if ($this->MIBData == null) |
@@ -283,9 +283,9 @@ discard block |
||
| 283 | 283 | /************************** Database queries *******************/ |
| 284 | 284 | |
| 285 | 285 | /** Get host(s) by IP (v4 or v6) or by name in IDO database |
| 286 | - * does not catch exceptions |
|
| 287 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 288 | - */ |
|
| 286 | + * does not catch exceptions |
|
| 287 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 288 | + */ |
|
| 289 | 289 | protected function getHostByIP($ip) |
| 290 | 290 | { |
| 291 | 291 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
@@ -304,9 +304,9 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** Get host(s) by name in IDO database |
| 307 | - * does not catch exceptions |
|
| 308 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 309 | - */ |
|
| 307 | + * does not catch exceptions |
|
| 308 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 309 | + */ |
|
| 310 | 310 | protected function getHostByName($name) |
| 311 | 311 | { |
| 312 | 312 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
@@ -325,9 +325,9 @@ discard block |
||
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | /** Get host groups by name in IDO database |
| 328 | - * does not catch exceptions |
|
| 329 | - * @return array of objects ( name, id (object_id), display_name) |
|
| 330 | - */ |
|
| 328 | + * does not catch exceptions |
|
| 329 | + * @return array of objects ( name, id (object_id), display_name) |
|
| 330 | + */ |
|
| 331 | 331 | protected function getHostGroupByName($ip) |
| 332 | 332 | { |
| 333 | 333 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
@@ -347,9 +347,9 @@ discard block |
||
| 347 | 347 | |
| 348 | 348 | |
| 349 | 349 | /** Get host IP (v4 and v6) by name in IDO database |
| 350 | - * does not catch exceptions |
|
| 351 | - * @return array ( name, display_name, ip4, ip6) |
|
| 352 | - */ |
|
| 350 | + * does not catch exceptions |
|
| 351 | + * @return array ( name, display_name, ip4, ip6) |
|
| 352 | + */ |
|
| 353 | 353 | protected function getHostInfoByID($id) |
| 354 | 354 | { |
| 355 | 355 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -368,9 +368,9 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | |
| 370 | 370 | /** Get host by objectid in IDO database |
| 371 | - * does not catch exceptions |
|
| 372 | - * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
| 373 | - */ |
|
| 371 | + * does not catch exceptions |
|
| 372 | + * @return array of objects ( id, name, display_name, ip, ip6, ) |
|
| 373 | + */ |
|
| 374 | 374 | protected function getHostByObjectID($id) // TODO : duplicate of getHostInfoByID above |
| 375 | 375 | { |
| 376 | 376 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -388,10 +388,10 @@ discard block |
||
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | /** Get services from object ( host_object_id) in IDO database |
| 391 | - * does not catch exceptions |
|
| 392 | - * @param $id int object_id |
|
| 393 | - * @return array display_name (of service), service_object_id |
|
| 394 | - */ |
|
| 391 | + * does not catch exceptions |
|
| 392 | + * @param $id int object_id |
|
| 393 | + * @return array display_name (of service), service_object_id |
|
| 394 | + */ |
|
| 395 | 395 | protected function getServicesByHostid($id) |
| 396 | 396 | { |
| 397 | 397 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
@@ -411,11 +411,11 @@ discard block |
||
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** Get services from hostgroup object id ( hostgroup_object_id) in IDO database |
| 414 | - * gets all hosts in hostgroup and return common services |
|
| 415 | - * does not catch exceptions |
|
| 416 | - * @param $id int object_id |
|
| 417 | - * @return array display_name (of service), service_object_id |
|
| 418 | - */ |
|
| 414 | + * gets all hosts in hostgroup and return common services |
|
| 415 | + * does not catch exceptions |
|
| 416 | + * @param $id int object_id |
|
| 417 | + * @return array display_name (of service), service_object_id |
|
| 418 | + */ |
|
| 419 | 419 | protected function getServicesByHostGroupid($id) |
| 420 | 420 | { |
| 421 | 421 | if (!preg_match('/^[0-9]+$/',$id)) { throw new Exception('Invalid id'); } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | //print_r($common_services); |
| 455 | 455 | foreach (array_keys($common_services) as $key) |
| 456 | 456 | { |
| 457 | - if ($common_services[$key]['num'] == $num_hosts) |
|
| 457 | + if ($common_services[$key]['num'] == $num_hosts) |
|
| 458 | 458 | { |
| 459 | 459 | array_push($result,array($key,$common_services[$key]['name'])); |
| 460 | 460 | } |
@@ -464,11 +464,11 @@ discard block |
||
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** Get services object id by host name / service name in IDO database |
| 467 | - * does not catch exceptions |
|
| 468 | - * @param $hostname string host name |
|
| 469 | - * @param $name string service name |
|
| 470 | - * @return array service id |
|
| 471 | - */ |
|
| 467 | + * does not catch exceptions |
|
| 468 | + * @param $hostname string host name |
|
| 469 | + * @param $name string service name |
|
| 470 | + * @return array service id |
|
| 471 | + */ |
|
| 472 | 472 | protected function getServiceIDByName($hostname,$name) |
| 473 | 473 | { |
| 474 | 474 | $db = $this->getIdoDb()->getConnection(); |
@@ -491,10 +491,10 @@ discard block |
||
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | /** Get object name from object_id in IDO database |
| 494 | - * does not catch exceptions |
|
| 495 | - * @param int $id object_id (default to null, used first if not null) |
|
| 496 | - * @return array name1 (host) name2 (service) |
|
| 497 | - */ |
|
| 494 | + * does not catch exceptions |
|
| 495 | + * @param int $id object_id (default to null, used first if not null) |
|
| 496 | + * @return array name1 (host) name2 (service) |
|
| 497 | + */ |
|
| 498 | 498 | protected function getObjectNameByid($id) |
| 499 | 499 | { |
| 500 | 500 | // select a.name1, b.display_name from icinga.icinga_objects AS a , icinga.icinga_hosts AS b WHERE (b.address = '192.168.56.101' OR b.address6= '123456') and b.host_object_id=a.object_id |
@@ -510,9 +510,9 @@ discard block |
||
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** Add handler rule in traps DB |
| 513 | - * @param array(<db item>=><value>) |
|
| 514 | - * @return int inserted id |
|
| 515 | - */ |
|
| 513 | + * @param array(<db item>=><value>) |
|
| 514 | + * @return int inserted id |
|
| 515 | + */ |
|
| 516 | 516 | protected function addHandlerRule($params) |
| 517 | 517 | { |
| 518 | 518 | // TODO Check for rule consistency |
@@ -534,9 +534,9 @@ discard block |
||
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** Update handler rule in traps DB |
| 537 | - * @param array(<db item>=><value>) |
|
| 538 | - * @return array affected rows |
|
| 539 | - */ |
|
| 537 | + * @param array(<db item>=><value>) |
|
| 538 | + * @return array affected rows |
|
| 539 | + */ |
|
| 540 | 540 | protected function updateHandlerRule($params,$ruleID) |
| 541 | 541 | { |
| 542 | 542 | // TODO Check for rule consistency |
@@ -554,8 +554,8 @@ discard block |
||
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** Delete rule by id |
| 557 | - * @param int $ruleID rule id |
|
| 558 | - */ |
|
| 557 | + * @param int $ruleID rule id |
|
| 558 | + */ |
|
| 559 | 559 | protected function deleteRule($ruleID) |
| 560 | 560 | { |
| 561 | 561 | if (!preg_match('/^[0-9]+$/',$ruleID)) { throw new Exception('Invalid id'); } |
@@ -569,9 +569,9 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /** Delete trap by ip & oid |
| 572 | - * @param $ip string source IP (v4 or v6) |
|
| 573 | - * @param $oid string oid |
|
| 574 | - */ |
|
| 572 | + * @param $ip string source IP (v4 or v6) |
|
| 573 | + * @param $oid string oid |
|
| 574 | + */ |
|
| 575 | 575 | protected function deleteTrap($ip,$oid) |
| 576 | 576 | { |
| 577 | 577 | |
@@ -597,9 +597,9 @@ discard block |
||
| 597 | 597 | |
| 598 | 598 | |
| 599 | 599 | /** count trap by ip & oid |
| 600 | - * @param $ip string source IP (v4 or v6) |
|
| 601 | - * @param $oid string oid |
|
| 602 | - */ |
|
| 600 | + * @param $ip string source IP (v4 or v6) |
|
| 601 | + * @param $oid string oid |
|
| 602 | + */ |
|
| 603 | 603 | protected function countTrap($ip,$oid) |
| 604 | 604 | { |
| 605 | 605 | |
@@ -625,8 +625,8 @@ discard block |
||
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | /** get configuration value |
| 628 | - * @param configuration name in db |
|
| 629 | - */ |
|
| 628 | + * @param configuration name in db |
|
| 629 | + */ |
|
| 630 | 630 | protected function getDBConfigValue($element) |
| 631 | 631 | { |
| 632 | 632 | |
@@ -657,8 +657,8 @@ discard block |
||
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** add configuration value |
| 660 | - * @param name value |
|
| 661 | - */ |
|
| 660 | + * @param name value |
|
| 661 | + */ |
|
| 662 | 662 | protected function addDBConfigValue($element,$value) |
| 663 | 663 | { |
| 664 | 664 | |
@@ -675,8 +675,8 @@ discard block |
||
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** set configuration value |
| 678 | - * @param name value |
|
| 679 | - */ |
|
| 678 | + * @param name value |
|
| 679 | + */ |
|
| 680 | 680 | protected function setDBConfigValue($element,$value) |
| 681 | 681 | { |
| 682 | 682 | |
@@ -690,13 +690,13 @@ discard block |
||
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** Check if director is installed |
| 693 | - * @return bool true/false |
|
| 694 | - */ |
|
| 693 | + * @return bool true/false |
|
| 694 | + */ |
|
| 695 | 695 | protected function isDirectorInstalled() |
| 696 | 696 | { |
| 697 | - $output=array(); |
|
| 698 | - exec('icingacli module list',$output); |
|
| 699 | - foreach ($output as $line) |
|
| 697 | + $output=array(); |
|
| 698 | + exec('icingacli module list',$output); |
|
| 699 | + foreach ($output as $line) |
|
| 700 | 700 | { |
| 701 | 701 | if (preg_match('/^director .*enabled/',$line)) |
| 702 | 702 | { |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | /** Get trap list from a mib |
| 57 | - * @param $mib string mib name |
|
| 58 | - * @return array(traps) |
|
| 59 | - */ |
|
| 57 | + * @param $mib string mib name |
|
| 58 | + * @return array(traps) |
|
| 59 | + */ |
|
| 60 | 60 | public function getTrapList($mib) |
| 61 | 61 | { |
| 62 | 62 | $traps=array(); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $query=$dbconn->select() |
| 65 | 65 | ->from( |
| 66 | 66 | $this->config->getMIBCacheTableName(), |
| 67 | - array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
| 67 | + array('name' => 'name', 'oid' => 'oid', 'description' => 'description')) |
|
| 68 | 68 | ->where("mib = '".$mib."' AND type='21'") ; |
| 69 | 69 | $names=$dbconn->fetchAll($query); |
| 70 | 70 | foreach ($names as $val) |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** Get objects a trap can have |
| 78 | - * @param int oid of trap |
|
| 79 | - * @return : null if trap not found, or array ( <oid> => name/mib/type ) |
|
| 80 | - */ |
|
| 78 | + * @param int oid of trap |
|
| 79 | + * @return : null if trap not found, or array ( <oid> => name/mib/type ) |
|
| 80 | + */ |
|
| 81 | 81 | public function getObjectList($trap) |
| 82 | 82 | { |
| 83 | 83 | $objects=array(); |
@@ -93,15 +93,15 @@ discard block |
||
| 93 | 93 | if ( ($id == null) || ! property_exists($id,'id') ) return null; |
| 94 | 94 | |
| 95 | 95 | $query=$dbconn->select() |
| 96 | - ->from( |
|
| 97 | - array('c' => $this->config->getMIBCacheTableName()), |
|
| 98 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 99 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 100 | - 'description' => 'c.description')) |
|
| 101 | - ->join( |
|
| 102 | - array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
| 103 | - 'o.trap_id='.$id->id ) |
|
| 104 | - ->where("o.object_id = c.id"); |
|
| 96 | + ->from( |
|
| 97 | + array('c' => $this->config->getMIBCacheTableName()), |
|
| 98 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 99 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 100 | + 'description' => 'c.description')) |
|
| 101 | + ->join( |
|
| 102 | + array('o' => $this->config->getMIBCacheTableTrapObjName()), |
|
| 103 | + 'o.trap_id='.$id->id ) |
|
| 104 | + ->where("o.object_id = c.id"); |
|
| 105 | 105 | $listObjects=$dbconn->fetchAll($query); |
| 106 | 106 | if ( count($listObjects)==0 ) return null; |
| 107 | 107 | |
@@ -119,12 +119,12 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** translate oid in MIB::Name |
| 122 | - * @param string oid |
|
| 123 | - * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
| 124 | - */ |
|
| 122 | + * @param string oid |
|
| 123 | + * @return array|null : return array with index (oid -> oid, mib -> mib name, name -> oid name, type -> oid type) |
|
| 124 | + */ |
|
| 125 | 125 | public function translateOID($oid) |
| 126 | 126 | { |
| 127 | - if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 127 | + if (!preg_match('/^\./',$oid)) $oid = '.' . $oid; // Add a leading '.' |
|
| 128 | 128 | $retArray=array('oid' => $oid, 'mib' => null, 'name'=>null,'type'=>null); |
| 129 | 129 | $dbconn = $this->db->getConnection(); |
| 130 | 130 | |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | ->from( |
| 133 | 133 | array('o' => $this->config->getMIBCacheTableName()), |
| 134 | 134 | array('mib'=>'o.mib','name' => 'o.name','type'=>'o.syntax', |
| 135 | - 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
| 135 | + 'type_enum'=>'o.type_enum', 'description'=>'o.description')) |
|
| 136 | 136 | ->where('o.oid=\''.$oid.'\''); |
| 137 | 137 | $object=$dbconn->fetchRow($query); |
| 138 | 138 | if ($object != null) |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | // Try to get oid name from snmptranslate |
| 149 | 149 | $matches=array(); |
| 150 | 150 | $translate=exec($this->snmptranslate . ' -m ALL -M +'.$this->snmptranslate_dirs. |
| 151 | - ' '.$oid); |
|
| 151 | + ' '.$oid); |
|
| 152 | 152 | $ret_code=preg_match('/(.*)::(.*)/',$translate,$matches); |
| 153 | 153 | if ($ret_code==0 || $ret_code==FALSE) { |
| 154 | 154 | return null; |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | " | grep SYNTAX | sed 's/SYNTAX[[:blank:]]*//'"); |
| 161 | 161 | if (preg_match('/(.*)\{(.*)\}/',$translate,$matches)) |
| 162 | 162 | { |
| 163 | - $retArray['type']=$matches[1]; |
|
| 164 | - $retArray['type_enum']=$matches[2]; |
|
| 163 | + $retArray['type']=$matches[1]; |
|
| 164 | + $retArray['type_enum']=$matches[2]; |
|
| 165 | 165 | } |
| 166 | 166 | else |
| 167 | 167 | { |
@@ -225,25 +225,25 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public function getTrapDetails($oid=null,$id=null) |
| 227 | 227 | { |
| 228 | - // Get trap id in DB |
|
| 229 | - if ($oid==null) |
|
| 230 | - { |
|
| 231 | - $where="c.id = '$id'"; |
|
| 232 | - } |
|
| 233 | - else |
|
| 234 | - { |
|
| 235 | - $where="c.oid = '$oid'"; |
|
| 236 | - } |
|
| 237 | - $query=$this->db->getConnection()->select() |
|
| 238 | - ->from( |
|
| 239 | - array('c' => $this->config->getMIBCacheTableName()), |
|
| 240 | - array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 241 | - 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 242 | - 'description' => 'c.description')) |
|
| 243 | - ->where($where); |
|
| 244 | - $trap=$this->db->getConnection()->fetchRow($query); |
|
| 228 | + // Get trap id in DB |
|
| 229 | + if ($oid==null) |
|
| 230 | + { |
|
| 231 | + $where="c.id = '$id'"; |
|
| 232 | + } |
|
| 233 | + else |
|
| 234 | + { |
|
| 235 | + $where="c.oid = '$oid'"; |
|
| 236 | + } |
|
| 237 | + $query=$this->db->getConnection()->select() |
|
| 238 | + ->from( |
|
| 239 | + array('c' => $this->config->getMIBCacheTableName()), |
|
| 240 | + array('name' => 'c.name','mib' => 'c.mib','oid' => 'c.oid','type_enum'=>'c.type_enum', |
|
| 241 | + 'type' => 'c.syntax', 'text_conv' => 'c.textual_convention', 'disp' => 'display_hint', |
|
| 242 | + 'description' => 'c.description')) |
|
| 243 | + ->where($where); |
|
| 244 | + $trap=$this->db->getConnection()->fetchRow($query); |
|
| 245 | 245 | |
| 246 | - return $trap; |
|
| 246 | + return $trap; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | } |
@@ -11,13 +11,12 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | //use Icinga\Web\Form as Form; |
| 13 | 13 | /** Rules management |
| 14 | - |
|
| 15 | -*/ |
|
| 14 | + */ |
|
| 16 | 15 | class HandlerController extends TrapsController |
| 17 | 16 | { |
| 18 | 17 | |
| 19 | 18 | /** index : list existing rules |
| 20 | - */ |
|
| 19 | + */ |
|
| 21 | 20 | public function indexAction() |
| 22 | 21 | { |
| 23 | 22 | $this->checkReadPermission(); |
@@ -39,29 +38,29 @@ discard block |
||
| 39 | 38 | */ |
| 40 | 39 | public function testruleAction() |
| 41 | 40 | { |
| 42 | - $this->checkReadPermission(); |
|
| 43 | - $this->getTabs()->add('get',array( |
|
| 44 | - 'active' => true, |
|
| 45 | - 'label' => $this->translate('Test Rule'), |
|
| 46 | - 'url' => Url::fromRequest() |
|
| 47 | - )); |
|
| 41 | + $this->checkReadPermission(); |
|
| 42 | + $this->getTabs()->add('get',array( |
|
| 43 | + 'active' => true, |
|
| 44 | + 'label' => $this->translate('Test Rule'), |
|
| 45 | + 'url' => Url::fromRequest() |
|
| 46 | + )); |
|
| 48 | 47 | |
| 49 | - //$db = $this->getDb(); |
|
| 48 | + //$db = $this->getDb(); |
|
| 50 | 49 | |
| 51 | - if ($this->params->get('rule') !== null) |
|
| 52 | - { |
|
| 53 | - $this->view->rule= $this->params->get('rule'); |
|
| 54 | - } |
|
| 55 | - else |
|
| 56 | - { |
|
| 57 | - $this->view->rule=''; |
|
| 58 | - } |
|
| 50 | + if ($this->params->get('rule') !== null) |
|
| 51 | + { |
|
| 52 | + $this->view->rule= $this->params->get('rule'); |
|
| 53 | + } |
|
| 54 | + else |
|
| 55 | + { |
|
| 56 | + $this->view->rule=''; |
|
| 57 | + } |
|
| 59 | 58 | } |
| 60 | 59 | |
| 61 | 60 | /** Add a handler |
| 62 | - * Get params fromid : setup from existing trap (id of trap table) |
|
| 63 | - * Get param ruleid : edit from existing handler (id of rule table) |
|
| 64 | - */ |
|
| 61 | + * Get params fromid : setup from existing trap (id of trap table) |
|
| 62 | + * Get param ruleid : edit from existing handler (id of rule table) |
|
| 63 | + */ |
|
| 65 | 64 | public function addAction() |
| 66 | 65 | { |
| 67 | 66 | $this->checkConfigPermission(); |
@@ -162,7 +161,7 @@ discard block |
||
| 162 | 161 | $currentObjectTypeEnum=$allObjects[$val->oid]['type_enum']; |
| 163 | 162 | } |
| 164 | 163 | $currentObject=array( |
| 165 | - $oid_index, |
|
| 164 | + $oid_index, |
|
| 166 | 165 | $val->oid, |
| 167 | 166 | $val->oid_name_mib, |
| 168 | 167 | $val->oid_name, |
@@ -184,7 +183,7 @@ discard block |
||
| 184 | 183 | { |
| 185 | 184 | if ($val==null) { continue; } |
| 186 | 185 | array_push($this->view->objectList, array( |
| 187 | - $oid_index, |
|
| 186 | + $oid_index, |
|
| 188 | 187 | $key, |
| 189 | 188 | $allObjects[$key]['mib'], |
| 190 | 189 | $allObjects[$key]['name'], |
@@ -223,61 +222,61 @@ discard block |
||
| 223 | 222 | $this->view->warning_message=''; |
| 224 | 223 | if ($this->view->hostname != null) |
| 225 | 224 | { |
| 226 | - $this->view->selectGroup=false; |
|
| 227 | - // Check if hostname still exists |
|
| 228 | - $host_get=$this->getHostByName($this->view->hostname); |
|
| 225 | + $this->view->selectGroup=false; |
|
| 226 | + // Check if hostname still exists |
|
| 227 | + $host_get=$this->getHostByName($this->view->hostname); |
|
| 229 | 228 | |
| 230 | - if (count($host_get)==0) |
|
| 231 | - { |
|
| 232 | - $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 233 | - $this->view->serviceGet=false; |
|
| 234 | - } |
|
| 235 | - else |
|
| 236 | - { |
|
| 237 | - // Tell JS to get services when page is loaded |
|
| 238 | - $this->view->serviceGet=true; |
|
| 239 | - // get service id for form to set : |
|
| 240 | - $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 241 | - if (count($serviceID) ==0) |
|
| 242 | - { |
|
| 243 | - $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 244 | - } |
|
| 245 | - else |
|
| 246 | - { |
|
| 247 | - $this->view->serviceSet=$serviceID[0]->id; |
|
| 248 | - } |
|
| 249 | - } |
|
| 229 | + if (count($host_get)==0) |
|
| 230 | + { |
|
| 231 | + $this->view->warning_message='Host '.$this->view->hostname. ' doesn\'t exists anymore'; |
|
| 232 | + $this->view->serviceGet=false; |
|
| 233 | + } |
|
| 234 | + else |
|
| 235 | + { |
|
| 236 | + // Tell JS to get services when page is loaded |
|
| 237 | + $this->view->serviceGet=true; |
|
| 238 | + // get service id for form to set : |
|
| 239 | + $serviceID=$this->getServiceIDByName($this->view->hostname,$ruleDetail->service_name); |
|
| 240 | + if (count($serviceID) ==0) |
|
| 241 | + { |
|
| 242 | + $this->view->warning_message=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 243 | + } |
|
| 244 | + else |
|
| 245 | + { |
|
| 246 | + $this->view->serviceSet=$serviceID[0]->id; |
|
| 247 | + } |
|
| 248 | + } |
|
| 250 | 249 | } |
| 251 | 250 | else |
| 252 | 251 | { |
| 253 | - $this->view->selectGroup=true; |
|
| 254 | - // Check if groupe exists |
|
| 255 | - $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
|
| 256 | - if (count($group_get)==0) |
|
| 257 | - { |
|
| 258 | - $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 259 | - $this->view->serviceGroupGet=false; |
|
| 260 | - } |
|
| 261 | - else |
|
| 262 | - { |
|
| 263 | - $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
|
| 264 | - $foundGrpService=0; |
|
| 265 | - foreach ($grpServices as $grpService) |
|
| 266 | - { |
|
| 267 | - if ($grpService[0] == $ruleDetail->service_name) |
|
| 268 | - { |
|
| 269 | - $foundGrpService=1; |
|
| 270 | - $this->view->serviceSet=$ruleDetail->service_name; |
|
| 271 | - } |
|
| 272 | - } |
|
| 252 | + $this->view->selectGroup=true; |
|
| 253 | + // Check if groupe exists |
|
| 254 | + $group_get=$this->getHostGroupByName($this->view->hostgroupname); |
|
| 255 | + if (count($group_get)==0) |
|
| 256 | + { |
|
| 257 | + $this->view->warning_message='HostGroup '.$this->view->hostgroupname. ' doesn\'t exists anymore'; |
|
| 258 | + $this->view->serviceGroupGet=false; |
|
| 259 | + } |
|
| 260 | + else |
|
| 261 | + { |
|
| 262 | + $grpServices=$this->getServicesByHostGroupid($group_get[0]->id); |
|
| 263 | + $foundGrpService=0; |
|
| 264 | + foreach ($grpServices as $grpService) |
|
| 265 | + { |
|
| 266 | + if ($grpService[0] == $ruleDetail->service_name) |
|
| 267 | + { |
|
| 268 | + $foundGrpService=1; |
|
| 269 | + $this->view->serviceSet=$ruleDetail->service_name; |
|
| 270 | + } |
|
| 271 | + } |
|
| 273 | 272 | |
| 274 | - // Tell JS to get services when page is loaded |
|
| 275 | - $this->view->serviceGroupGet=true; |
|
| 276 | - if ($foundGrpService==0) |
|
| 277 | - { |
|
| 278 | - $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 279 | - } |
|
| 280 | - } |
|
| 273 | + // Tell JS to get services when page is loaded |
|
| 274 | + $this->view->serviceGroupGet=true; |
|
| 275 | + if ($foundGrpService==0) |
|
| 276 | + { |
|
| 277 | + $this->view->warning_message.=' Service '.$ruleDetail->service_name. ' doesn\'t exists anymore'; |
|
| 278 | + } |
|
| 279 | + } |
|
| 281 | 280 | } |
| 282 | 281 | $this->view->mainoid=$ruleDetail->trap_oid; |
| 283 | 282 | $oidName=$this->getMIB()->translateOID($ruleDetail->trap_oid); |
@@ -302,7 +301,7 @@ discard block |
||
| 302 | 301 | if (($object=$this->getMIB()->translateOID($curOid)) != null) |
| 303 | 302 | { |
| 304 | 303 | array_push($curObjectList, array( |
| 305 | - $index, |
|
| 304 | + $index, |
|
| 306 | 305 | $curOid, |
| 307 | 306 | $object['mib'], |
| 308 | 307 | $object['name'], |
@@ -314,7 +313,7 @@ discard block |
||
| 314 | 313 | else |
| 315 | 314 | { |
| 316 | 315 | array_push($curObjectList, array( |
| 317 | - $index, |
|
| 316 | + $index, |
|
| 318 | 317 | $curOid, |
| 319 | 318 | 'not found', |
| 320 | 319 | 'not found', |
@@ -335,9 +334,9 @@ discard block |
||
| 335 | 334 | } |
| 336 | 335 | |
| 337 | 336 | /** Validate form and output message to user |
| 338 | - * @param in postdata |
|
| 339 | - * @return string status : OK / <Message> |
|
| 340 | - **/ |
|
| 337 | + * @param in postdata |
|
| 338 | + * @return string status : OK / <Message> |
|
| 339 | + **/ |
|
| 341 | 340 | protected function handlerformAction() |
| 342 | 341 | { |
| 343 | 342 | $postData=$this->getRequest()->getPost(); |
@@ -378,7 +377,7 @@ discard block |
||
| 378 | 377 | //$this->Module()-> |
| 379 | 378 | $this->_helper->json(array( |
| 380 | 379 | 'status'=>'OK', |
| 381 | - 'redirect'=>'trapdirector/handler' |
|
| 380 | + 'redirect'=>'trapdirector/handler' |
|
| 382 | 381 | |
| 383 | 382 | )); |
| 384 | 383 | } |
@@ -462,9 +461,9 @@ discard block |
||
| 462 | 461 | } |
| 463 | 462 | |
| 464 | 463 | /** Get trap detail by trapid. |
| 465 | - * @param integer $trapid : id of trap in received table |
|
| 466 | - * @return array (objects) |
|
| 467 | - */ |
|
| 464 | + * @param integer $trapid : id of trap in received table |
|
| 465 | + * @return array (objects) |
|
| 466 | + */ |
|
| 468 | 467 | protected function getTrapDetail($trapid) |
| 469 | 468 | { |
| 470 | 469 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -496,9 +495,9 @@ discard block |
||
| 496 | 495 | } |
| 497 | 496 | |
| 498 | 497 | /** Get trap objects |
| 499 | - * @param integer $trapid : trap id |
|
| 500 | - * @return array : full column in db of trap id |
|
| 501 | - */ |
|
| 498 | + * @param integer $trapid : trap id |
|
| 499 | + * @return array : full column in db of trap id |
|
| 500 | + */ |
|
| 502 | 501 | protected function getTrapobjects($trapid) |
| 503 | 502 | { |
| 504 | 503 | if (!preg_match('/^[0-9]+$/',$trapid)) { throw new Exception('Invalid id'); } |
@@ -529,9 +528,9 @@ discard block |
||
| 529 | 528 | } |
| 530 | 529 | |
| 531 | 530 | /** Get rule detail by ruleid. |
| 532 | - * @param integer $ruleid int id of rule in rule table |
|
| 533 | - * @return array : column objects in db |
|
| 534 | - */ |
|
| 531 | + * @param integer $ruleid int id of rule in rule table |
|
| 532 | + * @return array : column objects in db |
|
| 533 | + */ |
|
| 535 | 534 | protected function getRuleDetail($ruleid) |
| 536 | 535 | { |
| 537 | 536 | if (!preg_match('/^[0-9]+$/',$ruleid)) { throw new Exception('Invalid id'); } |
@@ -558,7 +557,7 @@ discard block |
||
| 558 | 557 | } |
| 559 | 558 | |
| 560 | 559 | /** Setup tabs for rules |
| 561 | - */ |
|
| 560 | + */ |
|
| 562 | 561 | protected function prepareTabs() |
| 563 | 562 | { |
| 564 | 563 | return $this->getTabs()->add('status', array( |
@@ -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(); |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | /** Get hostgroup list with filter (name) : hostgroup=<hostFilter> |
| 43 | - * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 44 | - */ |
|
| 43 | + * returns in JSON : status=>OK/NOK hosts=>array of hosts |
|
| 44 | + */ |
|
| 45 | 45 | public function gethostgroupsAction() |
| 46 | 46 | { |
| 47 | 47 | $postData=$this->getRequest()->getPost(); |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | /** Get service list by host name ( host=<host> ) |
| 71 | - * returns in JSON : |
|
| 72 | - * status=>OK/No services found/More than one host matches |
|
| 73 | - * services=>array of services (name) |
|
| 74 | - * hostid = host object id or -1 if not found. |
|
| 75 | - */ |
|
| 71 | + * returns in JSON : |
|
| 72 | + * status=>OK/No services found/More than one host matches |
|
| 73 | + * services=>array of services (name) |
|
| 74 | + * hostid = host object id or -1 if not found. |
|
| 75 | + */ |
|
| 76 | 76 | public function getservicesAction() |
| 77 | 77 | { |
| 78 | 78 | $postData=$this->getRequest()->getPost(); |
@@ -112,11 +112,11 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** Get service list by host group ( name=<host> ) |
| 115 | - * returns in JSON : |
|
| 116 | - * status=>OK/No services found/More than one host matches |
|
| 117 | - * services=>array of services (name) |
|
| 118 | - * groupid = group object id or -1 if not found. |
|
| 119 | - */ |
|
| 115 | + * returns in JSON : |
|
| 116 | + * status=>OK/No services found/More than one host matches |
|
| 117 | + * services=>array of services (name) |
|
| 118 | + * groupid = group object id or -1 if not found. |
|
| 119 | + */ |
|
| 120 | 120 | public function gethostgroupservicesAction() |
| 121 | 121 | { |
| 122 | 122 | $postData=$this->getRequest()->getPost(); |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** Get traps from mib : entry : mib=<mib> |
| 156 | - * returns in JSON : |
|
| 157 | - * status=>OK/No mib/Error getting mibs |
|
| 158 | - * traps=>array of array( oid -> name) |
|
| 159 | - */ |
|
| 156 | + * returns in JSON : |
|
| 157 | + * status=>OK/No mib/Error getting mibs |
|
| 158 | + * traps=>array of array( oid -> name) |
|
| 159 | + */ |
|
| 160 | 160 | public function gettrapsAction() |
| 161 | 161 | { |
| 162 | 162 | $postData=$this->getRequest()->getPost(); |
@@ -182,10 +182,10 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** Get trap objects from mib : entry : trap=<oid> |
| 185 | - * returns in JSON : |
|
| 186 | - * status=>OK/no trap/not found |
|
| 187 | - * objects=>array of array( oid -> name, oid->mib) |
|
| 188 | - */ |
|
| 185 | + * returns in JSON : |
|
| 186 | + * status=>OK/no trap/not found |
|
| 187 | + * objects=>array of array( oid -> name, oid->mib) |
|
| 188 | + */ |
|
| 189 | 189 | public function gettrapobjectsAction() |
| 190 | 190 | { |
| 191 | 191 | $postData=$this->getRequest()->getPost(); |
@@ -211,8 +211,8 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** Get list of all loaded mibs : entry : none |
| 214 | - * return : array of strings. |
|
| 215 | - */ |
|
| 214 | + * return : array of strings. |
|
| 215 | + */ |
|
| 216 | 216 | public function getmiblistAction() |
| 217 | 217 | { |
| 218 | 218 | try |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** Get MIB::Name from OID : entry : oid |
| 230 | - * status=>OK/No oid/not found |
|
| 231 | - * mib=>string |
|
| 232 | - * name=>string |
|
| 233 | - */ |
|
| 230 | + * status=>OK/No oid/not found |
|
| 231 | + * mib=>string |
|
| 232 | + * name=>string |
|
| 233 | + */ |
|
| 234 | 234 | public function translateoidAction() |
| 235 | 235 | { |
| 236 | 236 | $postData=$this->getRequest()->getPost(); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | 'name' => $object['name'], |
| 259 | 259 | 'type' => $object['type'], |
| 260 | 260 | 'type_enum' => $object['type_enum'], |
| 261 | - 'description' => $object['description'] |
|
| 261 | + 'description' => $object['description'] |
|
| 262 | 262 | ) |
| 263 | 263 | ); |
| 264 | 264 | } |
@@ -267,10 +267,10 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | /** Save or execute database purge of <n> days |
| 270 | - * days=>int |
|
| 271 | - * action=>save/execute |
|
| 272 | - * return : status=>OK/Message error |
|
| 273 | - */ |
|
| 270 | + * days=>int |
|
| 271 | + * action=>save/execute |
|
| 272 | + * return : status=>OK/Message error |
|
| 273 | + */ |
|
| 274 | 274 | public function dbmaintenanceAction() |
| 275 | 275 | { |
| 276 | 276 | |
@@ -339,11 +339,11 @@ discard block |
||
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** Save log output to db |
| 342 | - * destination=>log destination |
|
| 343 | - * file=>file name |
|
| 344 | - * level => int |
|
| 345 | - * return : status=>OK/Message error |
|
| 346 | - */ |
|
| 342 | + * destination=>log destination |
|
| 343 | + * file=>file name |
|
| 344 | + * level => int |
|
| 345 | + * return : status=>OK/Message error |
|
| 346 | + */ |
|
| 347 | 347 | public function logdestinationAction() |
| 348 | 348 | { |
| 349 | 349 | $postData=$this->getRequest()->getPost(); |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | $fileHandler=@fopen($file,'w'); |
| 368 | 368 | if ($fileHandler == false) |
| 369 | 369 | { // File os note writabe / cannot create |
| 370 | - $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
| 371 | - return; |
|
| 370 | + $this->_helper->json(array('status'=>'File not writable : '.$file)); |
|
| 371 | + return; |
|
| 372 | 372 | } |
| 373 | 373 | } |
| 374 | 374 | else |
@@ -418,50 +418,50 @@ discard block |
||
| 418 | 418 | public function testruleAction() |
| 419 | 419 | { |
| 420 | 420 | |
| 421 | - $postData=$this->getRequest()->getPost(); |
|
| 422 | - if (isset($postData['rule'])) |
|
| 423 | - { |
|
| 424 | - $rule=$postData['rule']; |
|
| 425 | - } |
|
| 426 | - else |
|
| 427 | - { |
|
| 428 | - $this->_helper->json(array('status'=>'No Rule')); |
|
| 429 | - } |
|
| 430 | - if (isset($postData['action'])) |
|
| 431 | - { |
|
| 432 | - $action=$postData['action']; |
|
| 433 | - if ($action != 'evaluate') |
|
| 434 | - { |
|
| 435 | - $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
| 436 | - return; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - else |
|
| 440 | - { |
|
| 441 | - $this->_helper->json(array('status'=>'No action')); |
|
| 442 | - return; |
|
| 443 | - } |
|
| 444 | - if ($action == 'evaluate') |
|
| 445 | - { |
|
| 446 | - try |
|
| 447 | - { |
|
| 448 | - require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 449 | - $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 450 | - $Trap = new Trap($icingaweb2_etc); |
|
| 451 | - // Cleanup spaces before eval |
|
| 452 | - $rule=$Trap->eval_cleanup($rule); |
|
| 453 | - // Eval |
|
| 454 | - $item=0; |
|
| 455 | - $rule=$Trap->evaluation($rule,$item); |
|
| 456 | - } |
|
| 457 | - catch (Exception $e) |
|
| 458 | - { |
|
| 459 | - $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 460 | - return; |
|
| 461 | - } |
|
| 462 | - $return=($rule==true)?'true':'false'; |
|
| 463 | - $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
| 464 | - } |
|
| 421 | + $postData=$this->getRequest()->getPost(); |
|
| 422 | + if (isset($postData['rule'])) |
|
| 423 | + { |
|
| 424 | + $rule=$postData['rule']; |
|
| 425 | + } |
|
| 426 | + else |
|
| 427 | + { |
|
| 428 | + $this->_helper->json(array('status'=>'No Rule')); |
|
| 429 | + } |
|
| 430 | + if (isset($postData['action'])) |
|
| 431 | + { |
|
| 432 | + $action=$postData['action']; |
|
| 433 | + if ($action != 'evaluate') |
|
| 434 | + { |
|
| 435 | + $this->_helper->json(array('status'=>'unknown action '.$action)); |
|
| 436 | + return; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + else |
|
| 440 | + { |
|
| 441 | + $this->_helper->json(array('status'=>'No action')); |
|
| 442 | + return; |
|
| 443 | + } |
|
| 444 | + if ($action == 'evaluate') |
|
| 445 | + { |
|
| 446 | + try |
|
| 447 | + { |
|
| 448 | + require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
|
| 449 | + $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
|
| 450 | + $Trap = new Trap($icingaweb2_etc); |
|
| 451 | + // Cleanup spaces before eval |
|
| 452 | + $rule=$Trap->eval_cleanup($rule); |
|
| 453 | + // Eval |
|
| 454 | + $item=0; |
|
| 455 | + $rule=$Trap->evaluation($rule,$item); |
|
| 456 | + } |
|
| 457 | + catch (Exception $e) |
|
| 458 | + { |
|
| 459 | + $this->_helper->json(array('status'=>'Evaluation error : '.$e->getMessage() )); |
|
| 460 | + return; |
|
| 461 | + } |
|
| 462 | + $return=($rule==true)?'true':'false'; |
|
| 463 | + $this->_helper->json(array('status'=>'OK', 'message' => $return)); |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | 466 | } |
| 467 | 467 | |
@@ -65,10 +65,10 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** Mib management |
| 68 | - * Post param : action=update_mib_db : update mib database |
|
| 69 | - * Post param : ation=check_update : check if mib update is finished |
|
| 70 | - * File post : mibfile -> save mib file |
|
| 71 | - */ |
|
| 68 | + * Post param : action=update_mib_db : update mib database |
|
| 69 | + * Post param : ation=check_update : check if mib update is finished |
|
| 70 | + * File post : mibfile -> save mib file |
|
| 71 | + */ |
|
| 72 | 72 | public function mibAction() |
| 73 | 73 | { |
| 74 | 74 | $this->prepareTabs()->activate('mib'); |
@@ -87,22 +87,22 @@ discard block |
||
| 87 | 87 | $return=exec('icingacli trapdirector mib update --pid /tmp/trapdirector_update.pid'); |
| 88 | 88 | if (preg_match('/OK/',$return)) |
| 89 | 89 | { |
| 90 | - $this->_helper->json(array('status'=>'OK')); |
|
| 90 | + $this->_helper->json(array('status'=>'OK')); |
|
| 91 | 91 | } |
| 92 | 92 | // Error |
| 93 | 93 | $this->_helper->json(array('status'=>$return)); |
| 94 | 94 | } |
| 95 | 95 | if ($action == 'check_update') |
| 96 | 96 | { |
| 97 | - $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
| 98 | - if ($file == false) |
|
| 99 | - { // process is dead |
|
| 100 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
| 101 | - return; |
|
| 102 | - } |
|
| 103 | - $pid=fgets($file); |
|
| 104 | - $output=array(); |
|
| 105 | - $retVal=0; |
|
| 97 | + $file=@fopen('/tmp/trapdirector_update.pid','r'); |
|
| 98 | + if ($file == false) |
|
| 99 | + { // process is dead |
|
| 100 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'Cannot open file')); |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | + $pid=fgets($file); |
|
| 104 | + $output=array(); |
|
| 105 | + $retVal=0; |
|
| 106 | 106 | exec('ps '.$pid,$output,$retVal); |
| 107 | 107 | if ($retVal == 0) |
| 108 | 108 | { // process is alive |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | } |
| 111 | 111 | else |
| 112 | 112 | { // process is dead |
| 113 | - $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
| 113 | + $this->_helper->json(array('status'=>'tu quoque fili','err'=>'no proc'.$pid)); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | $this->_helper->json(array('status'=>'ERR : no '.$action.' action possible' )); |
@@ -259,20 +259,20 @@ discard block |
||
| 259 | 259 | // TODO : see if useless |
| 260 | 260 | class UploadForm extends Form |
| 261 | 261 | { |
| 262 | - public function __construct($options = null) |
|
| 263 | - { |
|
| 264 | - parent::__construct($options); |
|
| 265 | - $this->addElements2(); |
|
| 266 | - } |
|
| 262 | + public function __construct($options = null) |
|
| 263 | + { |
|
| 264 | + parent::__construct($options); |
|
| 265 | + $this->addElements2(); |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - public function addElements2() |
|
| 269 | - { |
|
| 270 | - // File Input |
|
| 271 | - $file = new File('mib-file'); |
|
| 272 | - $file->setLabel('Mib upload'); |
|
| 273 | - //->setAttrib('multiple', null); |
|
| 274 | - $this->addElement($file); |
|
| 268 | + public function addElements2() |
|
| 269 | + { |
|
| 270 | + // File Input |
|
| 271 | + $file = new File('mib-file'); |
|
| 272 | + $file->setLabel('Mib upload'); |
|
| 273 | + //->setAttrib('multiple', null); |
|
| 274 | + $this->addElement($file); |
|
| 275 | 275 | $button = new Submit("upload",array('ignore'=>false)); |
| 276 | 276 | $this->addElement($button);//->setIgnore(false); |
| 277 | - } |
|
| 277 | + } |
|
| 278 | 278 | } |
@@ -22,37 +22,37 @@ discard block |
||
| 22 | 22 | public function indexAction() |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - // CHeck permissions : display tests in any case, but no configuration. |
|
| 25 | + // CHeck permissions : display tests in any case, but no configuration. |
|
| 26 | 26 | $this->view->configPermission=$this->checkModuleConfigPermission(1); |
| 27 | 27 | // But check read permission |
| 28 | 28 | $this->checkReadPermission(); |
| 29 | 29 | // Get message : sent on configuration problems detected by controllers |
| 30 | 30 | $dberrorMsg=$this->params->get('dberror'); |
| 31 | 31 | if ($dberrorMsg != '') |
| 32 | - $this->view->errorDetected=$dberrorMsg; |
|
| 33 | - $dberrorMsg=$this->params->get('idodberror'); |
|
| 34 | - if ($dberrorMsg != '') |
|
| 35 | - $this->view->errorDetected=$dberrorMsg; |
|
| 32 | + $this->view->errorDetected=$dberrorMsg; |
|
| 33 | + $dberrorMsg=$this->params->get('idodberror'); |
|
| 34 | + if ($dberrorMsg != '') |
|
| 35 | + $this->view->errorDetected=$dberrorMsg; |
|
| 36 | 36 | |
| 37 | - $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
| 37 | + $this->view->configErrorDetected == NULL; // Displayed error on various conifugration errors. |
|
| 38 | 38 | |
| 39 | - // Test if configuration exists, if not create for installer script |
|
| 39 | + // Test if configuration exists, if not create for installer script |
|
| 40 | 40 | //$emptyConfig=0; |
| 41 | - if ($this->Config()->isEmpty() == true) |
|
| 42 | - { |
|
| 43 | - $this->Config()->setSection('config'); // Set base config section. |
|
| 44 | - try |
|
| 45 | - { |
|
| 46 | - $this->Config()->saveIni(); |
|
| 47 | - $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
| 41 | + if ($this->Config()->isEmpty() == true) |
|
| 42 | + { |
|
| 43 | + $this->Config()->setSection('config'); // Set base config section. |
|
| 44 | + try |
|
| 45 | + { |
|
| 46 | + $this->Config()->saveIni(); |
|
| 47 | + $this->view->configErrorDetected='Configuration is empty : you can run install script with parameters (see Automatic installation below)'; |
|
| 48 | 48 | //$emptyConfig=1; |
| 49 | - } |
|
| 50 | - catch (Exception $e) |
|
| 51 | - { |
|
| 52 | - $this->view->configErrorDetected=$e->getMessage(); |
|
| 53 | - } |
|
| 49 | + } |
|
| 50 | + catch (Exception $e) |
|
| 51 | + { |
|
| 52 | + $this->view->configErrorDetected=$e->getMessage(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | // Test Database |
| 57 | 57 | $db_message=array( // index => ( message OK, message NOK, optional link if NOK ) |
| 58 | 58 | 0 => array('Database configuration OK','',''), |
@@ -97,20 +97,20 @@ discard block |
||
| 97 | 97 | //********* Test API |
| 98 | 98 | if ($this->Config()->get('config', 'icingaAPI_host') != '') |
| 99 | 99 | { |
| 100 | - $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
| 101 | - $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
| 102 | - try { |
|
| 103 | - list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
| 104 | - //$this->view->apimessageError=false; |
|
| 105 | - } catch (RuntimeException $e) { |
|
| 106 | - $this->view->apimessage='API config : ' . $e->getMessage(); |
|
| 107 | - $this->view->apimessageError=true; |
|
| 108 | - } |
|
| 100 | + $apitest=new Icinga2Api($this->Config()->get('config', 'icingaAPI_host'),$this->Config()->get('config', 'icingaAPI_port')); |
|
| 101 | + $apitest->setCredentials($this->Config()->get('config', 'icingaAPI_user'), $this->Config()->get('config', 'icingaAPI_password')); |
|
| 102 | + try { |
|
| 103 | + list($this->view->apimessageError,$this->view->apimessage)=$apitest->test($this->getModuleConfig()::getapiUserPermissions()); |
|
| 104 | + //$this->view->apimessageError=false; |
|
| 105 | + } catch (RuntimeException $e) { |
|
| 106 | + $this->view->apimessage='API config : ' . $e->getMessage(); |
|
| 107 | + $this->view->apimessageError=true; |
|
| 108 | + } |
|
| 109 | 109 | } |
| 110 | 110 | else |
| 111 | 111 | { |
| 112 | - $this->view->apimessage='API parameters not configured'; |
|
| 113 | - $this->view->apimessageError=true; |
|
| 112 | + $this->view->apimessage='API parameters not configured'; |
|
| 113 | + $this->view->apimessageError=true; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | //*********** Test snmptrapd alive and options |
@@ -125,33 +125,33 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
|
| 128 | + $this->view->tabs = $this->Module()->getConfigTabs()->activate('config'); |
|
| 129 | 129 | |
| 130 | 130 | // Check standard Icingaweb2 path |
| 131 | 131 | $this->view->icingaEtcWarn=0; |
| 132 | 132 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 133 | 133 | if ($icingaweb2_etc != "/etc/icingaweb2/" && $icingaweb2_etc != '') |
| 134 | 134 | { |
| 135 | - $output=array(); |
|
| 135 | + $output=array(); |
|
| 136 | 136 | |
| 137 | - exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output); |
|
| 137 | + exec('cat ' . $this->module->getBaseDir() .'/bin/trap_in.php | grep "\$icingaweb2_etc=" ',$output); |
|
| 138 | 138 | |
| 139 | - if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
| 140 | - { |
|
| 141 | - $this->view->icingaEtcWarn=1; |
|
| 142 | - $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
| 143 | - } |
|
| 139 | + if (! preg_match('#"'. $icingaweb2_etc .'"#',$output[0])) |
|
| 140 | + { |
|
| 141 | + $this->view->icingaEtcWarn=1; |
|
| 142 | + $this->view->icingaweb2_etc=$icingaweb2_etc; |
|
| 143 | + } |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | // Setup path for mini documentation |
| 147 | 147 | $this->view->traps_in_config= PHP_BINARY . ' ' . $this->Module()->getBaseDir() . '/bin/trap_in.php'; |
| 148 | 148 | |
| 149 | 149 | $this->view->installer= $this->Module()->getBaseDir() . '/bin/installer.sh ' |
| 150 | - . ' -c all ' |
|
| 151 | - . ' -d ' . $this->Module()->getBaseDir() |
|
| 152 | - . ' -p ' . PHP_BINARY |
|
| 153 | - . ' -a ' . exec('whoami') |
|
| 154 | - . ' -w ' . Icinga::app()->getConfigDir(); |
|
| 150 | + . ' -c all ' |
|
| 151 | + . ' -d ' . $this->Module()->getBaseDir() |
|
| 152 | + . ' -p ' . PHP_BINARY |
|
| 153 | + . ' -a ' . exec('whoami') |
|
| 154 | + . ' -w ' . Icinga::app()->getConfigDir(); |
|
| 155 | 155 | |
| 156 | 156 | // ******************* configuration form setup******************* |
| 157 | 157 | $this->view->form = $form = new TrapsConfigForm(); |
@@ -196,19 +196,19 @@ discard block |
||
| 196 | 196 | $dbResource = ResourceFactory::getResourceConfig($dbName); |
| 197 | 197 | $dbType=$dbResource->get('db'); |
| 198 | 198 | switch ($dbType) { |
| 199 | - case 'mysql': |
|
| 200 | - $dbFileExt='sql'; |
|
| 201 | - break; |
|
| 202 | - case 'pgsql': |
|
| 203 | - $dbFileExt='pgsql'; |
|
| 204 | - break; |
|
| 205 | - default: |
|
| 206 | - throw new ConfigurationError('Unsuported database : '.$dbType); |
|
| 199 | + case 'mysql': |
|
| 200 | + $dbFileExt='sql'; |
|
| 201 | + break; |
|
| 202 | + case 'pgsql': |
|
| 203 | + $dbFileExt='pgsql'; |
|
| 204 | + break; |
|
| 205 | + default: |
|
| 206 | + throw new ConfigurationError('Unsuported database : '.$dbType); |
|
| 207 | 207 | } |
| 208 | 208 | } catch (ConfigurationError $e ) |
| 209 | 209 | { |
| 210 | - printf("Database configuration error : %s",$e->getMessage()); |
|
| 211 | - return; |
|
| 210 | + printf("Database configuration error : %s",$e->getMessage()); |
|
| 211 | + return; |
|
| 212 | 212 | } |
| 213 | 213 | printf('<pre>'); |
| 214 | 214 | require_once $this->Module()->getBaseDir() .'/bin/trap_class.php'; |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | public function updateschemaAction() |
| 233 | 233 | { |
| 234 | 234 | $this->checkModuleConfigPermission(); |
| 235 | - $this->getTabs()->add('get',array( |
|
| 236 | - 'active' => true, |
|
| 237 | - 'label' => $this->translate('Update Schema'), |
|
| 238 | - 'url' => Url::fromRequest() |
|
| 239 | - )); |
|
| 235 | + $this->getTabs()->add('get',array( |
|
| 236 | + 'active' => true, |
|
| 237 | + 'label' => $this->translate('Update Schema'), |
|
| 238 | + 'url' => Url::fromRequest() |
|
| 239 | + )); |
|
| 240 | 240 | // check if needed |
| 241 | 241 | |
| 242 | 242 | $dberror=$this->getDb(true); // Get DB in test mode |
@@ -245,15 +245,15 @@ discard block |
||
| 245 | 245 | |
| 246 | 246 | if ($dberror[0] == 0) |
| 247 | 247 | { |
| 248 | - echo 'Schema already exists and is up to date<br>'; |
|
| 249 | - return; |
|
| 248 | + echo 'Schema already exists and is up to date<br>'; |
|
| 249 | + return; |
|
| 250 | 250 | } |
| 251 | 251 | if ($dberror[0] != 5) |
| 252 | 252 | { |
| 253 | - echo 'Database does not exists or is not setup correctly<br>'; |
|
| 254 | - return; |
|
| 253 | + echo 'Database does not exists or is not setup correctly<br>'; |
|
| 254 | + return; |
|
| 255 | 255 | } |
| 256 | - // setup |
|
| 256 | + // setup |
|
| 257 | 257 | require_once($this->Module()->getBaseDir() .'/bin/trap_class.php'); |
| 258 | 258 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
| 259 | 259 | $debug_level=4; |
@@ -266,20 +266,20 @@ discard block |
||
| 266 | 266 | $target_version=$dberror[2]; |
| 267 | 267 | |
| 268 | 268 | if ($this->params->get('msgok') == null) { |
| 269 | - // Check for messages and display if any |
|
| 270 | - echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
| 271 | - $Trap->setLogging(2,'syslog'); |
|
| 272 | - $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true); |
|
| 273 | - if ($message != '') |
|
| 274 | - { |
|
| 275 | - echo 'Note :<br><pre>'; |
|
| 276 | - echo $message; |
|
| 277 | - echo '</pre>'; |
|
| 278 | - echo '<br>'; |
|
| 279 | - echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
| 280 | - echo '<br>'; |
|
| 281 | - return; |
|
| 282 | - } |
|
| 269 | + // Check for messages and display if any |
|
| 270 | + echo "Upgrade databse is going to start.<br>Don't forget to backup your database before update<br>"; |
|
| 271 | + $Trap->setLogging(2,'syslog'); |
|
| 272 | + $message = $Trap->update_schema($updateSchema,$target_version,$prefix,true); |
|
| 273 | + if ($message != '') |
|
| 274 | + { |
|
| 275 | + echo 'Note :<br><pre>'; |
|
| 276 | + echo $message; |
|
| 277 | + echo '</pre>'; |
|
| 278 | + echo '<br>'; |
|
| 279 | + echo '<a class="link-button" style="font-size:large;font-weight:bold" href="' . Url::fromPath('trapdirector/settings/updateschema') .'?msgok=1">Click here to update</a>'; |
|
| 280 | + echo '<br>'; |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | $Trap->setLogging($debug_level,'display'); |
@@ -293,28 +293,28 @@ discard block |
||
| 293 | 293 | |
| 294 | 294 | private function checkSnmpTrapd() |
| 295 | 295 | { |
| 296 | - $psOutput=array(); |
|
| 297 | - // First check is someone is listening to port 162. As not root, we can't have pid... |
|
| 298 | - exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
| 299 | - if (count($psOutput) == 0) |
|
| 300 | - { |
|
| 301 | - return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
| 302 | - } |
|
| 303 | - $psOutput=array(); |
|
| 304 | - exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
| 305 | - if (count($psOutput) == 0) |
|
| 306 | - { |
|
| 307 | - return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 308 | - } |
|
| 309 | - // Assume there is only one line... TODO : see if there is a better way to do this |
|
| 310 | - $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
| 311 | - if (!preg_match('/-n/',$line)) |
|
| 312 | - return array(1,'snmptrapd has no -n option : '.$line); |
|
| 313 | - if (!preg_match('/-O[^ ]*n/',$line)) |
|
| 314 | - return array(1,'snmptrapd has no -On option : '.$line); |
|
| 315 | - if (!preg_match('/-O[^ ]*e/',$line)) |
|
| 316 | - return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 296 | + $psOutput=array(); |
|
| 297 | + // First check is someone is listening to port 162. As not root, we can't have pid... |
|
| 298 | + exec('netstat -an |grep -E "udp.*:162"',$psOutput); |
|
| 299 | + if (count($psOutput) == 0) |
|
| 300 | + { |
|
| 301 | + return array(1,'Port UDP/162 is not open : snmptrapd must not be started'); |
|
| 302 | + } |
|
| 303 | + $psOutput=array(); |
|
| 304 | + exec('ps fax |grep snmptrapd |grep -v grep',$psOutput); |
|
| 305 | + if (count($psOutput) == 0) |
|
| 306 | + { |
|
| 307 | + return array(1,"UDP/162 : OK, but no snmptrapd process (?)"); |
|
| 308 | + } |
|
| 309 | + // Assume there is only one line... TODO : see if there is a better way to do this |
|
| 310 | + $line = preg_replace('/^.*snmptrapd /','',$psOutput[0]); |
|
| 311 | + if (!preg_match('/-n/',$line)) |
|
| 312 | + return array(1,'snmptrapd has no -n option : '.$line); |
|
| 313 | + if (!preg_match('/-O[^ ]*n/',$line)) |
|
| 314 | + return array(1,'snmptrapd has no -On option : '.$line); |
|
| 315 | + if (!preg_match('/-O[^ ]*e/',$line)) |
|
| 316 | + return array(1,'snmptrapd has no -Oe option : '.$line); |
|
| 317 | 317 | |
| 318 | - return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
| 318 | + return array(0,'snmptrapd listening to UDP/162, options : '.$line); |
|
| 319 | 319 | } |
| 320 | 320 | } |