diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2021-08-13 17:13:55 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2021-08-13 17:13:55 +1200 |
commit | 22000f3c9befbfcf9ce4d237280ba1a43d025a1b (patch) | |
tree | 68b32c2d1c4d58227298b04d64c46bf3ef0b813c /nscaw.bash | |
parent | Relicense from MIT to GPLv3 (diff) | |
download | nscaw-22000f3c9befbfcf9ce4d237280ba1a43d025a1b.tar.gz nscaw-22000f3c9befbfcf9ce4d237280ba1a43d025a1b.zip |
Switch to tab indents
Diffstat (limited to 'nscaw.bash')
-rw-r--r-- | nscaw.bash | 46 |
1 files changed, 23 insertions, 23 deletions
@@ -31,27 +31,27 @@ self=nscaw # If there's a defaults file with environment variables for us, source it if [[ -r /etc/default/$self ]] ; then - source /etc/default/"$self" + source /etc/default/"$self" fi # Define a function to explain how to use this script usage() { - printf 'Usage: %s SERVICE -- COMMAND...\n' \ - "$self" + printf 'Usage: %s SERVICE -- COMMAND...\n' \ + "$self" } # Respond to requests for help with usage (exit success) case $1 in - -h|--help) - usage - exit 0 - ;; + -h|--help) + usage + exit 0 + ;; esac # Check that at least three arguments are present and in the correct form if (( $# < 3 )) || [[ $2 != -- ]] ; then - usage >&2 - exit 1 + usage >&2 + exit 1 fi # Pull the service from the first argument and shift the first two arguments @@ -70,26 +70,26 @@ username=$(whoami) # <http://mywiki.wooledge.org/BashFAQ/032> exec 3>&1 4>&2 TIMEFORMAT=$'real %3lR, user %3lU, sys %3lS\n' \ - time=$( { time "$@" 1>&3 2>&4 ; } 2>&1) ; ret=$? + time=$( { time "$@" 1>&3 2>&4 ; } 2>&1) ; ret=$? exec 3>&- 4>&- # Decide return code and message based on command exit value case $ret in - 0) - code=0 # OK - message=$(printf '%s: `%s` succeeded: %s' \ - "$self" "$*" "$time") - ;; - *) - code=2 # CRITICAL - message=$(printf '%s: `%s` failed (exit %d), USER %s, PATH=%s: %s' \ - "$self" "$*" "$ret" "$username" "$PATH" "$time") - ;; + 0) + code=0 # OK + message=$(printf '%s: `%s` succeeded: %s' \ + "$self" "$*" "$time") + ;; + *) + code=2 # CRITICAL + message=$(printf '%s: `%s` failed (exit %d), USER %s, PATH=%s: %s' \ + "$self" "$*" "$ret" "$username" "$PATH" "$time") + ;; esac # Format the passive check and pipe it into send_nsca; note that we ignore the # stdout of send_nsca as it's just a diagnostic message printf '%s\t%s\t%u\t%s\n' \ - "$hostname" "$service" "$code" "$message" | - send_nsca -H "${NSCAW_SERVER:-nsca}" \ - -c "${NSCAW_CONFIG:-/etc/send_nsca.cfg}" >/dev/null + "$hostname" "$service" "$code" "$message" | + send_nsca -H "${NSCAW_SERVER:-nsca}" \ + -c "${NSCAW_CONFIG:-/etc/send_nsca.cfg}" >/dev/null |