<!DOCTYPE html>
{% load hc_extras humanize %}

<p>
    {% if flip.new_status == "down" %}
    "{{ check.name_then_code }}" is DOWN{% if flip.reason %} ({{ flip.reason_long }}){% endif %}.
    {% else %}
    "{{ check.name_then_code }}" is UP.
    {% endif %}
    <a href="{{ check.cloaked_url }}">View on {% site_name %}&hellip;</a>
</p>


{% if check.desc %}
<p>
    <b>Description</b><br>
    {{ check.desc|linebreaksbr }}
</p>
{% endif %}

{% cycle '' '</tr><tr>' as trtr silent %}
<table>
    <tr>
        {% if check.project.name %}
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Project</b><br>
            {{ check.project.name }}
        </td>
        {{ trtr|safe }} {% cycle trtr %}
        {% endif %}

        {% if check.tags_list %}
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Tags</b><br>
            {% for tag in check.tags_list %}
            <code style="background-color: #eeeeee; padding: 2px 4px; border-radius: 2px;">{{ tag }}</code>
            {% endfor %}
        </td>
        {{ trtr|safe }} {% cycle trtr %}
        {% endif %}

        {% if check.kind == "simple" %}
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Period</b><br>
            {{ check.timeout|hc_duration }}
        </td>
        {{ trtr|safe }} {% cycle trtr %}
        {% endif %}

        {% if check.kind == "cron" or check.kind == "oncalendar" %}
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Schedule</b><br>
            <code>{{ check.schedule }}</code>
        </td>
        {{ trtr|safe }} {% cycle trtr %}
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Time Zone</b><br>
            {{ check.tz }}
        </td>
        {{ trtr|safe }} {% cycle trtr %}
        {% endif %}

        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Total Pings</b><br>
            {% if ping %}{{ ping.n }}{% else %}0{% endif %}
            {% if check.created %}(since {{ check.created|date:'M j, Y' }}){% endif %}
        </td>
    </tr>

    {% if ping %}
    <tr>
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Last Ping</b><br>
            {{ ping.created|naturaltime }}{% if ping.remote_addr %}, from {{ ping.remote_addr }}{% endif %}
        </td>
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Last Ping Type</b><br>
            {% if ping.kind == "ign" %}
            <span style="background-color: #eeeeee; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
                Ignored
            </span>
            {% elif ping.exitstatus > 0 %}
            <span style="background-color: #f2dede; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
                Exit status {{ ping.exitstatus }}
            </span>
            {% elif ping.exitstatus == 0 %}
            <span style="background-color: #dff0d8; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
                Exit status 0
            </span>
            {% elif ping.kind == "fail" %}
            <span style="background-color: #f2dede; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
                Failure
            </span>
            {% elif ping.kind == "start" %}
            <span style="background-color: #dff0d8; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
                Started
            </span>
            {% elif ping.kind == "log" %}
            <span style="background-color: #eeeeee; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
                Log
            </span>
            {% else %}
            <span style="background-color: #dff0d8; color: #333333; padding-left: 4px; padding-right: 4px; border-radius: 2px;">
                Success
            </span>
            {% endif %}
        </td>
    </tr>
    {% endif %}

    <tr>
        <td style="padding-right: 32px; padding-bottom: 8px; vertical-align: top;">
            <b>Status Changed to {{ flip.new_status|title }} at</b><br>
            {{ flip.created|date:"Y-m-d H:i:s T" }}
        </td>
    </tr>
</table>

{% if ping and ping.has_body %}
{% if subject %}
<p><b>Last Ping Subject</b><br>{{ subject }}</p>
{% endif %}

<p><b>Last Ping Body</b></p>
{% if body is None %}
<p>
    The request body data is being processed and will be available for viewing shortly.
    Please <a href="{{ check.cloaked_url }}">view it on the website</a>.
</p>
{% else %}
<pre style="font-family: monospace; line-height: 1em;">{{ body|slice:":10000"|linebreaksbr }}{% if body|length > 10000 %} [truncated]{% endif %}</pre>
{% endif %}
{% endif %}

{% if projects %}
<p><b>Projects Overview</b></p>
<table>
    {% for project in projects %}
    <tr>
        <td style="padding-right: 32px; padding-bottom: 4px;">
            <a href="{{ project.checks_url }}">{{ project }}</a>
        </td>
        <td style="padding-right: 32px; padding-bottom: 4px;">
            {% with project.get_n_down as n_down %}
                {% if n_down %}
                <b>{{ n_down }} check{{ n_down|pluralize }} down</b>
                {% else %}
                OK, all checks up
                {% endif %}
            {% endwith %}
        </td>
    </tr>
    {% endfor %}
</table>
{% endif %}

<br>
<p style="color: #666666; font-size: 90%">
&mdash;<br>
You are receiving this email because you are subscribed to {% site_name %} monitoring
notifications{% if check.project.name %} for project "{{ check.project.name }}"{% endif %}.<br>
Don't want to receive these notifications?
<a href="{{ unsub_link }}" target="_blank" style="color: #666666; text-decoration: underline;">Unsubscribe</a>.
</p>