<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    {# TODO: Option to not use CDNs #}
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

    <title>{{ site.definition.title }}</title>
  </head>
  <body>
<div class="container">
  <h1 class="mb-5 mt-5">
{% if site.definition.url %}
    <a class="text-dark" href="{{ site.definition.url }}">{{ site.definition.title }}</a>
{% else %}
    {{ site.definition.title }}
{% endif %}
  </h1>
  <div class="alert alert-{{ site.status.css }} mb-5 mt-5" role="alert">
    <h4 class="alert-heading">
{% if site.site_config.force_state %}
{{     site.site_config.message | markdown }}
{% else %}
{%     if site.status.css == "success" %}
        Everything is OK
{%     endif %}
{%     if site.status.css == "warning" %}
        Some services may be affected
{%     endif %}
{%     if site.status.css == "danger" %}
{%         if site.monitoring_is_down %}
        Monitoring may be down!
{%         else %}
        Some services are seriously affected
{%         endif %}
{%     endif %}
{% endif %}
    </h4>
  </div>
  <div class="">
{% for _, service in site.service_managers.items() %}
    <div class="card mb-3 mt-5">
      <h5 class="card-header">
        <span class="badge badge-pill badge-{{ service.status.css }}">&nbsp;</span>
        <span>
{%   if service.definition.url %}
          <a class="text-dark" href="{{ service.definition.url }}">{{ service.definition.name }}</a>
{%   else %}
          {{ service.definition.name }}
{%   endif %}
        </span>
        <span class="float-right">
{%  for component in service.components %}
          <span class="badge badge-{{ component.status.css }}">{{ component.definition.name }}</span>
{% endfor %}
        </span>
      </h5>
      <div class="card-body">
        <div class="card-deck">
{%  for component in service.components %}
          <div class="card">
            {#<img class="card-img-top" src=".../100px180/" alt="Card image cap">#}
            <div class="card-body">
              <h5 class="card-title">
                <span class="badge badge-pill badge-{{ component.status.css }}">&nbsp;</span>
                {{ component.definition.name }}
              </h5>
              <p class="card-text">{{ component.definition.description }}</p>
            </div>
            <!--<div class="card-footer">
              <small class="text-muted">Last incident: {{ (loop.index + 1) * 42 % 5 }} mins ago</small>
            </div>-->
          </div>
{% endfor %}
        </div>
      </div>
{% if service.status.css != "success" %}
      <div class="card-footer">
        <ul>
{%   if site.monitoring_is_down %}
          <li class="text-danger">Monitoring is down!</li>
{%   endif %}
{%   set service_alerts = service.current_incident.active_alerts if service.current_incident else {} %}
{%   for alertname in service_alerts.keys() %}
{%     set alert = service_alerts[alertname] %}
          <li>
            <strong class="text-{{ alert.status.css }}">{{ alert.annotations.summary if alert.annotations.summary else alertname }}</strong>
            {{ alert.annotations.description }}
          </li>
{%   endfor %}
        </ul>
      </div>
{% endif %}
    </div>
{% endfor %}
  </div>
  <div class="text-center text-muted mb-2 mt-5 pt-5">
    <p class="mb-3 mt-0">
      Last status update: {{ site.last_updated.getStr() }}
    </p>
    <p class="my-0">
      Created in a rush at <a class="text-dark" href="https://hack4glarus.ch">Hack4Glarus</a>, winter edition 2018.
    </p>
    <p class="mb-3 mt-0">
      Originally written by
      <a class="text-dark" href="https://kamila.is">AnotherKamila</a>
      and
      <a class="text-dark" href="https://evilham.com">Evilham</a>.
    </p>
    <p class="pb-3 mt-0">
      <a class="text-dark" href="https://farga.exo.cat/exo/prometheus-adlermanager">Source code</a>
    </p>
  </div>
</div>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  </body>
</html>
