<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<template>
    <type>DQL</type>
    <!--
        Meta description of the templates, that anybody
        knows what the template is doing
    -->
    <meta>
        <parameter name="name">Default icinga host history template</parameter>
        <parameter name="description">Displays status history about a host</parameter>
        <parameter name="author">icinga-web developers</parameter>
    </meta>

    <!--
        Options for the template. Change layout and view style to fit the type you
        want to display
    -->
    <option>
        <parameter name="mode">default</parameter>
        <parameter name="layout">CronkGridTemplateAjaxGridLayout</parameter>


    </option>

    <!--
        What data to display? Define icinga data targets and countfields
    -->
    <datasource>
        <parameter name="target">TARGET_HOST_STATUS_HISTORY</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>
    </grouping>

    <!--
        Field decleration: What to display and how
    -->
    <fields>
        <field name="host_icon">
            <datasource>
                <parameter name="field">HOST_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="host_icon == ''" />
                                        images/icons/server.png
                                    </tpl>
                                    <tpl if="host_icon != ''" />
                                        images/icinga/{host_icon}
                                    </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="statehistory_id">
            <datasource>
                <parameter name="field">STATEHISTORY_ID</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">StatehistoryId</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>
            </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">HostId</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>
            </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">150</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="additonalSort">service_name</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="default">false</parameter>
            </order>
        </field>

        <field name="host_alias">
            <datasource>
                <parameter name="field">HOST_ALIAS</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">Alias</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_ALIAS</parameter>
                <parameter name="api_valuefield">HOST_ALIAS</parameter>
            </filter>

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

        <field name="host_display_name">
            <datasource>
                <parameter name="field">HOST_DISPLAY_NAME</parameter>
            </datasource>

            <display>
                <parameter name="visible">false</parameter>
                <parameter name="label">Display Name</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_DISPLAY_NAME</parameter>
                <parameter name="api_valuefield">HOST_DISPLAY_NAME</parameter>
            </filter>

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

        <field name="statehistory_status">
            <datasource>
                <parameter name="field">STATEHISTORY_STATE</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Status</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">false</parameter>
            </filter>

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

        <field name="state_date">
            <datasource>
                <parameter name="field">STATEHISTORY_STATE_TIME</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Timestamp</parameter>
                <parameter name="width">120</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="state_output">
            <datasource>
                <parameter name="field">STATEHISTORY_OUTPUT</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Output</parameter>
                <parameter name="width">250</parameter>

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

            </display>

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

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

        <field name="state_check_attempt">
            <datasource>
                <parameter name="field">STATEHISTORY_CURRENT_CHECK_ATTEMPT</parameter>
            </datasource>

            <display>
                <parameter name="visible">true</parameter>
                <parameter name="label">Attempt</parameter>

                <parameter name="width">60</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="menuDisabled">true</parameter>
                </parameter>

                <parameter name="userFunc">
                    <parameter name="model">Cronks.ColumnDisplay.Format</parameter>
                    <parameter name="method">formatTemplate</parameter>
                    <parameter name="arguments">
                        <parameter name="format"><![CDATA[${field.state_check_attempt} / ${field.state_max_check_attempts}]]></parameter>
                    </parameter>
                </parameter>
            </display>

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

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

    </fields>

</template>
