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