summaryrefslogtreecommitdiffstats
path: root/library/Toplevelview/Monitoring/ServicestatusQuery.php
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:30:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:30:50 +0000
commitd5f222b7ebf4d2c2d47d20a25adcc9aadf67fbd5 (patch)
treeda9b32212bf99154450a7668f61a75f65617a9fa /library/Toplevelview/Monitoring/ServicestatusQuery.php
parentInitial commit. (diff)
downloadicingaweb2-module-toplevelview-upstream.tar.xz
icingaweb2-module-toplevelview-upstream.zip
Adding upstream version 0.3.3.upstream/0.3.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Toplevelview/Monitoring/ServicestatusQuery.php')
-rw-r--r--library/Toplevelview/Monitoring/ServicestatusQuery.php87
1 files changed, 87 insertions, 0 deletions
diff --git a/library/Toplevelview/Monitoring/ServicestatusQuery.php b/library/Toplevelview/Monitoring/ServicestatusQuery.php
new file mode 100644
index 0000000..addee2f
--- /dev/null
+++ b/library/Toplevelview/Monitoring/ServicestatusQuery.php
@@ -0,0 +1,87 @@
+<?php
+/* Copyright (C) 2017 Icinga Development Team <info@icinga.com> */
+
+namespace Icinga\Module\Toplevelview\Monitoring;
+
+use Icinga\Module\Monitoring\Backend\Ido\Query\ServicestatusQuery as IcingaServicestatusQuery;
+
+/**
+ * Patched version of ServicestatusQuery
+ */
+class ServicestatusQuery extends IcingaServicestatusQuery
+{
+ use IgnoredNotificationPeriods;
+ use Options;
+
+ public function __construct($ds, $columns = null, $options = null)
+ {
+ $this->setOptions($options);
+ parent::__construct($ds, $columns);
+ }
+
+ public function init()
+ {
+ if (($periods = $this->getOption('ignored_notification_periods')) !== null) {
+ $this->ignoreNotificationPeriods($periods);
+ }
+
+ $patchedColumnMap = array(
+ 'servicestatus' => array(
+ 'service_handled_wo_host' => 'CASE WHEN ss.problem_has_been_acknowledged > 0 THEN 1 ELSE 0 END',
+ ),
+ 'servicenotificationperiod' => array(
+ 'service_notification_period' => 'ntpo.name1',
+ 'service_in_notification_period' => '
+ CASE WHEN ntpo.name1 IS NULL
+ THEN 1
+ ELSE CASE WHEN ntpr.timeperiod_id IS NOT NULL
+ THEN 1
+ ELSE 0
+ END
+ END',
+ ),
+ );
+
+ foreach ($patchedColumnMap as $table => $columns) {
+ foreach ($columns as $k => $v) {
+ $this->columnMap[$table][$k] = $v;
+ }
+ }
+
+ parent::init();
+ }
+
+ protected function joinServicenotificationperiod()
+ {
+ $extraJoinCond = '';
+
+ if ($this->hasIgnoredNotifications()) {
+ $extraJoinCond .= $this->db->quoteInto(
+ ' AND ntpo.name1 NOT IN (?)',
+ $this->getIgnoredNotificationPeriods()
+ );
+ }
+
+ $this->select->joinLeft(
+ ["ntp" => $this->prefix . 'timeperiods'],
+ 'ntp.timeperiod_object_id = s.notification_timeperiod_object_id'
+ . ' AND ntp.config_type = 1 AND ntp.instance_id = s.instance_id',
+ []
+ );
+ $this->select->joinLeft(
+ ['ntpo' => $this->prefix . 'objects'],
+ 'ntpo.object_id = s.notification_timeperiod_object_id'
+ . $extraJoinCond,
+ []
+ );
+ $this->select->joinLeft(
+ ['ntpr' => $this->prefix . 'timeperiod_timeranges'],
+ 'ntpr.timeperiod_id = ntp.timeperiod_id
+ AND ntpr.day = DAYOFWEEK(CURRENT_DATE()) - 1
+ AND ntpr.start_sec < UNIX_TIMESTAMP() - UNIX_TIMESTAMP(CURRENT_DATE())
+ AND ntpr.end_sec > UNIX_TIMESTAMP() - UNIX_TIMESTAMP(CURRENT_DATE())
+ ',
+ []
+ );
+ }
+}