From e5ec9a36f7d32ce78388af74af9c88475d08ab5d Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 1 Jul 2022 18:03:06 +0200 Subject: [PATCH] monitoring: Fix conversion rules for timestamps in various queries --- .../Query/HostcommentdeletionhistoryQuery.php | 14 ++++++--- .../Ido/Query/HostcommenthistoryQuery.php | 16 +++++++--- .../Ido/Query/HostdowntimeendhistoryQuery.php | 14 ++++++--- .../Query/HostdowntimestarthistoryQuery.php | 16 +++++++--- .../Query/HostflappingstarthistoryQuery.php | 16 +++++++--- .../Ido/Query/HostnotificationQuery.php | 30 +++++++++--------- .../Ido/Query/HoststatehistoryQuery.php | 31 ++++++++++++++++--- .../ServicecommentdeletionhistoryQuery.php | 14 ++++++--- .../Ido/Query/ServicecommenthistoryQuery.php | 16 +++++++--- .../Query/ServicedowntimeendhistoryQuery.php | 14 ++++++--- .../ServicedowntimestarthistoryQuery.php | 16 +++++++--- .../ServiceflappingstarthistoryQuery.php | 16 +++++++--- .../Ido/Query/ServicenotificationQuery.php | 30 +++++++++--------- .../Ido/Query/ServicestatehistoryQuery.php | 31 ++++++++++++++++--- 14 files changed, 188 insertions(+), 86 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php index b602f8a69..d798d5614 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommentdeletionhistoryQuery.php @@ -3,18 +3,24 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for host comment removal records */ class HostcommentdeletionhistoryQuery extends HostcommenthistoryQuery { - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'hch.deletion_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('hch.deletion_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php index d7a25e054..b8f166ae3 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostcommenthistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for host comment history records */ @@ -40,7 +43,7 @@ class HostcommenthistoryQuery extends IdoQuery 'object_type' => '(\'host\')', 'output' => "('[' || hch.author_name || '] ' || hch.comment_data)", 'state' => '(-1)', - 'timestamp' => 'hch.comment_time', + 'timestamp' => 'UNIX_TIMESTAMP(hch.comment_time)', 'type' => "(CASE hch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)" ), 'hostgroups' => array( @@ -68,13 +71,16 @@ class HostcommenthistoryQuery extends IdoQuery ) ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'hch.comment_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('hch.comment_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php index 8df59c7b3..77d91e5ef 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimeendhistoryQuery.php @@ -3,18 +3,24 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for host downtime end history records */ class HostdowntimeendhistoryQuery extends HostdowntimestarthistoryQuery { - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'hdh.actual_end_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('hdh.actual_end_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php index ae3df5ffa..54ac6a11c 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostdowntimestarthistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for host downtime start history records */ @@ -40,7 +43,7 @@ class HostdowntimestarthistoryQuery extends IdoQuery 'object_type' => '(\'host\')', 'output' => "('[' || hdh.author_name || '] ' || hdh.comment_data)", 'state' => '(-1)', - 'timestamp' => 'hdh.actual_start_time', + 'timestamp' => 'UNIX_TIMESTAMP(hdh.actual_start_time)', 'type' => "('dt_start')" ), 'hostgroups' => array( @@ -68,13 +71,16 @@ class HostdowntimestarthistoryQuery extends IdoQuery ) ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'hdh.actual_start_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('hdh.actual_start_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php index 3532b72f5..497a49386 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostflappingstarthistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for host flapping start history records */ @@ -40,7 +43,7 @@ class HostflappingstarthistoryQuery extends IdoQuery 'object_type' => '(\'host\')', 'output' => '(hfh.percent_state_change || \'\')', 'state' => '(-1)', - 'timestamp' => 'hfh.event_time', + 'timestamp' => 'UNIX_TIMESTAMP(hfh.event_time)', 'type' => '(\'flapping\')' ), 'hostgroups' => array( @@ -68,13 +71,16 @@ class HostflappingstarthistoryQuery extends IdoQuery ) ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'hfh.event_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('hfh.event_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php index 052873f77..284468ed7 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HostnotificationQuery.php @@ -40,7 +40,7 @@ class HostnotificationQuery extends IdoQuery 'history' => array( 'output' => null, 'state' => 'hn.state', - 'timestamp' => 'hn.start_time', + 'timestamp' => 'UNIX_TIMESTAMP(hn.start_time)', 'type' => ' CASE hn.notification_reason WHEN 1 THEN \'notification_ack\' @@ -63,7 +63,7 @@ class HostnotificationQuery extends IdoQuery 'notification_output' => 'hn.output', 'notification_reason' => 'hn.notification_reason', 'notification_state' => 'hn.state', - 'notification_timestamp' => 'hn.start_time', + 'notification_timestamp' => 'UNIX_TIMESTAMP(hn.start_time)', 'object_type' => '(\'host\')' ), 'servicegroups' => array( @@ -81,24 +81,24 @@ class HostnotificationQuery extends IdoQuery protected function requireFilterColumns(Filter $filter) { - if ($filter instanceof FilterExpression && $filter->getColumn() === 'output') { - $this->requireColumn($filter->getColumn()); - $filter->setColumn('hn.output'); - return null; + if ($filter instanceof FilterExpression) { + switch ($filter->getColumn()) { + case 'output': + $this->requireColumn('output'); + $filter->setColumn('hn.output'); + return null; + case 'timestamp': + case 'notification_timestamp': + $this->requireColumn($filter->getColumn()); + $filter->setColumn('hn.start_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; + } } return parent::requireFilterColumns($filter); } - public function isTimestamp($field) - { - if (! parent::isTimestamp($field)) { - return $field === 'hn.start_time'; - } - - return true; - } - /** * {@inheritdoc} */ diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php index 7321d1a87..ac85c1f3b 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatehistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for host state history records */ @@ -73,18 +76,36 @@ class HoststatehistoryQuery extends IdoQuery 'object_type' => '(\'host\')', 'output' => '(CASE WHEN hh.state_type = 1 THEN hh.output ELSE \'[ \' || hh.current_check_attempt || \'/\' || hh.max_check_attempts || \' ] \' || hh.output END)', 'state' => 'hh.state', - 'timestamp' => 'hh.state_time', + 'timestamp' => 'UNIX_TIMESTAMP(hh.state_time)', 'type' => "(CASE WHEN hh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)" ), ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'hh.state_time'; + if ($filter instanceof FilterExpression) { + switch ($filter->getColumn()) { + case 'timestamp': + $this->requireColumn('timestamp'); + $filter->setColumn('hh.state_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; + case 'type': + if (! is_array($filter->getExpression())) { + $this->requireColumn('type'); + $filter->setColumn('hh.state_type'); + if (isset($this->types[$filter->getExpression()])) { + $filter->setExpression($this->types[$filter->getExpression()]); + } else { + $filter->setExpression(-1); + } + + return null; + } + } } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php index 1f134b2a2..33aaa259a 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommentdeletionhistoryQuery.php @@ -3,18 +3,24 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for service comment removal records */ class ServicecommentdeletionhistoryQuery extends ServicecommenthistoryQuery { - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'sch.deletion_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('sch.deletion_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php index 0a3183552..b3e9c1614 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicecommenthistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for service comment history records */ @@ -44,7 +47,7 @@ class ServicecommenthistoryQuery extends IdoQuery 'service_host' => 'so.name1 COLLATE latin1_general_ci', 'service_host_name' => 'so.name1', 'state' => '(-1)', - 'timestamp' => 'sch.comment_time', + 'timestamp' => 'UNIX_TIMESTAMP(sch.comment_time)', 'type' => "(CASE sch.entry_type WHEN 1 THEN 'comment' WHEN 2 THEN 'dt_comment' WHEN 3 THEN 'flapping' WHEN 4 THEN 'ack' END)" ), 'hostgroups' => array( @@ -69,13 +72,16 @@ class ServicecommenthistoryQuery extends IdoQuery ) ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'sch.comment_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('sch.comment_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php index 0c7049f3d..2d592c85f 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimeendhistoryQuery.php @@ -3,18 +3,24 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for host downtime end history records */ class ServicedowntimeendhistoryQuery extends ServicedowntimestarthistoryQuery { - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'sdh.actual_end_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('sdh.actual_end_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php index be096ec9b..f22e265cb 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicedowntimestarthistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for service downtime start history records */ @@ -44,7 +47,7 @@ class ServicedowntimestarthistoryQuery extends IdoQuery 'service_host' => 'so.name1 COLLATE latin1_general_ci', 'service_host_name' => 'so.name1', 'state' => '(-1)', - 'timestamp' => 'sdh.actual_start_time', + 'timestamp' => 'UNIX_TIMESTAMP(sdh.actual_start_time)', 'type' => "('dt_start')" ), 'hostgroups' => array( @@ -69,13 +72,16 @@ class ServicedowntimestarthistoryQuery extends IdoQuery ) ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'sdh.actual_start_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('sdh.actual_start_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php index 842166b25..f068681c6 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServiceflappingstarthistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for service flapping start history records */ @@ -43,7 +46,7 @@ class ServiceflappingstarthistoryQuery extends IdoQuery 'service_description' => 'so.name2', 'service_host_name' => 'so.name1', 'state' => '(-1)', - 'timestamp' => 'sfh.event_time', + 'timestamp' => 'UNIX_TIMESTAMP(sfh.event_time)', 'type' => "('flapping')" ), 'hostgroups' => array( @@ -68,13 +71,16 @@ class ServiceflappingstarthistoryQuery extends IdoQuery ) ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'sfh.event_time'; + if ($filter instanceof FilterExpression && $filter->getColumn() === 'timestamp') { + $this->requireColumn('timestamp'); + $filter->setColumn('sfh.event_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; } - return true; + return parent::requireFilterColumns($filter); } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php index 12e512da5..d3fccf0d0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicenotificationQuery.php @@ -31,7 +31,7 @@ class ServicenotificationQuery extends IdoQuery 'history' => array( 'output' => null, 'state' => 'sn.state', - 'timestamp' => 'sn.start_time', + 'timestamp' => 'UNIX_TIMESTAMP(sn.start_time)', 'type' => ' CASE sn.notification_reason WHEN 1 THEN \'notification_ack\' @@ -63,7 +63,7 @@ class ServicenotificationQuery extends IdoQuery 'notification_output' => 'sn.output', 'notification_reason' => 'sn.notification_reason', 'notification_state' => 'sn.state', - 'notification_timestamp' => 'sn.start_time', + 'notification_timestamp' => 'UNIX_TIMESTAMP(sn.start_time)', 'object_type' => '(\'service\')', 'service' => 'so.name2 COLLATE latin1_general_ci', 'service_description' => 'so.name2', @@ -81,24 +81,24 @@ class ServicenotificationQuery extends IdoQuery protected function requireFilterColumns(Filter $filter) { - if ($filter instanceof FilterExpression && $filter->getColumn() === 'output') { - $this->requireColumn($filter->getColumn()); - $filter->setColumn('sn.output'); - return null; + if ($filter instanceof FilterExpression) { + switch ($filter->getColumn()) { + case 'output': + $this->requireColumn('output'); + $filter->setColumn('sn.output'); + return null; + case 'timestamp': + case 'notification_timestamp': + $this->requireColumn($filter->getColumn()); + $filter->setColumn('sn.start_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; + } } return parent::requireFilterColumns($filter); } - public function isTimestamp($field) - { - if (! parent::isTimestamp($field)) { - return $field === 'sn.start_time'; - } - - return true; - } - /** * {@inheritdoc} */ diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php index a1bab89ce..f93ca8ac0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicestatehistoryQuery.php @@ -3,6 +3,9 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Data\Filter\Filter; +use Icinga\Data\Filter\FilterExpression; + /** * Query for service state history records */ @@ -74,18 +77,36 @@ class ServicestatehistoryQuery extends IdoQuery 'service_host' => 'so.name1 COLLATE latin1_general_ci', 'service_host_name' => 'so.name1', 'state' => 'sh.state', - 'timestamp' => 'sh.state_time', + 'timestamp' => 'UNIX_TIMESTAMP(sh.state_time)', 'type' => "(CASE WHEN sh.state_type = 1 THEN 'hard_state' ELSE 'soft_state' END)" ), ); - public function isTimestamp($field) + protected function requireFilterColumns(Filter $filter) { - if (! parent::isTimestamp($field)) { - return $field === 'sh.state_time'; + if ($filter instanceof FilterExpression) { + switch ($filter->getColumn()) { + case 'timestamp': + $this->requireColumn('timestamp'); + $filter->setColumn('sh.state_time'); + $filter->setExpression($this->timestampForSql($this->valueToTimestamp($filter->getExpression()))); + return null; + case 'type': + if (! is_array($filter->getExpression())) { + $this->requireColumn('type'); + $filter->setColumn('sh.state_type'); + if (isset($this->types[$filter->getExpression()])) { + $filter->setExpression($this->types[$filter->getExpression()]); + } else { + $filter->setExpression(-1); + } + + return null; + } + } } - return true; + return parent::requireFilterColumns($filter); } /**