From dc223128bbc243ea31b1efdc117e0eb38529791b Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Thu, 5 Mar 2015 17:18:52 +0100
Subject: [PATCH 01/52] Remove host_- and service_object_id from ContactQuery's
 columnMap

We do not use these columns.

refs #8614
---
 .../library/Monitoring/Backend/Ido/Query/ContactQuery.php       | 2 --
 1 file changed, 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
index b7dd449b2..ac549e00a 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
@@ -33,12 +33,10 @@ class ContactQuery extends IdoQuery
             'contact_notify_service_timeperiod' => 'st.alias COLLATE latin1_general_ci'
         ),
         'hosts' => array(
-            'host_object_id' => 'ho.object_id',
             'host_name'      => 'ho.name1 COLLATE latin1_general_ci',
             'host'           => 'ho.name1 COLLATE latin1_general_ci',
         ),
         'services' => array(
-            'service_object_id'   => 'so.object_id',
             'service_host_name'   => 'so.name1 COLLATE latin1_general_ci',
             'service'             => 'so.name1 COLLATE latin1_general_ci',
             'service_description' => 'so.name2 COLLATE latin1_general_ci',

From fc403e693b8f43394ca01b56374a5ed99aa15abc Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 6 Mar 2015 09:46:47 +0100
Subject: [PATCH 02/52] Fix array indentation in the ContactQuery

refs #8614
---
 .../Backend/Ido/Query/ContactQuery.php        | 52 +++++++++----------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
index ac549e00a..a55f582ee 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
@@ -7,39 +7,39 @@ class ContactQuery extends IdoQuery
 {
     protected $columnMap = array(
         'contacts' => array(
-            'contact_id'     => 'c.contact_id',
-            'contact_name'   => 'co.name1 COLLATE latin1_general_ci',
-            'contact_alias'  => 'c.alias COLLATE latin1_general_ci',
-            'contact_email'  => 'c.email_address COLLATE latin1_general_ci',
-            'contact_pager'  => 'c.pager_address',
-            'contact_object_id'                => 'c.contact_object_id',
-            'contact_has_host_notfications'    => 'c.host_notifications_enabled',
-            'contact_has_service_notfications' => 'c.service_notifications_enabled',
-            'contact_can_submit_commands'      => 'c.can_submit_commands',
-            'contact_notify_service_recovery'  => 'c.notify_service_recovery',
-            'contact_notify_service_warning'   => 'c.notify_service_warning',
-            'contact_notify_service_critical'  => 'c.notify_service_critical',
-            'contact_notify_service_unknown'   => 'c.notify_service_unknown',
-            'contact_notify_service_flapping'  => 'c.notify_service_flapping',
-            'contact_notify_service_downtime'  => 'c.notify_service_recovery',
-            'contact_notify_host_recovery'     => 'c.notify_host_recovery',
-            'contact_notify_host_down'         => 'c.notify_host_down',
-            'contact_notify_host_unreachable'  => 'c.notify_host_unreachable',
-            'contact_notify_host_flapping'     => 'c.notify_host_flapping',
-            'contact_notify_host_downtime'     => 'c.notify_host_downtime',
+            'contact_id'                        => 'c.contact_id',
+            'contact_name'                      => 'co.name1 COLLATE latin1_general_ci',
+            'contact_alias'                     => 'c.alias COLLATE latin1_general_ci',
+            'contact_email'                     => 'c.email_address COLLATE latin1_general_ci',
+            'contact_pager'                     => 'c.pager_address',
+            'contact_object_id'                 => 'c.contact_object_id',
+            'contact_has_host_notfications'     => 'c.host_notifications_enabled',
+            'contact_has_service_notfications'  => 'c.service_notifications_enabled',
+            'contact_can_submit_commands'       => 'c.can_submit_commands',
+            'contact_notify_service_recovery'   => 'c.notify_service_recovery',
+            'contact_notify_service_warning'    => 'c.notify_service_warning',
+            'contact_notify_service_critical'   => 'c.notify_service_critical',
+            'contact_notify_service_unknown'    => 'c.notify_service_unknown',
+            'contact_notify_service_flapping'   => 'c.notify_service_flapping',
+            'contact_notify_service_downtime'   => 'c.notify_service_recovery',
+            'contact_notify_host_recovery'      => 'c.notify_host_recovery',
+            'contact_notify_host_down'          => 'c.notify_host_down',
+            'contact_notify_host_unreachable'   => 'c.notify_host_unreachable',
+            'contact_notify_host_flapping'      => 'c.notify_host_flapping',
+            'contact_notify_host_downtime'      => 'c.notify_host_downtime'
         ),
         'timeperiods' => array(
-            'contact_notify_host_timeperiod' => 'ht.alias COLLATE latin1_general_ci',
+            'contact_notify_host_timeperiod'    => 'ht.alias COLLATE latin1_general_ci',
             'contact_notify_service_timeperiod' => 'st.alias COLLATE latin1_general_ci'
         ),
         'hosts' => array(
-            'host_name'      => 'ho.name1 COLLATE latin1_general_ci',
-            'host'           => 'ho.name1 COLLATE latin1_general_ci',
+            'host'      => 'ho.name1 COLLATE latin1_general_ci',
+            'host_name' => 'ho.name1 COLLATE latin1_general_ci',
         ),
         'services' => array(
-            'service_host_name'   => 'so.name1 COLLATE latin1_general_ci',
-            'service'             => 'so.name1 COLLATE latin1_general_ci',
-            'service_description' => 'so.name2 COLLATE latin1_general_ci',
+            'service'               => 'so.name1 COLLATE latin1_general_ci',
+            'service_description'   => 'so.name2 COLLATE latin1_general_ci',
+            'service_host_name'     => 'so.name1 COLLATE latin1_general_ci',
         )
     );
 

From 2b91ec7f2c90c12ae7b8e5f52c2cca6904694f79 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 6 Mar 2015 09:54:12 +0100
Subject: [PATCH 03/52] Comment out unused query in the ContactgroupQuery

refs #8614
---
 .../Monitoring/Backend/Ido/Query/ContactgroupQuery.php    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
index d975da05e..c19670e8d 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
@@ -95,10 +95,10 @@ class ContactgroupQuery extends IdoQuery
 
     protected function joinServices()
     {
-        $scgSub = $this->db->select()->distinct()->from(
-            $this->prefix . 'service_contactgroups',
-            array('contactgroup_object_id', 'service_id')
-        );
+//        $scgSub = $this->db->select()->distinct()->from(
+//            $this->prefix . 'service_contactgroups',
+//            array('contactgroup_object_id', 'service_id')
+//        );
 
             /*
             This subselect is a workaround for a fucking stupid bug. Other tables

From 64d1d12c7347a7027f8547079325f9ba107289d8 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 6 Mar 2015 10:02:20 +0100
Subject: [PATCH 04/52] Do not join icinga_hosts when fetching a service's
 contact groups

refs #8614
---
 .../library/Monitoring/Object/MonitoredObject.php           | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
index 4baa7aa9b..bf417c4f4 100644
--- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
+++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
@@ -426,10 +426,12 @@ abstract class MonitoredObject implements Filterable
         $contactsGroups = $this->backend->select()->from('contactgroup', array(
                 'contactgroup_name',
                 'contactgroup_alias'
-        ))
-            ->where('host_name', $this->host_name);
+        ));
         if ($this->type === self::TYPE_SERVICE) {
+            $contactsGroups->where('service_host_name', $this->host_name);
             $contactsGroups->where('service_description', $this->service_description);
+        } else {
+            $contactsGroups->where('host_name', $this->host_name);
         }
         $this->contactgroups = $contactsGroups->getQuery()->fetchAll();
         return $this;

From 6d436737540132b34099f2c5b2c7402aa14614b5 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 6 Mar 2015 13:13:02 +0100
Subject: [PATCH 05/52] Do not always join host and service status in the
 DowntimeQuery

Now the hoststatus and servicestatus tables are only joined if necessary.

refs #8614
---
 .../Backend/Ido/Query/DowntimeQuery.php       | 44 +++++++++++++------
 1 file changed, 30 insertions(+), 14 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
index 96b0dd5d7..db4305c0d 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
@@ -21,19 +21,26 @@ class DowntimeQuery extends IdoQuery
             'downtime_duration'         => 'sd.duration',
             'downtime_is_in_effect'     => 'sd.is_in_effect',
             'downtime_internal_id'      => 'sd.internal_downtime_id',
+            'downtime_objecttype'       => "CASE WHEN ho.object_id IS NULL THEN 'service' ELSE 'host' END",
             'downtime_host'             => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci', // #7278, #7279
             'host'                      => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END COLLATE latin1_general_ci',
+            'host_name'                 => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END',
             'downtime_service'          => 'so.name2 COLLATE latin1_general_ci',
             'service'                   => 'so.name2 COLLATE latin1_general_ci', // #7278, #7279
-            'downtime_objecttype'       => "CASE WHEN ho.object_id IS NOT NULL THEN 'host' ELSE CASE WHEN so.object_id IS NOT NULL THEN 'service' ELSE NULL END END",
-            'downtime_host_state'       => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END',
-            'downtime_service_state'    => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END'
+            'service_description'       => 'so.name2',
+            'service_host_name'         => 'so.name1'
         ),
         'hosts' => array(
-            'host_display_name'         => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END'
+            'host_display_name'         => 'CASE WHEN h.display_name IS NULL THEN sh.display_name ELSE h.display_name END'
+        ),
+        'hoststatus' => array(
+            'downtime_host_state'       => 'CASE WHEN hs.has_been_checked = 0 OR hs.has_been_checked IS NULL THEN 99 ELSE hs.current_state END'
         ),
         'services' => array(
             'service_display_name'      => 's.display_name'
+        ),
+        'servicestatus' => array(
+            'downtime_service_state'    => 'CASE WHEN ss.has_been_checked = 0 OR ss.has_been_checked IS NULL THEN 99 ELSE ss.current_state END'
         )
     );
 
@@ -53,16 +60,6 @@ class DowntimeQuery extends IdoQuery
             'sd.object_id = so.object_id AND so.is_active = 1 AND so.objecttype_id = 2',
             array()
         );
-        $this->select->joinLeft(
-            array('hs' => $this->prefix . 'hoststatus'),
-            'ho.object_id = hs.host_object_id',
-            array()
-        );
-        $this->select->joinLeft(
-            array('ss' => $this->prefix . 'servicestatus'),
-            'so.object_id = ss.service_object_id',
-            array()
-        );
         $this->joinedVirtualTables = array('downtime' => true);
     }
 
@@ -76,6 +73,15 @@ class DowntimeQuery extends IdoQuery
         return $this;
     }
 
+    protected function joinHoststatus()
+    {
+        $this->select->joinLeft(
+            array('hs' => $this->prefix . 'hoststatus'),
+            'ho.object_id = hs.host_object_id',
+            array()
+        );
+    }
+
     protected function joinServices()
     {
         $this->select->joinLeft(
@@ -90,4 +96,14 @@ class DowntimeQuery extends IdoQuery
         );
         return $this;
     }
+
+    protected function joinServicestatus()
+    {
+        $this->select->joinLeft(
+            array('ss' => $this->prefix . 'servicestatus'),
+            'so.object_id = ss.service_object_id',
+            array()
+        );
+        return $this;
+    }
 }

From db99c323cc85357efa3bcaabe7ad34a99f20bde1 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 6 Mar 2015 13:13:48 +0100
Subject: [PATCH 06/52] Add host and service name columns to the Downtime data
 view

refs #8614
---
 modules/monitoring/library/Monitoring/DataView/Downtime.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/DataView/Downtime.php b/modules/monitoring/library/Monitoring/DataView/Downtime.php
index 54a47e6b4..07123dd4f 100644
--- a/modules/monitoring/library/Monitoring/DataView/Downtime.php
+++ b/modules/monitoring/library/Monitoring/DataView/Downtime.php
@@ -33,7 +33,10 @@ class Downtime extends DataView
             'downtime_host_state',
             'downtime_service_state',
             'host_display_name',
-            'service_display_name'
+            'service_display_name',
+            'host_name',
+            'service_host_name',
+            'service_description'
         );
     }
 

From 7317aa7158198716399a2cd923278b73d0fd63fe Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 6 Mar 2015 13:14:20 +0100
Subject: [PATCH 07/52] Do not join hosts when fetching a service's downtimes

refs #8614
---
 .../library/Monitoring/Object/MonitoredObject.php    | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
index bf417c4f4..0f382f214 100644
--- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
+++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
@@ -281,16 +281,18 @@ abstract class MonitoredObject implements Filterable
             'is_flexible'       => 'downtime_is_flexible',
             'is_fixed'          => 'downtime_is_fixed',
             'is_in_effect'      => 'downtime_is_in_effect',
-            'entry_time'        => 'downtime_entry_time',
-            'host'              => 'downtime_host',
-            'service'           => 'downtime_service'
+            'entry_time'        => 'downtime_entry_time'
         ))
             ->where('downtime_objecttype', $this->type)
-            ->where('downtime_host', $this->host_name)
             ->order('downtime_is_in_effect', 'DESC')
             ->order('downtime_scheduled_start', 'ASC');
         if ($this->type === self::TYPE_SERVICE) {
-            $downtimes->where('downtime_service', $this->service_description);
+            $downtimes
+                ->where('service_host_name', $this->host_name)
+                ->where('service_description', $this->service_description);
+        } else {
+            $downtimes
+                ->where('host_name', $this->host_name);
         }
         $this->downtimes = $downtimes->getQuery()->fetchAll();
         return $this;

From cbf39a2d99bb3b55d3757267c1c2b41816aca72c Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Fri, 6 Mar 2015 13:14:56 +0100
Subject: [PATCH 08/52] Use host_name and service_description columns in the
 downtime overview

refs #8614
---
 modules/monitoring/application/controllers/ListController.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/modules/monitoring/application/controllers/ListController.php b/modules/monitoring/application/controllers/ListController.php
index b1b96b477..6ac7e16ed 100644
--- a/modules/monitoring/application/controllers/ListController.php
+++ b/modules/monitoring/application/controllers/ListController.php
@@ -282,8 +282,8 @@ class Monitoring_ListController extends Controller
             'is_fixed'        => 'downtime_is_fixed',
             'is_in_effect'    => 'downtime_is_in_effect',
             'entry_time'      => 'downtime_entry_time',
-            'host'            => 'downtime_host',
-            'service'         => 'downtime_service',
+            'host'            => 'host_name',
+            'service'         => 'service_description',
             'host_state'      => 'downtime_host_state',
             'service_state'   => 'downtime_service_state',
             'host_display_name',

From 2d3fec9a42f5362b525912aa5f844f56f5dc7344 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 09:57:51 +0100
Subject: [PATCH 09/52] Do not select host_state_type in the service detail
 view

The column host_state_type is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 774511ae3..69717a9ea 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -109,7 +109,6 @@ class Service extends MonitoredObject
             'host_name',
             'host_display_name',
             'host_state',
-            'host_state_type',
             'host_last_state_change',
             'host_address',
             'host_problem',

From 330b575c7cf30c71205814d3de4426c0e12cc37b Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 09:58:36 +0100
Subject: [PATCH 10/52] Remove duplicate service_last_check column from the
 service detail view select

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 69717a9ea..dff8e7c52 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -132,7 +132,6 @@ class Service extends MonitoredObject
             'service_notifications_enabled_changed',
             'service_action_url',
             'service_notes_url',
-            'service_last_check',
             'service_next_check',
             'service_attempt',
             'service_last_notification',

From af4bce35575b4ffcfb182c2c4eb3c11009ee0157 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 10:00:07 +0100
Subject: [PATCH 11/52] Do not select icon_image columns in the service detail
 view

The columns host_icon_image and service_icon_image are not used in the service detail view.

refs #8665
refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 2 --
 1 file changed, 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index dff8e7c52..4d043d878 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -122,7 +122,6 @@ class Service extends MonitoredObject
             'service_unhandled',
             'service_output',
             'service_last_state_change',
-            'service_icon_image',
             'service_long_output',
             'service_is_flapping',
             'service_state_type',
@@ -138,7 +137,6 @@ class Service extends MonitoredObject
             'service_check_command',
             'service_check_source',
             'service_current_notification_number',
-            'host_icon_image',
             'host_acknowledged',
             'host_output',
             'host_long_output',

From b2bb5af0a74be5ee1d7720db50a48a9b177094f3 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:01:41 +0100
Subject: [PATCH 12/52] Don't select host_problem in the service detail view

The column host_problem is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 4d043d878..f182bd065 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -111,7 +111,6 @@ class Service extends MonitoredObject
             'host_state',
             'host_last_state_change',
             'host_address',
-            'host_problem',
             'host_handled',
             'service_description',
             'service_display_name',

From 2ba5e8eb0cab01a61608f8e19f0adc5149930418 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:02:57 +0100
Subject: [PATCH 13/52] Don't select service_unhandled column in the service
 detail view

The column service_unhandled is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index f182bd065..419ef2f12 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -118,7 +118,6 @@ class Service extends MonitoredObject
             'service_in_downtime',
             'service_acknowledged',
             'service_handled',
-            'service_unhandled',
             'service_output',
             'service_last_state_change',
             'service_long_output',

From 6d78ab69ef571a1ac032d40562b564d8069946f3 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:03:55 +0100
Subject: [PATCH 14/52] Don't select service_severity column in the service
 detail view

The column service_severity is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 419ef2f12..45278e79e 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -123,7 +123,6 @@ class Service extends MonitoredObject
             'service_long_output',
             'service_is_flapping',
             'service_state_type',
-            'service_severity',
             'service_last_check',
             'service_notifications_enabled',
             'service_notifications_enabled_changed',

From 9dc6e65e5f1643298ba71ffe4cd1f12d5afa58fa Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:05:39 +0100
Subject: [PATCH 15/52] Don't select host_output column in the service detail
 view

The column host_output is not used in the service detail view

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 45278e79e..99867a09f 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -135,7 +135,6 @@ class Service extends MonitoredObject
             'service_check_source',
             'service_current_notification_number',
             'host_acknowledged',
-            'host_output',
             'host_long_output',
             'host_in_downtime',
             'host_is_flapping',

From da7f959db5c68644f0bfc7e3438692d5bdf42ffb Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:09:59 +0100
Subject: [PATCH 16/52] Don't select host_long_output in the service detail
 view

The column host_long_output is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 99867a09f..25730d448 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -135,7 +135,6 @@ class Service extends MonitoredObject
             'service_check_source',
             'service_current_notification_number',
             'host_acknowledged',
-            'host_long_output',
             'host_in_downtime',
             'host_is_flapping',
             'host_last_check',

From 151d87f38ca730e6f7776d0418caee27f9ad7fab Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:19:37 +0100
Subject: [PATCH 17/52] Don't select host_is_flapping in the service detail
 view

The column host_is_flapping is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 25730d448..82975de85 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -136,7 +136,6 @@ class Service extends MonitoredObject
             'service_current_notification_number',
             'host_acknowledged',
             'host_in_downtime',
-            'host_is_flapping',
             'host_last_check',
             'host_notifications_enabled',
             'host_unhandled_services',

From 4102ee290b338d640bf7a2c92e01b14204593bf1 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:22:28 +0100
Subject: [PATCH 18/52] Don't select host_last_check in the service detail view

The column host_last_check is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 82975de85..23a89454e 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -136,7 +136,6 @@ class Service extends MonitoredObject
             'service_current_notification_number',
             'host_acknowledged',
             'host_in_downtime',
-            'host_last_check',
             'host_notifications_enabled',
             'host_unhandled_services',
             'host_action_url',

From b9ec2844f5191f445f974249afe5eef456f876a4 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:25:25 +0100
Subject: [PATCH 19/52] Don't select host_unhandled_services in the service
 detail view

The column host_unhandled_services is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 23a89454e..8be746d88 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -137,7 +137,6 @@ class Service extends MonitoredObject
             'host_acknowledged',
             'host_in_downtime',
             'host_notifications_enabled',
-            'host_unhandled_services',
             'host_action_url',
             'host_notes_url',
             'host_display_name',

From 0f65f83374481a7d264c84dcddffe81a38c30fe6 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:26:47 +0100
Subject: [PATCH 20/52] Don't select host_action_url in the service detail view

The column host_action_url is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 8be746d88..acfddd90f 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -137,7 +137,6 @@ class Service extends MonitoredObject
             'host_acknowledged',
             'host_in_downtime',
             'host_notifications_enabled',
-            'host_action_url',
             'host_notes_url',
             'host_display_name',
             'host_alias',

From 5f57e290c72ef991637ed7c7ba78383aebb7db59 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:27:07 +0100
Subject: [PATCH 21/52] Don't select host_notes_url in the service detail view

The column host_notes_url is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index acfddd90f..647ae5ca6 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -137,7 +137,6 @@ class Service extends MonitoredObject
             'host_acknowledged',
             'host_in_downtime',
             'host_notifications_enabled',
-            'host_notes_url',
             'host_display_name',
             'host_alias',
             'host_ipv4',

From 9146a62573207f7cadec00a2829524df63271fa3 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:28:44 +0100
Subject: [PATCH 22/52] Don't select host_ipv4 in the service detail view

The column host_ipv4 is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 647ae5ca6..8fa495648 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -139,7 +139,6 @@ class Service extends MonitoredObject
             'host_notifications_enabled',
             'host_display_name',
             'host_alias',
-            'host_ipv4',
             'host_severity',
             'host_perfdata',
             'host_active_checks_enabled',

From e1dbe0b9a75ffebce4e4844f43468fca87998d91 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:29:39 +0100
Subject: [PATCH 23/52] Don't select host_severity in the service detail view

The column host_severity is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 8fa495648..8412d8542 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -139,7 +139,6 @@ class Service extends MonitoredObject
             'host_notifications_enabled',
             'host_display_name',
             'host_alias',
-            'host_severity',
             'host_perfdata',
             'host_active_checks_enabled',
             'host_passive_checks_enabled',

From 232b3d3a9f52e6fa5b03b2e11629dce1b7775ae1 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:30:03 +0100
Subject: [PATCH 24/52] Don't select host_perfdata in the service detail view

The column host_perfdata is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 8412d8542..e2c3fe801 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -139,7 +139,6 @@ class Service extends MonitoredObject
             'host_notifications_enabled',
             'host_display_name',
             'host_alias',
-            'host_perfdata',
             'host_active_checks_enabled',
             'host_passive_checks_enabled',
             'host_last_hard_state',

From 2cbeab55daa51c65a5da1a43145fc43620638eeb Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:31:32 +0100
Subject: [PATCH 25/52] Don't select host_last_hard_state* in the service
 detail view

The columns host_last_hard_state and host_last_hard_state_change are not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 2 --
 1 file changed, 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index e2c3fe801..88a62294b 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -141,8 +141,6 @@ class Service extends MonitoredObject
             'host_alias',
             'host_active_checks_enabled',
             'host_passive_checks_enabled',
-            'host_last_hard_state',
-            'host_last_hard_state_change',
             'host_last_time_up',
             'host_last_time_down',
             'host_last_time_unreachable',

From 34ad174f89d4532ce757a3e03ea7a8a93378d392 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:32:28 +0100
Subject: [PATCH 26/52] Don't select host_last_time_* in the service detail
 view

The columns host_last_time_ up, down and unreachable are not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 88a62294b..810b326d9 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -141,9 +141,6 @@ class Service extends MonitoredObject
             'host_alias',
             'host_active_checks_enabled',
             'host_passive_checks_enabled',
-            'host_last_time_up',
-            'host_last_time_down',
-            'host_last_time_unreachable',
             'host_modified_host_attributes',
             'host',
             'service',

From d65aa39ebd862673d926ca94f337fa70d8108393 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:33:17 +0100
Subject: [PATCH 27/52] Don't select host_modified_host_attributes in the
 service detail view

The column host_modified_host_attributes is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 810b326d9..16cb64e0c 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -141,7 +141,6 @@ class Service extends MonitoredObject
             'host_alias',
             'host_active_checks_enabled',
             'host_passive_checks_enabled',
-            'host_modified_host_attributes',
             'host',
             'service',
             'service_hard_state',

From 4e308016bfd48fa3b96e6048c3c79ab228f30537 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:37:40 +0100
Subject: [PATCH 28/52] Don't select service_hard_state in the service detail
 view

The column service_hard_state is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 16cb64e0c..526e367d6 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -143,7 +143,6 @@ class Service extends MonitoredObject
             'host_passive_checks_enabled',
             'host',
             'service',
-            'service_hard_state',
             'service_problem',
             'service_perfdata',
             'service_active_checks_enabled',

From 3bbd68dc95f0f9403738a203398bf7e47fca86bc Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:38:12 +0100
Subject: [PATCH 29/52] Don't select service_problem in the service detail view

The column service_problem is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 526e367d6..ce60d6c69 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -143,7 +143,6 @@ class Service extends MonitoredObject
             'host_passive_checks_enabled',
             'host',
             'service',
-            'service_problem',
             'service_perfdata',
             'service_active_checks_enabled',
             'service_active_checks_enabled_changed',

From 88dce0c1f4f578779227651ee6278c9d6cc1fc9d Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:38:30 +0100
Subject: [PATCH 30/52] Don't select host and service columns in the service
 detail view

The columns host and service are not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 2 --
 1 file changed, 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index ce60d6c69..7e792c3c1 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -141,8 +141,6 @@ class Service extends MonitoredObject
             'host_alias',
             'host_active_checks_enabled',
             'host_passive_checks_enabled',
-            'host',
-            'service',
             'service_perfdata',
             'service_active_checks_enabled',
             'service_active_checks_enabled_changed',

From 70ef6263b2ab3c63197b13e00c7afb1d41df0572 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:45:20 +0100
Subject: [PATCH 31/52] Don't select service_last_hard_state* in the service
 detail view

The columns service_last_hard_state and service_last_hard_state_change are not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 2 --
 1 file changed, 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 7e792c3c1..242870231 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -146,8 +146,6 @@ class Service extends MonitoredObject
             'service_active_checks_enabled_changed',
             'service_passive_checks_enabled',
             'service_passive_checks_enabled_changed',
-            'service_last_hard_state',
-            'service_last_hard_state_change',
             'service_last_time_ok',
             'service_last_time_warning',
             'service_last_time_critical',

From 0cc6b5d0c2851e738316a2efd5e5581346b2716d Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:46:09 +0100
Subject: [PATCH 32/52] Don't select service_last_time_* in the service detail
 view

The columns service_last_time_ ok, warning, critical and unknown are not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 242870231..6ef118973 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -146,10 +146,6 @@ class Service extends MonitoredObject
             'service_active_checks_enabled_changed',
             'service_passive_checks_enabled',
             'service_passive_checks_enabled_changed',
-            'service_last_time_ok',
-            'service_last_time_warning',
-            'service_last_time_critical',
-            'service_last_time_unknown',
             'service_check_execution_time',
             'service_check_latency',
             'service_current_check_attempt',

From 87e5bdfa4cb0105c8be9f84d8f3d265d370cc083 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 13:47:20 +0100
Subject: [PATCH 33/52] Do not select columns for check attempt twice in the
 service detail view

The column service_attempt is used in favor of service_current_check_attempt and service_max_check_attempts.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 2 --
 1 file changed, 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 6ef118973..ee59ed806 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -148,8 +148,6 @@ class Service extends MonitoredObject
             'service_passive_checks_enabled_changed',
             'service_check_execution_time',
             'service_check_latency',
-            'service_current_check_attempt',
-            'service_max_check_attempts',
             'service_obsessing',
             'service_obsessing_changed',
             'service_event_handler_enabled',

From 62f0f5b6a4d890c8ef9200b34a81ff1096fa500c Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 14:00:17 +0100
Subject: [PATCH 34/52] Don't select service_modified_service_attributes in the
 service detail view

The column service_modified_service_attributes is not used in the service detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index ee59ed806..93328a48c 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -154,7 +154,6 @@ class Service extends MonitoredObject
             'service_event_handler_enabled_changed',
             'service_flap_detection_enabled',
             'service_flap_detection_enabled_changed',
-            'service_modified_service_attributes',
             'service_process_performance_data',
             'process_perfdata' => 'service_process_performance_data',
             'service_percent_state_change',

From e0acebf474d90e35c6635e86d5a1dd17d579b82b Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 14:09:53 +0100
Subject: [PATCH 35/52] Don't select service_host_name in the service detail
 view

We already select the host_name.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 93328a48c..2ffc5a74b 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -156,8 +156,7 @@ class Service extends MonitoredObject
             'service_flap_detection_enabled_changed',
             'service_process_performance_data',
             'process_perfdata' => 'service_process_performance_data',
-            'service_percent_state_change',
-            'service_host_name'
+            'service_percent_state_change'
         ))
             ->where('host_name', $this->host->getName())
             ->where('service_description', $this->service);

From fcb94af93c4a55d8dcab661eb9f5c588ec952cce Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 14:11:50 +0100
Subject: [PATCH 36/52] Don't select service_process_performance_data twice in
 the service detail view

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 2ffc5a74b..9599a51cb 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -154,8 +154,7 @@ class Service extends MonitoredObject
             'service_event_handler_enabled_changed',
             'service_flap_detection_enabled',
             'service_flap_detection_enabled_changed',
-            'service_process_performance_data',
-            'process_perfdata' => 'service_process_performance_data',
+            'service_process_perfdata' => 'service_process_performance_data',
             'service_percent_state_change'
         ))
             ->where('host_name', $this->host->getName())

From e6949eaab4d56e4b770b30ce67e291426ca68fb8 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 14:17:09 +0100
Subject: [PATCH 37/52] Reorder columns to select in the Service object

refs #8614
---
 .../library/Monitoring/Object/Service.php     | 76 +++++++++----------
 1 file changed, 38 insertions(+), 38 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index 9599a51cb..fc317fc8d 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -106,56 +106,56 @@ class Service extends MonitoredObject
     protected function getDataView()
     {
         return $this->backend->select()->from('serviceStatus', array(
-            'host_name',
-            'host_display_name',
-            'host_state',
-            'host_last_state_change',
-            'host_address',
-            'host_handled',
-            'service_description',
-            'service_display_name',
-            'service_state',
-            'service_in_downtime',
-            'service_acknowledged',
-            'service_handled',
-            'service_output',
-            'service_last_state_change',
-            'service_long_output',
-            'service_is_flapping',
-            'service_state_type',
-            'service_last_check',
-            'service_notifications_enabled',
-            'service_notifications_enabled_changed',
-            'service_action_url',
-            'service_notes_url',
-            'service_next_check',
-            'service_attempt',
-            'service_last_notification',
-            'service_check_command',
-            'service_check_source',
-            'service_current_notification_number',
             'host_acknowledged',
-            'host_in_downtime',
-            'host_notifications_enabled',
-            'host_display_name',
-            'host_alias',
             'host_active_checks_enabled',
+            'host_address',
+            'host_alias',
+            'host_display_name',
+            'host_display_name',
+            'host_handled',
+            'host_in_downtime',
+            'host_last_state_change',
+            'host_name',
+            'host_notifications_enabled',
             'host_passive_checks_enabled',
-            'service_perfdata',
+            'host_state',
+            'service_acknowledged',
+            'service_action_url',
             'service_active_checks_enabled',
             'service_active_checks_enabled_changed',
-            'service_passive_checks_enabled',
-            'service_passive_checks_enabled_changed',
+            'service_attempt',
+            'service_check_command',
             'service_check_execution_time',
             'service_check_latency',
-            'service_obsessing',
-            'service_obsessing_changed',
+            'service_check_source',
+            'service_current_notification_number',
+            'service_description',
+            'service_display_name',
             'service_event_handler_enabled',
             'service_event_handler_enabled_changed',
             'service_flap_detection_enabled',
             'service_flap_detection_enabled_changed',
+            'service_handled',
+            'service_in_downtime',
+            'service_is_flapping',
+            'service_last_check',
+            'service_last_notification',
+            'service_last_state_change',
+            'service_long_output',
+            'service_next_check',
+            'service_notes_url',
+            'service_notifications_enabled',
+            'service_notifications_enabled_changed',
+            'service_obsessing',
+            'service_obsessing_changed',
+            'service_output',
+            'service_passive_checks_enabled',
+            'service_passive_checks_enabled_changed',
+            'service_percent_state_change',
+            'service_perfdata',
             'service_process_perfdata' => 'service_process_performance_data',
-            'service_percent_state_change'
+            'service_state',
+            'service_state_type'
         ))
             ->where('host_name', $this->host->getName())
             ->where('service_description', $this->service);

From 5ed6838f509e5877b301776c20d40e6a70efe1fa Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Tue, 10 Mar 2015 14:18:08 +0100
Subject: [PATCH 38/52] Don't select host_display_name twice in the service
 detail view

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Service.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php
index fc317fc8d..4195b0ff4 100644
--- a/modules/monitoring/library/Monitoring/Object/Service.php
+++ b/modules/monitoring/library/Monitoring/Object/Service.php
@@ -111,7 +111,6 @@ class Service extends MonitoredObject
             'host_address',
             'host_alias',
             'host_display_name',
-            'host_display_name',
             'host_handled',
             'host_in_downtime',
             'host_last_state_change',

From 132ae9e44c645c04a16a5a8cae5d8cb536068697 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 10:43:19 +0100
Subject: [PATCH 39/52] Use {@inheritdoc} in the Comment data view ...

... instead of duplicating method documentation.

refs #8614
---
 .../monitoring/library/Monitoring/DataView/Comment.php    | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/DataView/Comment.php b/modules/monitoring/library/Monitoring/DataView/Comment.php
index f2d98895c..5172690bb 100644
--- a/modules/monitoring/library/Monitoring/DataView/Comment.php
+++ b/modules/monitoring/library/Monitoring/DataView/Comment.php
@@ -9,9 +9,7 @@ namespace Icinga\Module\Monitoring\DataView;
 class Comment extends DataView
 {
     /**
-     * Retrieve columns provided by this view
-     *
-     * @return array
+     * {@inheritdoc}
      */
     public function getColumns()
     {
@@ -34,9 +32,7 @@ class Comment extends DataView
     }
 
     /**
-     * Retrieve default sorting rules for particular columns. These involve sort order and potential additional to sort
-     *
-     * @return array
+     * {@inheritdoc}
      */
     public function getSortRules()
     {

From c69a46d005959afae483571fc63d415d55bfedfc Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 11:30:38 +0100
Subject: [PATCH 40/52] Add PHPDoc to the Downtime query

refs #8614
---
 .../Backend/Ido/Query/DowntimeQuery.php       | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
index db4305c0d..f1981ef7f 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
@@ -3,8 +3,14 @@
 
 namespace Icinga\Module\Monitoring\Backend\Ido\Query;
 
+/**
+ * Query for host and service downtimes
+ */
 class DowntimeQuery extends IdoQuery
 {
+    /**
+     * {@inheritdoc}
+     */
     protected $columnMap = array(
         'downtime' => array(
             'downtime_author'           => 'sd.author_name',
@@ -44,6 +50,9 @@ class DowntimeQuery extends IdoQuery
         )
     );
 
+    /**
+     * {@inheritdoc}
+     */
     protected function joinBaseTables()
     {
         $this->select->from(
@@ -63,6 +72,11 @@ class DowntimeQuery extends IdoQuery
         $this->joinedVirtualTables = array('downtime' => true);
     }
 
+    /**
+     * Join downtimes' hosts
+     *
+     * @return $this
+     */
     protected function joinHosts()
     {
         $this->select->joinLeft(
@@ -73,6 +87,11 @@ class DowntimeQuery extends IdoQuery
         return $this;
     }
 
+    /**
+     * Join downtimes' hosts' status
+     *
+     * @return $this
+     */
     protected function joinHoststatus()
     {
         $this->select->joinLeft(
@@ -80,8 +99,14 @@ class DowntimeQuery extends IdoQuery
             'ho.object_id = hs.host_object_id',
             array()
         );
+        return $this;
     }
 
+    /**
+     * Join downtimes' services
+     *
+     * @return $this
+     */
     protected function joinServices()
     {
         $this->select->joinLeft(
@@ -97,6 +122,11 @@ class DowntimeQuery extends IdoQuery
         return $this;
     }
 
+    /**
+     * Join downtimes' services' status
+     *
+     * @return $this
+     */
     protected function joinServicestatus()
     {
         $this->select->joinLeft(

From ea32d3dfb31cd92cfe89a85165be08e13c6d3851 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 11:54:23 +0100
Subject: [PATCH 41/52] Add PHPDoc to the EventHistory query

refs #8614
---
 .../Backend/Ido/Query/EventHistoryQuery.php   | 44 ++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php
index 12395abca..370fad9af 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php
@@ -6,10 +6,23 @@ namespace Icinga\Module\Monitoring\Backend\Ido\Query;
 use Zend_Db_Select;
 use Icinga\Data\Filter\Filter;
 
+/**
+ * Query for event history
+ */
 class EventHistoryQuery extends IdoQuery
 {
+    /**
+     * Subqueries used for the event history query
+     *
+     * @type    IdoQuery[]
+     *
+     * @see     EventHistoryQuery::joinBaseTables() For the used subqueries.
+     */
     protected $subQueries = array();
 
+    /**
+     * {@inheritdoc}
+     */
     protected $columnMap = array(
         'eventhistory' => array(
             'cnt_notification'      => "SUM(CASE eh.type WHEN 'notify' THEN 1 ELSE 0 END)",
@@ -41,8 +54,14 @@ class EventHistoryQuery extends IdoQuery
         )
     );
 
+    /**
+     * {@inheritdoc}
+     */
     protected $useSubqueryCount = true;
 
+    /**
+     * {@inheritdoc}
+     */
     protected function joinBaseTables()
     {
         $columns = array(
@@ -77,15 +96,20 @@ class EventHistoryQuery extends IdoQuery
         $this->joinedVirtualTables = array('eventhistory' => true);
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function order($columnOrAlias, $dir = null)
     {
         foreach ($this->subQueries as $sub) {
             $sub->requireColumn($columnOrAlias);
         }
-
         return parent::order($columnOrAlias, $dir);
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function addFilter(Filter $filter)
     {
         foreach ($this->subQueries as $sub) {
@@ -94,6 +118,9 @@ class EventHistoryQuery extends IdoQuery
         return $this;
     }
 
+    /**
+     * {@inheritdoc}
+     */
     public function where($condition, $value = null)
     {
         $this->requireColumn($condition);
@@ -103,6 +130,11 @@ class EventHistoryQuery extends IdoQuery
         return $this;
     }
 
+    /**
+     * Join host groups
+     *
+     * @return $this
+     */
     protected function joinHostgroups()
     {
         $this->select->join(
@@ -121,6 +153,11 @@ class EventHistoryQuery extends IdoQuery
         return $this;
     }
 
+    /**
+     * Join hosts
+     *
+     * @return $this
+     */
     protected function joinHosts()
     {
         $this->select->joinLeft(
@@ -131,6 +168,11 @@ class EventHistoryQuery extends IdoQuery
         return $this;
     }
 
+    /**
+     * Join services
+     *
+     * @return $this
+     */
     protected function joinServices()
     {
         $this->select->joinLeft(

From e72670cb753db1f9cb96751a9f42200f93b356e2 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 12:03:05 +0100
Subject: [PATCH 42/52] Use default sorting for an object's event history

refs #8614
---
 modules/monitoring/library/Monitoring/Object/MonitoredObject.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
index 0f382f214..38053f5a2 100644
--- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
+++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
@@ -459,7 +459,6 @@ abstract class MonitoredObject implements Filterable
                 'output',
                 'type'
         ))
-            ->order('timestamp', 'DESC')
             ->where('host_name', $this->host_name);
         if ($this->type === self::TYPE_SERVICE) {
             $eventHistory->where('service_description', $this->service_description);

From 37d09511c630e6217e9b4ba3e986ac49db401b67 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 13:07:33 +0100
Subject: [PATCH 43/52] Don't select host_modified_host_attributes in the host
 detail view

The column host_modified_host_attributes is not used in the host detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Host.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php
index 273c65eae..93db2b815 100644
--- a/modules/monitoring/library/Monitoring/Object/Host.php
+++ b/modules/monitoring/library/Monitoring/Object/Host.php
@@ -128,7 +128,6 @@ class Host extends MonitoredObject
             'host_is_flapping',
             'host_action_url',
             'host_notes_url',
-            'host_modified_host_attributes',
             'host_problem',
             'host_process_performance_data',
             'process_perfdata' => 'host_process_performance_data'

From 84f56f4e5185feabb77680c41e8e5a356dd913ed Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 13:08:11 +0100
Subject: [PATCH 44/52] Don't select host_problem in the host detail view

The column host_problem is not used in the host detail view.

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Host.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php
index 93db2b815..502be01a1 100644
--- a/modules/monitoring/library/Monitoring/Object/Host.php
+++ b/modules/monitoring/library/Monitoring/Object/Host.php
@@ -128,7 +128,6 @@ class Host extends MonitoredObject
             'host_is_flapping',
             'host_action_url',
             'host_notes_url',
-            'host_problem',
             'host_process_performance_data',
             'process_perfdata' => 'host_process_performance_data'
         );

From ef4970c0c13d11280e12fcdd604d83558ead7b33 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 13:08:53 +0100
Subject: [PATCH 45/52] Don't select host_process_performance_data twice in the
 host detail view

refs #8614
---
 modules/monitoring/library/Monitoring/Object/Host.php | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php
index 502be01a1..7c132c22b 100644
--- a/modules/monitoring/library/Monitoring/Object/Host.php
+++ b/modules/monitoring/library/Monitoring/Object/Host.php
@@ -128,8 +128,7 @@ class Host extends MonitoredObject
             'host_is_flapping',
             'host_action_url',
             'host_notes_url',
-            'host_process_performance_data',
-            'process_perfdata' => 'host_process_performance_data'
+            'host_process_perfdata' => 'host_process_performance_data'
         );
         if ($this->backend->getType() === 'livestatus') {
             $columns[] = 'host_contacts';

From b501fef62b3000453dd4761b4f51b073a5399165 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 13:10:55 +0100
Subject: [PATCH 46/52] Rearrange columns in the Host object

refs #8614
---
 .../library/Monitoring/Object/Host.php        | 60 +++++++++----------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/Host.php b/modules/monitoring/library/Monitoring/Object/Host.php
index 7c132c22b..359065e57 100644
--- a/modules/monitoring/library/Monitoring/Object/Host.php
+++ b/modules/monitoring/library/Monitoring/Object/Host.php
@@ -89,46 +89,46 @@ class Host extends MonitoredObject
     protected function getDataView()
     {
         $columns = array(
-            'host_name',
-            'host_display_name',
-            'host_alias',
-            'host_address',
-            'host_state',
-            'host_state_type',
-            'host_handled',
-            'host_in_downtime',
             'host_acknowledged',
-            'host_last_state_change',
-            'host_last_notification',
-            'host_last_check',
-            'host_next_check',
+            'host_action_url',
+            'host_active_checks_enabled',
+            'host_active_checks_enabled_changed',
+            'host_address',
+            'host_alias',
+            'host_check_command',
             'host_check_execution_time',
             'host_check_latency',
             'host_check_source',
-            'host_output',
-            'host_long_output',
-            'host_check_command',
-            'host_perfdata',
-            'host_passive_checks_enabled',
-            'host_passive_checks_enabled_changed',
-            'host_obsessing',
-            'host_obsessing_changed',
-            'host_notifications_enabled',
-            'host_notifications_enabled_changed',
+            'host_current_check_attempt',
+            'host_current_notification_number',
+            'host_display_name',
             'host_event_handler_enabled',
             'host_event_handler_enabled_changed',
             'host_flap_detection_enabled',
             'host_flap_detection_enabled_changed',
-            'host_active_checks_enabled',
-            'host_active_checks_enabled_changed',
-            'host_current_check_attempt',
-            'host_max_check_attempts',
-            'host_current_notification_number',
-            'host_percent_state_change',
+            'host_handled',
+            'host_in_downtime',
             'host_is_flapping',
-            'host_action_url',
+            'host_last_check',
+            'host_last_notification',
+            'host_last_state_change',
+            'host_long_output',
+            'host_max_check_attempts',
+            'host_name',
+            'host_next_check',
             'host_notes_url',
-            'host_process_perfdata' => 'host_process_performance_data'
+            'host_notifications_enabled',
+            'host_notifications_enabled_changed',
+            'host_obsessing',
+            'host_obsessing_changed',
+            'host_output',
+            'host_passive_checks_enabled',
+            'host_passive_checks_enabled_changed',
+            'host_percent_state_change',
+            'host_perfdata',
+            'host_process_perfdata' => 'host_process_performance_data',
+            'host_state',
+            'host_state_type'
         );
         if ($this->backend->getType() === 'livestatus') {
             $columns[] = 'host_contacts';

From 0286641369d39c7aa47c6051b38099e178919b66 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 13:32:54 +0100
Subject: [PATCH 47/52] Don't fetch comments and downtimes twice in an object's
 detail view

The controller counts comments and downtimes on the object, which will automatically fetch comments and downtimes.
After that came a call to MonitoredObject::populate() which again fetched comments and downtimes.
Now the object is populated before counting comments and dowtimes.

refs #8614
---
 .../Monitoring/Web/Controller/MonitoredObjectController.php    | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
index f553c12f3..1b8fd2336 100644
--- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
+++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
@@ -73,6 +73,7 @@ abstract class MonitoredObjectController extends Controller
                 }
             }
         }
+        $this->object->populate();
         if (count($this->object->comments) > 0 && $auth->hasPermission('monitoring/command/comment/delete')) {
             $delCommentForm = new DeleteCommentCommandForm();
             $delCommentForm
@@ -93,7 +94,7 @@ abstract class MonitoredObjectController extends Controller
             ->setObjects($this->object)
             ->handleRequest();
         $this->view->toggleFeaturesForm = $toggleFeaturesForm;
-        $this->view->object = $this->object->populate();
+        $this->view->object = $this->object;
     }
 
     /**

From 361afdcf13fe488c0d42cb63fb2883b7becc2710 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Wed, 11 Mar 2015 14:08:43 +0100
Subject: [PATCH 48/52] Use ! empty in favor of count > 0 in the
 MonitoredObjectController

refs #8614
---
 .../Controller/MonitoredObjectController.php  | 28 +++++++++----------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
index 1b8fd2336..04102e9d2 100644
--- a/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
+++ b/modules/monitoring/library/Monitoring/Web/Controller/MonitoredObjectController.php
@@ -74,26 +74,26 @@ abstract class MonitoredObjectController extends Controller
             }
         }
         $this->object->populate();
-        if (count($this->object->comments) > 0 && $auth->hasPermission('monitoring/command/comment/delete')) {
-            $delCommentForm = new DeleteCommentCommandForm();
-            $delCommentForm
-                ->setObjects($this->object)
-                ->handleRequest();
-            $this->view->delCommentForm = $delCommentForm;
-        }
-        if (count($this->object->downtimes > 0) && $auth->hasPermission('monitoring/command/downtime/delete')) {
-            $delDowntimeForm = new DeleteDowntimeCommandForm();
-            $delDowntimeForm
-                ->setObjects($this->object)
-                ->handleRequest();
-            $this->view->delDowntimeForm = $delDowntimeForm;
-        }
         $toggleFeaturesForm = new ToggleObjectFeaturesCommandForm();
         $toggleFeaturesForm
             ->load($this->object)
             ->setObjects($this->object)
             ->handleRequest();
         $this->view->toggleFeaturesForm = $toggleFeaturesForm;
+        if (! empty($this->object->comments) && $auth->hasPermission('monitoring/command/comment/delete')) {
+            $delCommentForm = new DeleteCommentCommandForm();
+            $delCommentForm
+                ->setObjects($this->object)
+                ->handleRequest();
+            $this->view->delCommentForm = $delCommentForm;
+        }
+        if (! empty($this->object->downtimes) && $auth->hasPermission('monitoring/command/downtime/delete')) {
+            $delDowntimeForm = new DeleteDowntimeCommandForm();
+            $delDowntimeForm
+                ->setObjects($this->object)
+                ->handleRequest();
+            $this->view->delDowntimeForm = $delDowntimeForm;
+        }
         $this->view->object = $this->object;
     }
 

From 7212434856723f16425420aa243bac307227da00 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Thu, 12 Mar 2015 16:32:05 +0100
Subject: [PATCH 49/52] Remove COLLATE from host_name and service_description
 in the Contact query

refs #8614
refs #8613
---
 .../library/Monitoring/Backend/Ido/Query/ContactQuery.php   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
index a55f582ee..1b5e744d4 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
@@ -34,12 +34,12 @@ class ContactQuery extends IdoQuery
         ),
         'hosts' => array(
             'host'      => 'ho.name1 COLLATE latin1_general_ci',
-            'host_name' => 'ho.name1 COLLATE latin1_general_ci',
+            'host_name' => 'ho.name1',
         ),
         'services' => array(
             'service'               => 'so.name1 COLLATE latin1_general_ci',
-            'service_description'   => 'so.name2 COLLATE latin1_general_ci',
-            'service_host_name'     => 'so.name1 COLLATE latin1_general_ci',
+            'service_description'   => 'so.name2',
+            'service_host_name'     => 'so.name1',
         )
     );
 

From 112f8eb2f9b51a58d04f796e5f91b6ac4cb92149 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Thu, 12 Mar 2015 16:33:28 +0100
Subject: [PATCH 50/52] Remove COLLATE from host_name and service_description
 in the Contactgroup query

refs #8614
refs #8613
---
 .../Monitoring/Backend/Ido/Query/ContactgroupQuery.php      | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
index c19670e8d..cf1586626 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
@@ -33,13 +33,13 @@ class ContactgroupQuery extends IdoQuery
             'contact_notify_host_downtime'      => 'c.notify_host_downtime',
         ),
         'hosts' => array(
-            'host'      => 'ho.name1',
+            'host'      => 'ho.name1 COLLATE latin1_general_ci',
             'host_name' => 'ho.name1'
         ),
         'services' => array(
             'service'               => 'so.name2 COLLATE latin1_general_ci',
-            'service_description'   => 'so.name2 COLLATE latin1_general_ci',
-            'service_host_name'     => 'so.name1 COLLATE latin1_general_ci'
+            'service_description'   => 'so.name2',
+            'service_host_name'     => 'so.name1'
         )
     );
 

From 29b5e4fd4331c3ff00bfde1fac7602d316b9ec4c Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Thu, 12 Mar 2015 16:38:32 +0100
Subject: [PATCH 51/52] Add host_name and service_description columns w/o
 collation to the comment query

refs #8614
---
 .../library/Monitoring/Backend/Ido/Query/CommentQuery.php      | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php
index ce72de5a2..1348371d3 100644
--- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php
+++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php
@@ -22,6 +22,9 @@ class CommentQuery extends IdoQuery
             'comment_service'       => 'so.name2 COLLATE latin1_general_ci',
             'service'               => 'so.name2 COLLATE latin1_general_ci', // #7278, #7279
             'comment_objecttype'    => "CASE WHEN ho.object_id IS NOT NULL THEN 'host' ELSE CASE WHEN so.object_id IS NOT NULL THEN 'service' ELSE NULL END END",
+            'service_description'   => 'so.name2',
+            'host_name'             => 'CASE WHEN ho.name1 IS NULL THEN so.name1 ELSE ho.name1 END',
+            'service_host_name'     => 'so.name1'
         ),
         'hosts' => array(
             'host_display_name'     => 'CASE WHEN sh.display_name IS NOT NULL THEN sh.display_name ELSE h.display_name END'

From 7156bd7dfb24526d7d4cfb82030b1abd367cf621 Mon Sep 17 00:00:00 2001
From: Eric Lippmann <eric.lippmann@netways.de>
Date: Thu, 12 Mar 2015 16:39:20 +0100
Subject: [PATCH 52/52] Fetch object comments by host_name and
 service_description

refs #8614
---
 .../Monitoring/Object/MonitoredObject.php     | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
index 38053f5a2..f50d7249c 100644
--- a/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
+++ b/modules/monitoring/library/Monitoring/Object/MonitoredObject.php
@@ -253,10 +253,13 @@ abstract class MonitoredObject implements Filterable
             'type'      => 'comment_type',
         ))
             ->where('comment_type', array('comment', 'ack'))
-            ->where('comment_objecttype', $this->type)
-            ->where('comment_host', $this->host_name);
+            ->where('comment_objecttype', $this->type);
         if ($this->type === self::TYPE_SERVICE) {
-            $comments->where('comment_service', $this->service_description);
+            $comments
+                ->where('service_host_name', $this->host_name)
+                ->where('service_description', $this->service_description);
+        } else {
+            $comments->where('host_name', $this->host_name);
         }
         $this->comments = $comments->getQuery()->fetchAll();
         return $this;
@@ -387,8 +390,9 @@ abstract class MonitoredObject implements Filterable
                 'contact_pager',
         ));
         if ($this->type === self::TYPE_SERVICE) {
-            $contacts->where('service_host_name', $this->host_name);
-            $contacts->where('service_description', $this->service_description);
+            $contacts
+                ->where('service_host_name', $this->host_name)
+                ->where('service_description', $this->service_description);
         } else {
             $contacts->where('host_name', $this->host_name);
         }
@@ -430,8 +434,9 @@ abstract class MonitoredObject implements Filterable
                 'contactgroup_alias'
         ));
         if ($this->type === self::TYPE_SERVICE) {
-            $contactsGroups->where('service_host_name', $this->host_name);
-            $contactsGroups->where('service_description', $this->service_description);
+            $contactsGroups
+                ->where('service_host_name', $this->host_name)
+                ->where('service_description', $this->service_description);
         } else {
             $contactsGroups->where('host_name', $this->host_name);
         }