[icinga-checkins] icinga.org: icinga-web/support/1.9: Fix multiple problems with the Downtime related views

git at icinga.org git at icinga.org
Fri May 31 11:04:50 CEST 2013


Module: icinga-web
Branch: support/1.9
Commit: 5dfc7d5f53d9a94a3876deef4f368b1cb379c9e8
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=5dfc7d5f53d9a94a3876deef4f368b1cb379c9e8

Author: Markus Frosch <markus at lazyfrosch.de>
Date:   Wed May 29 17:46:53 2013 +0200

Fix multiple problems with the Downtime related views

* Host status not being displayed on service downtimes
* Credentials for host/servicegroups and contactgroups
  were not applied correctly
* Added a filter to support filtering by host_state
  (needed due to the first fix here)
* some smaller cleanup

refs #4205

---

 app/modules/Api/config/views/misc.xml |   85 +++++++++++++--------------------
 1 files changed, 34 insertions(+), 51 deletions(-)

diff --git a/app/modules/Api/config/views/misc.xml b/app/modules/Api/config/views/misc.xml
index 51df304..565f8d1 100644
--- a/app/modules/Api/config/views/misc.xml
+++ b/app/modules/Api/config/views/misc.xml
@@ -40,14 +40,14 @@
         <dql name="TARGET_DOWNTIME">
             <query>
             <![CDATA[
-                SELECT
+                SELECT DISTINCT
                     i.instance_name AS INSTANCE_NAME,
                     d.scheduleddowntime_id   AS DOWNTIME_ID,
                     d.internal_downtime_id AS DOWNTIME_INTERNAL_DOWNTIME_ID,
                     d.downtime_type AS DOWNTIME_DOWNTIME_TYPE,
                     COALESCE(h.host_object_id,sh.host_object_id)   AS HOST_OBJECT_ID,
                     o.name1 AS HOST_NAME,
-                    hs.current_state AS HOST_CURRENT_STATE,
+                    COALESCE(hs.current_state,shs.current_state) AS HOST_CURRENT_STATE,
                     s.service_object_id AS SERVICE_OBJECT_ID,
                     o.name2 AS SERVICE_NAME,
                     ss.current_state AS SERVICE_CURRENT_STATE,
@@ -65,11 +65,16 @@
                LEFT JOIN s.status as ss
                LEFT JOIN o.host as h
                LEFT JOIN h.status as hs
+               LEFT JOIN sh.status as shs
                WHERE s.config_type = '${retained_flag}'
                OR h.config_type = '${retained_flag}'
             ]]>
             </query>
 
+            <filter name="host_current_state" type="dql">
+                <resolve>COALESCE(hs.current_state,shs.current_state)</resolve>
+            </filter>
+
             <credential name="IcingaHost" type="MultiLike" affects="host">
                 <parameter name="target">IcingaHost</parameter>
                 <parameter name="column">o.name1</parameter>
@@ -78,8 +83,6 @@
             <credential name="IcingaService" type="MultiLike" affects="service">
                 <parameter name="target">IcingaService</parameter>
                 <parameter name="column">o.name2</parameter>
-                <!-- In mixed views we allow the service to be null => its a host -->
-                <parameter name="ornull">true</parameter>
             </credential>
 
             <credential name="IcingaServicegroup" type="dql" affects="service">
@@ -88,43 +91,33 @@
 
                 <orwhere>
                     <![CDATA[
-
-                        (osg.name1 IN (${credential_value})
-                        OR o.objecttype_id = 1)
+                        osg.name1 IN (${credential_value})
                     ]]>
                 </orwhere>
             </credential>
 
             <credential name="IcingaHostgroup" type="dql" affects="host">
                 <leftjoin>h.hostgroups hg</leftjoin>
-                <leftjoin>sh.hostgroups shg</leftjoin>
                 <leftjoin>hg.object ohg</leftjoin>
-                <leftjoin>shg.object sohg</leftjoin>
+                <leftjoin>sh.hostgroups shg</leftjoin>
+                <leftjoin>shg.object oshg</leftjoin>
 
                 <orwhere>
                     <![CDATA[
-                        (o.objecttype_id = 2
-                        OR ohg.name1 IN (${credential_value}))
-                    ]]>
-                </orwhere>
-                <orwhere>
-                    <![CDATA[
-                        (o.objecttype_id = 1
-                        OR sohg.name1 IN (${credential_value}))
+                        (ohg.name1 IN (${credential_value})
+                        OR oshg.name1 IN (${credential_value}))
                     ]]>
                 </orwhere>
             </credential>
 
             <credential name="IcingaContactgroup" type="dql" affects="host">
+                <leftjoin>h.contactgroups hcg</leftjoin>
+                <leftjoin>sh.contactgroups shcg</leftjoin>
 
-                <leftjoin>
-                    h.contactgroups hcg
-                </leftjoin>
                 <orwhere>
                     <![CDATA[
-                    hcg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id})
-                    OR o.objecttype_id = 2
-
+                    (hcg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id})
+                    OR shcg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id}))
                     ]]>
                 </orwhere>
             </credential>
@@ -133,11 +126,10 @@
                 <leftjoin>
                     s.contactgroups scg
                 </leftjoin>
+
                 <orwhere>
                     <![CDATA[
                     scg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id})
-                    OR o.objecttype_id = 1
-
                     ]]>
                 </orwhere>
             </credential>
@@ -158,14 +150,14 @@
 	<dql name="TARGET_DOWNTIMEHISTORY">
             <query>
             <![CDATA[
-                SELECT
+                SELECT DISTINCT
                     i.instance_name AS INSTANCE_NAME,
                     d.downtimehistory_id   AS DOWNTIME_ID,
                     d.internal_downtime_id AS DOWNTIME_INTERNAL_DOWNTIME_ID,
                     d.downtime_type AS DOWNTIME_DOWNTIME_TYPE,
                     COALESCE(h.host_object_id,sh.host_object_id)   AS HOST_OBJECT_ID,
                     o.name1 AS HOST_NAME,
-                    hs.current_state AS HOST_CURRENT_STATE,
+                    COALESCE(hs.current_state,shs.current_state) AS HOST_CURRENT_STATE,
                     s.service_object_id AS SERVICE_OBJECT_ID,
                     o.name2 AS SERVICE_NAME,
                     ss.current_state AS SERVICE_CURRENT_STATE,
@@ -183,12 +175,17 @@
                LEFT JOIN o.host as h
                LEFT JOIN s.host as sh
                LEFT JOIN h.status as hs
+               LEFT JOIN sh.status as shs
                WHERE (s.config_type = '${retained_flag}'
                OR h.config_type = '${retained_flag}')
                AND d.was_started = '1'
             ]]>
             </query>
 
+            <filter name="host_current_state" type="dql">
+                <resolve>COALESCE(hs.current_state,shs.current_state)</resolve>
+            </filter>
+
             <credential name="IcingaHost" type="MultiLike" affects="host">
                 <parameter name="target">IcingaHost</parameter>
                 <parameter name="column">o.name1</parameter>
@@ -197,8 +194,6 @@
             <credential name="IcingaService" type="MultiLike" affects="service">
                 <parameter name="target">IcingaService</parameter>
                 <parameter name="column">o.name2</parameter>
-                <!-- In mixed views we allow the service to be null => its a host -->
-                <parameter name="ornull">true</parameter>
             </credential>
 
             <credential name="IcingaServicegroup" type="dql" affects="service">
@@ -207,43 +202,33 @@
 
                 <orwhere>
                     <![CDATA[
-
-                        (osg.name1 IN (${credential_value})
-                        OR o.objecttype_id = 1)
+                        osg.name1 IN (${credential_value})
                     ]]>
                 </orwhere>
             </credential>
 -
             <credential name="IcingaHostgroup" type="dql" affects="host">
                 <leftjoin>h.hostgroups hg</leftjoin>
-                <leftjoin>sh.hostgroups shg</leftjoin>
                 <leftjoin>hg.object ohg</leftjoin>
-                <leftjoin>shg.object sohg</leftjoin>
+                <leftjoin>sh.hostgroups shg</leftjoin>
+                <leftjoin>shg.object oshg</leftjoin>
 
                 <orwhere>
                     <![CDATA[
-                        (o.objecttype_id = 2
-                        OR ohg.name1 IN (${credential_value}))
-                    ]]>
-                </orwhere>
-                <orwhere>
-                    <![CDATA[
-                        (o.objecttype_id = 1
-                        OR sohg.name1 IN (${credential_value}))
+                        (ohg.name1 IN (${credential_value})
+                        OR oshg.name1 IN (${credential_value}))
                     ]]>
                 </orwhere>
             </credential>
 
             <credential name="IcingaContactgroup" type="dql" affects="host">
+                <leftjoin>h.contactgroups hcg</leftjoin>
+                <leftjoin>sh.contactgroups shcg</leftjoin>
 
-                <leftjoin>
-                    h.contactgroups hcg
-                </leftjoin>
                 <orwhere>
                     <![CDATA[
-                    hcg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id})
-                    OR o.objecttype_id = 2
-
+                    (hcg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id})
+                    OR shcg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id}))
                     ]]>
                 </orwhere>
             </credential>
@@ -252,16 +237,14 @@
                 <leftjoin>
                     s.contactgroups scg
                 </leftjoin>
+
                 <orwhere>
                     <![CDATA[
                     scg.contactgroup_id  IN (${TARGET_CONTACTGROUPS.contactgroup_id})
-                    OR o.objecttype_id = 1
-
                     ]]>
                 </orwhere>
             </credential>
 
-
             <credential name="IcingaHostCustomVariablePair" type="CustomVariable" affects="host">
                 <parameter name="alias">h</parameter>
                 <parameter name="target">host</parameter>





More information about the icinga-checkins mailing list