Current File : //lib64/nagios/plugins/nccustom/check_kernelcare.sh |
#!/bin/sh
## check Kernel Care updates and if patches were applied
## Copyright (c) 2017, Namecheap.com
## Written by Yuri Muravyov <y.muravyov@gmail.com>
## Updated by Bogdan Kukharskiy <bogdan.kukharskiy@namecheap.com>
PROGNAME=check_kernel_care
REVISION=0.3
PROGNAME=`basename $0`
CHECK_UPDATES_STR="The latest patch is applied."
CHECK_UPDATES_STR2="This kernel doesn't require any patches."
CHECK_PATCHES_STR="kpatch-state: patch is applied"
print_revision() {
echo $PROGNAME $REVISION
}
print_usage() {
echo "Usage: $PROGNAME [options]"
echo " e.g. $PROGNAME"
echo
echo "Options:"
echo -e "\t --help | -h print help"
echo -e "\t --version | -V print version"
}
print_help() {
print_revision $PROGNAME $REVISION
echo
echo "This script checks kernel care state (updates and patches)"
echo
print_usage
echo
exit 3
}
# parse cmd arguments
if [ "$#" -gt 0 ]; then
while [ "$#" -gt 0 ]; do
case "$1" in
'--help'|'-h')
print_help
exit 3
;;
'--version'|'-V')
print_revision $PROGNAME $REVISION
exit 3
;;
*)
echo "Unknown option!"
print_usage
exit 3
;;
esac
done
fi
KCARE_UPDATES_CHECK=`sudo /usr/bin/kcarectl --check 2>&1`;
KCARE_PATCHES_CHECK=`sudo /usr/bin/kcarectl -i | grep kpatch-state 2>&1`;
if [ "$KCARE_UPDATES_CHECK" != "$CHECK_UPDATES_STR" ] && [ "$KCARE_UPDATES_CHECK" != "$CHECK_UPDATES_STR2" ]; then
echo "CRITICAL: $KCARE_UPDATES_CHECK"
exit 2
elif [ "$KCARE_PATCHES_CHECK" != "$CHECK_PATCHES_STR" ] && [ ${#KCARE_PATCHES_CHECK} != 0 ]; then
echo "CRITICAL: $KCARE_PATCHES_CHECK"
exit 2
fi
echo "OK: $KCARE_UPDATES_CHECK $KCARE_PATCHES_CHECK"
exit 0