Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions check_reboot_req.bash
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`
Copy link

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.

PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
Copy link

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.

REVISION="1.0"

. $PROGPATH/utils.sh
Copy link

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.


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
Copy link

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.

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
Copy link

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.

;;
-h)
print_help
exit $STATE_OK
Copy link

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.

;;
--version)
print_revision $PROGNAME $REVISION
Copy link

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.

exit $STATE_OK
Copy link

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.

;;
-V)
print_revision $PROGNAME $REVISION
Copy link

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.

exit $STATE_OK
Copy link

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.

;;
--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
Copy link

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.

;;
esac
shift
done

# Check begins here
if [ -z $warn ]; then
Copy link

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.

declare -i warn=0
fi
if [ -z $crit ]; then
Copy link

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.

declare -i crit=1
fi
#
if [ -f "${RFILENAME}" ]; then
CDATE=$(date +%s)
FDATE=`stat -c %Y -- "${RFILENAME}"`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $(...) notation instead of legacy backticked ....

DDIFF=$(($CDATE-$FDATE))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$/${} is unnecessary on arithmetic variables.

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
Copy link

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.

Loading