icinga2-checks/check_service_bsd.sh

39 lines
838 B
Bash
Executable File

#!/bin/sh
# Parse named arguments
while [ "$#" -gt 0 ]; do
case "$1" in
--service)
SERVICE="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 3
;;
esac
done
# Check if the service name is provided
if [ -z "$SERVICE" ]; then
echo "UNKNOWN - Service name not provided"
exit 3
fi
# Check if the service is running
service_status=$(service ${SERVICE} onestatus)
# If the service is running, return OK
if echo "$service_status" | grep -iq "${SERVICE} is running \(as\|with\) pid [0-9]*."; then
echo "OK - ${SERVICE} is running"
exit 0
# If the service is not running, return CRITICAL
elif echo "$service_status" | grep -iq "${SERVICE} is not running."; then
echo "CRITICAL - ${SERVICE} is not running"
exit 2
# If the check failed, return UNKNOWN
else
echo "UNKNOWN - Check failed"
exit 3
fi