Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Commit

Permalink
Add amtool configuration on alertmanager host (#135)
Browse files Browse the repository at this point in the history
[minor] release
  • Loading branch information
till authored Jul 21, 2020
1 parent b078c3f commit ff3f1e7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ All variables which can be overridden are stored in [defaults/main.yml](defaults
| `alertmanager_receivers` | [] | A list of notification receivers. Configuration same as in [official docs](https://prometheus.io/docs/alerting/configuration/#<receiver>) |
| `alertmanager_inhibit_rules` | [] | List of inhibition rules. Same as in [official docs](https://prometheus.io/docs/alerting/configuration/#inhibit_rule) |
| `alertmanager_route` | {} | Alert routing. More in [official docs](https://prometheus.io/docs/alerting/configuration/#<route>) |
| `alertmanager_amtool_config_file` | amtool.yml.j2 | Template for amtool config |
| `alertmanager_amtool_config_alertmanager_url` | `alertmanager_web_external_url` | URL of the alertmanager |
| `alertmanager_amtool_config_output` | extended | Extended output, use `""` for simple output. |

## Example

Expand Down
9 changes: 9 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,12 @@ alertmanager_route: {}
# - match:
# owner: team-Y
# receiver: team-Y-pager

# The template for amtool's configuration
alertmanager_amtool_config_file: 'amtool.yml.j2'

# Location (URL) of the alertmanager
alertmanager_amtool_config_alertmanager_url: "{{ alertmanager_web_external_url }}"

# Extended output of `amtool` commands, use '' for less verbosity
alertmanager_amtool_config_output: 'extended'
11 changes: 10 additions & 1 deletion tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
---
- name: copy amtool config
template:
force: true
src: "{{ alertmanager_amtool_config_file }}"
dest: "{{ _alertmanager_amtool_config_dir }}/config.yml"
owner: alertmanager
group: alertmanager
mode: 0644

- name: copy alertmanager config
template:
force: true
Expand All @@ -7,7 +16,7 @@
owner: alertmanager
group: alertmanager
mode: 0644
validate: "{{ _alertmanager_binary_install_dir }}/amtool --alertmanager.url= check-config %s"
validate: "{{ _alertmanager_binary_install_dir }}/amtool check-config %s"
notify:
- restart alertmanager

Expand Down
1 change: 1 addition & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- "{{ alertmanager_config_dir }}"
- "{{ alertmanager_config_dir }}/templates"
- "{{ alertmanager_db_dir }}"
- "{{ _alertmanager_amtool_config_dir }}"

- block:
- name: download alertmanager binary to local folder
Expand Down
4 changes: 4 additions & 0 deletions templates/amtool.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alertmanager.url: "{{ alertmanager_amtool_config_alertmanager_url }}"
{%if alertmanager_amtool_config_output != "" %}
output: "{{ alertmanager_amtool_config_output }}"
{% endif %}
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ go_arch_map:

go_arch: "{{ go_arch_map[ansible_architecture] | default(ansible_architecture) }}"
_alertmanager_binary_install_dir: '/usr/local/bin'

# The expected location of the amtool configuration file
_alertmanager_amtool_config_dir: '/etc/amtool'

0 comments on commit ff3f1e7

Please sign in to comment.