| Linux hosting5.siteguarding.com 3.10.0-962.3.2.lve1.5.88.el7.x86_64 #1 SMP Fri Sep 26 14:06:42 UTC 2025 x86_64 Path : /usr/local/bin/ |
| Current File : //usr/local/bin/check_whm_reboot.sh |
#!/bin/sh
#
#
# Simple Nagios plugin to check if WHM requests the reboot.
#
#Michail Borovoy
#2019-09-09
#NK Support
#
me="$(basename $0)"
usage () {
cat <<EOF
Usage: $me [options]
If no options then asks WHM API about the reboot needed
Else print help text and exit.
Options:
--help, -h Print this help text.
EOF
}
## exit statuses recognized by Nagios
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
## helper functions
die () {
rc="$1"
shift
(echo -n "$me: ERROR: ";
if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
exit $rc
}
warn () {
(echo -n "$me: WARNING: ";
if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
}
have_command () {
type "$1" >/dev/null 2>/dev/null
}
require_command () {
if ! have_command "$1"; then
die $UNKNOWN "Could not find required command '$1' in system PATH. Aborting."
fi
}
is_absolute_path () {
expr match "$1" '/' >/dev/null 2>/dev/null
}
## parse command-line
short_opts='hm:'
long_opts='message:,help'
# test which `getopt` version is available:
# - GNU `getopt` will generate no output and exit with status 4
# - POSIX `getopt` will output `--` and exit with status 0
getopt -T > /dev/null
rc=$?
if [ "$rc" -eq 4 ]; then
# GNU getopt
args=$(getopt --name "$me" --shell sh -l "$long_opts" -o "$short_opts" -- "$@")
if [ $? -ne 0 ]; then
die 1 "Type '$me --help' to get usage information."
fi
# use 'eval' to remove getopt quoting
eval set -- $args
else
# old-style getopt, use compatibility syntax
args=$(getopt "$short_opts" "$@")
if [ $? -ne 0 ]; then
die 1 "Type '$me --help' to get usage information."
fi
set -- $args
fi
while [ $# -gt 0 ]; do
case "$1" in
--help|-h) usage; exit 0 ;;
--) shift; break ;;
esac
shift
done
## main
require_command sudo
require_command /usr/sbin/whmapi1
#RESULT=$(sudo whmapi1 system_needs_reboot | grep -w needs_reboot | awk '{print $2}')
RESULT=$(sudo whmapi1 system_needs_reboot | grep needs_reboot | grep '[0-1]' | awk '{print $2}')
case "$RESULT" in
0) echo "OK: Reboot is not required"; exit $OK;;
1) echo "CRITICAL: Reboot is required"; exit $CRITICAL;;
*) echo "UNKNOWN: Something strange is occured, exitcode of last command is $?";;
esac
exit $UNKNOWN;