From 1faeb755678fff60110d03ed2080d78812baaf15 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Wed, 6 Mar 2019 16:24:07 +0100 Subject: [PATCH] Implement Notification Period ignoring for TLVServiceNode --- .../Toplevelview/Monitoring/Servicestatus.php | 4 ++-- .../Monitoring/ServicestatusQuery.php | 22 +++++++++++-------- library/Toplevelview/Tree/TLVServiceNode.php | 7 +++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/library/Toplevelview/Monitoring/Servicestatus.php b/library/Toplevelview/Monitoring/Servicestatus.php index c5be9ba..e43572f 100644 --- a/library/Toplevelview/Monitoring/Servicestatus.php +++ b/library/Toplevelview/Monitoring/Servicestatus.php @@ -15,11 +15,11 @@ class Servicestatus extends IcingaServiceStatus * @param array|null $columns * @noinspection PhpMissingParentConstructorInspection */ - public function __construct(ConnectionInterface $connection, array $columns = null) + public function __construct(ConnectionInterface $connection, array $columns = null, $options = null) { /** @var MonitoringBackend $connection */ $this->connection = $connection; - $this->query = new ServicestatusQuery($connection->getResource(), $columns); + $this->query = new ServicestatusQuery($connection->getResource(), $columns, $options); } /** diff --git a/library/Toplevelview/Monitoring/ServicestatusQuery.php b/library/Toplevelview/Monitoring/ServicestatusQuery.php index 958da45..addee2f 100644 --- a/library/Toplevelview/Monitoring/ServicestatusQuery.php +++ b/library/Toplevelview/Monitoring/ServicestatusQuery.php @@ -10,17 +10,20 @@ */ class ServicestatusQuery extends IcingaServicestatusQuery { - // TODO: not used in this query - //use IgnoredNotificationPeriods; - //use Options; + use IgnoredNotificationPeriods; + use Options; + + public function __construct($ds, $columns = null, $options = null) + { + $this->setOptions($options); + parent::__construct($ds, $columns); + } public function init() { - /* TODO: not used in this query if (($periods = $this->getOption('ignored_notification_periods')) !== null) { $this->ignoreNotificationPeriods($periods); } - */ $patchedColumnMap = array( 'servicestatus' => array( @@ -52,11 +55,12 @@ protected function joinServicenotificationperiod() { $extraJoinCond = ''; - /* TODO: not used in this query - if (! empty ($this->ignoredNotificationPeriods)) { - $extraJoinCond .= $this->db->quoteInto(' AND ntpo.name1 NOT IN (?)', $this->ignoredNotificationPeriods); + if ($this->hasIgnoredNotifications()) { + $extraJoinCond .= $this->db->quoteInto( + ' AND ntpo.name1 NOT IN (?)', + $this->getIgnoredNotificationPeriods() + ); } - */ $this->select->joinLeft( ["ntp" => $this->prefix . 'timeperiods'], diff --git a/library/Toplevelview/Tree/TLVServiceNode.php b/library/Toplevelview/Tree/TLVServiceNode.php index 21d2f3c..2036714 100644 --- a/library/Toplevelview/Tree/TLVServiceNode.php +++ b/library/Toplevelview/Tree/TLVServiceNode.php @@ -59,12 +59,17 @@ public static function fetch(TLVTree $root) 'service_in_downtime', ); + $options = []; + foreach (['notification_periods', 'host_never_unhandled', 'ignored_notification_periods'] as $opt) { + $options[$opt] = $root->get($opt); + } + if ($root->get('notification_periods') === true) { $columns[] = 'service_in_notification_period'; } // Note: this uses a patched version of Servicestatus / ServicestatusQuery ! - $services = new Servicestatus($root->getBackend(), $columns); + $services = new Servicestatus($root->getBackend(), $columns, $options); $services->where('host_name', $names); foreach ($services as $service) {