Last active
May 30, 2024 18:18
-
-
Save guisea/b16431029c9b78d5c8b692effe7f6e48 to your computer and use it in GitHub Desktop.
A Custom Check for CheckMK - Checks RHEL/Debian and derived OS's for pending reboots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Filename: /local/share/check_mk/agents/custom/linux-reboot/lib/local/600/needs-restarted | |
source /etc/os-release | |
VERSION=$(echo ${VERSION} | awk -F . '{ print $1 }') | |
# RHEL and Derivatives | |
if ([[ $ID_LIKE =~ 'fedora' ]] || [[ $ID =~ 'rhel' ]]) && [[ $VERSION =~ '8' ]]; | |
then | |
# RHEL 8 | |
REBOOT=`dnf needs-restarting -r >/dev/null 2>&1; echo $?;` | |
elif ([[ $ID_LIKE =~ 'fedora' ]] || [[ $ID =~ 'rhel' ]]) && [[ $VERSION =~ '7' ]] | |
then | |
# RHEL 7 | |
REBOOT=`needs-restarting -r >/dev/null 2>&1; echo $?;` | |
fi | |
# Debian and Derivatives | |
if ([[ $ID_LIKE =~ 'debian' ]] || [[ $ID =~ 'debian' ]]); | |
then | |
# Nice and easy, check if /var/run/reboot-required is present | |
if [ -f /var/run/reboot-required ]; | |
then | |
REBOOT=1 | |
else | |
REBOOT=0 | |
fi | |
fi | |
if [[ $REBOOT -eq 0 ]] | |
then | |
echo "0 reboot-required - OK: Reboot not required" | |
elif [[ $REBOOT -ge 1 ]] | |
then | |
echo "1 reboot-required - WARN: Updated packages indicate reboot is required" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment