Re: [Nagios-users] start a script automatically

2006-04-05 Thread tomvo
Hi,

I just did this a few days ago using eventhandlers, I'll post my config 
for your convenience, actually, it's dead easy:

this is the config of the service check:

define service{
use generic-service ; Name of 
service template to use
host_name   www..be
service_description HTTP_check_www.x.be_.5_interface
contact_groups  solaris-admins
retry_check_interval3
event_handler   restart_xxxweb
check_command check_webtest!xxx-5.scr!http://www.xxx.be interface 
.5 via internet
}


the key here is the event_handler line. This 'function' is executed 
whenever a state change occurs.

in checkcommands.cfg you must define this function:

define command{
command_namerestart_xxxweb
command_line 
/usr/lib/nagios/plugins/eventhandlers/restart_xweb $SERVICESTATE$ 
$SERVICESTATETYPE$ $SERVICEATTEMPT$
}


This provides the link to the script that will be executed each time a 
state change occurs.


below the contents of this script (I found it somewhere on a nagios 
support site) and modified it slightly for my environment. As you will 
see, I'm using the nagios client mechanism to restart the service on the 
remote host.



#!/bin/sh
#
# Event handler script for restarting the web server on the local machine
#
# Note: This script will only restart the web server if the service is
#   retried 3 times (in a soft state) or if the web service somehow
#   manages to fall into a hard error state.
#


# What state is the HTTP service in?
case $1 in
OK)
# The service just came back up, so don't do anything...
;;
WARNING)
# We don't really care about warning states, since the service is 
probably still running...
;;
UNKNOWN)
# We don't know what might be causing an unknown error, so don't 
do anything...
;;
CRITICAL)
# Aha!  The HTTP service appears to have a problem - perhaps we 
should restart the server...

# Is this a soft or a hard state?
case $2 in
# We're in a soft state, meaning that Nagios is in the middle of 
retrying the
# check before it turns into a hard state and contacts get 
notified...
SOFT)

# What check attempt are we on?  We don't want to restart 
the web server on the first
# check, because it may just be a fluke!
case $3 in

# Wait until the check has been tried 3 times before 
restarting the web server.
# If the check fails on the 4th time (after we restart the 
web server), the state
# type will turn to hard and contacts will be notified 
of the problem.
# Hopefully this will restart the web server successfully, 
so the 4th check will
# result in a soft recovery.  If that happens no one 
gets notified because we
# fixed the problem!
1)
echo $(date): Dit is de eerste soft state voor 
web, we herstarten de gateway  /tmp/eventhandler_test
/usr/lib/nagios/plugins/check_nrpe -H 
193.110.158.5  -c restart_xxxweb
;;

2)
echo $(date): Dit is de tweede soft state voor 
xxxweb, we herstarten de gateway voor de 2e keer  
/tmp/eventhandler_test
/usr/lib/nagios/plugins/check_nrpe -H 
193.110.158.5  -c restart_xxxweb
;;
3)
echo $(date): Dit is de derde soft state voor 
xxxweb, we herstarten de gateway voor de laatste maal, indien het nog niet 
werkt is er iets goed fout  /tmp/eventhandler_test
/usr/lib/nagios/plugins/check_nrpe -H 
193.110.158.5  -c restart_xxxweb
;;

esac
;;

# The HTTP service somehow managed to turn into a hard error 
without getting fixed.
# It should have been restarted by the code above, but for some 
reason it didn't.
# Let's give it one last try, shall we?
# Note: Contacts have already been notified of a problem with the 
service at this
# point (unless you disabled notifications for this service)

HARD)
echo $(date): na 3x proberen wil de xxxweb gateway nog 
altijd niet opstarte, misschien eens proberen met de server te rebooten ? 
 /tmp/eventhandler_test
;;
esac
esac
exit 0









---
Tom Van Overbeke - ABSI Service Delivery Coordinator
email: [EMAIL PROTECTED]
Tel: +32 2 333 40 00 - Fax: +32 2 332 34 69
website: http://www.absi.be
---





Marco Borsani [EMAIL PROTECTED]
Sent by: [EMAIL PROTECTED]
03/04/2006 13:57
 
   

RE: [Nagios-users] start a script automatically

2006-04-05 Thread Marc Powell


 -Original Message-
 From: Marco Borsani [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, April 05, 2006 2:59 AM
 To: Marc Powell
 Cc: 'NAGIOS'
 Subject: R: [Nagios-users] start a script automatically
 
 
 -}Marc wrote:
 -}
 -}Not without the rest of the error that you chopped off.
 -}What's the '' part? That's probably the most useful bit
 -}of information. You've been on the list long enough to know
 -}we need more information than that
 -};)
 
 Complete message is:
 Warning: Attempting to execute the command
 /usr/local/nagios/libexec/eventhandlers/restart-http $SERVICESTATE$
 $STATETYPE$ $SERVICEATTEMPT$
 

It's a moot point now it seems but in the future, there should be even
more to this error and the variables would have been filled in. From the
code, the complete line will look like --

base/utils.c:
snprintf(buffer,sizeof(buffer)-1,Warning: Attempting to execute the
command \%s\ resulted in a return code of %d.  Make sure the script or
binary you are trying to execute actually exists...\n,cmd,result);

The return code would have been the interesting part.

A real example --

var/archives/nagios-04-11-2004-00.log:[1081457063] Warning: Attempting
to execute the command /usr/local/nagios/libexec/check_ping
208.182.181.2 100 100 5000.0 5000.0 -p 1 -t 30 resulted in a return
code of 127.  Make sure the script or binary you are trying to execute
actually exists...

--
Marc


---
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnkkid0944bid$1720dat1642
___
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue.
::: Messages without supporting info will risk being sent to /dev/null


RE: [Nagios-users] start a script automatically

2006-04-04 Thread Marc Powell


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:nagios-users-
 [EMAIL PROTECTED] On Behalf Of Marco Borsani
 Sent: Tuesday, April 04, 2006 9:04 AM
 To: [EMAIL PROTECTED]
 Cc: 'NAGIOS'
 Subject: R: [Nagios-users] start a script automatically
 
 I followed istructions on the manual.
 
 When Nagios try to run the command, in the nagios.log I still read :
 
 Warning: Attempting to execute the command
 /usr/local/nagios/libexec/eventhandlers/restart-http  
 
 ls -la /usr/local/nagios/libexec/eventhandlers/restart-http
 -rwxr-xr-x   1 root   sys 489 Apr  4 15:06
 /usr/local/nagios/libexec/eventhandlers/restart-http
 
 Any idea?

Not without the rest of the error that you chopped off. What's the
'' part? That's probably the most useful bit of information. You've
been on the list long enough to know we need more information than that
;)

Can you run restart-http as the nagios user? Show us the command and
service definition. Verify that you're using full paths for commands
used within restart-http. Detail what restart-http is doing
specifically.

--
Marc


---
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnkkid0944bid$1720dat1642
___
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting 
any issue.
::: Messages without supporting info will risk being sent to /dev/null


Re: [Nagios-users] start a script automatically

2006-04-03 Thread joseph . petrucci

Look into event handlers.

Joe Petrucci 
Office: 704-383-6089
Cell : 724-462-0443






Marco Borsani
[EMAIL PROTECTED] 
Sent by: [EMAIL PROTECTED]
04/03/2006 07:57 AM





To
'NAGIOS' nagios-users@lists.sourceforge.net


cc



Subject
[Nagios-users] start a script
automatically








Hi all!

Is it possible to start a script automatically on a remote host in case
of a
particolar event?

For example, if nagios detects that process named on a DNS
server is down,
will Nagios can run a remote command on that server to restart the process?

Regards

Marco Borsani 
  
Unix  Monitoring System Administrator
Technical Operation
Tel.  +39 010 4310115
Fax   +39 010 4327454
E-mail: [EMAIL PROTECTED]

ITnet S.r.l. - Direzione e Coordinamento di WIND Telecomunicazioni S.p.A.
Internet Service Provider
Sede legale: 
 Via C.G.Viola, 48 - 00148 Roma
Dir. Centrale e Amministrativa: 
Via Pacinotti, 39

  
   16151 Genova (Italy)
  
  


http://www.it.net
   
mailto:[EMAIL PROTECTED] 
___
Altre sedi ITnet:
MILANO tel.: +39 02 30114900  [EMAIL PROTECTED]
ROMA  tel.: +39 06 83116707  [EMAIL PROTECTED]
___
ITnet is associated to CIX (Commercial IP eXchange) and RIPE
ITnet is associated to AIIP (Associazione Italiana Internet Providers)




---
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnkkid=110944bid=241720dat=121642
___
Nagios-users mailing list
Nagios-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting
any issue. 
::: Messages without supporting info will risk being sent to /dev/null

ForwardSourceID:NT00014CEE