Re: [Nagios-users] need help with my custom perl plugin

2007-09-04 Thread August Simonelli
good thought on perms - i double checked and i'm running as nagios so all
good there ...

marcel i think you are right, my match condition is just wrong for some
reason ...

when i change the while loop to:

while (){
next if /^Trying/;
next if /^Connected/;
if ($_ =~ /Escape/) {
print "success $_";
exit($ERRORS{'OK'});
}
else {
print "Connect died at: $_";
exit($ERRORS{'CRITICAL'});
}

this works and nagios reports OK.

but if i let it get to that last line, which is the 220 line, it won't
match. i'm guessing this is something to do with how the while loop handles
the last line of input and places it into $_

but i don't get why nagios doens't see it and command line works ...

i'll keep trying and if anyone spots it please let me know!

august



On 9/5/07, Marcel Mitsuto Fucatu Sugano <[EMAIL PROTECTED]> wrote:
>
> Comments inline:
>
> On Wed, 2007-09-05 at 08:48 +1000, August Simonelli wrote:
> >
> >
> > but when all those conditions ARE met nagios always makes it right
> > past
> >
> > if ($_ =~ /^220/) {
> > print "$_ this works";
> > exit($ERRORS{'OK'});
> >
> > and gives me
> >
> > print "fell thru";
> > exit($ERRORS{'WARNING'});
> >
> > printing out $_ in the while loop has the expected 220 line ...
> >
>
> Probably, telnet responds something different that the regexp match
> expects, like "\r220: (...)", so if 220 is the OK condition, try
> removing the leading "^", and you're done.
>
> HTH
>
>
> AVISO: A informação contida neste e-mail, bem como em qualquer de seus
> anexos, é CONFIDENCIAL e destinada ao uso exclusivo do(s) destinatário(s)
> acima referido(s), podendo conter informações sigilosas e/ou legalmente
> protegidas. Caso você não seja o destinatário desta mensagem, informamos que
> qualquer divulgação, distribuição ou cópia deste e-mail e/ou de qualquer de
> seus anexos é absolutamente proibida. Solicitamos que o remetente seja
> comunicado imediatamente, respondendo esta mensagem, e que o original desta
> mensagem e de seus anexos, bem como toda e qualquer cópia e/ou impressão
> realizada a partir destes, sejam permanentemente apagados e/ou destruídos.
> Informações adicionais sobre nossa empresa podem ser obtidas no site
> http://sobre.uol.com.br/.
>
> NOTICE: The information contained in this e-mail and any attachments
> thereto is CONFIDENTIAL and is intended only for use by the recipient named
> herein and may contain legally privileged and/or secret information. If you
> are not the e-mail´s intended recipient, you are hereby notified that any
> dissemination, distribution or copy of this e-mail, and/or any attachments
> thereto, is strictly prohibited. Please immediately notify the sender
> replying to the above mentioned e-mail address, and permanently delete
> and/or destroy the original and any copy of this e-mail and/or its
> attachments, as well as any printout thereof. Additional information about
> our company may be obtained through the site http://www.uol.com.br/ir/.
>
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/___
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] need help with my custom perl plugin

2007-09-04 Thread Marcel Mitsuto Fucatu Sugano
Comments inline:

On Wed, 2007-09-05 at 08:48 +1000, August Simonelli wrote:
> 
> 
> but when all those conditions ARE met nagios always makes it right
> past
> 
> if ($_ =~ /^220/) {
> print "$_ this works";
> exit($ERRORS{'OK'});
> 
> and gives me
> 
> print "fell thru";
> exit($ERRORS{'WARNING'});
> 
> printing out $_ in the while loop has the expected 220 line ...
> 

Probably, telnet responds something different that the regexp match
expects, like "\r220: (...)", so if 220 is the OK condition, try
removing the leading "^", and you're done.

HTH


AVISO: A informação contida neste e-mail, bem como em qualquer de seus anexos, 
é CONFIDENCIAL e destinada ao uso exclusivo do(s) destinatário(s) acima 
referido(s), podendo conter informações sigilosas e/ou legalmente protegidas. 
Caso você não seja o destinatário desta mensagem, informamos que qualquer 
divulgação, distribuição ou cópia deste e-mail e/ou de qualquer de seus anexos 
é absolutamente proibida. Solicitamos que o remetente seja comunicado 
imediatamente, respondendo esta mensagem, e que o original desta mensagem e de 
seus anexos, bem como toda e qualquer cópia e/ou impressão realizada a partir 
destes, sejam permanentemente apagados e/ou destruídos. Informações adicionais 
sobre nossa empresa podem ser obtidas no site http://sobre.uol.com.br/.

NOTICE: The information contained in this e-mail and any attachments thereto is 
CONFIDENTIAL and is intended only for use by the recipient named herein and may 
contain legally privileged and/or secret information. If you are not the 
e-mail´s intended recipient, you are hereby notified that any dissemination, 
distribution or copy of this e-mail, and/or any attachments thereto, is 
strictly prohibited. Please immediately notify the sender replying to the above 
mentioned e-mail address, and permanently delete and/or destroy the original 
and any copy of this e-mail and/or its attachments, as well as any printout 
thereof. Additional information about our company may be obtained through the 
site http://www.uol.com.br/ir/.

-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
___
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


[Nagios-users] need help with my custom perl plugin

2007-09-04 Thread August Simonelli
Hey all ...

I need to use nagios to check that a remote mail server can reach its relay.
the remote mail server is an appliance and all i can do on it is run a
telnet. to do this i've written a perl plugin that ssh's from the nagios box
to the appliance and then executes a telnet to the mail relay's port 25. the
script works perfectly on the command line - i can get all states (warn,
crit and ok).

Now, when i move it into nagios, i can only get critical and warning states.
for some reason, my test and exit for the OK state just gets missed and the
plugin returns the default warning status from the scripts last few lines
(see below).

i'm new to perl and nagios plugin writing, so i've probably messed up some
fundamental thing here ... but i can't seem to get it ...

any thoughts/corrections/criticisms/comments are greatly appreciated.

here's the script:

#!/usr/bin/perl -w
use strict;

use utils qw(%ERRORS $TIMEOUT);

# in case we just hang -
$SIG{ALRM} = sub {
print "CRITICAL: Plugin timed out.\n";
exit 2
};

alarm(10);

my ($host, $key, $remote) = @ARGV;
unless ($host and $key and $remote) {
die "Usage: $0 hostname ssh_key remote_mail_server\n";
}

# default error
# my $connect_result = "Remote Test Failure";

open (SSH, "ssh -i $key $host telnet $remote 25|") or die "Can't open pipe:
$!";

# iterate through the loop and skip lines that don't have what we want.
then, store the last var - we know the telnet action is 4 lines
while (){
next if /^Trying/;
next if /^Connected/;
next if /^Escape/;
if ($_ =~ /^220/) {
print "$_ this works";
exit($ERRORS{'OK'});
}
else {
print "Connect died at: $_";
exit($ERRORS{'CRITICAL'});
}
close SSH;
}
print "fell thru";
exit($ERRORS{'WARNING'});
close SSH;


again, if i change the if statements to create an error (change ^Trying to
^rying for instance) nagios reports critical and clearly uses:

else {
print "Connect died at: $_";
exit($ERRORS{'CRITICAL'});
}

and $_ is set to the line that didn't match and caused the error ...

but when all those conditions ARE met nagios always makes it right past

if ($_ =~ /^220/) {
print "$_ this works";
exit($ERRORS{'OK'});

and gives me

print "fell thru";
exit($ERRORS{'WARNING'});

printing out $_ in the while loop has the expected 220 line ...

ok ... hope this is not too verbose; sorry if this is just such bad code
that you all wanna slap me down! :-)

thanks,

august

ps. the service is defined as (names changed to protect the innocent):

define service{
host_name   mailhost
service_description smtp relay check test
is_volatile 0
check_command
check_smtp_relay!/usr/local/nagios/.ssh/id_dsa!remoterelay.mydomain.com#
max_check_attempts  3
normal_check_interval   2
retry_check_interval1
check_period24x7
notification_interval   240
notification_period 24x7
notification_optionsw,u,c,r
contact_groups  unix-admins
}

and the command is:

define command{
command_namecheck_smtp_relay
command_line$USER1$/smtpchecker.pl $HOSTADDRESS$ $ARG1$ $ARG2$
}
-
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/___
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