Skip to content

Commit 97aa210

Browse files
authored
Provision alert notification channels using config file (cloudalchemy#227)
[minor] release
1 parent 6df7301 commit 97aa210

File tree

4 files changed

+50
-32
lines changed

4 files changed

+50
-32
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
5858
| `grafana_datasources` | [] | List of datasources which should be configured |
5959
| `grafana_environment` | {} | Optional Environment param for Grafana installation, useful ie for setting http_proxy |
6060
| `grafana_plugins` | [] | List of Grafana plugins which should be installed |
61+
| `grafana_alert_notifications` | [] | List of alert notification channels to be created, updated, or deleted |
6162

6263
Datasource example:
6364

@@ -78,6 +79,30 @@ grafana_dashboards:
7879
revision_id: 1
7980
datasource: prometheus
8081
```
82+
83+
Alert notification channel example:
84+
85+
**NOTE**: setting the variable `grafana_alert_notifications` will only come into
86+
effect when `grafana_use_provisioning` is `true`. That means the new
87+
provisioning system using config files, which is available starting from Grafana
88+
v5.0, needs to be in use.
89+
90+
```yaml
91+
grafana_alert_notifications:
92+
notifiers:
93+
- name: Channel 1
94+
type: email
95+
uid: channel1
96+
is_default: false
97+
send_reminder: false
98+
settings:
99+
addresses: "[email protected]"
100+
autoResolve: true
101+
delete_notifiers:
102+
- name: Channel 2
103+
uid: channel2
104+
```
105+
81106
Use a custom Grafana Yum repo template example:
82107

83108
- Put your template next to your playbook under `templates` folder

defaults/main.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,12 @@ grafana_dashboards_dir: "dashboards"
211211

212212
# Alert notification channels to configure
213213
grafana_alert_notifications: []
214-
# - name: "Email Alert"
215-
# type: "email"
216-
# isDefault: true
217-
# settings:
218-
# addresses: "[email protected]"
214+
# - name: "Email Alert"
215+
# type: "email"
216+
# uid: channel1
217+
# is_default: true
218+
# settings:
219+
# addresses: "[email protected]"
219220

220221
# Datasources to configure
221222
grafana_datasources: []

molecule/alternative/playbook.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,13 @@
7373
grafana_plugins:
7474
- raintank-worldping-app
7575
grafana_alert_notifications:
76-
- name: "Email Alert"
77-
type: "email"
78-
isDefault: true
79-
settings:
80-
addresses: "[email protected]"
76+
notifiers:
77+
- name: "Email Alert"
78+
type: "email"
79+
uid: notifier1
80+
is_default: true
81+
settings:
82+
addresses: "[email protected]"
8183
grafana_dashboards:
8284
- dashboard_id: '1860'
8385
revision_id: '4'

tasks/notifications.yml

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
---
2-
- name: Check alert notifications list
3-
uri:
4-
url: "{{ grafana_api_url }}/api/alert-notifications"
5-
user: "{{ grafana_security.admin_user }}"
6-
password: "{{ grafana_security.admin_password }}"
7-
force_basic_auth: true
8-
return_content: true
9-
no_log: true
10-
register: alert_notifications
11-
12-
- name: Create grafana alert notification channels
13-
uri:
14-
url: "{{ grafana_api_url }}/api/alert-notifications"
15-
user: "{{ grafana_security.admin_user }}"
16-
password: "{{ grafana_security.admin_password }}"
17-
force_basic_auth: true
18-
method: POST
19-
body_format: json
20-
body: "{{ item | to_json }}"
21-
with_items: "{{ grafana_alert_notifications }}"
22-
no_log: true
23-
when: ((alert_notifications['json'] | selectattr("name", "equalto", item['name'])) | list) | length == 0
2+
- name: Create/Delete/Update alert notifications channels (provisioning)
3+
become: true
4+
copy:
5+
content: |
6+
apiVersion: 1
7+
{{ grafana_alert_notifications | to_nice_yaml }}
8+
dest: /etc/grafana/provisioning/notifiers/ansible.yml
9+
owner: root
10+
group: grafana
11+
mode: 0640
12+
notify: restart grafana
13+
when: grafana_use_provisioning

0 commit comments

Comments
 (0)