Page 2 of 2

Re: Nagios perform command on server down

Posted: Tue May 22, 2012 8:56 am
by scottwilkerson
Can you post your nsc.ini from server B (blocking out any sensitive data)

Re: Nagios perform command on server down

Posted: Wed May 23, 2012 7:32 am
by MDL
Hi Scott,

I already got it to work. I misplaced my command under the [External Script] section instead of [External Scripts]. Now it does work when I turn off server A. However, server A is an MSSQL server and I actually want Nagios to perform the action as soon as the MSSQL Server Agent stops working on server A. I already added the MSSQL server check in Nagios to server A. Currently Nagios is trying to connect to the MSSQL server using a MSSQL username and password. As soon as I take the MSSQL server agent down, Nagios produces a critical warning on this service, telling it is down. And that's when I want Nagios to perform the Event Handler, instead of waiting untill the whole server is down.

Could you please describe how to configure the Event Handler to occur when this specific service check fails?

Thank you for all your kind help so far.

Re: Nagios perform command on server down

Posted: Wed May 23, 2012 10:57 am
by scottwilkerson
You can add the event handler to a service the same way you added it to the host, like so:

Go to Configure -> Core Config Manager -> Services -> Modify -> Check Settings Tab
Set
Event handler = run_script_on_b_when_a_down

Re: Nagios perform command on server down

Posted: Tue Jun 19, 2012 9:47 am
by MDL
Thank you Scott.
I am facing another problem now. The .bat file, which the NSclient should execute, only does its action on the machine where the .bat is located. For example, in the .bat file are commands described to rename a hosts file in the system32 folder on localhost and also on some hosts in the LAN network. When I execute the script by hand, all the hosts files on all the hosts in the LAN network are renamed. But when Nagios calls the script, only the hosts file on the host where the script is located gets renamed.

I see the following in the nsclient.log at the time of the script execution:
error:modules\NRPEListener\NRPEListener.cpp:465: Truncating return data as it is bigger then NRPE allows :(

Can anyone tell me how to get this fixed or what the error means? When Nagios calls the script I need it to perform all the commands in it, not only the first one on localhost.

Re: Nagios perform command on server down

Posted: Tue Jun 19, 2012 10:01 am
by scottwilkerson
I'm not positive, but I am guessing that the user that NSClient++ is running under doesn't have permissions to change the files on other machines. You may need to have NSClient++ run as a different user...

Re: Nagios perform command on server down

Posted: Tue Jun 19, 2012 10:05 am
by slansing

Code: Select all

error:modules\NRPEListener\NRPEListener.cpp:465: Truncating return data as it is bigger then NRPE allows
Means that the check has maxed out the amount of data which can be sent through NRPE to Nagios. The maximum amount that can be sent is 1024 B so it is cutting off the extra commands. In order to change this you must edit the source of check_nrpe, and recompile it. A ticket was opened on the NSClient website which should help you out in this area.
http://nsclient.org/nscp/ticket/133

Re: Nagios perform command on server down

Posted: Wed Jun 20, 2012 2:20 pm
by MDL
Hi Slansing,

I figured out that even when I place the commands to rename the hosts file on localhost at the bottom of my script, these are still the only ones getting executed. The first ones don't which describe to rename the hosts file on another remote host in the LAN. So I assume it has got nothing to do with the maximum length. How would it otherwise be possible that the whole script is skipped, and only the last 2 lines describing a rename action on localhost is executed?
Before I forget: It doesn't matter where I place the commands for localhost. Even if I place them in the middle of my script, those are still the only ones getting executed. All the ones on remote hosts don't.
I cannot understand why... The NSClient doesn't have to do anything, only call a .bat file to execute. The real execution is done by the batch file....

Re: Nagios perform command on server down

Posted: Wed Jun 20, 2012 3:06 pm
by scottwilkerson
scottwilkerson wrote:I'm not positive, but I am guessing that the user that NSClient++ is running under doesn't have permissions to change the files on other machines. You may need to have NSClient++ run as a different user...
Did you check this?

By default NSClient++ runs under the Local system account which likely doesn't have access to your remote machines. To change this (or at least test it) you can
open services
right click on NSCLient+
chose properties
Log On Tab
Change to specify the account that you logon as,the one that CAN run the commands on the other server.
Click OK
restart NSClient++

Then try again.

Re: Nagios perform command on server down

Posted: Thu Jun 21, 2012 6:21 am
by MDL
scottwilkerson wrote:
scottwilkerson wrote:I'm not positive, but I am guessing that the user that NSClient++ is running under doesn't have permissions to change the files on other machines. You may need to have NSClient++ run as a different user...
Did you check this?

By default NSClient++ runs under the Local system account which likely doesn't have access to your remote machines. To change this (or at least test it) you can
open services
right click on NSCLient+
chose properties
Log On Tab
Change to specify the account that you logon as,the one that CAN run the commands on the other server.
Click OK
restart NSClient++

Then try again.
Thank you Scott! You saved my day.
Works like a charm.

I was unsure if this would work because the servers are not in a domain, only in the same LAN network. But adding the same account to every server and granting .\<username> rights on the NSclient service worked.

Re: Nagios perform command on server down

Posted: Thu Jun 21, 2012 10:39 am
by scottwilkerson
No problem. Glad it worked for you.