From 8674ae474689bf68c0fe12fd4b684cbc7c256908 Mon Sep 17 00:00:00 2001 From: Chris Wage Date: Tue, 1 Aug 2017 18:40:50 -0500 Subject: [PATCH] added option to configure smokeping as a slave rather than master --- smokeping.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/smokeping.sh b/smokeping.sh index a4aa292..3ae54c3 100755 --- a/smokeping.sh +++ b/smokeping.sh @@ -17,6 +17,7 @@ #=============================================================================== set -o nounset # Treat unset variables as an error +slave=false ### gmail: Configure ssmtp for gmail # Arguments: @@ -46,6 +47,18 @@ AuthPass='"$pass"' s|^#*\(FromLineOverride=\).*|\1YES|' $conf } +### slave: configure this instance as a slave +# Arguments: +# master) master server to use +# secret) secret word +slave() { local master="$1" name="$2" secret="$3" + echo $secret > /etc/smokeping/secret.txt + chown smokeping:smokeping /etc/smokeping/secret.txt + chmod 0600 /etc/smokeping/secret.txt + MASTER=$master + NAME=$name +} + ### email: Configure owners email address # Arguments: # email) your email address @@ -141,6 +154,11 @@ Options (fields in '[]' are optional, '<>' are required): required arg: \"\" - your gmail username required arg: \"\" - your gmail password of app password These are only set in your docker container + -s \"\" Configure smokeping as slave + required arg: \"\" - master URL to use + required arg: \"\" - slave's name to send + required arg: \"\" - secret to authenticate this slave + These are only set in your docker container -t \"[;alert]\" Configure smokeping targets required arg: \"\" - name for site of tests required arg: \"\" - name for check @@ -156,10 +174,11 @@ The 'command' (if provided and valid) will be run instead of smokeping exit $RC } -while getopts ":hg:e:o:t:T:w" opt; do +while getopts ":hg:e:s:o:t:T:w" opt; do case "$opt" in h) usage ;; g) eval gmail $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;; + s) slave=true && eval slave $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;; e) email "$OPTARG" ;; o) owner "$OPTARG" ;; t) eval target $(sed 's/^\|$/"/g; s/;/" "/g' <<< $OPTARG) ;; @@ -177,6 +196,7 @@ shift $(( OPTIND - 1 )) [[ "${EMAIL:-""}" ]] && email "$EMAIL" [[ "${OWNER:-""}" ]] && owner "$OWNER" [[ "${TARGET:-""}" ]] && eval target $(sed 's/^\|$/"/g; s/;/" "/g' <<< $TARGET) +[[ "${SLAVE:-""}" ]] && slave=true && eval slave $(sed 's/^\|$/"/g; s/;/" "/g' <<< $SLAVE) [[ "${TZ:-""}" ]] && timezone "$TZ" [[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o smokeping [[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o smokeping @@ -190,6 +210,10 @@ chmod -R g+ws /var/cache/smokeping /var/lib/smokeping /run/smokeping 2>&1 | if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then exec "$@" +elif [ $slave == true ]; then + echo "Running as slave instance for ${MASTER}" + su -l ${SPUSER:-smokeping} -s /bin/bash -c \ + "exec /usr/sbin/smokeping --nodaemon --logfile=/tmp/log ${DEBUG:+--debug} --master-url=${MASTER} --slave-name=${NAME} --shared-secret=/etc/smokeping/secret.txt --cache-dir=/var/cache/smokeping" elif [[ $# -ge 1 ]]; then echo "ERROR: command not found: $1" exit 13 @@ -200,4 +224,4 @@ else su -l ${SPUSER:-smokeping} -s /bin/bash -c \ "exec /usr/sbin/smokeping --logfile=/tmp/log ${DEBUG:+--debug}" exec lighttpd -D -f /etc/lighttpd/lighttpd.conf -fi \ No newline at end of file +fi