Add a reboot-required check

This commit is contained in:
Salt 2021-08-18 22:57:41 -05:00
parent 972fdaf614
commit 875a961eba
1 changed files with 28 additions and 0 deletions

28
check_reboot_required Executable file
View File

@ -0,0 +1,28 @@
#! /bin/bash
#
# check_reboot_required.sh
# Copyright (C) 2021 Vintage Salt <rehashedsalt@cock.li>
#
# Distributed under terms of the MIT license.
#
rr="/var/run/reboot-required"
# 604800 - 1 week in seconds
threshold="604800"
if [ -f "$rr" ]; then
# We have a pending reboot; alert in different states depending on its age
lastmod=$(date +%s -r "$rr")
now=$(date +%s)
if (( now - lastmod > threshold )); then
echo "CRITICAL - Pending reboot older than $threshold seconds: $(cat rr)"
exit 2
else
echo "WARNING - Pending reboot: $(cat rr)"
exit 1
fi
else
# We have no pending reboots
echo "OK - No pending reboots"
exit 0
fi