From ee6d63325d5e0267be90a70ae0c9db0e35764968 Mon Sep 17 00:00:00 2001 From: Kamila Souckova Date: Sun, 11 Mar 2018 01:28:26 +0100 Subject: [PATCH] new __prometheus_alertmanager; fixes to __prometheus_server --- .../type/__prometheus_alertmanager/manifest | 62 ++++++++++++++----- .../parameter/boolean | 1 + .../parameter/default/retention-days | 1 + .../parameter/optional | 1 + .../parameter/required | 1 - cdist/conf/type/__prometheus_server/manifest | 13 ++-- .../parameter/default/target-heap-size | 1 - .../__prometheus_server/parameter/optional | 1 - 8 files changed, 57 insertions(+), 24 deletions(-) create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/boolean create mode 100644 cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days delete mode 100644 cdist/conf/type/__prometheus_server/parameter/default/target-heap-size diff --git a/cdist/conf/type/__prometheus_alertmanager/manifest b/cdist/conf/type/__prometheus_alertmanager/manifest index 0dbce3c2..926ad712 100755 --- a/cdist/conf/type/__prometheus_alertmanager/manifest +++ b/cdist/conf/type/__prometheus_alertmanager/manifest @@ -1,34 +1,64 @@ #!/bin/sh -e -GOBIN=/opt/gocode/bin # where to find go binaries +##### HARD-CODED CONFIG ##################################################### + CONF_DIR=/etc/prometheus -LOGLEVEL=info CONF=$CONF_DIR/alertmanager.yml -### Prometheus server ####################################################### +##### 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")" +# listen_address="$(cat "$__object/parameter/listen-address")" -FLAGS="config.file '$CONF' -storage.path '$storage_path' -web.listen-address '$listen_address' -log.level $LOGLEVEL" +##### INSTALL THE PACKAGE ################################################### -REAL_FLAGS="$(echo "$FLAGS" | sed -nE 's/^([^#]+).*/ --\1 \\/p')" +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") -__go_get github.com/prometheus/alertmanager/cmd/... + 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 -__user prometheus --system -require="__user/prometheus" __directory "$storage_path" --owner prometheus --parents -require="__user/prometheus" __directory "$CONF_DIR" --owner prometheus --parents +##### PREPARE PATHS AND SUCH ################################################ -__daemontools_service alertmanager --run "setuidgid prometheus $GOBIN/alertmanager $REAL_FLAGS" +require="$require $require_pkg" __directory "$storage_path" --owner prometheus --parents -require="$require __directory/$storage_path __user/prometheus" \ +# 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 "svc -h /service/alertmanager" # TODO when a config-check tool is available, check config here + --onchange "service prometheus-alertmanager reload" # TODO when a config-check tool is available, check config here diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/boolean b/cdist/conf/type/__prometheus_alertmanager/parameter/boolean new file mode 100644 index 00000000..5d15e93d --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/boolean @@ -0,0 +1 @@ +install-from-backports diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days b/cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days new file mode 100644 index 00000000..d61f00d8 --- /dev/null +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/default/retention-days @@ -0,0 +1 @@ +90 diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/optional b/cdist/conf/type/__prometheus_alertmanager/parameter/optional index f99d0d37..7fe79009 100644 --- a/cdist/conf/type/__prometheus_alertmanager/parameter/optional +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/optional @@ -1 +1,2 @@ storage-path +retention-days diff --git a/cdist/conf/type/__prometheus_alertmanager/parameter/required b/cdist/conf/type/__prometheus_alertmanager/parameter/required index 02cb49d0..04204c7c 100644 --- a/cdist/conf/type/__prometheus_alertmanager/parameter/required +++ b/cdist/conf/type/__prometheus_alertmanager/parameter/required @@ -1,2 +1 @@ config -listen-address diff --git a/cdist/conf/type/__prometheus_server/manifest b/cdist/conf/type/__prometheus_server/manifest index d19d35b1..a5c31b4e 100755 --- a/cdist/conf/type/__prometheus_server/manifest +++ b/cdist/conf/type/__prometheus_server/manifest @@ -17,6 +17,7 @@ rule_files="$(cat "$__object/parameter/rule-files")" ##### 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") @@ -30,6 +31,7 @@ if [ -f "$__object/parameter/install-from-backports" ]; then [ "$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 --target-release $lsb_codename-backports + require_pkg="__package_apt/prometheus" ;; *) echo "--install-from-backports is only supported on Devuan -- ignoring" >&2 @@ -38,21 +40,22 @@ if [ -f "$__object/parameter/install-from-backports" ]; then esac else __package prometheus + require_pkg="__package/prometheus" fi ##### PREPARE PATHS AND SUCH ################################################ -require="__package_apt/prometheus" __directory "$storage_path" --owner prometheus --parents +require="$require $require_pkg" __directory "$storage_path" --owner prometheus --parents ##### CONFIGURE ############################################################# -FLAGS="--storage.tsdb.path $storage_path --storage.tsdb.retention $(($retention_days*24))h" +FLAGS="--storage.tsdb.path $storage_path --storage.tsdb.retention $(($retention_days*24))h --web.listen-address [::]:9090" # TODO it would be neat to restart prometheus on change -- __key_value really should have an --onchange parameter -require="$require __package_apt/prometheus" \ +require="$require $require_pkg" \ __key_value prometheus_args --file /etc/default/prometheus --key "ARGS" --value "\"$FLAGS\"" --delimiter "=" -require="$require __directory/$storage_path __package_apt/prometheus" \ +require="$require __directory/$storage_path $require_pkg" \ __config_file $CONF \ --source $config \ --group prometheus --mode 640 \ @@ -60,7 +63,7 @@ __config_file $CONF \ for file in $rule_files; do dest=$CONF_DIR/$(basename $file) - require="$require __package_apt/prometheus" \ + require="$require $require_pkg" \ __config_file "$dest" \ --source "$file" \ --owner prometheus \ diff --git a/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size b/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size deleted file mode 100644 index 865faf10..00000000 --- a/cdist/conf/type/__prometheus_server/parameter/default/target-heap-size +++ /dev/null @@ -1 +0,0 @@ -auto diff --git a/cdist/conf/type/__prometheus_server/parameter/optional b/cdist/conf/type/__prometheus_server/parameter/optional index 4d8d8f3e..cb437211 100644 --- a/cdist/conf/type/__prometheus_server/parameter/optional +++ b/cdist/conf/type/__prometheus_server/parameter/optional @@ -1,4 +1,3 @@ -target-heap-size retention-days rule-files storage-path