nagios-scripts/check-dummy.sh

93 lines
2.3 KiB
Bash

#!/bin/bash
#
#/
#/ Usage:
#/ check-dummy.sh [--ok|--warning|--critical] --help
#/
#/ Does not check anything.
#/
#/ Options:
#/ -o, --ok Trigger a OK status (default)
#/ -w, --warning Trigger a warning
#/ -c, --critical Trigger a critical warning
#/ -u, --unknown Trigger a unknown status
#/ -h, --help Display this help message
#/
#/
#/ Exit Codes:
#/ 0 Everything OK
#/ 1 Warning level exceeded
#/ 2 Critical level exceeded
#/ 3 Unknown status
#/
Usage() {
grep '^#/' "${script_dir}/${script_name}" | sed 's/^#\/\w*//'
}
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS='owcuh'
LONGOPTS='ok,warning,critical,unknown,help'
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
# -activate quoting/enhanced mode (e.g. by writing out “--options”)
# -pass arguments only via -- "$@" to separate them correctly
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
# e.g. return value is 1
# then getopt has complained about wrong arguments to stdout
Usage
fi
# read getopt's output this way to handle the quoting right:
eval set -- "$PARSED"
# now enjoy the options in order and nicely split until we see --
while true; do
case "$1" in
-o|--ok)
rval=0
rmsg="OK"
shift
;;
-w|--warning)
rval=1
rmsg="WARNING"
shift
;;
-c|--critical)
rval=2
rmsg="CRITICAL"
shift
;;
-u|--unknown)
rval=3
rmsg="UNKNOWN"
shift
;;
-h|--help)
Usage
exit 0
;;
--)
shift
break
;;
*)
echo "DUMMY UNKNOWN - ${1} is not a valid parameter"
exit 3
;;
esac
done
}
script_name=$(basename "${0}")
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
rval=0
rmsg="OK"
GetOptions "$@"
echo "DUMMY $rmsg"
exit $rval