{% extends "base.html" %}
{% load i18n %}

{% block title %}{% trans "Nagios Service" %}{% endblock %}
{% block smallheader %}{% endblock %}
{% block largeheader %}{% blocktrans %}Nagios Service is <b> {{ friendly_status }}</b>{% endblocktrans %}{% endblock %}
{% block nav1 %}{% trans "Nagios Service" %}{% endblock %}

{% block content %}


    {% if form %}
        <form action="#" method="post" class="form-horizontal">{% csrf_token %}
            {% if status == 0 %}
                <button class="btn btn-success" type="submit" name="reload">{% trans "Reload" %}</button>
                <button class="btn " type="submit" name="stop">{% trans "Stop" %}</button>
                <button class="btn " type="submit" name="restart">{% trans "Restart" %}</button>
            {% endif %}
            {% if status == 1 %}
                <button class="btn btn-success" type="submit" name="start">{% trans "Start" %}</button>
            {% endif %}
            {% if status > 1 %}
                <button class="btn btn-success" type="submit" name="start">{% trans "Start" %}</button>
                <button class="btn " type="submit" name="stop">{% trans "Stop" %}</button>
                <button class="btn " type="submit" name="restart">{% trans "Restart" %}</button>
                <button class="btn" type="submit" name="reload">{% trans "Reload" %}</button>
            {% endif %}
            <button class="btn " type="submit" name="status">{% trans "Status" %}</button>
             <button class="btn " type="submit" name="verify">{% trans "Verify" %}</button>
        </form>
    {% else %}
        {% trans "No form found" %}
    {%  endif %}



    {% if command %}
        <div >
            {% blocktrans %} "Executing <b>nagios {{ command }}</b>" {% endblocktrans %}
            {% if stderr %}
                <h4>{% trans "Errors" %}</h4>
                <pre>{{ stderr }}</pre>
            {% endif %}

            {% if stdout %}
                <pre>{{ stdout }}</pre>
            {% endif %}
        </div>

        {% if stderr|slice:":5" == 'sudo:' %}
            <div class="alert alert-danger">
                <p>
                    {% blocktrans %}Something does not smell right. We ran {{ command }} and got the error above.
                    Usually when this happens there is a problem with sudoers configuration.{% endblocktrans %}
                </p>
                <p>
                    {% blocktrans %}Inspect webserver apache log and check if there are any sudo errors.
                    Your <a>/etc/sudoers.d/adagios</a> should have something like this:{% endblocktrans %}
                </p>
            <pre>
Defaults:{{ local_user }}    !requiretty
{{ local_user }} ALL = (root) NOPASSWD: /sbin/service nagios *
{{ local_user }} ALL = (root) NOPASSWD: {{ nagios_bin }} -v *
            </pre>
            </div>
        {% endif %}

    {% endif %}

    <hr>
    <div>{% blocktrans %}Nagios Service is <b>{{ friendly_status }}</b>.{% endblocktrans %}</div>

{% endblock %}


{% block toolbar %}
{% endblock %}


{% block header %} {{ block.super }} {% endblock %}

{% block sidebar %}
    <h5>{% trans "Diagnostics" %}</h5>
        <div>{% blocktrans %}Nagios Service is {{ friendly_status }}.{% endblocktrans %}</div>

{% endblock %}

{% block footer %} {{ block.super }} {% endblock %}
