<?xml version="1.0" encoding="UTF-8"?>
<ae:configurations xmlns:view="http://icinga.org/icinga/config/global/api/views/1.0"
    xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0"
>
    <ae:configuration>


        <dql name="TARGET_HOSTGROUP_SUMMARY" >
            <query>
                <![CDATA[
                SELECT
                    hg.hostgroup_id AS hostgroup_id,
                    o.name1 AS hostgroup_name,
                    hg.alias AS hostgroup_alias,
                    i.instance_id AS instance_id,
                    i.instance_name AS instance_name,
                    COUNT(COALESCE(hs.current_state,0)) AS host_status_count,
                    COALESCE(hs.current_state,0) AS host_current_state,
                    COALESCE(hs.current_state,0) AS host_status,
                    COALESCE(hs.has_been_checked,0) as host_has_been_checked
                FROM IcingaHostgroups hg
                INNER JOIN hg.instance i
                INNER JOIN hg.object o
                INNER JOIN hg.members hgm
                LEFT JOIN hgm.status hs
                INNER JOIN hs.host h

                GROUP BY  hg.hostgroup_id, o.name1,
                    hg.alias, i.instance_id, i.instance_name,
                    hs.current_state,
                    hs.has_been_checked

                WHERE hg.config_type = '${retained_flag}'
                ]]>

            </query>

            <credential name="IcingaHost" type="MultiLike" affects="host">
                <parameter name="target">IcingaHost</parameter>
                <parameter name="column">h.display_name</parameter>
            </credential>

            <credential name="IcingaHostgroup" type="dql" affects="host">
                <orwhere>
                    <![CDATA[
                        o.name1 IN (${credential_value})
                    ]]>
                </orwhere>
            </credential>

            <credential name="IcingaContactgroup" type="dql" affects="host">
                <leftjoin>
                    h.contactgroups cg
                </leftjoin>
                <orwhere>
                    <![CDATA[
                    cg.contactgroup_id IN (${TARGET_CONTACTGROUPS.contactgroup_id})
                    ]]>
                </orwhere>
            </credential>

            <credential name="IcingaHostCustomVariablePair" type="CustomVariable" affects="host">
                <parameter name="alias">h</parameter>
                <parameter name="target">host</parameter>
            </credential>

        </dql>

    </ae:configuration>
</ae:configurations>
