diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-03-18 09:46:51 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-03-18 09:46:51 +1300 |
commit | 13c15f7058ac10e1de6dda084695cb424cc26452 (patch) | |
tree | bb298c6d6215209cf47891e32215497904945453 /nscaw | |
parent | First commit of project (diff) | |
download | nscaw-13c15f7058ac10e1de6dda084695cb424cc26452.tar.gz nscaw-13c15f7058ac10e1de6dda084695cb424cc26452.zip |
Include running time in output of check
Diffstat (limited to 'nscaw')
-rwxr-xr-x | nscaw | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -49,27 +49,36 @@ shift 2 # it can be overridden with the value of NSCAW_HOSTNAME if defined hostname=${NSCAW_HOSTNAME:-$(hostname -s)} -# Attempt to run command -"$@" +# Attempt to run command within a time wrapper +# <http://mywiki.wooledge.org/BashFAQ/032> +exec 3>&1 4>&2 +time=$( { time "$@" 1>&3 2>&4 ; } 2>&1) ; ret=$? +exec 3>&- 4>&- + +# Munge the time to make it palatable as a single line +time=${time#$'\n'} # Strip leading newline +time=${time//$'\n'/, } # Change all newlines to comma-space +time=${time//$'\t'/ } # Change all tabs to spaces # Decide return code and message based on command exit value -case $? in +case $ret in 0) code=0 # OK - message=$(printf '%s: Command "%s" ran successfully' \ - "$self" "$*") + message=$(printf '%s: `%s` ran with no errors as user %s: %s' \ + "$self" "$*" "$USER" "$time") ;; 127) code=3 # UNKNOWN - message=$(printf '%s: Command "%s" could not be found' \ - "$self" "$*") + message=$(printf '%s: `%s` could not be found as user %s with PATH=%s' \ + "$self" "$1" "$USER" "$PATH") ;; *) code=2 # CRITICAL - message=$(printf '%s: Command "%s" ran with errors' \ - "$self" "$*") + message=$(printf '%s: `%s` ran with errors as user %s: %s' \ + "$self" "$*" "$USER" "$time") ;; esac +printf '%s\n' "$message" # 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 |