From 681b788ac4c70ec37054b51d4d382ee7f28cf710 Mon Sep 17 00:00:00 2001 From: uumas Date: Thu, 21 Dec 2023 01:22:26 +0200 Subject: [PATCH] prometheus: add support for installing webhook server --- roles/prometheus/defaults/main.yml | 1 + roles/prometheus/meta/argument_specs.yml | 46 +++++++++++++++++++++ roles/prometheus/tasks/main.yml | 14 +++++++ roles/prometheus/templates/webhooks.yaml.j2 | 5 +++ 4 files changed, 66 insertions(+) create mode 100644 roles/prometheus/templates/webhooks.yaml.j2 diff --git a/roles/prometheus/defaults/main.yml b/roles/prometheus/defaults/main.yml index 3d995d1..47b1272 100644 --- a/roles/prometheus/defaults/main.yml +++ b/roles/prometheus/defaults/main.yml @@ -7,5 +7,6 @@ prometheus_install_grafana: false prometheus_hcloud_relabel_configs: [] prometheus_install_alertmanager: true +prometheus_install_webhook: false alertmanager_storage_retention: "{{ prometheus_storage_retention }}" diff --git a/roles/prometheus/meta/argument_specs.yml b/roles/prometheus/meta/argument_specs.yml index 5e52e6d..cdd612a 100644 --- a/roles/prometheus/meta/argument_specs.yml +++ b/roles/prometheus/meta/argument_specs.yml @@ -51,6 +51,11 @@ argument_specs: type: bool required: false default: true + prometheus_install_webhook: + description: If true, installs webhook server in the same docker network as prometheus and configures it + type: bool + required: false + default: false alertmanager_storage_retention: description: Period of time for which alertmanager data is stored for. A number followed by unit (s, m, h, d, w, y). Passed directly to alertmanager role @@ -58,6 +63,47 @@ argument_specs: required: false default: "{{ prometheus_storage_retention | default('3650d') }}" + prometheus_webhook_handlers: + description: List of webhook server handlers + type: list + required: "{{ prometheus_install_webhook }}" + elements: dict + options: + id: + description: specifies the ID of your hook. This value is used to create the HTTP endpoint + type: str + required: true + execute-command: + description: specifies the command that should be executed when the hook is triggered + type: str + required: true + command-working-directory: + description: specifies the working directory that will be used for the script when it's executed + type: str + required: false + pass-arguments-to-command: + description: > + specifies the list of arguments that will be passed to the + command. See for more info: + https://github.com/adnanh/webhook/blob/master/docs/Referencing-Request-Values.md + type: list + required: false + elements: dict + options: + source: + description: Source of the argument. Use `string` to specify argument here. + type: str + required: true + choices: + - string + - header + - url + - request + - payload + name: + description: Argument if source is string, otherwise the source attribute name. + type: str + required: true # All options after this will be passed directly to the container role docker_service_suffix: diff --git a/roles/prometheus/tasks/main.yml b/roles/prometheus/tasks/main.yml index 98befaf..e0f7461 100644 --- a/roles/prometheus/tasks/main.yml +++ b/roles/prometheus/tasks/main.yml @@ -31,6 +31,20 @@ - name: prometheus when: prometheus_install_alertmanager +- name: Webhook container for prometheus + include_role: + name: container + vars: + docker_service: prometheus_webhook + docker_image: thecatlady/webhook + reverse_proxy_type: none + docker_mounts: + - template: webhooks.yaml + path: /config/hooks.yml + docker_networks: + - name: prometheus + when: prometheus_install_webhook + - name: Grafana container for prometheus include_role: name: grafana diff --git a/roles/prometheus/templates/webhooks.yaml.j2 b/roles/prometheus/templates/webhooks.yaml.j2 new file mode 100644 index 0000000..8ea3fd3 --- /dev/null +++ b/roles/prometheus/templates/webhooks.yaml.j2 @@ -0,0 +1,5 @@ +--- + +{% for item in prometheus_webhook_handlers %} +- {{ item }} +{% endfor %}