From b25f66629c0f46cf5b91fa3c6c770d2332821918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 4 Dec 2020 10:59:55 +0100 Subject: [PATCH] Add minimal alertmanager type --- .../files/alertmanager.yml.sh | 61 +++++++++++++++++++ type/__prometheus_alertmanager/manifest | 44 +++++++++++++ .../parameter/required | 5 ++ type/__prometheus_alertmanager/singleton | 0 4 files changed, 110 insertions(+) create mode 100755 type/__prometheus_alertmanager/files/alertmanager.yml.sh create mode 100644 type/__prometheus_alertmanager/manifest create mode 100644 type/__prometheus_alertmanager/parameter/required create mode 100644 type/__prometheus_alertmanager/singleton diff --git a/type/__prometheus_alertmanager/files/alertmanager.yml.sh b/type/__prometheus_alertmanager/files/alertmanager.yml.sh new file mode 100755 index 0000000..541d848 --- /dev/null +++ b/type/__prometheus_alertmanager/files/alertmanager.yml.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +cat << EOF +global: + # The smarthost and SMTP sender used for mail notifications. + smtp_smarthost: '${SMTP_SMARTHOST:?}' + smtp_from: '${SMTP_FROM:?}' + smtp_auth_username: '${SMTP_USER:?}' + smtp_auth_password: '${SMTP_PASSWORD}' + +# The root route on which each incoming alert enters. +route: + # The labels by which incoming alerts are grouped together. For example, + # multiple alerts coming in for cluster=A and alertname=LatencyHigh would + # be batched into a single group. + group_by: ['alertname', 'cluster', 'service'] + + # When a new group of alerts is created by an incoming alert, wait at + # least 'group_wait' to send the initial notification. + # This way ensures that you get multiple alerts for the same group that start + # firing shortly after another are batched together on the first + # notification. + group_wait: 30s + + # When the first notification was sent, wait 'group_interval' to send a batch + # of new alerts that started firing for that group. + group_interval: 5m + + # If an alert has successfully been sent, wait 'repeat_interval' to + # resend them. + repeat_interval: 3h + + # A default receiver + receiver: admin-mails + + # All the above attributes are inherited by all child routes and can + # overwritten on each. + + # The child route trees. + routes: [] + + +# Inhibition rules allow to mute a set of alerts given that another alert is +# firing. +# We use this to mute any warning-level notifications if the same alert is +# already critical. +inhibit_rules: +- source_match: + severity: 'critical' + target_match: + severity: 'warning' + # Apply inhibition if the alertname is the same. + equal: ['alertname', 'cluster', 'service'] + + +receivers: +- name: 'admin-mails' + email_configs: + - to: '${RECEIVER_EMAIL:?}' + +EOF diff --git a/type/__prometheus_alertmanager/manifest b/type/__prometheus_alertmanager/manifest new file mode 100644 index 0000000..522f085 --- /dev/null +++ b/type/__prometheus_alertmanager/manifest @@ -0,0 +1,44 @@ +#!/bin/sh + +os="$(cat "${__global:?}/explorer/os")" +case "$os" in + alpine) + service=alertmanager + package=alertmanager + alertmanager_yml=/etc/alertmanager/alertmanager.yml + ;; + + ubuntu|debian) + service=prometheus-alertmanager + package=prometheus-alertmanager + alertmanager_yml=/etc/prometheus/alertmanager.yml + ;; + *) + echo "This type does not supper $os. Exiting." >&2 + exit 1 + ;; +esac + +SMTP_SMARTHOST=$(cat "${__object:?}/parameter/smtp-smarthost") +SMTP_FROM=$(cat "${__object:?}/parameter/smtp-from") +SMTP_USER=$(cat "${__object:?}/parameter/smtp-user") +SMTP_PASSWORD=$(cat "${__object:?}/parameter/smtp-password") +export SMTP_SMARTHOST SMTP_USER SMTP_FROM SMTP_PASSWORD + +RECEIVER_EMAIL=$(cat "${__object:?}/parameter/receiver") +export RECEIVER_EMAIL + +# Install Alertmanager. +__package "$package" + +# Generate and deploy configuration +mkdir -p "${__object:?}/files" +"${__type:?}/files/alertmanager.yml.sh" > "${__object:?}/files/alertmanager.yml" + +require="__package/$package" __file "$alertmanager_yml" \ + --source "${__object:?}/files/alertmanager.yml" \ + --mode 0644 \ + --onchange "service $service restart" + +require="__package/$package" __start_on_boot "$service" +#require="__package/$package" __service "$service" --action start diff --git a/type/__prometheus_alertmanager/parameter/required b/type/__prometheus_alertmanager/parameter/required new file mode 100644 index 0000000..f906117 --- /dev/null +++ b/type/__prometheus_alertmanager/parameter/required @@ -0,0 +1,5 @@ +smtp-smarthost +smtp-from +smtp-user +smtp-password +receiver diff --git a/type/__prometheus_alertmanager/singleton b/type/__prometheus_alertmanager/singleton new file mode 100644 index 0000000..e69de29