2017-03-09 06:12:27 -05:00
|
|
|
{%- from "prometheus/map.jinja" import server with context %}
|
|
|
|
|
2017-04-11 06:17:08 -04:00
|
|
|
{%- set alerts = {} %}
|
|
|
|
{%- set recordings = {} %}
|
|
|
|
|
|
|
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
|
|
|
{%- set server_grain = node_grains.get('prometheus', {}).get('server', {}) %}
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- for recordingname, recording in server_grain.get('recording', {}).iteritems() %}
|
|
|
|
{%- do recordings.update({recordingname: recording}) %}
|
2017-04-11 06:17:08 -04:00
|
|
|
{%- endfor %}
|
|
|
|
{%- endfor %}
|
|
|
|
|
2017-12-20 05:28:41 -05:00
|
|
|
groups:
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- set recordings = salt['grains.filter_by']({'default': recordings}, merge=server.get('recording', {})) %}
|
2017-12-20 05:28:41 -05:00
|
|
|
- name: recording.rules
|
|
|
|
rules:
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- for recordingname, recording in recordings.iteritems() %}
|
|
|
|
{%- if recording.get('enabled', True) %}
|
2017-12-20 05:28:41 -05:00
|
|
|
- record: {{ recordingname }}
|
|
|
|
expr: >-
|
|
|
|
{{ recording.query | indent(6, False) }}
|
2017-04-11 06:17:08 -04:00
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|
|
|
|
|
|
|
|
{%- for node_name, node_grains in salt['mine.get']('*', 'grains.items').iteritems() %}
|
|
|
|
{%- set server_grain = node_grains.get('prometheus', {}).get('server', {}) %}
|
|
|
|
{%- for alertname, alert in server_grain.get('alert', {}).iteritems() %}
|
|
|
|
{%- do alerts.update({alertname: alert}) %}
|
|
|
|
{%- endfor %}
|
2017-03-29 06:39:52 -04:00
|
|
|
{%- endfor %}
|
|
|
|
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- set alerts = salt['grains.filter_by']({'default': alerts}, merge=server.get('alert', {})) %}
|
2017-12-20 05:28:41 -05:00
|
|
|
- name: alert.rules
|
|
|
|
rules:
|
2017-04-11 06:17:08 -04:00
|
|
|
{%- for alertname, alert in alerts.iteritems() %}
|
2017-04-25 08:37:44 -04:00
|
|
|
{%- if alert.get('enabled', True) %}
|
2017-12-20 05:28:41 -05:00
|
|
|
- alert: {{ alertname }}
|
|
|
|
expr: >-
|
|
|
|
{{ alert.if | indent(6, False) }}
|
|
|
|
{%- if alert.for is defined %}
|
|
|
|
for: {{ alert.for }}{%- endif %}
|
|
|
|
{#- Handle labels #}
|
|
|
|
{%- if alert.labels is not defined %}
|
|
|
|
{%- do alert.update({'labels': {}}) %}
|
|
|
|
{%- endif %}
|
|
|
|
{%- for label_name, label_value in server.get('config', {}).get('alert', {}).get('labels_add', {}).iteritems() %}
|
|
|
|
{%- if label_name not in alert.labels %}
|
|
|
|
{%- do alert.labels.update({label_name: label_value}) %}
|
2017-06-25 08:53:01 -04:00
|
|
|
{%- endif %}
|
2017-12-20 05:28:41 -05:00
|
|
|
{%- endfor %}
|
|
|
|
{%- if alert.labels %}
|
|
|
|
labels:
|
|
|
|
{%- for name, value in alert.labels.iteritems() %}
|
|
|
|
{{ name }}: "{{ value }}"
|
2017-06-25 08:53:01 -04:00
|
|
|
{%- endfor %}
|
2017-12-20 05:28:41 -05:00
|
|
|
{%- endif %}
|
|
|
|
{#- Handle annotations #}
|
|
|
|
{%- if alert.annotations is defined %}
|
|
|
|
annotations:
|
|
|
|
{%- for name, value in alert.annotations.iteritems() %}
|
|
|
|
{{ name }}: "{{ value }}"
|
|
|
|
{%- endfor %}
|
|
|
|
{%- endif %}
|
2017-03-09 06:12:27 -05:00
|
|
|
{%- endif %}
|
|
|
|
{%- endfor %}
|