Nagios plugin: monitor a systemd service

Here’s a tiny plugin to check if a systemd service is running:

#!/bin/bash
#
# машины
# 
# Check a if a systemd service is running
# 
# Usage: $0 
#
#Nagios exit codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
 
SERVICE=$1
 
# Check service status
 
systemctl -q is-active $SERVICE
if [[ $? -ne 0 ]]; then
    echo "ERROR: service $SERVICE is not running"
    exit $CRITICAL
fi
 
echo "OK: service $SERVICE is running"
exit $OK