File: //lib64/nagios/plugins/check_nimbus.sh
#!/bin/bash
# check_nimbus - check nimbus core services and statuses
# Requirements: n/a
# Author: Tsvetan Gerov <tsvetan@worldhost.group>
# Version 0.3
# Initialize flags and error message
CRTIICAL=false
WARNING=false
ERROR_MESSAGE=""
# Check all PHP FPM services
check_fpm(){
INSTALLED_PHP=$(ls /usr/bin/php[0-9]*)
for PHP in $INSTALLED_PHP; do
FPM=$(echo "$(basename $PHP)-fpm.service")
if ! systemctl is-active $FPM >/dev/null 2>&1; then
CRTIICAL=true
ERROR_MESSAGE+="$FPM is down, "
fi
done
}
# Check Platform Agent
check_agent(){
local NAME="platform-agent.service"
if ! systemctl is-active $NAME >/dev/null 2>&1; then
CRTIICAL=true
ERROR_MESSAGE+="$NAME is down, "
fi
}
# Check Platform Metrics service
check_platform-metrics(){
local NAME="platform-metrics.service"
if ! systemctl is-active $NAME >/dev/null 2>&1; then
CRTIICAL=true
ERROR_MESSAGE+="$NAME is down, "
fi
}
# Check Platform Metrics Schedule service
check_platform-metrics-schedule(){
local NAME="platform-metrics-schedule.service"
if ! systemctl is-active $NAME >/dev/null 2>&1; then
CRTIICAL=true
ERROR_MESSAGE+="$NAME is down, "
fi
}
# Check ElasticSearch
check_elastic(){
CODE=$(curl 127.0.0.1:9200 -s -o /dev/null -w "%{http_code}")
if [ $CODE -ne "200" ]; then
CRTIICAL=true
ERROR_MESSAGE+="ElasticSearch is down, "
fi
}
# Check Redis
check_redis(){
if ! redis-cli ping >/dev/null 2>&1; then
CRTIICAL=true
ERROR_MESSAGE+="Redis is down, "
fi
}
# Perform checks
if ls /usr/bin/php[0-9]* 1>/dev/null 2>&1; then
check_fpm
fi
if [ -f "/etc/systemd/system/platform-agent.service" ]; then
check_agent
fi
if [ -f "/etc/systemd/system/platform-metrics.service" ]; then
check_platform-metrics
fi
if [ -f "/etc/systemd/system/platform-metrics-schedule.service" ]; then
check_platform-metrics-schedule
fi
if [ -f "/usr/share/elasticsearch/bin/elasticsearch" ]; then
check_elastic
fi
if [ -f "/usr/bin/redis-server" ]; then
check_redis
fi
# Return final state
if [ "$CRTIICAL" = true ]; then
echo "[CRTIICAL] ${ERROR_MESSAGE%, }"
exit 2
elif [ "$WARNING" = true ]; then
echo "[WARNING] ${ERROR_MESSAGE%, }"
exit 1
else
echo "[OK] All services are running correctly."
exit 0
fi