#!/bin/sh -e ##### HARD-CODED CONFIG ##################################################### CONF_DIR=/etc/prometheus CONF=$CONF_DIR/alertmanager.yml ##### GET SETTINGS ########################################################## config="$(cat "$__object/parameter/config")" retention_days="$(cat "$__object/parameter/retention-days")" storage_path="$(cat "$__object/parameter/storage-path")" # listen_address="$(cat "$__object/parameter/listen-address")" ##### INSTALL THE PACKAGE ################################################### require_pkg="" # what to require if I want to require "the package" if [ -f "$__object/parameter/install-from-backports" ]; then os=$(cat "$__global/explorer/os") lsb_codename=$(cat "$__global/explorer/lsb_codename") case $os in devuan) if [ -z "$lsb_codename" ]; then echo "Command `lsb_release` not functional -- is package `lsb-release` installed?" >&2 exit 1 fi [ "$lsb_codename" = "n/a" ] && lsb_codename='ascii' # TODO this is a devuan bug that should be fixed soon => remove when no longer needed __apt_source backports --uri http://auto.mirror.devuan.org/merged --distribution $lsb_codename-backports --component main require="$require __apt_source/backports" __package_apt prometheus-alertmanager --target-release $lsb_codename-backports require_pkg="__package_apt/prometheus-alertmanager" ;; *) echo "--install-from-backports is only supported on Devuan -- ignoring" >&2 echo "send a pull request if you require it" >&2 ;; esac else __package prometheus-alertmanager require_pkg="__package/prometheus-alertmanager" fi ##### PREPARE PATHS AND SUCH ################################################ require="$require $require_pkg" __directory "$storage_path" --owner prometheus --parents # TODO this is a bug in the init script, patching it like this is awful and it should be reported require="$require $require_pkg" \ __key_value alertmanager_fix_init_script --file /etc/init.d/prometheus-alertmanager --key="NAME" --value="prometheus-alertmanager" --delimiter "=" ##### CONFIGURE ############################################################# FLAGS="--storage.path $storage_path --data.retention $(($retention_days*24))h --web.listen-address [::]:9093" require="$require $require_pkg" \ __key_value alertmanager_args --file /etc/default/prometheus-alertmanager --key="ARGS" --value="\"$FLAGS\"" --delimiter "=" require="$require __directory/$storage_path $require_pkg" \ __config_file $CONF \ --source $config \ --group prometheus --mode 640 \ --onchange "service prometheus-alertmanager reload" # TODO when a config-check tool is available, check config here