Hey all ...<br><br>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). 
<br><br>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).
<br><br>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 ...<br><br>any thoughts/corrections/criticisms/comments are greatly appreciated.
<br><br>here's the script:<br><br>#!/usr/bin/perl -w<br>use strict;<br><br>use utils qw(%ERRORS $TIMEOUT);<br><br># in case we just hang - <br>$SIG{ALRM} = sub {<br>    print "CRITICAL: Plugin timed out.\n";
<br>    exit 2<br>};<br><br>alarm(10);<br><br>my ($host, $key, $remote) = @ARGV;<br>unless ($host and $key and $remote) {<br>    die "Usage: $0 hostname ssh_key remote_mail_server\n";<br>}<br><br># default error
<br># my $connect_result = "Remote Test Failure";<br><br>open (SSH, "ssh -i $key $host telnet $remote 25|") or die "Can't open pipe: $!";<br><br># 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
<br>while (<SSH>){<br>    next if /^Trying/;<br>    next if /^Connected/;<br>    next if /^Escape/;<br>        if ($_ =~ /^220/) {<br>            print "$_ this works";<br>            exit($ERRORS{'OK'});
<br>        }<br>        else {<br>            print "Connect died at: $_";<br>            exit($ERRORS{'CRITICAL'});<br>        }<br>close SSH;<br>}<br>print "fell thru";<br>exit($ERRORS{'WARNING'});
<br>close SSH;<br><br><br>again, if i change the if statements to create an error (change ^Trying to ^rying for instance) nagios reports critical and clearly uses:<br><br>        else {<br>
            print "Connect died at: $_";<br>
            exit($ERRORS{'CRITICAL'});<br>
        }<br><br>and $_ is set to the line that didn't match and caused the error ...<br><br>but when all those conditions ARE met nagios always makes it right past<br><br>        if ($_ =~ /^220/) {<br>
            print "$_ this works";<br>
            exit($ERRORS{'OK'});<br><br>and gives me<br><br>print "fell thru";<br>
exit($ERRORS{'WARNING'});<br><br>printing out $_ in the while loop has the expected 220 line ...<br><br>ok ... hope this is not too verbose; sorry if this is just such bad code that you all wanna slap me down! :-)
<br><br>thanks,<br><br>august<br><br>ps. the service is defined as (names changed to protect the innocent):<br><br>define service{<br>        host_name               mailhost<br>        service_description     smtp relay check test
<br>        is_volatile             0<br>        check_command           check_smtp_relay!/usr/local/nagios/.ssh/id_dsa!remoterelay.mydomain.com#<br>        max_check_attempts      3<br>        normal_check_interval   2<br>
        retry_check_interval    1<br>        check_period            24x7<br>        notification_interval   240<br>        notification_period     24x7<br>        notification_options    w,u,c,r<br>        contact_groups          unix-admins
<br>        }<br><br>and the command is:<br><br>define command{<br>        command_name    check_smtp_relay<br>        command_line    $USER1$/smtpchecker.pl $HOSTADDRESS$ $ARG1$ $ARG2$<br>        }<br><br><br><br><br><br>