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: 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; } 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 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', 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 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); 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); }