<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<template>
    <type>DQL</type>


    <meta>
        <parameter name="name">Open problems status template</parameter>
        <parameter name="description">Displays information about occured problems</parameter>
        <parameter name="author">icinga-web developers</parameter>
    </meta>

    <option>
        <parameter name="mode">default</parameter>
        <parameter name="layout">CronkGridTemplateAjaxGridLayout</parameter>



        <parameter name="gridEvents">

        </parameter>

        <parameter name="selection_model">checkbox</parameter>

        <!--
            Enable/disable commands and specify which of type you'll need
        -->
        <parameter name="commands">
            <!--
                Generally enabled od disabled
            -->
            <parameter name="enabled">false</parameter>

            <parameter name="source">
                <parameter name="IcingaApiConstants::COMMAND_HOST">host_name</parameter>
                <parameter name="IcingaApiConstants::COMMAND_INSTANCE">instance_name</parameter>
            </parameter>

            <parameter name="predefined">
                <parameter name="IcingaApiConstants::COMMAND_AUTHOR">${xmlfn.author}</parameter>
            </parameter>

            <!--
                Which commands are available in this template and can charged
                with template data
            -->


        </parameter>

        <!--
            Additional filter
            * Keep in mind to map the names in datasource.additional_filter_fields
        -->
        <parameter name="filter">

        </parameter>
    </option>

    <!--
        What data to display? Define icinga data targets and countfields
    -->
    <datasource>
        <parameter name="target">TARGET_OPEN_PROBLEMS</parameter>
        <parameter name="countmode">field</parameter>

        <parameter name="countfields">
            <parameter>PROBLEMS_OBJECT_ID</parameter>
        </parameter>

    </datasource>

    <!--
        Paging record on its result
    -->
    <pager>
        <parameter name="enabled">true</parameter>

        <parameter name="start">0</parameter>
    </pager>

    <grouping>
        <parameter name="enabled">false</parameter>
        <parameter name="field">A_XML_FIELD_TO_GROUP</parameter>
    </grouping>

    <!--
        Field decleration: What to display and how
    -->
    <fields>
        <field name="icon">
            <datasource>
                <parameter name="field">ICON_IMAGE</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Object image</parameter>
                <parameter name="icon">icinga-icon-image</parameter>
                <parameter name="width">25</parameter>
                <parameter name="Ext.grid.Column">
                    <parameter name="menuDisabled">true</parameter>
                    <parameter name="fixed">true</parameter>
                </parameter>
                <parameter name="jsFunc">
                    <parameter>
                        <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                        <parameter name="function">columnImage</parameter>

                        <!-- renderer/gridevent[cellclick|celldblclick|...] -->
                        <parameter name="type">renderer</parameter>

                        <parameter name="arguments">
                            <parameter name="image">
                                <![CDATA[
                                    <tpl if="objecttype_id == 1" />
                                      <tpl if="icon == ''" />
                                        images/icons/server.png
                                      </tpl>
                                      <tpl if="icon != ''" />
                                        images/icinga/{icon}
                                      </tpl>
                                    </tpl>
                                    <tpl if="objecttype_id == 2" />
                                      <tpl if="icon == ''" />
                                        images/icons/application-monitor.png
                                      </tpl>
                                      <tpl if="icon != ''" />
                                        images/icinga/{icon}
                                      </tpl>
                                    </tpl>
                                ]]>
                            </parameter>
                        </parameter>
                    </parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
                <parameter name="default">false</parameter>
            </order>

        </field>

        <field name="instance_name">
            <datasource>
                <parameter name="field">INSTANCE_NAME</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">Instance</parameter>

                <parameter name="width">60</parameter>

                <parameter name="Ext.grid.Column">
                    <parameter name="fixed">false</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.api</parameter>

                <!-- Operator type is needed because we don't know which type returned-->
                <parameter name="operator_type">text</parameter>

                <parameter name="api_target">instance</parameter>
                <parameter name="api_keyfield">INSTANCE_NAME</parameter>
                <parameter name="api_valuefield">INSTANCE_NAME</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>


        <field name="object_id">
            <datasource>
                <parameter name="field">PROBLEMS_OBJECT_ID</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">Id</parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.number</parameter>

                <parameter name="no_operator">false</parameter>

                <parameter name="field">PROBLEMS_OBJECT_ID</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>

        <field name="objecttype_id">
            <datasource>
                <parameter name="field">OBJECTTYPE_ID</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">Type Id</parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.number</parameter>

                <parameter name="no_operator">false</parameter>

                <parameter name="field">OBJECTTYPE_ID</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>

        <field name="host_object_id">
            <datasource>
                <parameter name="field">HOST_OBJECT_ID</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">Host Id</parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.number</parameter>

                <parameter name="no_operator">false</parameter>

                <parameter name="field">HOST_OBJECT_ID</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>

        <field name="service_object_id">
            <datasource>
                <parameter name="field">SERVICE_OBJECT_ID</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">Service Id</parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.number</parameter>

                <parameter name="no_operator">false</parameter>

                <parameter name="field">SERVICE_OBJECT_ID</parameter>
            </filter>

            <order>
                <parameter name="enabled">false</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>

        <field name="host_name">
            <datasource>
                <parameter name="field">HOST_NAME</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Host</parameter>
                <parameter name="width">110</parameter>

                <parameter name="jsFunc">

                    <parameter>
                        <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                        <parameter name="function">columnElement</parameter>

                        <!-- renderer/gridevent[cellclick|celldblclick|...] -->
                        <parameter name="type">renderer</parameter>

                        <parameter name="arguments">
                            <parameter name="css">x-icinga-grid-link</parameter>

                            <parameter name="attr">
                                <parameter name="ext:qtip">Click to view covered services</parameter>
                            </parameter>

                        </parameter>
                    </parameter>

                    <parameter>
                        <parameter name="namespace">Cronk.grid.IcingaColumnRenderer</parameter>
                        <parameter name="function">subGrid</parameter>

                        <!-- renderer/gridevent[cellclick|celldblclick|...] -->
                        <parameter name="type">cellclick</parameter>

                        <parameter name="arguments">
                            <parameter name="idPrefix">servicesForHost</parameter>
                            <parameter name="titlePrefix">Services for</parameter>
                            <parameter name="targetTemplate">icinga-service-template</parameter>
                            <parameter name="filterMap">
                                <parameter name="host_object_id">host_object_id</parameter>
                            </parameter>
                            <parameter name="labelField">host_name</parameter>
                        </parameter>
                    </parameter>

                </parameter>
            </display>


            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.api</parameter>
                <parameter name="operator_type">text</parameter>
                <parameter name="api_target">host</parameter>
                <parameter name="api_keyfield">HOST_NAME</parameter>
                <parameter name="api_valuefield">HOST_NAME</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <!--  <parameter name="field">A_NEW_FIELD_TO_SORT</parameter> -->
            </order>
        </field>

        <field name="service_name">
            <datasource>
                <parameter name="field">SERVICE_NAME</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Service</parameter>
                <parameter name="width">150</parameter>

                <parameter name="jsFunc">

                    <parameter>
                        <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                        <parameter name="function">columnElement</parameter>

                        <parameter name="type">renderer</parameter>

                        <parameter name="arguments">
                            <parameter name="css">x-icinga-grid-link</parameter>

                            <parameter name="attr">
                                <parameter name="ext:qtip">Click to view this service</parameter>
                            </parameter>

                        </parameter>
                    </parameter>

                    <parameter>
                        <parameter name="namespace">Cronk.grid.IcingaColumnRenderer</parameter>
                        <parameter name="function">subGrid</parameter>

                        <parameter name="type">cellclick</parameter>

                        <parameter name="arguments">
                            <parameter name="idPrefix">singleService</parameter>
                            <parameter name="titlePrefix">Service</parameter>
                            <parameter name="targetTemplate">icinga-service-template</parameter>
                            <parameter name="filterMap">
                                <parameter name="service_object_id">service_object_id</parameter>
                            </parameter>
                            <parameter name="labelField">service_name</parameter>
                        </parameter>
                    </parameter>

                </parameter>

            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.api</parameter>
                <parameter name="operator_type">text</parameter>
                <parameter name="api_target">service</parameter>
                <parameter name="api_keyfield">SERVICE_NAME</parameter>
                <parameter name="api_valuefield">SERVICE_NAME</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <!--  <parameter name="field">A_NEW_FIELD_TO_SORT</parameter> -->
            </order>
        </field>

        <field name="state_type">
            <datasource>
                <parameter name="field">STATE_TYPE</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">State type</parameter>
                <parameter name="width">60</parameter>
                <parameter name="Ext.grid.Column">
                    <parameter name="fixed">true</parameter>
                </parameter>
                <parameter name="jsFunc">
                    <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                    <parameter name="function">stateType</parameter>

                    <!-- renderer/gridevent[cellclick|celldblclick|...] -->
                    <parameter name="type">renderer</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.statetype</parameter>
                <parameter name="no_operator">false</parameter>
                <parameter name="field">state_type</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
            </order>
        </field>

        <field name="host_status">
            <datasource>
                <parameter name="field">HOST_CURRENT_STATE</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Host state</parameter>
                <parameter name="width">100</parameter>

                <!-- Config for the AJAX grid (see http://www.extjs.com/deploy/dev/docs/?class=Ext.grid.Column) -->
                <parameter name="Ext.grid.Column">
                    <parameter name="fixed">true</parameter>
                </parameter>

                <parameter name="jsFunc">
                    <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                    <parameter name="function">hostStatus</parameter>

                    <!-- renderer/gridevent[cellclick|celldblclick|...] -->
                    <parameter name="type">renderer</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.hoststatus</parameter>

                <parameter name="no_operator">false</parameter>

                <!-- Override the default field -->
                <parameter name="field">COALESCE(hs.current_state,shs.current_state)</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>

        <field name="service_state">
            <datasource>
                <parameter name="field">SERVICE_CURRENT_STATE</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Service state</parameter>
                <parameter name="width">100</parameter>

                <parameter name="Ext.grid.Column">
                    <parameter name="fixed">true</parameter>
                </parameter>

                <parameter name="jsFunc">
                    <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                    <parameter name="function">serviceStatus</parameter>

                    <!-- renderer/gridevent[cellclick|celldblclick|...] -->
                    <parameter name="type">renderer</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">true</parameter>

                <!-- Filter configuration -->
                <parameter name="type">extjs</parameter>
                <parameter name="subtype">appkit.ext.filter.servicestatus</parameter>

                <parameter name="no_operator">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <parameter name="default">false</parameter>
            </order>
        </field>

        <field name="output">
            <datasource>
                <parameter name="field">OUTPUT</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Check output</parameter>
                <parameter name="width">200</parameter>
            </display>

            <filter>
                <parameter name="enabled">false</parameter>

            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <!--  <parameter name="field">A_NEW_FIELD_TO_SORT</parameter> -->
            </order>
        </field>

        <field name="last_state_change">
            <datasource>
                <parameter name="field">LAST_STATE_CHANGE</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label"><![CDATA[Last state change]]></parameter>
                <parameter name="width">110</parameter>

                <!-- Let the agavi translation manager transform the date -->
                <parameter name="userFunc">
                    <parameter name="model">Cronks.ColumnDisplay.Format</parameter>
                    <parameter name="method">agaviDateFormat</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <parameter name="default">true</parameter>
                <parameter name="order">DESC</parameter>
            </order>
        </field>

        <field name="host_last_check">
            <datasource>
                <parameter name="field">HOST_LAST_CHECK</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label"><![CDATA[Last <b>host</b> check]]></parameter>

                <!-- Let the agavi translation manager transform the date -->
                <parameter name="userFunc">
                    <parameter name="model">Cronks.ColumnDisplay.Format</parameter>
                    <parameter name="method">agaviDateFormat</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <parameter name="default">false</parameter>
                <parameter name="order">DESC</parameter>
            </order>
        </field>

        <field name="service_last_check">
            <datasource>
                <parameter name="field">SERVICE_LAST_CHECK</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label"><![CDATA[Last <b>service</b> check]]></parameter>

                <!-- Let the agavi translation manager transform the date -->
                <parameter name="userFunc">
                    <parameter name="model">Cronks.ColumnDisplay.Format</parameter>
                    <parameter name="method">agaviDateFormat</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <parameter name="default">false</parameter>
                <parameter name="order">DESC</parameter>
            </order>
        </field>

        <field name="duration">
	    <datasource>
                <!-- <parameter name="field">COALESCE(hs.last_state_change,ss.last_state_change,ps.program_start_time)</parameter> -->
                <parameter name="field">DURATION_START</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Duration</parameter>
                <parameter name="width">125</parameter>
                <parameter name="jsFunc">
                    <parameter name="namespace">Cronk.grid.ColumnRenderer</parameter>
                    <parameter name="function">durationField</parameter>
                    <parameter name="type">renderer</parameter>
                </parameter>
            </display>

            <filter>
                <parameter name="enabled">false</parameter>
            </filter>

            <order>
                <parameter name="enabled">true</parameter>
                <parameter name="default">false</parameter>
                <parameter name="order">ASC</parameter>
            </order>
          </field>

    </fields>

</template>
