Xymon Mailing List Archive search

trouble with SCRIPT directive

5 messages in this thread

list Kevin · Sat, 5 Jan 2008 11:38:21 -0500 ·
Hi all,

 
This might seem long winded but I wanted to describe the problem in detail
and see if anyone could help please.

 
 I am trying to make use of the SCRIPT function in hobbit-alerts.cfg I am
trying to send snmp traps from hobbit to another receiver using a utility
called trapgen and I think the syntax of SCRIPT and trapgen are getting in
each others way. 

 
SCRIPT seems to have this syntax:

 
SCRIPT  <program>  <recipient>  <options>

 
And trapgen has this syntax:

 
trapgen  -d  destination   <options>

 
So, when I try to assemble it, it has this form:

 
SCRIPT  /home/hobbit/server/ext/trapgen -d 10.10.0.13 <options>

 
I get an error in the page.log that says trapgen needs at least a
destination specified as:

 
trapgen -d IPADDRESS   ..but it DOES have a destination!!!

 
It seems that the SCRIPT directive is intercepting the "-d IPADDRESS" and
interpreting it as it's own "recipient" directive.??

 
Is there a way around this? Is there a way to ignore the "recipient"
directive using SCRIPT?

 
Thanks for any ideas

 
KEvin
list Galen Johnson · Sat, 5 Jan 2008 12:14:36 -0500 ·
Have you tried putting in a bogus recipient address and your options to trapgen at the end?

=G=
quoted from Kevin

-----Original Message-----
From: kevin [mailto:user-a004b26f09c6@xymon.invalid]
Sent: Sat 1/5/2008 11:38 AM
To: user-ae9b8668bcde@xymon.invalid
Subject: [hobbit] trouble with SCRIPT directive
 
Hi all,

 
This might seem long winded but I wanted to describe the problem in detail
and see if anyone could help please.

 
 I am trying to make use of the SCRIPT function in hobbit-alerts.cfg I am
trying to send snmp traps from hobbit to another receiver using a utility
called trapgen and I think the syntax of SCRIPT and trapgen are getting in
each others way. 

 
SCRIPT seems to have this syntax:

 
SCRIPT  <program>  <recipient>  <options>

 
And trapgen has this syntax:

 
trapgen  -d  destination   <options>

 
So, when I try to assemble it, it has this form:

 
SCRIPT  /home/hobbit/server/ext/trapgen -d 10.10.0.13 <options>

 
I get an error in the page.log that says trapgen needs at least a
destination specified as:

 
trapgen -d IPADDRESS   ..but it DOES have a destination!!!

 
It seems that the SCRIPT directive is intercepting the "-d IPADDRESS" and
interpreting it as it's own "recipient" directive.??

 
Is there a way around this? Is there a way to ignore the "recipient"
directive using SCRIPT?

 
Thanks for any ideas

 
KEvin
list Dave Haertig · Sat, 5 Jan 2008 10:59:49 -0700 ·
You could make a dummy shell script named "trapgen_wrapper" that just
hardcodes the ip address parameter and then calls the real trapgen using
that.  Reference trapgen_wrapper in your hobbit alert config file,
passing it that same bogus_parameter for the recipient (which is
meaningless for your application, but required by Hobbit syntax).

If you don't want to hardcode the ip address in trapgen_wrapper, you
could make trapgen_wrapper parse out the info from the environment
variable "RCPT".

Here's a similar example I use to kill a process.  The SCRIPT directive
in hobbit-alerts.cfg passes this script three parameters, the hostname,
the userid, and a patternmatch for the kill.


SCRIPT kill_script hostname,userid,pattern_to_match


And here's the script that processes the above:

#!/bin/perl
# RCS $Id: kill_script,v 1.3 2007/09/26 15:19:07 hobbit Exp $
#$debug++;      # Comment-out this line for normal operation
($host, $id, $pattern) = split(/,/, $ENV{RCPT}, 3);
exit unless ((defined $host) && (defined $id) && (defined $pattern));
$command = qq!ssh $id\@$host "pkill -f '$pattern'"!;
if ($debug) {
        $command =~ s/pkill/pgrep -l/;
        print `$command`;
}
else {
        `$command`;
quoted from Galen Johnson
}

-----Original Message-----
From: Galen Johnson [mailto:user-87f955643e3d@xymon.invalid] 
Sent: Saturday, January 05, 2008 10:15 AM
To: user-ae9b8668bcde@xymon.invalid
Subject: RE: [hobbit] trouble with SCRIPT directive


Have you tried putting in a bogus recipient address and your options to
trapgen at the end?

=G=

-----Original Message-----
From: kevin [mailto:user-a004b26f09c6@xymon.invalid]
Sent: Sat 1/5/2008 11:38 AM
To: user-ae9b8668bcde@xymon.invalid
Subject: [hobbit] trouble with SCRIPT directive
 
Hi all,

 
This might seem long winded but I wanted to describe the problem in
detail and see if anyone could help please.

 
 I am trying to make use of the SCRIPT function in hobbit-alerts.cfg I
am trying to send snmp traps from hobbit to another receiver using a
utility called trapgen and I think the syntax of SCRIPT and trapgen are
getting in each others way. 

 
SCRIPT seems to have this syntax:

 
SCRIPT  <program>  <recipient>  <options>

 
And trapgen has this syntax:

 
trapgen  -d  destination   <options>

 
So, when I try to assemble it, it has this form:

 
SCRIPT  /home/hobbit/server/ext/trapgen -d 10.10.0.13 <options>

 
I get an error in the page.log that says trapgen needs at least a
destination specified as:

 
trapgen -d IPADDRESS   ..but it DOES have a destination!!!

 
It seems that the SCRIPT directive is intercepting the "-d IPADDRESS"
and interpreting it as it's own "recipient" directive.??

 
Is there a way around this? Is there a way to ignore the "recipient"
directive using SCRIPT?

 
Thanks for any ideas

 
KEvin
list Dave Haertig · Sat, 5 Jan 2008 11:09:50 -0700 ·
Sorry for the formatting of the script example in my p[revious post.  I
seem to be having cut-paste problems.  Cutting from a Putty window to a
Linux box and pasting into Outlook on a Windows box looks to be a little
glitchy.  I suppose if you understand PERL syntax in the first place,
you probably guessed that I had newlines after the semi-colons in the
original text.

I will try reformatting it again and see if it comes out better this
time:
quoted from Dave Haertig

#!/bin/perl
# RCS $Id: kill_script,v 1.3 2007/09/26 15:19:07 hobbit Exp $
#$debug++;      # Comment-out this line for normal operation
($host, $id, $pattern) = split(/,/, $ENV{RCPT}, 3);
exit unless ((defined $host) && (defined $id) && (defined $pattern));
$command = qq!ssh $id\@$host "pkill -f '$pattern'"!;
if ($debug) {
        $command =~ s/pkill/pgrep -l/;
        print `$command`;
}
else {
        `$command`;
}

-----Original Message-----
From: Haertig, David F (Dave) [mailto:user-68874b735d77@xymon.invalid] 
Sent: Saturday, January 05, 2008 11:00 AM
To: user-ae9b8668bcde@xymon.invalid
Subject: RE: [hobbit] trouble with SCRIPT directive

You could make a dummy shell script named "trapgen_wrapper" that just
hardcodes the ip address parameter and then calls the real trapgen using
that.  Reference trapgen_wrapper in your hobbit alert config file,
passing it that same bogus_parameter for the recipient (which is
meaningless for your application, but required by Hobbit syntax).

If you don't want to hardcode the ip address in trapgen_wrapper, you
could make trapgen_wrapper parse out the info from the environment
variable "RCPT".

Here's a similar example I use to kill a process.  The SCRIPT directive
in hobbit-alerts.cfg passes this script three parameters, the hostname,
the userid, and a patternmatch for the kill.


SCRIPT kill_script hostname,userid,pattern_to_match


And here's the script that processes the above:

#!/bin/perl
# RCS $Id: kill_script,v 1.3 2007/09/26 15:19:07 hobbit Exp $
#$debug++;      # Comment-out this line for normal operation
($host, $id, $pattern) = split(/,/, $ENV{RCPT}, 3); exit unless
((defined $host) && (defined $id) && (defined $pattern)); $command =
qq!ssh $id\@$host "pkill -f '$pattern'"!; if ($debug) {
        $command =~ s/pkill/pgrep -l/;
        print `$command`;
}
else {
        `$command`;
}

-----Original Message-----
From: Galen Johnson [mailto:user-87f955643e3d@xymon.invalid]
Sent: Saturday, January 05, 2008 10:15 AM
To: user-ae9b8668bcde@xymon.invalid
Subject: RE: [hobbit] trouble with SCRIPT directive


Have you tried putting in a bogus recipient address and your options to
trapgen at the end?

=G=

-----Original Message-----
From: kevin [mailto:user-a004b26f09c6@xymon.invalid]
Sent: Sat 1/5/2008 11:38 AM
To: user-ae9b8668bcde@xymon.invalid
Subject: [hobbit] trouble with SCRIPT directive
 
Hi all,

 
This might seem long winded but I wanted to describe the problem in
detail and see if anyone could help please.

 
 I am trying to make use of the SCRIPT function in hobbit-alerts.cfg I
am trying to send snmp traps from hobbit to another receiver using a
utility called trapgen and I think the syntax of SCRIPT and trapgen are
getting in each others way. 

 
SCRIPT seems to have this syntax:

 
SCRIPT  <program>  <recipient>  <options>

 
And trapgen has this syntax:

 
trapgen  -d  destination   <options>

 
So, when I try to assemble it, it has this form:

 
SCRIPT  /home/hobbit/server/ext/trapgen -d 10.10.0.13 <options>

 
I get an error in the page.log that says trapgen needs at least a
destination specified as:

 
trapgen -d IPADDRESS   ..but it DOES have a destination!!!

 
It seems that the SCRIPT directive is intercepting the "-d IPADDRESS"
and interpreting it as it's own "recipient" directive.??

 
Is there a way around this? Is there a way to ignore the "recipient"
directive using SCRIPT?

 
Thanks for any ideas

 
KEvin
list Greg L Hubbard · Mon, 7 Jan 2008 08:29:58 -0600 ·
Kevin,
 
The "simplest" way around this problem is not to try to embed a trapgen
call into the script directive, but to write a wrapper script that will
accept whatever arguments that SCRIPT sends, and then provides any
format conversion, etc. needed before calling trapgen (or any other
program).  Seems like I had to grab a lot of info out of environment
variables when I wrote one of these a year or so ago, so you would be
extremely lucky if you could do it all in one step.
 
GLH
quoted from Kevin


	From: kevin [mailto:user-a004b26f09c6@xymon.invalid] 
	Sent: Saturday, January 05, 2008 10:38 AM
	To: user-ae9b8668bcde@xymon.invalid
	Subject: [hobbit] trouble with SCRIPT directive
	
	
	Hi all,

	 
	This might seem long winded but I wanted to describe the problem
in detail  and see if anyone could help please.

	 
	 I am trying to make use of the SCRIPT function in
hobbit-alerts.cfg I am trying to send snmp traps from hobbit to another
receiver using a utility called trapgen and I think the syntax of SCRIPT
and trapgen are getting in each others way. 

	 
	SCRIPT seems to have this syntax:

	 
	SCRIPT  <program>  <recipient>  <options>

	 
	And trapgen has this syntax:

	 
	trapgen  -d  destination   <options>

	 
	So, when I try to assemble it, it has this form:

	 
	SCRIPT  /home/hobbit/server/ext/trapgen -d 10.10.0.13 <options>

	 
	I get an error in the page.log that says trapgen needs at least
a destination specified as:

	 
	trapgen -d IPADDRESS   ......but it DOES have a destination!!!

	 
	It seems that the SCRIPT directive is intercepting the "-d
IPADDRESS" and interpreting it as it's own "recipient" directive.??

	 
	Is there a way around this? Is there a way to ignore the
"recipient" directive using SCRIPT?

	 
	Thanks for any ideas

	 
	KEvin