Page 1 of 2

checks fails at one script callback second script

Posted: Thu Sep 18, 2014 9:54 am
by ganeshanrs1983
hello,

We have to implement nagios monitoring for the below test script. Let me know how to implement if check fails at first script we need to callback second script. Any ideas ?

•Check looks for “i_am_here” in /tmp

#!/bin/bash
if [[ -e “/tmp/i_am_here” ]]
then
exit 0;
else
exit 1;
fi
•On fail do the following execute “restart script” callback

#!/bin/bash
date >> /tmp/restart_test
date >> /tmp/i_am_here

if [[ -e “/tmp/i_am_here” ]]
then
exit 0;
else
exit 1;
fi

Re: checks fails at one script callback second script

Posted: Thu Sep 18, 2014 9:59 am
by tmcdonald
We have a great doc on exactly this:

http://assets.nagios.com/downloads/nagi ... ios-XI.pdf

Re: checks fails at one script callback second script

Posted: Thu Sep 18, 2014 10:14 am
by ganeshanrs1983
Thanks will check the link.

Re: checks fails at one script callback second script

Posted: Thu Sep 18, 2014 11:39 am
by slansing
Let us know if you need help implementing an event handler, a lot of it is going to be down to the architecture on your side though.

Re: checks fails at one script callback second script

Posted: Fri Sep 19, 2014 6:41 am
by ganeshanrs1983
Yes i need help in implementing the event handler. Below is our new requirement could you please provide the steps how to implement monitoring in Nagios XI.
If apache/tomcat process stopped in server Nagios has to start the apache/tomcat process. If restart fails , halt monitoring and set as critical.

1.Run check script
2.Send result to OS client
3. If failure detected attempt restart for apache/tomcat
4. If restart fail, halt monitoring and set as critical
5.Forward result to monitoring station
6. Report on restart status using standard framework

Re: checks fails at one script callback second script

Posted: Fri Sep 19, 2014 1:49 pm
by sreinhardt
You would use the check script as normal via a standard service check. You would handle the rest with a single event handler. My suggestion, since this is not local to the nagios system, would be to configure check_by_ssh to call a script on the remote system that will perform all the needed steps such as restarting services and checking things. If you need it to forward checks, having that event handler call the check script you originally ran and use send_nrdp to forward back to nagios would be relatively easy, but you could also let nagios use the retry check to do a second much quicker check instead. That way you wouldn't have to include additional unneeded logic and nagios would still get results before and after the repair event handler was run.

Re: checks fails at one script callback second script

Posted: Fri Sep 19, 2014 2:40 pm
by ganeshanrs1983
Below is my requirement. Could you please explain briefly in steps how to implement Nagios monitoring.

We have to implement nagios monitoring for the below test script. Let me know how to implement if check fails at first script we need to callback second script. Any ideas ?

•Check looks for “i_am_here” in /tmp

#!/bin/bash
if [[ -e “/tmp/i_am_here” ]]
then
exit 0;
else
exit 1;
fi

-----------------------------------------------------------------------------------------
•On fail do the following execute “restart script” callback

#!/bin/bash
date >> /tmp/restart_test
date >> /tmp/i_am_here

if [[ -e “/tmp/i_am_here” ]]
then
exit 0;
else
exit 1;
fi

Re: checks fails at one script callback second script

Posted: Fri Sep 19, 2014 2:45 pm
by tmcdonald
The document I linked explains step-by-step how to add an event handler to a service check.

Re: checks fails at one script callback second script

Posted: Fri Sep 19, 2014 2:52 pm
by ganeshanrs1983
Thanks for your response. Let me follow this document. Will get back to you if i stuck in the middle.

Re: checks fails at one script callback second script

Posted: Fri Sep 19, 2014 3:02 pm
by ganeshanrs1983
I am really new to this event handler option. Let me know which plugin i need to use to get the output on nagios monitoring system.