Last active
December 18, 2015 21:59
-
-
Save allardhoeve/5851795 to your computer and use it in GitHub Desktop.
check_shorewall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# nagios check for shorewall | |
# checks the state file by getting the status of shorewall and checking the return output | |
# flip hess <[email protected]> - May 14 - 2013 | |
STATE_OK=0 | |
STATE_WARNING=1 | |
STATE_CRITICAL=2 | |
STATE_UNKNOWN=3 | |
# check for shorewall binary! | |
SHOREWALL="/sbin/shorewall" | |
CONFDIR="/etc/shorewall" | |
if [ ! -x "${SHOREWALL}" ]; | |
then | |
echo -e "Shorewall UNKNOWN - Binary ${SHOREWALL} not found! Exiting script!"; | |
exit "${STATE_UNKNOWN}"; | |
fi | |
# check shorewall state file | |
if [ ! -f "/var/lib/shorewall/state" ] | |
then | |
echo -e "Shorewall UNKNOWN - Failed to read /var/lib/shorewall/state"; | |
exit "${STATE_UNKNOWN}" | |
fi | |
# check shorewall state | |
STATE="$( cat /var/lib/shorewall/state )" | |
if [ "${?}" != 0 ] ; then | |
echo "Shorwall UNKNOWN - Failed to get state from /var/lib/shorewall/state"; | |
exit "${STATE_UNKNOWN}" | |
fi | |
# check exit code | |
CHECKSTATE="$( echo "${STATE}" | egrep -q '(Started|Restored)' )" | |
if [ "${?}" != 0 ] | |
then | |
echo "Shorewall CRITICAL - Not Started - State is ${STATE}" | |
exit "${STATE_CRITICAL}" | |
fi | |
# check shorewall syntax | |
COMMAND="$( ${SHOREWALL} try "${CONFDIR}" 2>&1 )" | |
EXIT="${?}" | |
OUTPUT="$( echo -e "${COMMAND}" | tail -n1 )" | |
# make results | |
if [ "${EXIT}" == 0 ] && ( echo -e "${COMMAND}" | grep -q 'done.' ) | |
then | |
# ok | |
echo -e "Shorewall OK - State is: ${STATE} - Output of check command was: ${OUTPUT}" | |
exit "${STATE_OK}" | |
else | |
# nok | |
echo -e "Shorewall CRITICAL - State was: ${STATE} - Output of check command was: ${OUTPUT}" | |
exit "${STATE_CRITICAL}" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment