Hello,<div><br></div><div>I've written an Event Handler using Perl. The intent is to verify on the remote box that we do need to restart the daemon in question, and then perform a restart if needed.</div><div><br></div>
<div>The script works perfectly via the command line when I execute it as the nagios user. Unfortunately, if the script doesn't work properly when it is executed by nagios in response to a state change. It dies before completion.</div>
<div><br></div><div>I've put in various hooks (Basicly just made it send me an email at various stages of the script) to determine exactly where it dies, and have isolated it. Here is the portion that causes the script to die when nagios executes it. (Please trust me and assume that $hostname and $username contain proper values. I've tested the variables extensively to insure that they are being populated.)</div>
<div><br></div><div>If I run the below, I'll see a log entry and an email for Step 1, but nothing for Step 2 and beyond.</div><div><br></div><div><div>#!/usr/bin/perl</div><div>require '/usr/local/scripts/subs.pl';<br>
</div><div><br></div><div>report_findings("Step 1",".");</div><div>my $command = "grep check_tacplus /usr/local/nagios/etc/nrpe.commands";</div><div>my %tac_expected = run_command($command, $hostname, $username);</div>
<div>report_findings("Step 2",".");</div><div><br></div><div><div>sub run_command {</div><div>        my $command = $_[0];</div><div>        my $host = $_[1];</div><div>        my $username = $_[2];</div>
<div><br></div><div>        my %result = SSHexec($command, $hostname, $username);</div><div>        if ($result{'err'}) {</div><div>                my $subject = "Automated refreshtac failed on $hostname";</div>
<div>                my $message = "Error when attempting SSH connection to $hostname:\n";</div><div>                $message .= "  ".$result{'err'}."\n";</div><div>                report_findings($subject, $message, $recipients);</div>
<div>                exit;</div><div>        }</div><div>        return %result;</div><div>}</div><div><br></div><div><div><div>sub SSHexec {</div><div>        use Net::SSH::Perl;</div><div><br></div><div>        my $CMD = $_[0];</div>
<div>        my $HOST = $_[1];</div><div>        my $USR = $_[2];</div><div>        my %RESULT;</div><div><br></div><div>        if (pingHost($HOST)) {</div><div>                %RESULT = ("err", "Connectivity Failure");</div>
<div>                return %RESULT;</div><div>        }</div><div><br></div><div>        my $ssh = Net::SSH::Perl->new($HOST, options => [ "protocol '2,1'" ]);</div><div>        unless ($ssh->login($USR)) {</div>
<div>                %RESULT = ("err", "Authentication Failure");</div><div>                return %RESULT;</div><div>        }</div><div>        my ($out,$err,$exit) = $ssh->cmd($CMD);</div><div>        %RESULT = ("out", $out,</div>
<div>                        "err", $err,</div><div>                        "exit", $exit);</div><div>        return %RESULT;</div><div>}</div></div><div><br></div><div>&report_findings is nothing but a wrapper for logging and sending email. This works up until the SSH call.</div>
<div><br></div><div>&SSHexec is contained in /usr/local/scripts/subs.pl which holds common subroutines that I use frequently when writing scripts. I use other subs from there, so I know it's getting loaded.</div><div>
<br></div><div>I cannot figure out why this is working as an automation, when it works perfectly otherwise. Any advice/hints/suggestions?<br></div><div><br></div><div><br></div></div></div></div>