first commit
This commit is contained in:
parent
d885161d6a
commit
1c34e9715f
|
@ -22,7 +22,7 @@
|
|||
# Script: check_reboot-required #
|
||||
# License: This file is licensed under the GPLv3 License #
|
||||
# Purpose: Check if reboot is required #
|
||||
# Tested on: Proxmox 6, CentOS 6/7/8, Debian 8/9/10 and Ubuntu 16.04/18.04/20.04 #
|
||||
# Tested on: Proxmox 6, CentOS 6/7/8, Debian 7/8/9/10 and Ubuntu 16.04/18.04/20.04 #
|
||||
# #
|
||||
##############################################################################################
|
||||
# #
|
||||
|
@ -36,17 +36,27 @@
|
|||
|
||||
APPNAME=`basename $0`
|
||||
|
||||
OK=0
|
||||
WARNING=1
|
||||
CRITICAL=2
|
||||
UNKNOWN=3
|
||||
# Defining standard messages and exit error levels
|
||||
# https://nagios-plugins.org/doc/guidelines.html
|
||||
OK_EXIT_CODE=0
|
||||
WARNING_EXIT_CODE=1
|
||||
CRITICAL_EXIT_CODE=2
|
||||
UNKNOWN_EXIT_CODE=3
|
||||
OK_MSG="OK"
|
||||
WARNING_MSG="Warning"
|
||||
CRITICAL_MSG="Critical"
|
||||
UNKNOWN_MSG="Unknown"
|
||||
|
||||
# Using Unknown as default
|
||||
EXIT_CODE=$UNKNOWN_EXIT_CODE
|
||||
EXIT_MSG=$UNKNOWN_MSG
|
||||
|
||||
warn_only="false"
|
||||
|
||||
which lsb_release 2>/dev/null >/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "lsb_release is missing"
|
||||
exit ${UNKNOWN}
|
||||
exit ${UNKNOWN_EXIT_CODE}
|
||||
fi
|
||||
|
||||
function usage() {
|
||||
|
@ -70,7 +80,7 @@ case $1 in
|
|||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
exit ${OK_EXIT_CODE}
|
||||
;;
|
||||
esac
|
||||
|
||||
|
@ -82,20 +92,22 @@ function check_debian() {
|
|||
packages=""
|
||||
fi
|
||||
if [ -z "${packages}" ]; then
|
||||
EXIT_MSG_BODY="System reboot is required"
|
||||
if [ "${warn_only}" == "true" ]; then
|
||||
echo "System reboot is required"
|
||||
exit ${WARNING}
|
||||
EXIT_MSG=${WARNING_MSG}
|
||||
EXIT_CODE=${WARNING_EXIT_CODE}
|
||||
else
|
||||
echo "System reboot is required"
|
||||
exit ${CRITICAL}
|
||||
EXIT_MSG=${CRITICAL_MSG}
|
||||
EXIT_CODE=${CRITICAL_EXIT_CODE}
|
||||
fi
|
||||
else
|
||||
EXIT_MSG_BODY="System reboot is required by: ${packages}"
|
||||
if [ "${warn_only}" == "true" ]; then
|
||||
echo "System reboot is required by: ${packages}"
|
||||
exit ${WARNING}
|
||||
EXIT_MSG=${WARNING_MSG}
|
||||
EXIT_CODE=${WARNING_EXIT_CODE}
|
||||
else
|
||||
echo "System reboot is required by: ${packages}"
|
||||
exit ${CRITICAL}
|
||||
EXIT_MSG=${CRITICAL_MSG}
|
||||
EXIT_CODE=${CRITICAL_EXIT_CODE}
|
||||
fi
|
||||
fi
|
||||
else
|
||||
|
@ -112,14 +124,16 @@ function check_redhat() {
|
|||
|
||||
output=$(needs-restarting -r | xargs)
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${output}"
|
||||
exit ${OK}
|
||||
echo "No reboot required: ${output}"
|
||||
exit ${OK_EXIT_CODE}
|
||||
elif [ $? -eq 1 ]; then
|
||||
echo "${output}"
|
||||
EXIT_MSG_BODY="${output}"
|
||||
if [ "${warn_only}" == "true" ]; then
|
||||
exit ${WARNING}
|
||||
EXIT_MSG=${WARNING_MSG}
|
||||
EXIT_CODE=${WARNING_EXIT_CODE}
|
||||
else
|
||||
exit ${CRITICAL}
|
||||
EXIT_MSG=${CRITICAL_MSG}
|
||||
EXIT_CODE=${CRITICAL_EXIT_CODE}
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -128,15 +142,17 @@ function check_running_kernel() {
|
|||
newest_installed_kernel=`ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | head -n1`
|
||||
running_kernel=`uname -r`
|
||||
if [[ $newest_installed_kernel != $running_kernel ]]; then
|
||||
echo "System reboot is required by: newer kernel (${newest_installed_kernel}) is available, running kernel is ${running_kernel}"
|
||||
EXIT_MSG_BODY="System reboot is required by: newer kernel (${newest_installed_kernel}) is available, running kernel is ${running_kernel}"
|
||||
if [ "${warn_only}" == "true" ]; then
|
||||
exit ${WARNING}
|
||||
EXIT_MSG=${WARNING_MSG}
|
||||
EXIT_CODE=${WARNING_EXIT_CODE}
|
||||
else
|
||||
exit ${CRITICAL}
|
||||
EXIT_MSG=${CRITICAL_MSG}
|
||||
EXIT_CODE=${CRITICAL_EXIT_CODE}
|
||||
fi
|
||||
else
|
||||
echo "No reboot required"
|
||||
exit ${OK}
|
||||
exit ${OK_EXIT_CODE}
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -154,5 +170,6 @@ case "${distro}" in
|
|||
;;
|
||||
esac
|
||||
|
||||
# Never reached
|
||||
exit ${UNKNOWN}
|
||||
# Echo message and exit
|
||||
echo "${EXIT_MSG}: ${EXIT_MSG_BODY}"
|
||||
exit $EXIT_CODE
|
||||
|
|
Loading…
Reference in New Issue