Created
August 6, 2013 11:05
-
-
Save piotr1212/6163588 to your computer and use it in GitHub Desktop.
nagios chkconfig check for red hat based os'es: checks which daemons should be running according to chkconfig, then checks status for each daemon
This file contains 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 | |
# check_chkconfig_status | |
# | |
# Checks which services should be running according | |
# to chkconfig and check if they actually are. | |
# | |
# 2013-08-06: Piotr Popieluch | |
# | |
# for this to run from nrpe add the following line to /etc/sudoers: | |
# nrpe ALL=(ALL) NOPASSWD: /sbin/service * status | |
# and comment | |
# Defaults requiretty | |
RUNLEVEL=$(/sbin/runlevel | awk '{print $2}') | |
RUNNING='' | |
STOPPED_COUNT=0 | |
STOPPED_NAME='' | |
IGNORE='lvm2-monitor' | |
for SERVICE in `/sbin/chkconfig --list | grep -v ${IGNORE} | grep "${RUNLEVEL}:on" | awk '{print $1}'`; do | |
/usr/bin/sudo /sbin/service ${SERVICE} status >/dev/null | |
if [ $? -ne 0 ]; then | |
STOPPED_COUNT=$(( ${STOPPED_COUNT} + 1 )) | |
STOPPED_NAME="${STOPPED_NAME} ${SERVICE}" | |
fi | |
done | |
# service stopped | |
if [ ${STOPPED_COUNT} -gt 0 ]; then | |
echo "SERVICES CRITICAL -${STOPPED_NAME} not running | failed_service=${STOPPED_COUNT}" | |
exit 2 | |
fi | |
# all services are running | |
if [ ${STOPPED_COUNT} -eq 0 ]; then | |
echo "SERVICES OK - all services running | failed_service=${STOPPED_COUNT}" | |
exit 0 | |
fi | |
# unknown error | |
echo "SERVICES UNKONWN - unknown error" | |
exit 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment