sending external commands remotely

Eric Pearce epearce at amberpoint.com
Tue Mar 17 23:46:17 CET 2009


Thanks for the input - the following seems to work:

Turn off service notification:

 wget --quiet -O - --http-user=myuser --http-password=mypassword --post-data 
'cmd_typ=23&cmd_mod=2&host=myhost&service=myservice&btnSubmit=Commit' 
http://webserver/nagios/cgi-bin/cmd.cgi > /dev/null

Turn on service notification:

 wget --quiet -O - --http-user=myuser --http-password=mypassword --post-data 
'cmd_typ=22&cmd_mod=2&host=myhost&service=myservice&btnSubmit=Commit' 
http://webserver/nagios/cgi-bin/cmd.cgi > /dev/null

I'd probably put the username and password in a ~nagios/.wgetrc file, so a 
resulting Solaris crontab entry might look like:

# turn on notfications
/usr/bin/su - nagios -c "/usr/local/bin/wget --quiet -O - --post-data 
'cmd_typ=23&cmd_mod=2&host=myhost&service=myservice&btnSubmit=Commit' 
http://webserver/nagios/cgi-bin/cmd.cgi" > /dev/null 2>&1

I was also able to do this on Windows using GnuWin wget:

C:\PROGRA~1\GnuWin32\bin>wget --quiet -O - --post-data 
"cmd_typ=23&cmd_mod=2&host=myhost&service=myservice&btnSubmit=Commit" 
http://webserver/nagios/cgi-bin/cmd.cgi

(.wgetrc becomes c:/progra~1/wget/etc/wgetrc)

-e

----- Original Message ----- 
From: "frank" <ratty at they.org>
To: "Eric Pearce" <epearce at amberpoint.com>
Cc: <nagios-users at lists.sourceforge.net>
Sent: Monday, March 16, 2009 9:53 PM
Subject: Re: [Nagios-users] sending external commands remotely


> Here are 2 ways to do this:
>
> 1. Click thru the web interface the normal way you would (un)silence the
> service(s)/servicegroup(s) in question but before submitting the form do a
> View-Source and use the variables and values there to create yourself a
> properly encoded URI and call it with wget. ex:
> (silence)
> wget -O - 
> http://nagios-server/nagios/cgi-bin/cmd.cgi?cmd_typ=23&cmd_mod=2&host=hostname&service=svcdesc > 
> /dev/null
> (unsilence)
> wget -O - 
> http://nagios-server/nagios/cgi-bin/cmd.cgi?cmd_typ=22&cmd_mod=2&host=hostname&service=svcdesc > 
> /dev/null
>
> I haven't read thru the source or tried these examples so I don't know if
> you also need to include "&btnSubmit=Commit" to the URI. Or perhaps it
> won't work at all as a GET instead of a POST.
>
>
> 2. Write a CGI that accepts host, service, and silence/unsilence
> variables. Feed the results directly to the Nagios command pipe
> (/var/log/nagios/rw/nagios.cmd). Once you've verified your input args,
> feed them to the pipe like:
>
> my $time = time();
> open(CMD,">>/var/log/nagios/rw/nagios.cmd");
> print CMD "[$time] DISABLE_SVC_NOTIFICATIONS;hostname;servicename\n";
> close(CMD);
>
> Again, I haven't tested any of this, but it oughtta work in theory.
>
> -f
>
> On Mon, 16 Mar 2009, Eric Pearce wrote:
>
>> Date: Mon, 16 Mar 2009 14:48:55 -0700
>> From: Eric Pearce <epearce at amberpoint.com>
>> To: nagios-users at lists.sourceforge.net
>> Subject: [Nagios-users] sending external commands remotely
>>
>>
>> I'd like to be able to remotely turn off/turn on service/host checks. For 
>> example, a remote
>> machine could turn off a service check while running a backup and turn it 
>> back on after it is
>> done. Ideally, this is a simple perl script, wrapper for 'wget', batch 
>> file, etc that could run
>> on Unix or Windows (maybe using SSL for securing the password?). I assume 
>> it would talk
>> directly to cgi on the nagios server. I've seen some others asking for 
>> something similar, but
>> no definitive replies. My understanding of NSCA is that is simply for 
>> collecting passive
>> information, and can't actually change things, right?
>>
>> Yes, I could schedule downtime via Nagios, but the downtime is of 
>> variable length, the so the
>> exact backup window is not known in advance. The machine doing the actual 
>> backup "knows
>> best" when turn monitoring on and off. NFS mounting the nagios command 
>> file is not an
>> option. I did see the old remote_ctl.pl script on nagiosexchange but I 
>> don't want to
>> do anything non-standard on the nagios server if possible. I understand 
>> that I could use ssh to
>> run local commands on nagios server, but I'm looking for something more 
>> elegant.
>>
>> My setup is Linux server running Nagios 3.0.6 and 1.4.13 plugins 
>> monitoring Linux, Solaris and
>> Windows 2000/XP/2003/Vista/2008 hosts.
>>
>> Thanks
>> -e
>>
>>
>> 


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Nagios-users mailing list
Nagios-users at 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





More information about the Users mailing list