monitoring: Fix conversion rules for timestamps in various queries

This commit is contained in:
Johannes Meyer 2022-07-01 18:03:06 +02:00
parent 46998464ea
commit e5ec9a36f7
14 changed files with 188 additions and 86 deletions

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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}
*/

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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);
}
/**

View File

@ -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}
*/

View File

@ -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);
}
/**