From de546858c2dcc9c9c584d82dbbace2cbb444e947 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 30 Jan 2014 16:34:23 +0100 Subject: [PATCH] Add missing fetch routine for customvars in AbstractObject refs #4490 --- .../views/scripts/list/hosts.phtml | 4 --- .../Backend/Ido/Query/CustomvarQuery.php | 7 ++--- .../Monitoring/Object/AbstractObject.php | 28 ++++++++++++++++--- .../library/Monitoring/Object/Host.php | 4 +-- .../library/Monitoring/Object/Service.php | 4 +-- 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml index 91cff3b22..2383db43c 100644 --- a/modules/monitoring/application/views/scripts/list/hosts.phtml +++ b/modules/monitoring/application/views/scripts/list/hosts.phtml @@ -33,10 +33,7 @@ $viewHelper = $this->getHelper('MonitoringState'); - - action_url = 'http://$HOSTNAME$/$HOSTADDRESS$/BANA/$HOSTNAME$/$_HOSTMACADDRESS$' : $host->action_url = "test"; ($i == 1) ? $i++ : $i = $i + 1;?> - util()->getHostStateName($host->host_state)); ?> href('monitoring/show/host', array('host' => $host->host_name)); ?> @@ -122,7 +119,6 @@ $viewHelper = $this->getHelper('MonitoringState');
- makroResolver($host->action_url, $host, false); ?> host_icon_image) : ?>
diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php index 365fe52ae..fec118a0b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php @@ -4,8 +4,6 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; class CustomvarQuery extends IdoQuery { - protected $object_id = 'object_id'; - protected $columnMap = array( 'customvars' => array( 'varname' => 'cvs.varname', @@ -24,12 +22,11 @@ class CustomvarQuery extends IdoQuery protected function joinBaseTables() { $this->baseQuery = $this->db->select()->from( - array('cvs' => $this->prefix . 'customvariablestatus'), + array('cvs' => $this->prefix . 'customvariables'), array() )->join( array('cvo' => $this->prefix . 'objects'), - 'cvs.object_id = cvo.' . $this->object_id - . ' AND cvo.is_active = 1', + 'cvs.object_id = cvo.object_id AND cvo.is_active = 1', array() ); diff --git a/modules/monitoring/library/Monitoring/Object/AbstractObject.php b/modules/monitoring/library/Monitoring/Object/AbstractObject.php index 1b8d755c6..ea433c2f8 100644 --- a/modules/monitoring/library/Monitoring/Object/AbstractObject.php +++ b/modules/monitoring/library/Monitoring/Object/AbstractObject.php @@ -2,17 +2,14 @@ namespace Icinga\Module\Monitoring\Object; -use Icinga\Data\BaseQuery as Query; -use \Icinga\Module\Monitoring\Backend; use Icinga\Module\Monitoring\DataView\Contact; use Icinga\Module\Monitoring\DataView\Contactgroup; use Icinga\Module\Monitoring\DataView\Downtime; use Icinga\Module\Monitoring\DataView\EventHistory; use Icinga\Module\Monitoring\DataView\Hostgroup; -use Icinga\Module\Monitoring\DataView\HostStatus; use Icinga\Module\Monitoring\DataView\Comment; use Icinga\Module\Monitoring\DataView\Servicegroup; -use Icinga\Module\Monitoring\DataView\ServiceStatus; +use Icinga\Module\Monitoring\DataView\Customvar; use Icinga\Web\Request; abstract class AbstractObject @@ -81,6 +78,29 @@ abstract class AbstractObject return $this; } + public function fetchCustomvars() + { + $query = Customvar::fromRequest( + $this->request, + array( + 'varname', + 'varvalue' + ) + )->getQuery(); + + if ($this->type === self::TYPE_HOST) { + $query->where('host_name', $this->host_name) + ->where('object_type', 'host'); + } else { + $query->where('host_name', $this->host_name) + ->where('object_type', 'service') + ->where('service_description', $this->service_description); + } + + $this->customvars = $query->fetchPairs(); + return $this; + } + public function fetchContacts() { $this->contacts = Contact::fromRequest( diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php index 4e7a5a133..e0067491b 100644 --- a/modules/monitoring/library/Monitoring/Object/Host.php +++ b/modules/monitoring/library/Monitoring/Object/Host.php @@ -2,7 +2,6 @@ namespace Icinga\Module\Monitoring\Object; -use Icinga\Data\BaseQuery as Query; use Icinga\Module\Monitoring\DataView\HostStatus; class Host extends AbstractObject @@ -19,7 +18,8 @@ class Host extends AbstractObject ->fetchDowntimes() ->fetchHostgroups() ->fetchContacts() - ->fetchContactGroups(); + ->fetchContactGroups() + ->fetchCustomvars(); } protected function getProperties() diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index d566e5260..dcd6e117d 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -2,7 +2,6 @@ namespace Icinga\Module\Monitoring\Object; -use Icinga\Data\BaseQuery as Query; use Icinga\Module\Monitoring\DataView\ServiceStatus; class Service extends AbstractObject @@ -19,7 +18,8 @@ class Service extends AbstractObject ->fetchHostgroups() ->fetchServicegroups() ->fetchContacts() - ->fetchContactGroups(); + ->fetchContactGroups() + ->fetchCustomvars(); } protected function getProperties()