---
{{ ansible_managed | comment }}

{% macro raw(string) -%}
{{ "{{" }} {{ string }} {{ "}}" }}
{%- endmacro %}

groups:

  - name: docker.rules
    rules:

    - alert: ContainerDown
      expr: docker_container_running_state != 1
      for: 0m
      labels:
        severity: critical
      annotations:
        summary: >-
          Le container Docker est éteint / tombé 
          (container {{ raw('$labels.name') }})
    
    - alert: ContainerFailed
      expr: sum(increase(docker_container_restart_count[5m])) > 2
      for: 0m
      labels:
        severity: critical
      annotations:
        summary: >- 
          Le container Docker redémarre souvent 
          (container {{ raw('$labels.name') }})
    
    - alert: ContainerFailed
      expr: 
          (
            docker_container_cpu_used_total 
            / 
            docker_container_cpu_capacity_total
          ) * 100
          > 30
      for: 0m
      labels:
        severity: critical
      annotations:
        summary: >-
          Le container Docker utilise beaucoup de CPU 
          (container {{ raw('$labels.name') }}, 
          valeur {{ raw('$value | printf "%.1f"') }})
        
...