6
0
Fork 0

Add minimal alertmanager type

This commit is contained in:
Timothée Floure 2020-12-04 10:59:55 +01:00
parent 25a6edfe75
commit b25f66629c
Signed by: tfloure
GPG key ID: 4502C902C00A1E12
4 changed files with 110 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,5 @@
smtp-smarthost
smtp-from
smtp-user
smtp-password
receiver

View file