b845f3fc69
This change will enable possibility to add custom labels to alerts. This can be used ex. to provite routing key for pushkin (notification service) If given key already exists in alert, it will NOT be overriden. prometheus: server: config: alert: labels_add: route: 'mail,skype' Change-Id: I0b21d8a9695e8a15d0d6b80e6ddd0476682c80c2
61 lines
2.3 KiB
YAML
61 lines
2.3 KiB
YAML
{%- from "prometheus/map.jinja" import server with context %}
|
|
|
|
{%- 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', {}) %}
|
|
{%- for recordingname, recording in server_grain.get('recording', {}).iteritems() %}
|
|
{%- do recordings.update({recordingname: recording}) %}
|
|
{%- endfor %}
|
|
{%- endfor %}
|
|
|
|
{%- set recordings = salt['grains.filter_by']({'default': recordings}, merge=server.get('recording', {})) %}
|
|
|
|
{%- for recordingname, recording in recordings.iteritems() %}
|
|
{%- if recording.get('enabled', True) %}
|
|
{{ recordingname }} = {{ recording.query }}
|
|
{%- 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 %}
|
|
{%- endfor %}
|
|
|
|
{%- set alerts = salt['grains.filter_by']({'default': alerts}, merge=server.get('alert', {})) %}
|
|
|
|
{%- for alertname, alert in alerts.iteritems() %}
|
|
{%- if alert.get('enabled', True) %}
|
|
ALERT {{ alertname }}
|
|
IF {{ alert.if }}
|
|
{%- 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}) %}
|
|
{%- endif %}
|
|
{%- endfor %}
|
|
{%- if alert.labels %}
|
|
LABELS {
|
|
{%- for name, value in alert.labels.iteritems() %}
|
|
{{ name }} = "{{ value }}"{%- if not loop.last %},{%- endif %}
|
|
{%- endfor %}
|
|
}
|
|
{%- endif %}
|
|
{#- Handle annotations #}
|
|
{%- if alert.annotations is defined %}
|
|
ANNOTATIONS {
|
|
{%- for name, value in alert.annotations.iteritems() %}
|
|
{{ name }} = "{{ value }}"{%- if not loop.last %},{%- endif %}
|
|
{%- endfor %}
|
|
}
|
|
{%- endif %}
|
|
{%- endif %}
|
|
{%- endfor %}
|