Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #___ ___ _____ ___
- #| _ \ _ \_ _/ __|
- #| _/ / | || (_ |
- #|_| |_|_\ |_| \___|
- # NETWORK MONITOR
- #-------------------
- #(c) 2016 Dariusz Gorka, Paessler AG
- #
- #This script checks if a certain service us running.
- #The script also tries to restart the service if it is not started.
- #
- #Enter the correct process name. (ps -e)
- service=$1
- #Enter the server address of your PRTG, including HTTPS/HTTP and the sensor port.
- prtghost=$2
- #Enter the Identification Token of the HTTP Push Data Advanced sensor.
- identtoken=$3
- #Check if process is running
- if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
- then
- #Send response to PRTG that the service is running.
- wget -O/dev/null "$prtghost/$identtoken?content=<prtg><result><channel>$service status</channel><value>1</value></result><text>Service: $service is running!</text></prtg>"
- else
- #Send response to PRTG that the service is not started.
- wget -O/dev/null "$prtghost/$identtoken?content=<prtg><result><channel>$service status</channel><value>0</value></result><text>Service: $service is down, but will restart!</text></prtg>"
- #Try to restart the service
- /etc/init.d/$service start
- #Check if restart was successfully
- if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
- then
- #Send response to PRTG that the restart was successfully
- wget -O/dev/null "$prtghost/$identtoken?content=<prtg><result><channel>$service status</channel><value>1</value></result><text>Service: $service restarted properly!</text></prtg>"
- else
- #Send response to PRTG that the restart was not succesfully
- wget -O/dev/null "$prtghost/$identtoken?content=<prtg><result><channel>$service status</channel><value>0</value></result><text>Service: $service can't restart properly! Please take action!</text></prtg>"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement