{% extends "base_status.html" %}

{% load static %}
{% load i18n %}

{% block title %}{% trans "Error" %}{% endblock %}
{% block smallheader %}{% endblock %}
{% block largeheader %}{% trans "Oh no, something went wrong ☹" %}{% endblock %}

{% block nav1 %}{{ block.super }}{% endblock %}
{% load adagiostags %}

{% block content %}

    <div id="friendly_livestatus_message" class=hide>

        {% if exception_type == "LivestatusNotConfiguredException" or nagios_running and not num_problems %}
            {% trans "Adagios cannot connect to livestatus. Don't worry, you can still use the other parts of Adagios, but to get the status part to work check the following:" %}
            <ul>
                <li>{% blocktrans %}Is <a href="http://mathias-kettner.de/checkmk_livestatus.html\">mk-livestatus</a> installed ?{% endblocktrans %}</li>
                <li>{% url "objectbrowser.views.edit_nagios_cfg" as the_url %}{% blocktrans %}Does <a href="{{ the_url }}">nagios.cfg</a> have a broker_module= line that loads mk-livestatus ?{% endblocktrans %}</li>
                <li>{% url "status.views.log" as the_url %}{% blocktrans %}Are there any errors related to livestatus in  <a href="{{ the_url }}?search=livestatus">nagios logfiles</a>{% endblocktrans %} ?</li>
            </ul>

            {% trans "Install instructions for rpm-based systems:" %}
            <pre>
yum --enablerepo=ok-testing install mk-livestatus
pynag config --append "broker_module=/usr/lib64/mk-livestatus/livestatus.o /var/spool/nagios/cmd/livestatus"
service nagios reload
            </pre>
            {% trans "Install instructions for debian-based systems:" %}
            <pre>
apt-get install check-mk-livestatus
pynag config --append "broker_module=/usr/lib/check_mk/livestatus.o /var/lib/nagios3/rw/livestatus"
service nagios3 reload
            </pre>
        {% endif %}

        {% if not nagios_running %}
            <hr>
            <p>
                {% trans "Is our monitoring engine even running ? If so we cant detect it." %}
            </p>
            <p>
                {% trans "Don't worry you can still configure stuff but you might want to start it so you can start monitoring stuff." %}
            </p>
            <ul>
                <li>
                    {% url "misc.views.settings" as the_url %}{% blocktrans %}Please verify your <a href="{{ the_url }}">settings</a> and check all paths are valid.{% endblocktrans %}
                </li>
                <li>
                    {% trans "check that nagios is in fact running and sudoers.d is correctly configured." %}
                </li>
                <li>
                    {% url "misc.views.nagios_service" as the_url %}{% blocktrans %}Try starting it by clicking <a href="{{ the_url }}">here</a> and see if you are getting some sort of errors{% endblocktrans %}
                </li>
            </ul>
        {% endif %}


    </div>
        {% if exception_type == "ConfigFileNotFound" %}
            <p>
            {% trans "So! Adagios is up and running. But you need to install and configure a monitoring engine." %}
            </p>
            <p>
                {% url "adagios.misc.views.settings" as the_url %}{% blocktrans %}If Nagios (or a compatible engine like Icinga, Shinken or Naemon) is already installed.
                You should head over to <a href="{{ the_url  }}">settings page</a> and
                configure right paths.{% endblocktrans %}
            </p>
            <p>
                {% blocktrans %}If you don't have a monitoring engine installed you should take a look at our
                <a href="http://adagios.org">installation instructions</a> to get started.{% endblocktrans %}
            </p>
        {% endif %}
        {% if exception_type == "EventHandlerError" %}
            {% if "Not a git repository" in exception %}
                <p>{% trans "So! Seems like your configuration directory is not a git repository but Adagios was configured to that it uses git." %}</p>
                <p>
                    {% url "adagios.misc.views.gitlog" as the_url %}
		    {% blocktrans %}It's not a big deal, all you have to do is to visit <a href="{{ the_url  }}">this page</a> and we will generate one for you.{% endblocktrans %}
                </p>
                <p>
                    {% trans "You configuration files should always be a git repository anyway, so this is for your own good :)" %}
                </p>
            {% endif %}
        {% endif %}
        <hr>



    {% if exception %}
        <div id="error_message" class="alert alert-danger">
            <b>{{ exception_type }}</b>: {{ exception }}
        </div>
    {% endif %}


    <button id="debug_button" class="btn" onclick="$('#traceback').toggle(); $('#debug_button').toggle();">{% trans "show debug information" %}</button>
    <div id="traceback" class="hide">
        {% if traceback %}
            {% blocktrans %}<p>If you think this is a bug. Send the following information to the <a href="https://github.com/opinkerfi/adagios/issues">developers</a>:</p>{% endblocktrans %}
            <pre>{{ traceback }}</pre>
        {% endif %}
    </div>
{% endblock %}

{% block toolbar %} {% endblock %}

{% block footer %}
    {{ block.super }}
    <script>
        $(document).ready(function() {
            var error = $('#error_message').text();
            if ( error.search("livestatus") > 0) { $('#friendly_livestatus_message').show(); }
        });
    </script>
{% endblock %}
