Compare commits

...

3 Commits

Author SHA1 Message Date
Jeroen De Meerleer d41ba60101
Refactor command line options for all scripts to include a help option. 2023-06-01 16:15:54 +02:00
Jeroen De Meerleer e849092a4d
Add script name and directory variables to check-systemctl-service.sh
This commit adds two new variables, script_name and script_dir, to the check-systemctl-service.sh file. These variables are used to store the name of the script and its directory path respectively.
2023-06-01 16:09:07 +02:00
Jeroen De Meerleer b01af8010d
Refactor check-dummy.sh to add options for warning, critical and unknown status
This commit refactors the check-dummy.sh script to include options for warning, critical and unknown status. The script now accepts the following command line arguments: --ok (default), --warning, --critical and --unknown. The exit codes have also been updated to reflect these new statuses.
2023-06-01 16:08:49 +02:00
8 changed files with 97 additions and 36 deletions

View File

@ -3,13 +3,14 @@
#
#/
#/ Usage:
#/ check-disk.sh --warning=<level> --critical=<level>
#/ check-disk.sh --warning=<level> --critical=<level> --help
#/
#/ Checks the disk usage
#/
#/ Options:
#/ -w, --warning=<level> The level of when to trigger a warning (level=loadavg/nproc)
#/ -c, --critical=<level> The level of when to trigger a critical warning (level=loadavg/nproc)
#/ -h, --help Display this help message
#/
#/ Exit Codes:
#/ 0 Everything OK
@ -25,8 +26,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=w:c:
LONGOPTS=warning:,critical:
OPTIONS=w:c:h
LONGOPTS=warning:,critical:,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -54,6 +55,9 @@ GetOptions() {
crit="$2"
shift 2
;;
-h|--help)
Usage
exit 0;
--)
shift
break

View File

@ -3,13 +3,23 @@
#
#/
#/ Usage:
#/ check-dummy.sh
#/ check-dummy.sh [--ok|--warning|--critical] --help
#/
#/ Does not check anything. Always gives OK!
#/ 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() {
@ -18,8 +28,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=''
LONGOPTS=''
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
@ -30,7 +40,6 @@ GetOptions() {
# e.g. return value is 1
# then getopt has complained about wrong arguments to stdout
Usage
exit 2
fi
# read getopt's output this way to handle the quoting right:
@ -39,23 +48,45 @@ GetOptions() {
# 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 "URL UNKNOWN - ${1} is not a valid parameter"
echo "DUMMY UNKNOWN - ${1} is not a valid parameter"
exit 3
;;
esac
done
if [ -z ${1+x} ]; then
echo "URL UNKNOWN - url not given"
exit 3
else
url=${1}
fi
}
echo "DUMMY OK"
exit 0
script_name=$(basename "${0}")
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
rval=0
rmsg="OK"
GetOptions "$@"
echo "DUMMY $rmsg"
exit $rval

View File

@ -3,7 +3,7 @@
#
#/
#/ Usage:
#/ check-load.sh --warning=<level> --critical=<level> --average=<level>
#/ check-load.sh --warning=<level> --critical=<level> --average=<level> --help
#/
#/ Checks the system load
#/
@ -11,6 +11,7 @@
#/ -w, --warning=<level> The level of when to trigger a warning (level=loadavg/nproc)
#/ -c, --critical=<level> The level of when to trigger a critical warning (level=loadavg/nproc)
#/ -a, --average=<average> Which avarage to use for the load level (possible values are 1, 5 and 15)
#/ -h, --help Display this help message
#/
#/ Exit Codes:
#/ 0 Everything OK
@ -26,8 +27,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=w:c:a:
LONGOPTS=warning:,critical:,avarage:
OPTIONS=w:c:a:h
LONGOPTS=warning:,critical:,avarage:,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -63,6 +64,9 @@ GetOptions() {
check="$2"
shift 2
;;
-h|--help)
Usage
exit 0;
--)
shift
break

View File

@ -3,13 +3,14 @@
#
#/
#/ Usage:
#/ check-md.sh --warning=<events> --critical=<events> <md-device>
#/ check-md.sh --warning=<events> --critical=<events> --help <md-device>
#/
#/ Checks the raid-device status
#/
#/ Options:
#/ -w, --warning=<events> The events of when to trigger a warning (comma-separated)
#/ -c, --critical=<events> The events of when to trigger a critical warning (comma-separated)
#/ -h, --help Display this help message
#/
#/ Possible events
#/ - clean
@ -31,8 +32,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=w:c:
LONGOPTS=warning:,critical:
OPTIONS=w:c:h
LONGOPTS=warning:,critical:,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -65,6 +66,9 @@ GetOptions() {
IFS=$OLDIFS
shift 2
;;
-h|--help)
Usage
exit 0;
--)
shift
break

View File

@ -3,13 +3,14 @@
#
#/
#/ Usage:
#/ check-memory.sh --warning=<level> --critical=<level>
#/ check-memory.sh --warning=<level> --critical=<level> --help
#/
#/ Checks the memory usage
#/
#/ Options:
#/ -w, --warning=<level> The level of when to trigger a warning (level=loadavg/nproc)
#/ -c, --critical=<level> The level of when to trigger a critical warning (level=loadavg/nproc)
#/ -h, --help Display this help message
#/
#/ Exit Codes:
#/ 0 Everything OK
@ -25,8 +26,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=w:c:
LONGOPTS=warning:,critical:
OPTIONS=w:c:h
LONGOPTS=warning:,critical:,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -54,6 +55,9 @@ GetOptions() {
crit="$2"
shift 2
;;
-h|--help)
Usage
exit 0;
--)
shift
break

View File

@ -3,10 +3,11 @@
#
#/
#/ Usage:
#/ check-systemctl-service.sh <unit-file>
#/ check-systemctl-service.sh --help <unit-file>
#/
#/ Options:
#/ -u, --user Check for running within current user
#/ -h, --help Display this help message
#/
#/ Checks if a systemd unit is active
#/
@ -23,8 +24,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=u
LONGOPTS=user
OPTIONS=uh
LONGOPTS=user,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -48,6 +49,9 @@ GetOptions() {
user='--user'
shift 1
;;
-h|--help)
Usage
exit 0;
--)
shift
break
@ -69,6 +73,8 @@ GetOptions() {
user=''
service=''
LC_NUMERIC="C"
script_name=$(basename "${0}")
script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
GetOptions "$@"
if [[ $(systemctl ${user} list-unit-files "${service}*" | wc -l) -gt 3 ]]; then

View File

@ -3,7 +3,7 @@
#
#/
#/ Usage:
#/ check-url.sh --proxy=<proxy-url> --warning=<level> --critical=<level> <URL>
#/ check-url.sh --proxy=<proxy-url> --warning=<level> --critical=<level> --help <URL>
#/
#/ Checks if URL is available
#/
@ -11,6 +11,7 @@
#/ -p, --proxy=<proxy-url> The proxy server to use
#/ -w, --warning=<sec> The amount of response time to trigger a warning (in sec)
#/ -c, --critical=<sec> The amount of response time to trigger a critcal warning (in sec)
#/ -h, --help Display this help message
#/
#/ Exit Codes:
#/ 0 Everything OK
@ -26,8 +27,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=p:w:c:
LONGOPTS=proxy:,warning:,critical:
OPTIONS=p:w:c:h
LONGOPTS=proxy:,warning:,critical:,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -59,6 +60,9 @@ GetOptions() {
crit="$2"
shift 2
;;
-h|--help)
Usage
exit 0;
--)
shift
break

View File

@ -3,7 +3,7 @@
#
#/
#/ Usage:
#/ check-webcron.sh --proxy=<proxy-url> [--daemon] --warning=<level> --critical=<level> <URL>
#/ check-webcron.sh --proxy=<proxy-url> [--daemon] --warning=<level> --critical=<level> --help <URL>
#/
#/ Checks webcron jobs
#/
@ -12,6 +12,7 @@
#/ -d, --daemon When no daemon is running trigger a critical warning
#/ -w, --warning=<ratio> The ratio of failed jobs to trigger a warning (1 = all jobs; 0.5 = half of all jobs)
#/ -c, --critical=<ratio> The ratio of failed jobs to trigger a critcal warning (1 = all jobs; 0.5 = half of all jobs)
#/ -h, --help Display this help message
#/
#/ Exit Codes:
#/ 0 Everything OK
@ -27,8 +28,8 @@ Usage() {
GetOptions() {
# https://stackoverflow.com/a/29754866
OPTIONS=p:dw:c:
LONGOPTS=proxy:,daemon,warning:,critical:
OPTIONS=p:dw:c:h
LONGOPTS=proxy:,daemon,warning:,critical:,help
# -use ! and PIPESTATUS to get exit code with errexit set
# -temporarily store output to be able to check for errors
@ -63,6 +64,9 @@ GetOptions() {
crit="$2"
shift 2
;;
-h|--help)
Usage
exit 0;
--)
shift
break