add check_service_bsd.sh
This commit is contained in:
parent
0c8f675676
commit
5f5f831d02
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Parse named arguments
|
||||||
|
while [ "$#" -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--service=*)
|
||||||
|
SERVICE="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
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 -q "${SERVICE} is running as pid [0-9]*."; then
|
||||||
|
echo "OK - ${SERVICE} is running"
|
||||||
|
exit 0
|
||||||
|
# If the service is not running, return CRITICAL
|
||||||
|
elif echo "$service_status" | grep -q "${SERVICE} is not running."; then
|
||||||
|
echo "CRITICAL - ${SERVICE} is not running"
|
||||||
|
exit 2
|
||||||
|
# If the check failed, return UNKNOWN
|
||||||
|
else
|
||||||
|
echo -e "UNKNOWN - Check failed:\n$service_status"
|
||||||
|
exit 3
|
||||||
|
fi
|
Loading…
Reference in New Issue