diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index 1773337eb..0b482cfce 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -4,32 +4,64 @@ namespace Icinga\Module\Monitoring\Object; -use Icinga\Module\Monitoring\DataView\HostStatus; -use Icinga\Data\Db\DbQuery; +use Icinga\Module\Monitoring\Backend; +/** + * A Icinga host + */ class Host extends MonitoredObject { - public $type = 'host'; + /** + * Type of the Icinga host + * + * @var string + */ + public $type = self::TYPE_HOST; + + /** + * Prefix of the Icinga host + * + * @var string + */ public $prefix = 'host_'; - protected function applyObjectFilter(DbQuery $query) + /** + * Host name + * + * @var string + */ + protected $host; + + /** + * Create a new host + * + * @param Backend $backend Backend to fetch host information from + * @param string $host Host name + */ + public function __construct(Backend $backend, $host) { - return $query->where('host_name', $this->host_name); + parent::__construct($backend); + $this->host = $host; } - public function populate() + /** + * Get the host name + * + * @return string + */ + public function getHost() { - $this->fetchComments() - ->fetchHostgroups() - ->fetchContacts() - ->fetchContactGroups() - ->fetchCustomvars() - ->fetchDowntimes(); + return $this->host; } - protected function getProperties() + /** + * Get the data view to fetch the host information from + * + * @return \Icinga\Module\Monitoring\DataView\HostStatus + */ + protected function getDataView() { - $this->view = HostStatus::fromParams(array('backend' => null), array( + return $this->backend->select()->from('hostStatus', array( 'host_name', 'host_alias', 'host_address', @@ -70,8 +102,8 @@ class Host extends MonitoredObject 'host_notes_url', 'host_modified_host_attributes', 'host_problem', - 'process_perfdata' => 'host_process_performance_data', - ))->where('host_name', $this->params->get('host')); - return $this->view->getQuery()->fetchRow(); + 'host_process_performance_data' + )) + ->where('host_name', $this->host); } } diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index 3325ecc6b..1c1c80679 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -4,33 +4,83 @@ namespace Icinga\Module\Monitoring\Object; -use Icinga\Module\Monitoring\DataView\ServiceStatus; -use Icinga\Data\Db\DbQuery; +use Icinga\Module\Monitoring\Backend; +/** + * A Icinga service + */ class Service extends MonitoredObject { - public $type = 'service'; + /** + * Type of the Icinga service + * + * @var string + */ + public $type = self::TYPE_SERVICE; + + /** + * Prefix of the Icinga service + * + * @var string + */ public $prefix = 'service_'; - protected function applyObjectFilter(DbQuery $query) + /** + * Host name the service is running on + * + * @var string + */ + protected $host; + + /** + * Service name + * + * @var string + */ + protected $service; + + /** + * Create a new service + * + * @param Backend $backend Backend to fetch service information from + * @param string $host Host name the service is running on + * @param string $service Service name + */ + public function __construct(Backend $backend, $host, $service) { - return $query->where('service_host_name', $this->host_name) - ->where('service_description', $this->service_description); + parent::__construct($backend); + $this->host = $host; + $this->service = $service; } - public function populate() + /** + * Get the host name the service is running on + * + * @return string + */ + public function getHost() { - $this->fetchComments() - ->fetchServicegroups() - ->fetchContacts() - ->fetchContactGroups() - ->fetchCustomvars() - ->fetchDowntimes(); + return $this->host; } - protected function getProperties() + /** + * Get the service name + * + * @return string + */ + public function getService() { - $this->view = ServiceStatus::fromParams(array('backend' => null), array( + return $this->service; + } + + /** + * Get the data view + * + * @return \Icinga\Module\Monitoring\DataView\ServiceStatus + */ + protected function getDataView() + { + return $this->backend->select()->from('serviceStatus', array( 'host_name', 'host_state', 'host_state_type', @@ -114,30 +164,10 @@ class Service extends MonitoredObject 'service_flap_detection_enabled', 'service_flap_detection_enabled_changed', 'service_modified_service_attributes', - 'process_perfdata' => 'service_process_performance_data', - ))->where('host_name', $this->params->get('host')) - ->where('service_description', $this->params->get('service')); - - return $this->view->getQuery()->fetchRow(); - } - - /** - * Get the host name the service is running on - * - * @return string - */ - public function getHostName() - { - return $this->params->get('host'); - } - - /** - * Get the service name - * - * @return string - */ - public function getName() - { - return $this->params->get('service'); + 'service_process_performance_data', + 'service_percent_state_change' + )) + ->where('host_name', $this->host) + ->where('service_description', $this->service); } }