<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-2022-jp">
<META content="MSHTML 6.00.2800.1170" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff
size=2>Remember that nagios will try to execute the script as the nagios user
not as root. Restarting the service requires root access.</FONT></SPAN></DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff size=2>The
way that I do it is to run sudo.</FONT></SPAN></DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff
size=2>Example for your event handler script:</FONT></SPAN></DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff size=2>ssh $4
sudo /etc/rc.d/init.d/httpd restart</FONT></SPAN></DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff size=2>Of
course you need to configure sudo and also make sure that ssh is exchanging keys
as the nagios user.</FONT></SPAN></DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff size=2>Mitch
Smith</FONT></SPAN></DIV>
<DIV><SPAN class=309011312-10062003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Original Message-----<BR><B>From:</B> Soeun Vanny
[mailto:vanny@artemis-it.com]<BR><B>Sent:</B> Tuesday, June 10, 2003 1:15
AM<BR><B>To:</B> nagiosplug-help@lists.sourceforge.net<BR><B>Subject:</B>
[Nagiosplug-help] Help with Event handler again!!<BR><BR></FONT></DIV>
<DIV><FONT size=2>Hello everybody!</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>I've tried to apply the event handler to restart a
service,which is probed to be down by nagios,on a remote host.I don't know
what's wrong with my work. Please take a look at my work as mentioned
below.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>1. the script that is called by nagios to restart a
service.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> #!/bin/sh</FONT></DIV>
<DIV><FONT size=2> </FONT></DIV>
<DIV><FONT size=2> case "$1" in</FONT></DIV>
<DIV><FONT size=2> OK)</FONT></DIV>
<DIV><FONT size=2>
;;</FONT></DIV>
<DIV><FONT size=2> WARNING)</FONT></DIV>
<DIV><FONT size=2>
;;</FONT></DIV>
<DIV><FONT size=2> UNKNOWN)</FONT></DIV>
<DIV><FONT size=2>
;;</FONT></DIV>
<DIV><FONT size=2> CRITICAL)</FONT></DIV>
<DIV><FONT
size=2>
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT
size=2> case
"$2" in</FONT></DIV>
<DIV><FONT
size=2>
SOFT)</FONT></DIV>
<DIV><FONT
size=2>
case "$3" in</FONT></DIV>
<DIV><FONT size=2>
3)</FONT></DIV>
<DIV><FONT size=2>
ssh $4 /etc/rc.d/init.d/httpd restart</FONT></DIV>
<DIV><FONT size=2>
;;</FONT></DIV>
<DIV><FONT size=2>
esac</FONT></DIV>
<DIV><FONT size=2>
;;</FONT></DIV>
<DIV><FONT size=2>
HARD)</FONT></DIV>
<DIV><FONT size=2>
ssh $4 /etc/rc.d/init.d/httpd
restart</FONT></DIV>
<DIV><FONT size=2>
;;</FONT></DIV>
<DIV><FONT size=2>
esac</FONT></DIV>
<DIV><FONT size=2>
;;</FONT></DIV>
<DIV><FONT size=2> esac</FONT></DIV>
<DIV><FONT size=2> exit 0</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>2. Here is the syntax of serviccs.cfg</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2># Service definition<BR>define
service{<BR> use generic-service ; Name
of service template to use</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> host_name
hestia<BR> service_description HTTP<BR> is_volatile
0<BR> check_period
24x7<BR> max_check_attempts
4<BR> normal_check_interval
5<BR> retry_check_interval
1<BR> contact_groups
admins<BR> notification_interval
120<BR> notification_period
24x7<BR> notification_options w,u,c,r</DIV>
<DIV> event_handler_enabled 1</DIV>
<DIV> check_event_handler service-restart<BR> check_command
check_http<BR> }</DIV>
<DIV> </DIV>
<DIV>3. Here is the syntax of checkcommands.cfg</DIV>
<DIV> </DIV>
<DIV># 'event_handler' command definition<BR>define
command{<BR> command_name
service-restart<BR> command_line /usr/local/nagios/libexec/service-restart
$SERVICESTATE$ $STATETYPE$ $SERVICEATTEMP$ $HOSTADDRESS$<BR> }</DIV>
<DIV> </DIV>
<DIV>For test i stopped the http service on a remote machine and tried
to execute by hand the following command:
<DIV> ssh 192.168.1.200 /etc/rc.d/init.d/httpd restart
. Well, it worked well (of course i set ssh to passwordless).</DIV>
<DIV> </DIV>
<DIV>Is there anything wrong with my script?</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Thanks in advance for your help</DIV>
<DIV> </DIV></DIV>
<DIV> </DIV><PRE> </PRE></FONT>
<DIV> </DIV>
<DIV><FONT
size=2>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/<BR>_/<BR>_/$B!!!!F|K\%"%k%F%_%93t<02q<R(J<BR>_/$B!!!!%9!<%s!&%t%!%K!<(J
(Soeun Vanny)<BR>_/$B!!!!(Jmailto : <A
href="mailto:vanny@artemis-it.com">vanny@artemis-it.com</A><BR>_/<BR>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/<BR></FONT></DIV></BLOCKQUOTE></BODY></HTML>