From 62f502d2768ac2c351cbab8fab6ce02b28d78c7e Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Thu, 28 Aug 2014 15:13:15 +0200 Subject: [PATCH 1/7] Postgres/StatusQuery: Fix concatenation and group by refs #5896 --- .../Monitoring/Backend/Ido/Query/StatusQuery.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php index 2006228b1..d5da738a0 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php @@ -487,10 +487,10 @@ class StatusQuery extends IdoQuery { $sub = '(SELECT' . ' lc.object_id,' - . " CASE WHEN lc.entry_type = 1 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_comment_data," - . " CASE WHEN lc.entry_type = 2 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_downtime_data," - . " CASE WHEN lc.entry_type = 3 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_flapping_data," - . " CASE WHEN lc.entry_type = 4 THEN CONCAT('[' || c.author_name || '] ' || c.comment_data) ELSE NULL END AS last_ack_data" + . " CASE WHEN lc.entry_type = 1 THEN '[' || c.author_name || '] ' || c.comment_data ELSE NULL END AS last_comment_data," + . " CASE WHEN lc.entry_type = 2 THEN '[' || c.author_name || '] ' || c.comment_data ELSE NULL END AS last_downtime_data," + . " CASE WHEN lc.entry_type = 3 THEN '[' || c.author_name || '] ' || c.comment_data ELSE NULL END AS last_flapping_data," + . " CASE WHEN lc.entry_type = 4 THEN '[' || c.author_name || '] ' || c.comment_data ELSE NULL END AS last_ack_data" . ' FROM icinga_comments c' . ' JOIN (SELECT' . ' MAX(comment_id) as comment_id,' @@ -499,7 +499,8 @@ class StatusQuery extends IdoQuery . ' FROM icinga_comments' . ' WHERE entry_type = 1 OR entry_type = 4' . ' GROUP BY object_id, entry_type' - . ') lc ON lc.comment_id = c.comment_id GROUP BY lc.object_id)'; + . ') lc ON lc.comment_id = c.comment_id' + . ' GROUP BY lc.object_id, lc.entry_type, c.author_name, c.comment_data)'; return new Zend_Db_Expr($sub); } From 751d2e6d119cf6c8cfe1a578f49c9176b075b9e5 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Fri, 29 Aug 2014 10:57:05 +0200 Subject: [PATCH 2/7] ErrorController: Log exception and stacktrace refe #5896 --- application/controllers/ErrorController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 7d30d62e5..074e2fdc2 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -4,6 +4,7 @@ // namespace Icinga\Application\Controllers; +use Icinga\Logger\Logger; use Icinga\Web\Controller\ActionController; use Icinga\Application\Icinga; @@ -21,6 +22,10 @@ class ErrorController extends ActionController { $error = $this->_getParam('error_handler'); $exception = $error->exception; + + Logger::error($exception); + Logger::error('Stacktrace: %s', $exception->getTraceAsString()); + switch ($error->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: From e46dd4bdfd000dea4aa259f011638ef61385d8c6 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Fri, 29 Aug 2014 11:37:20 +0200 Subject: [PATCH 3/7] DowntimeQuery: Postgres fixes Change is_fixed to boolean check and illegal postgres timerange of '0000-00-00 00:00:00'. refs #5896 --- .../library/Monitoring/Backend/Ido/Query/DowntimeQuery.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php index 1f5e17c6c..fe1152076 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php @@ -23,8 +23,8 @@ class DowntimeQuery extends IdoQuery 'downtime_triggered_by_id' => 'sd.triggered_by_id', 'downtime_scheduled_start' => 'UNIX_TIMESTAMP(sd.scheduled_start_time)', 'downtime_scheduled_end' => 'UNIX_TIMESTAMP(sd.scheduled_end_time)', - 'downtime_start' => "UNIX_TIMESTAMP(CASE WHEN sd.trigger_time != '0000-00-00 00:00:00' then sd.trigger_time ELSE sd.scheduled_start_time END)", - 'downtime_end' => 'CASE WHEN sd.is_fixed THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END', + 'downtime_start' => "UNIX_TIMESTAMP(CASE WHEN UNIX_TIMESTAMP(sd.trigger_time) > 0 then sd.trigger_time ELSE sd.scheduled_start_time END)", + 'downtime_end' => 'CASE WHEN sd.is_fixed > 0 THEN UNIX_TIMESTAMP(sd.scheduled_end_time) ELSE UNIX_TIMESTAMP(sd.trigger_time) + sd.duration END', 'downtime_duration' => 'sd.duration', 'downtime_is_in_effect' => 'sd.is_in_effect', 'downtime_internal_id' => 'sd.internal_downtime_id', From b4e9bad87a6b04a023289fb6d2e189c79f0edcea Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Fri, 29 Aug 2014 11:45:06 +0200 Subject: [PATCH 4/7] NotificationHistoryQuery: Add missing field to group statement refs #5896 --- .../Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php index e557f4c7b..64c7e69b8 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php @@ -85,7 +85,8 @@ class NotificationhistoryQuery extends IdoQuery $this->select->group('n.object_id') ->group('n.start_time') ->group('n.output') - ->group('n.state'); + ->group('n.state') + ->group('o.objecttype_id'); } $this->joinedVirtualTables = array('history' => true); From 30f391035c0c497e046e29ffa82766042750a80c Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Fri, 29 Aug 2014 13:41:41 +0200 Subject: [PATCH 5/7] Postgres/DbQuery: Add orderfields to select refs #6896 --- library/Icinga/Data/Db/DbQuery.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index 605e36af9..a89544be8 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -89,6 +89,17 @@ class DbQuery extends SimpleQuery public function getSelectQuery() { $select = $this->dbSelect(); + + // Add order fields to select for postgres distinct queries (#6351) + if ($this->hasOrder() + && $this->getDatasource()->getDbType() === 'pgsql' + && $select->getPart(Zend_Db_Select::DISTINCT) === true) { + foreach ($this->getOrder() as $fieldAndDirection) { + list($alias, $field) = explode('.', $fieldAndDirection[0]); + $this->columns[$field] = $fieldAndDirection[0]; + } + } + $select->columns($this->columns); $this->applyFilterSql($select); @@ -102,6 +113,7 @@ class DbQuery extends SimpleQuery ); } } + return $select; } From 21f0b4c925ed133f1f253994b31f29ae419b118d Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Fri, 29 Aug 2014 16:52:09 +0200 Subject: [PATCH 6/7] CommandQuery: Remove select * from joins (Postgres) refs #5896 --- .../library/Monitoring/Backend/Ido/Query/CommandQuery.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php index 664cb3576..c730c078e 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommandQuery.php @@ -51,10 +51,12 @@ class CommandQuery extends IdoQuery { $this->select->join( array('cnc' => $this->prefix . 'contact_notificationcommands'), - 'cnc.command_object_id = co.object_id' + 'cnc.command_object_id = co.object_id', + array() )->join( array('con' => $this->prefix . 'contacts'), - 'con.contact_id = cnc.contact_id' + 'con.contact_id = cnc.contact_id', + array() ); } } \ No newline at end of file From f47bc466547e5bfe5d7b666e4af68292da4f16fc Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Mon, 1 Sep 2014 09:53:17 +0200 Subject: [PATCH 7/7] GroupSummary/Postgres: Fix group by in initial join query refs #5896 --- .../Monitoring/Backend/Ido/Query/GroupsummaryQuery.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php index 914441d03..3b7fdaa06 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query; +use Icinga\Logger\Logger; use Zend_Db_Select; class GroupSummaryQuery extends IdoQuery @@ -69,8 +70,15 @@ class GroupSummaryQuery extends IdoQuery ) ); + $groupColumn = 'hostgroup'; + + if (in_array('servicegroup', $this->desiredColumns)) { + $groupColumn = 'servicegroup'; + } + $union = $this->db->select()->union(array($hosts, $services), Zend_Db_Select::SQL_UNION_ALL); - $this->select->from(array('statussummary' => $union), '*')->group($columns[0]); + $this->select->from(array('statussummary' => $union), array($groupColumn))->group(array($groupColumn)); + $this->joinedVirtualTables = array( 'servicestatussummary' => true, 'hoststatussummary' => true