-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create check_reboot_req.bash #414
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
#!/bin/bash | ||
# | ||
# Check if reboot is required plugin for Nagios for Debian/Ubuntu Systems | ||
# Written by Senthil Nathan | ||
# Last Modified: 10/31/2023 | ||
# | ||
# Usage: ./check_reboot_req -w 0 -c 2 | ||
# | ||
# Description: | ||
# | ||
# This plugin will send an alert if the servers needs to be rebooted | ||
# | ||
# Output: | ||
# | ||
# System OK | ||
# Reboot required | ||
# | ||
# | ||
# Notes: | ||
# | ||
# Update RFILENAME as required | ||
# | ||
# | ||
|
||
ECHO="/bin/echo" | ||
GREP="/bin/egrep" | ||
DIFF="/usr/bin/diff" | ||
TAIL="/usr/bin/tail" | ||
CAT="/bin/cat" | ||
RM="/bin/rm" | ||
CHMOD="/bin/chmod" | ||
TOUCH="/bin/touch" | ||
|
||
PROGNAME=`/usr/bin/basename $0` | ||
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
REVISION="1.0" | ||
|
||
. $PROGPATH/utils.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
|
||
RFILENAME=/var/run/reboot-required | ||
|
||
print_usage() { | ||
echo "Without parameters defaults to -w 0 and -c 1" | ||
echo "Usage: $PROGNAME" | ||
echo "Usage: $PROGNAME -w days -c days" | ||
echo "Usage: $PROGNAME --help" | ||
echo "Usage: $PROGNAME --version" | ||
} | ||
|
||
print_help() { | ||
print_revision $PROGNAME $REVISION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
echo "" | ||
print_usage | ||
echo "" | ||
echo "Plugin for Nagios to alert if system needs a reboot" | ||
echo "" | ||
support | ||
} | ||
|
||
# Grab the command line arguments | ||
|
||
exitstatus=$STATE_WARNING #default | ||
while test -n "$1"; do | ||
case "$1" in | ||
--help) | ||
print_help | ||
exit $STATE_OK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
;; | ||
-h) | ||
print_help | ||
exit $STATE_OK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
;; | ||
--version) | ||
print_revision $PROGNAME $REVISION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
exit $STATE_OK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
;; | ||
-V) | ||
print_revision $PROGNAME $REVISION | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
exit $STATE_OK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
;; | ||
--warning) | ||
warn=$2 | ||
shift | ||
;; | ||
-w) | ||
warn=$2 | ||
shift | ||
;; | ||
--critical) | ||
crit=$2 | ||
shift | ||
;; | ||
-c) | ||
crit=$2 | ||
shift | ||
;; | ||
-x) | ||
exitstatus=$2 | ||
shift | ||
;; | ||
--exitstatus) | ||
exitstatus=$2 | ||
shift | ||
;; | ||
*) | ||
echo "Unknown argument: $1" | ||
print_usage | ||
exit $STATE_UNKNOWN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
;; | ||
esac | ||
shift | ||
done | ||
|
||
# Check begins here | ||
if [ -z $warn ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
declare -i warn=0 | ||
fi | ||
if [ -z $crit ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
||
declare -i crit=1 | ||
fi | ||
# | ||
if [ -f "${RFILENAME}" ]; then | ||
CDATE=$(date +%s) | ||
FDATE=`stat -c %Y -- "${RFILENAME}"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use $(...) notation instead of legacy backticked |
||
DDIFF=$(($CDATE-$FDATE)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
DIFFDAYS=$((DDIFF/86400)) | ||
if [ $DIFFDAYS -ge $crit ]; then | ||
exitstatus=$STATE_CRITICAL | ||
elif [ $DIFFDAYS -ge $warn ]; then | ||
exitstatus=$STATE_WARNING | ||
else | ||
exitstatus=$STATE_OK | ||
fi | ||
echo "Reboot required" | ||
else | ||
echo "System OK" | ||
exitstatus=$STATE_OK | ||
fi | ||
exit $exitstatus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double quote to prevent globbing and word splitting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double quote to prevent globbing and word splitting.