From 3ccfe347f327d4a5575edb5aa88f6d6545d79e6a Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 17 Jun 2014 13:10:54 +0000 Subject: [PATCH] Monitoring\Object: replace fromRequest with params This is only a temporary solution, the Monitoring\Object should be fetched from the backend created in our front controller. --- .../controllers/ShowController.php | 6 ++-- .../Monitoring/Object/AbstractObject.php | 32 +++++++++---------- .../library/Monitoring/Object/Host.php | 2 +- .../library/Monitoring/Object/Service.php | 6 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/modules/monitoring/application/controllers/ShowController.php b/modules/monitoring/application/controllers/ShowController.php index e8f3dd1b4..4e3c34f46 100644 --- a/modules/monitoring/application/controllers/ShowController.php +++ b/modules/monitoring/application/controllers/ShowController.php @@ -57,12 +57,12 @@ class Monitoring_ShowController extends Controller public function init() { if ($this->getRequest()->getActionName() === 'host') { - $this->view->object = new Host($this->getRequest()); + $this->view->object = new Host($this->params); } elseif ($this->getRequest()->getActionName() === 'service') { - $this->view->object = new Service($this->getRequest()); + $this->view->object = new Service($this->params); } else { // TODO: Well... this could be done better - $this->view->object = AbstractObject::fromRequest($this->getRequest()); + $this->view->object = AbstractObject::fromParams($this->params); } if (Hook::has('ticket')) { $this->view->tickets = Hook::first('ticket'); diff --git a/modules/monitoring/library/Monitoring/Object/AbstractObject.php b/modules/monitoring/library/Monitoring/Object/AbstractObject.php index b20c6495b..17be0cacf 100644 --- a/modules/monitoring/library/Monitoring/Object/AbstractObject.php +++ b/modules/monitoring/library/Monitoring/Object/AbstractObject.php @@ -17,7 +17,8 @@ use Icinga\Module\Monitoring\DataView\Hostgroup; use Icinga\Module\Monitoring\DataView\Comment; use Icinga\Module\Monitoring\DataView\Servicegroup; use Icinga\Module\Monitoring\DataView\Customvar; -use Icinga\Web\Request; +use Icinga\Web\UrlParams; + abstract class AbstractObject { @@ -35,14 +36,14 @@ abstract class AbstractObject protected $view; private $properties = array(); - private $request = null; + protected $params; // TODO: Fetching parent states if any would be nice // Same goes for host/service dependencies - public function __construct(Request $request) + public function __construct(UrlParams $params) { - $this->request = $request; + $this->params = $params; $this->properties = $this->getProperties(); } @@ -117,9 +118,7 @@ abstract class AbstractObject public function fetchCustomvars() { - $query = Customvar::fromRequest( - $this->request, - array( + $query = Customvar::fromParams(array('backend' => null), array( 'varname', 'varvalue' ) @@ -173,14 +172,13 @@ abstract class AbstractObject public function fetchServicegroups() { - $query = Servicegroup::fromRequest( - $this->request, - array( + $query = Servicegroup::fromParams(array('backend' => null), array( 'servicegroup_name', 'servicegroup_alias', ) ); - + $query->where('service_host_name', $this->host_name); + $query->where('service_description', $this->service_description); $this->servicegroups = $query->getQuery()->fetchPairs(); return $this; } @@ -226,7 +224,7 @@ abstract class AbstractObject 'output', 'type' ) - )->sort('raw_timestamp', 'DESC'); + )->sort('timestamp', 'DESC'); if ($this->type === 'service') { $query->where('service_host_name', $this->host_name); $query->where('service_description', $this->service_description); @@ -253,12 +251,12 @@ abstract class AbstractObject return $this->$expandedName; } - public static function fromRequest(Request $request) + public static function fromParams(UrlParams $params) { - if ($request->has('service') && $request->has('host')) { - return new Service($request); - } elseif ($request->has('host')) { - return new Host($request); + if ($params->has('service') && $params->has('host')) { + return new Service($params); + } elseif ($params->has('host')) { + return new Host($params); } } diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index 70bd67bda..f9e1e6ec5 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -27,7 +27,7 @@ class Host extends AbstractObject protected function getProperties() { - $this->view = HostStatus::fromRequest($this->request, array( + $this->view = HostStatus::fromParams(array('backend' => null), array( 'host_name', 'host_alias', 'host_address', diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index 62ddca771..a27aa19f9 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -28,7 +28,7 @@ class Service extends AbstractObject protected function getProperties() { - $this->view = ServiceStatus::fromRequest($this->request, array( + $this->view = ServiceStatus::fromParams(array('backend' => null), array( 'host_name', 'host_state', 'host_state_type', @@ -111,7 +111,9 @@ class Service extends AbstractObject 'service_flap_detection_enabled', 'service_flap_detection_enabled_changed', 'service_modified_service_attributes', - )); + ))->where('host_name', $this->params->get('host')) + ->where('service_description', $this->params->get('service')); + return $this->view->getQuery()->fetchRow(); } }