monitower

nimble and trivial monitoring suite
Log | Files | Refs

commit 0973a3ee80119ac951f36943f3e0575ed45d9c78
parent 773799d18b305cfb28a16e7ac0dadb8f53f64bc7
Author: Josuah Demangeon <me@josuah.net>
Date:   Mon, 26 Oct 2020 05:10:59 +0100

assume key=value and not key="value space" then simplify

Diffstat:
Mmonitower-run | 26+++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/monitower-run b/monitower-run @@ -7,31 +7,23 @@ # script is inexpensive enough to be run from a /etc/crontab. # -check() { set -u +e - local state "$@" +check() { set -ue + local "$@" mkdir -p "$MONITOWER_SPOOL/$host" - "$cmd" "$@" >/dev/null 2>&1 - - case $? in - (0) state=ok ;; - (*) state=err - logger -cs -p "$MONITOWER_FACILITY.${level:-alert}" \ - -t monitower time="$NOW" state="$state" "$@" - ;; - esac - - echo time="$NOW" state="$state" "$@" >>$MONITOWER_SPOOL/$host/$name.log + if "$cmd" "$@" >/dev/null 2>&1; then + echo time="$(date +%s)" state=ok "$@" + else + echo time="$(date +%s)" state=err "$@" + logger -cs -p "$MONITOWER_FACILITY.${level:-alert}" -t monitower "$@" + fi >>$MONITOWER_SPOOL/$host/$name.log } : ${MONITOWER_SPOOL:=/var/spool/monitower} : ${MONITOWER_FACILITY:=local7} -NOW=$(date +%s) -IFS=' -' while read line; do - check $(echo $line | xargs -n 1) & + check $line & done <${1:-/etc/monitower.conf} wait