2023-05-31 14:28:07 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
#/
|
|
|
|
#/ Usage:
|
2023-06-01 16:06:02 +02:00
|
|
|
#/ check-dummy.sh [--ok|--warning|--critical]
|
2023-05-31 14:28:07 +02:00
|
|
|
#/
|
2023-06-01 16:06:02 +02:00
|
|
|
#/ 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
|
2023-05-31 14:28:07 +02:00
|
|
|
#/
|
|
|
|
#/
|
|
|
|
#/ Exit Codes:
|
|
|
|
#/ 0 Everything OK
|
2023-06-01 16:06:02 +02:00
|
|
|
#/ 1 Warning level exceeded
|
|
|
|
#/ 2 Critical level exceeded
|
|
|
|
#/ 3 Unknown status
|
2023-05-31 14:28:07 +02:00
|
|
|
#/
|
|
|
|
|
|
|
|
Usage() {
|
|
|
|
grep '^#/' "${script_dir}/${script_name}" | sed 's/^#\/\w*//'
|
|
|
|
}
|
|
|
|
|
|
|
|
GetOptions() {
|
|
|
|
# https://stackoverflow.com/a/29754866
|
2023-06-01 16:06:02 +02:00
|
|
|
OPTIONS='owcu'
|
|
|
|
LONGOPTS='ok,warning,critical,unknown'
|
2023-05-31 14:28:07 +02:00
|
|
|
|
|
|
|
# -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
|
2023-06-01 16:06:02 +02:00
|
|
|
-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
|
|
|
|
;;
|
2023-05-31 14:28:07 +02:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
2023-06-01 16:06:02 +02:00
|
|
|
echo "DUMMY UNKNOWN - ${1} is not a valid parameter"
|
2023-05-31 14:28:07 +02:00
|
|
|
exit 3
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
2023-06-01 16:06:02 +02:00
|
|
|
script_name=$(basename "${0}")
|
|
|
|
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
rval=0
|
|
|
|
rmsg="OK"
|
|
|
|
GetOptions "$@"
|
|
|
|
|
|
|
|
echo "DUMMY $rmsg"
|
|
|
|
exit $rval
|