monitoring-scripts/check_reboot_required

42 lines
1011 B
Plaintext
Raw Normal View History

2021-08-18 22:57:41 -05:00
#! /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"
rrpkgs="/var/run/reboot-required.pkgs"
2021-08-18 22:57:41 -05:00
# 604800 - 1 week in seconds
threshold_crit="${1:-604800}"
# 259200 - 3 days in seconds
threshold_warn="${2:-259200}"
2021-08-18 22:57:41 -05:00
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)
pkgs="$(cat "$rr")"
if [ -f "$rrpkgs" ]; then
pkgs="$(cat "$rrpkgs")"
fi
if [ -z "$pkgs" ]; then
pkgs="(No output)"
fi
if (( now - lastmod < threshold_warn )); then
echo "OK - Pending reboot: $pkgs"
exit 0
elif (( now - lastmod < threshold_crit )); then
echo "WARNING - Pending reboot older than $threshold_warn seconds: $pkgs"
2021-08-18 22:57:41 -05:00
exit 1
else
echo "CRITICAL - Pending reboot older than $threshold_crit seconds: $pkgs"
exit 2
2021-08-18 22:57:41 -05:00
fi
else
# We have no pending reboots
echo "OK - No pending reboots"
exit 0
fi