Monitoring plugins for Nagios, Icinga and all other NRPE compatible monitoring solutions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
980 B

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
while getopts "s:t:a:S:" opt; do
case $opt in
s)
servicestate=$OPTARG
;;
t)
servicestatetype=$OPTARG
;;
a)
serviceattempt=$OPTARG
;;
S)
service=$OPTARG
;;
esac
done
if ( [ -z $servicestate ] || [ -z $servicestatetype ] || [ -z $serviceattempt ] || [ -z $service ] ); then
echo "USAGE: $0 -s servicestate -z servicestatetype -a serviceattempt -S service"
exit 3;
else
# Only restart on the third attempt of a critical event in soft state and in first attempt of a critical event in hard state
if [ $servicestate == "CRITICAL" ] && ( ( [ $serviceattempt -eq 3 ] && [ $servicestatetype == "SOFT" ] ) || ( [ $serviceattempt -eq 1 ] && [ $servicestatetype == "HARD" ] ) ); then
pidof systemd >/dev/null
if [ $? -eq 0 ]; then
sudo systemctl restart $service
else
sudo service $service restart
fi
fi
fi