- Go to the Windows server and create a local user
- Create the following script called iisreset.sh in your Nagios plugins directory replacing the username and password in the three locations below
#!/bin/sh # # Event handler script for restarting IIS on windows server # Requires a local user on the server with the username and password below if [ $# -eq 3 ] then if [ "$1" = "CRITICAL" ] then if [ "$2" = "HARD" ] then # Start the service /usr/bin/net rpc service stop W3SVC -I $3 -U User%password >/dev/null sleep 4 /usr/bin/net rpc service start W3SVC -I $3 -U User%password >/dev/null 2>&1 sleep 4 /usr/bin/net rpc service status W3SVC -I $3 -U User%password | grep 'W3SVC' exit 0 fi fi else echo "Invalid number of arguments" exit 1 fi
- Edit your commands.cfg file in the Nagios configuration directory
define command { command_name iisreset command_line $USER1$/iisreset.sh $SERVICESTATE$ $SERVICESTATETYPE$ $HOSTADDRESS$ }
- Add the event handler command to an existing service definition
define service{ host_name somehost service_description HTTP event_handler iisreset ... }
- The script will be called like this. You can put this in a command line to confirm it will work. /usr/lib/nagios/plugins/iisreset.sh CRITICAL HARD 10.10.0.2
- Reload or start Nagios
/etc/init.d/nagios3 reload
Tips and Tricks for Microsoft Dynamics AX, now Microsoft Dynamics 365 for Finance and Operations, also formerly known as Dynamics AX 4.0, 2009, 2012 and even Axapta.
Showing posts with label Nagios. Show all posts
Showing posts with label Nagios. Show all posts
Sunday, September 26, 2010
Nagios: Automatically restart IIS after a CRITICAL alert
You can execute code when a service or host changes state. These are called event handlers.
Subscribe to:
Posts (Atom)