{% extends "base.html" %}


{% load adagiostags %}
{% load i18n %}

{% block title %}{% trans "Dashboard" %}{% endblock %}

{% block header %}
    {{ block.super }}
    <meta http-equiv="refresh" content="60">
    <style>
    body {
        background-color: #d5d8de;
    }
    </style>
{% endblock %}

{% block toolbar %}{% endblock %}
{% block page_header %}{% endblock %}
{% block page_footer %}{% endblock %}
{% block left_sidebar %}{% endblock %}

{% block page_content %}

    <div id="status_dashboard" >
        <div class="row-fluid row" >

            <!-- Tactical Overview -->
            <div class="span6" id="dashboard_tactical_overview">

                <table class="table well table-condensed">
                    <thead>
                    <tr>
                        <th>{% trans "Tactical Overview" %}</th>
                        <th>{% trans "Total" %}</th>
                        <th>{% trans "Problems" %}</th>
                        <th>{% trans "Unhandled" %}</th>
                        <!-- <th><i class="glyph-warning-sign" title="Unhandled Problems"></i></th>-->
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>{% trans "Network Parents" %}</td>
                        <td><a href="{% url 'status.views.network_parents' %}">{{ total_network_parents }}</a></td>
                        <td>
                            <a href="{% url 'status.views.network_parents' %}?state__isnot=0">
                            <div class="alert alert-warning">{{ total_network_problems }}</div>
                            </a>
                        </td>
                        <td>
                            <a href="{% url 'status.views.network_parents' %}?unhandled">
                            {% if total_unhandled_network_problems == 0 %}
                                <div class="alert alert-success">{{ total_unhandled_network_problems }}</div>
                            {% else %}
                                <div class="alert alert-danger">{{ total_unhandled_network_problems }}</div>
                            {% endif %}
                            </a>
                        </td>
                    </tr>
                    <tr>
                        <td>{% trans "Hosts" %}</td>
                        <td><a href="{% url 'status.views.hosts' %}">{{ total_hosts }}</a></td>
                        <td>
                            <a href="{% url 'status.views.hosts' %}?state__isnot=0">
                            <div class="alert alert-warning">{{  total_host_problems }}</div>
                            </a>
                        </td>
                        <td>
                            <a href="{% url 'status.views.hosts' %}?unhandled">
                            {% if host_problems|length == 0 %}
                                <div class="alert alert-success">{{ host_problems|length }}</div>
                            {% else %}
                                <div class="alert alert-danger">{{ host_problems|length }}</div>
                            {% endif %}
                            </a>
                        </td>

                    </tr>
                    <tr>
                        <td>{% trans "Services" %}</td>
                        <td><a href="{% url 'status.views.services' %}"> {{ total_services }}</a></td>
                        <td>
                            <a href="{% url 'status.views.services' %}?state__isnot=0">
                            <div class="alert alert-warning">{{ total_service_problems }}</div>
                            </a>
                        </td>
                        <td>
                            <a href="{% url 'status.views.services' %}?unhandled">
                            {% if service_problems|length == 0 %}
                                <div class="alert alert-success">{{ service_problems|length }}</div>
                            {% else %}
                                <div class="alert alert-danger">{{ service_problems|length }}</div>
                            {% endif %}
                            </a>
                        </td>

                    </tr>
                    </tbody>
                </table>

            </div>

            <!-- Unused space -->
            <div class="span2"> </div>

            <!-- Current Health Percentage -->
            <div class="span4" id="dashboard_health_percentage">
                <table class="table well">
                    <tr>
                        <td colspan="2"><h4>{% trans "Current Health" %}</h4></td>
                    </tr>
                    <tr>
                        <td  class="small nowrap" >{% trans "All hosts" %}</td>
                        <th>
                            <div class="progress">
                                <div class="bar bar-success" style=" width: {{ host_totals_percent.0 }}%;">{{ host_totals_percent.0|floatformat }}%</div>
                                <div class="bar bar-warning" style=" width: {{ host_totals_percent.1 }}%;"></div>
                                <div class="bar bar-danger" style=" width: {{ host_totals_percent.2 }}%;"></div>
                                <div class="bar bar-unknown" style=" width: {{ host_totals_percent.3 }}%;"></div>
                            </div>

                        </th>
                    </tr>
                    <tr>
                        <td class="small nowrap">{% trans "All services" %}</td>
                        <th>
                            <div class="progress">
                                <div class="bar bar-success" style=" width: {{ service_totals_percent.0 }}%;">{{ service_totals_percent.0|floatformat }}%</div>
                                <div class="bar bar-warning" style=" width: {{ service_totals_percent.1 }}%;"></div>
                                <div class="bar bar-danger" style=" width: {{ service_totals_percent.2 }}%;"></div>
                                <div class="bar bar-unknown" style=" width: {{ service_totals_percent.3 }}%;"></div>
                            </div>

                        </th>
                    </tr>
                </table>

            </div>

        </div>

        <div class="row-fluid row" id="dashboard_host_problems">
            {% if host_problems %}
                <h4>{% trans "Unhandled Host Problems" %}</h4>
                <!-- Host Problems -->
                {% include "snippets/status_hostlist_snippet.html" with hosts=host_problems%}
            {% else %}
                <h4>{% trans "There are no unhandled host problems." %}</h4>
            {% endif %}
        </div>

        <div class="row row-fluid" id="dashboard_service_problems">

            {% if service_problems%}
                <div class="span12">
                    <h4>{% trans "Unhandled Service Problems" %}</h4>
                    <table class="table well table-condensed">
                        <tr>
                            <th>{% trans "Host" %}</th>
                            <th>{% trans "Service" %}</th>
                            <th>{% trans "Output" %}</th>
                            <th>{% trans "Duration" %}</th>
                            <th>{% trans "Last Check" %}</th>
                        </tr>
                        {% for i in service_problems %}
                            {% if i.state == 0 %}<tr class="dashboard alert alert-success">{% endif %}
                            {% if i.state == 1 %}<tr class="dashboard alert alert-warning">{% endif %}
                            {% if i.state == 2 %}<tr class="dashboard alert alert-danger">{% endif %}
                            {% if i.state == 3 %}<tr class="dashboard alert alert-danger">{% endif %}
                                <td>
                                    <a href="{% url 'adagios.status.views.detail' %}/?host_name={{ i.host_name }}">
                                        {{ i.host_name }}
                                    </a>
                                </td>
                                <td>
                                    <a href="{% url 'adagios.status.views.detail' %}/?host_name={{ i.host_name }}&service_description={{ i.description }}">
                                    {{ i.description }}
                                    </a>
                                </td>

                                <td>
                                    <span class="dashboard_plugin_output" title="{{ i.plugin_output }}" >
                                        {{ i.plugin_output|slice:"70" }}
                                    </span>
                                </td>
                                <td>{{ i.last_state_change|timestamp|timesince }}</td>
                                <td>{{ i.last_check|timestamp|date:'Y-m-d H:i' }}</td>
                            </tr>
                        {% endfor %}
                    </table>
                </div>
            {% else %}
                <h4>{% trans "There are no unhandled service problems" %}</h4>
            {% endif %}

        </div>

</div>

{% endblock %}

{% block footer %}
    {{ block.super }}
    <script>
        $("#status_dashboard input").hide();
    </script>
{% endblock footer %}
