Nagios perform command on server down
Nagios perform command on server down
Hi All,
I have a question about a Nagios XI feature.
I have 3 servers: Nagios, server A and server B. Nagios is monitoring both server A and B. I want Nagios to perform an action on server B when server A goes down. Server A and B are both accessible by the Nagios machine.
So basically, Nagios should start a Windows batch script on server B when server A goes down.
Can anyone tell me how to configure this?
I have a question about a Nagios XI feature.
I have 3 servers: Nagios, server A and server B. Nagios is monitoring both server A and B. I want Nagios to perform an action on server B when server A goes down. Server A and B are both accessible by the Nagios machine.
So basically, Nagios should start a Windows batch script on server B when server A goes down.
Can anyone tell me how to configure this?
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios perform command on server down
If these are windows machines running NSClient++ you could do something like the following:
in the nsc.ini you need to make sure you are using NRPE and have the following uncommented
Add your custom vbs under this section
On the XI server, go to Configure -> Core Config Manager -> Commands -> Add New
Command* = run_vbs_on_b
Command line* = $USER1$/check_nrpe -H <SERVER_B_IP> -c a_is_down
Command type = misc command
Save
Then, go to Configure -> Core Config Manager -> Host -> A -> Modify -> Check Settings Tab
Set
Event handler = run_vbs_on_b
Save
Apply configuration
in the nsc.ini you need to make sure you are using NRPE and have the following uncommented
Code: Select all
NRPEListener.dll
CheckExternalScripts.dll
Code: Select all
[External Scripts]
a_is_down=c:\path\to\script.vbs
Command* = run_vbs_on_b
Command line* = $USER1$/check_nrpe -H <SERVER_B_IP> -c a_is_down
Command type = misc command
Save
Then, go to Configure -> Core Config Manager -> Host -> A -> Modify -> Check Settings Tab
Set
Event handler = run_vbs_on_b
Save
Apply configuration
Re: Nagios perform command on server down
Hello Scott,
Thank you for your reply. However, I am facing some problems.
I did what you said to do. In the nsc.ini located in de NSclient++ directory I removed the ';' comment tag behind NRPEListener.dll and CheckExternalScripts.dll.
Then, under [External Script] I added the line a_is_down=C:\Script\Script.bat (I am using a .bat here not a .vbs).
After that is all set, I went to Nagios XI -> Core config -> Commands -> Add New.
I named the command run_script_on_b_when_a_down
command line = $USER1$/check_nrpe -H <SERVER_B_IP> -c a_is_down
command type = misc command
Saved.
Then under the Check Settings Tab in the modify menu for server A, I set the event handler on run_script_on_b_when_a_down
Then I pressed save and applied the configuration. So far so good.
Then to test, I took server A down by shutting the server off. Nagios told me A is down. However, the script isn't running on server B... Nothing happens at all. What am I doing wrong here? Maybe because the script is a batch file instead of visualbasic? Or should I restart the NSclient on server B because I edited the nsc.ini?
Thank you in advance for your response.
Thank you for your reply. However, I am facing some problems.
I did what you said to do. In the nsc.ini located in de NSclient++ directory I removed the ';' comment tag behind NRPEListener.dll and CheckExternalScripts.dll.
Then, under [External Script] I added the line a_is_down=C:\Script\Script.bat (I am using a .bat here not a .vbs).
After that is all set, I went to Nagios XI -> Core config -> Commands -> Add New.
I named the command run_script_on_b_when_a_down
command line = $USER1$/check_nrpe -H <SERVER_B_IP> -c a_is_down
command type = misc command
Saved.
Then under the Check Settings Tab in the modify menu for server A, I set the event handler on run_script_on_b_when_a_down
Then I pressed save and applied the configuration. So far so good.
Then to test, I took server A down by shutting the server off. Nagios told me A is down. However, the script isn't running on server B... Nothing happens at all. What am I doing wrong here? Maybe because the script is a batch file instead of visualbasic? Or should I restart the NSclient on server B because I edited the nsc.ini?
Thank you in advance for your response.
Re: Nagios perform command on server down
You definitely have to restart the nsclient++ service if you made any changes in the NCS.in file, so that the changes can take effect. You can restart it from a DOS prompt:
Hope this helps.
Code: Select all
net stop nsclientpp
net start nsclientpp
Be sure to check out our Knowledgebase for helpful articles and solutions!
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios perform command on server down
Also, make sure on the Check Settings Tab you have "Event handler enabled"=on
I forgot to mention this the first time...
I forgot to mention this the first time...
Re: Nagios perform command on server down
Hello,
I have 10 IIS Windows servers on which the action should be performed. Could you tell me if the following is possible?
On the New Command page, configure the following command: $USER1$/check_nrpe -H <SERVER_B_IP> <SERVER_C_IP> <SERVER_D_IP> <SERVER_E_IP> ... -c a_is_down
Thanks in advance.
I have 10 IIS Windows servers on which the action should be performed. Could you tell me if the following is possible?
On the New Command page, configure the following command: $USER1$/check_nrpe -H <SERVER_B_IP> <SERVER_C_IP> <SERVER_D_IP> <SERVER_E_IP> ... -c a_is_down
Thanks in advance.
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios perform command on server down
This is not possible, however what is possible would be to write a shell script that contained the seperate commands and add it as the command
Something like this
Something like this
Code: Select all
#! /bin/sh
/usr/local/nagios/libexec/check_nrpe -H <SERVER_B_IP> -c a_is_down
/usr/local/nagios/libexec/check_nrpe -H <SERVER_C_IP> -c a_is_down
/usr/local/nagios/libexec/check_nrpe -H <SERVER_D_IP> -c a_is_down
/usr/local/nagios/libexec/check_nrpe -H <SERVER_E_IP> -c a_is_down
/usr/local/nagios/libexec/check_nrpe -H <SERVER_F_IP> -c a_is_down
/usr/local/nagios/libexec/check_nrpe -H <SERVER_G_IP> -c a_is_down
Re: Nagios perform command on server down
Thanks again for your response.
I still can't get the command to work. I did everything Scottwilkerson described. Then I turned on the option "Event handler enabled"=on on server A in Nagios. After that, I stopped and started the nsclient on the destination machine (server B).
But still, when I shutdown server A, and Nagios tells me that it is down, there is still nothing happening on server B.
The only 2 lines in the batch script which should be run on server B are the following:
The script works fine when I manually start it but Nagios still doesn't perform anything when I take server A down.
What am I doing wrong?
I still can't get the command to work. I did everything Scottwilkerson described. Then I turned on the option "Event handler enabled"=on on server A in Nagios. After that, I stopped and started the nsclient on the destination machine (server B).
But still, when I shutdown server A, and Nagios tells me that it is down, there is still nothing happening on server B.
The only 2 lines in the batch script which should be run on server B are the following:
Code: Select all
REN C:\Windows\System32\Drivers\etc\hosts hosts_original
REN C:\Windows\System32\Drivers\etc\hosts_backup hosts
What am I doing wrong?
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Nagios perform command on server down
Can you verify that if you run the following from the command line on your Nagios server it runs on the client
I am thinking that it could possible be a permissions problem. After executing the command above look at the nsclient.log on SERVER_B to see if you see any errors
Code: Select all
/usr/local/nagios/libexec/check_nrpe -H <SERVER_B_IP> -c a_is_down
Re: Nagios perform command on server down
When I run the command i get the following:
UNKNOWN: No handler for that command
Hope you can help me out.
UNKNOWN: No handler for that command
Hope you can help me out.