I guess a good break from it was all I needed. Coming back from the holiday weekend I took another look and have solved my issue by adding the following to my script:<div><br></div><div>$ENV{'HOME'} = '/home/nagios';</div>
<div><br></div><div>Thanks, everyone, for the assistance provided.<br><br><div class="gmail_quote">On Wed, Nov 26, 2008 at 3:06 PM, Badri Pillai <span dir="ltr"><<a href="mailto:badri@diglinks.com">badri@diglinks.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">








<div lang="DE" link="blue" vlink="purple">

<div>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">Hi Jason,</span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">I tried the following perl code as plugin and worked for me.</span></p>

<div style="border-top:solid windowtext 1.0pt;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:none;padding:1.0pt 0cm 1.0pt 0cm">

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">#!/usr/bin/perl</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">open
L,">>/tmp/ssh_check.log" or die "Can't open log";</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">print
L "perl check..\n";</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">print
L scalar localtime(),"\n" ;</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">my
$string =`/usr/bin/ssh -n -i /var/log/nagios/id_nagios_rsa root\@<a href="http://EXAMPLE.COM" target="_blank">EXAMPLE.COM</a>
uname -a`;</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">print
L $string;</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">close
L;</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">print
"Check done";</span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p style="border:none;padding:0cm"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">exit
0;</span></p>

</div>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">May be:</span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p style="text-indent:-18.0pt"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"><span>1)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">Embedded perl? In nagios 3.x
you can disable easily</span></p>

<p style="text-indent:-18.0pt"><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"><span>2)<span style="font:7.0pt "Times New Roman"">     
</span></span></span><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">OR the Net::SSH:Perl module,
to be honest I've never used it and is not installed on my test system.</span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">Hope you find the problem soon.</span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">Regards,</span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D">Badri</span></p>

<p><span lang="EN-US" style="font-size:11.0pt;color:#1F497D"> </span></p>

<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">

<p><b><span style="font-size:10.0pt">Von:</span></b><span style="font-size:10.0pt"> Jason
[mailto:<a href="mailto:daelic@gmail.com" target="_blank">daelic@gmail.com</a>] <br>
<b>Gesendet:</b> Mittwoch, 26. November 2008 21:47<br>
<b>An:</b> Nagios Developers List<br>
<b>Betreff:</b> Re: [Nagios-devel] Perl EVENT HANDLER SSH Remote Command
Exection</span></p>

</div><div><div></div><div class="Wj3C7c">

<p> </p>

<p>Ok, I've re-tooled, using more simplified logic for the
purpose of testing the SSH connection. The script now has no logic, it just
attempts to ssh to the remote host and run /usr/bin/uname -a.</p>

<div>

<p> </p>

</div>

<div>

<p>I've also explicitly defined my SSH key.</p>

</div>

<div>

<p> </p>

</div>

<div>

<p>As before, the script works perfectly when run manually as
nagios user via the command line, but fails at the SSH call when executed via
event handler from the nagios daemon.</p>

</div>

<div>

<p> </p>

</div>

<div>

<p>I'm beginning to wonder if Nagios & Net::SSH::Perl
simply do not play nice with each other.</p>

</div>

<div>

<p> </p>

</div>

<div>

<p>I've attached my simplified script if anyone wants to see
the exact code in full context.</p>

</div>

<div>

<p> </p>

</div>

<div>

<div>

<p>On Wed, Nov 26, 2008 at 10:26 AM, Jason <<a href="mailto:daelic@gmail.com" target="_blank">daelic@gmail.com</a>> wrote:</p>

<p>Yes, I am using public key authentication. It works fine
when I run the script manually from the command prompt under the Nagios user,
just not when the script is launched via nagios.</p>

<div>

<p> </p>

</div>

<div>

<p>Combining your reply with the reply from Sascha Runschke,
I'm wondering if it's not finding $HOME/.ssh due to the environment being
stripped down. I'm going to try explicitly defining my private key.</p>

</div>

<div>

<p> </p>

</div>

<div>

<p>I did put in full paths to my remote commands, and that did
not resolve the problem.</p>

<div>

<div>

<p style="margin-bottom:12.0pt"> </p>

<div>

<p>On Tue, Nov 25, 2008 at 11:34 PM, Badri Pillai <<a href="mailto:badri@diglinks.com" target="_blank">badri@diglinks.com</a>>
wrote:</p>

<p>Hi Jason,<br>
<br>
I assume you are using public key authentication.<br>
<br>
If yes,<br>
I don't see ssh key to be used  being passed as argument,<br>
cause the key files are searched by default in "$HOME/.ssh"<br>
may be this directory is not accessible for the server?<br>
<br>
Other options to check -> if you  need a  " pty??  or
not.<br>
<br>
<br>
Regards,<br>
<span style="color:#888888"><br>
BP</span></p>

<div>

<div>

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

</div>

</div>

<p>>
------------------------------------------------------------------------</p>

<div>

<div>

<p>><br>
> -------------------------------------------------------------------------<br>
> This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge<br>
> Build the coolest Linux based applications with Moblin SDK & win great
prizes<br>
> Grand prize is a trip for two to an Open Source event anywhere in the
world<br>
> <a href="http://moblin-contest.org/redirect.php?banner_id=100&url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&url=/</a><br>
> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> Nagios-devel mailing list<br>
> <a href="mailto:Nagios-devel@lists.sourceforge.net" target="_blank">Nagios-devel@lists.sourceforge.net</a><br>
> <a href="https://lists.sourceforge.net/lists/listinfo/nagios-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/nagios-devel</a><br>
><br>
<br>
<br>
-------------------------------------------------------------------------<br>
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge<br>
Build the coolest Linux based applications with Moblin SDK & win great
prizes<br>
Grand prize is a trip for two to an Open Source event anywhere in the world<br>
<a href="http://moblin-contest.org/redirect.php?banner_id=100&url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&url=/</a><br>
_______________________________________________<br>
Nagios-devel mailing list<br>
<a href="mailto:Nagios-devel@lists.sourceforge.net" target="_blank">Nagios-devel@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/nagios-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/nagios-devel</a></p>

</div>

</div>

</div>

<p> </p>

</div>

</div>

</div>

</div>

<p> </p>

</div>

</div></div></div>

</div>


<br>-------------------------------------------------------------------------<br>
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge<br>
Build the coolest Linux based applications with Moblin SDK & win great prizes<br>
Grand prize is a trip for two to an Open Source event anywhere in the world<br>
<a href="http://moblin-contest.org/redirect.php?banner_id=100&url=/" target="_blank">http://moblin-contest.org/redirect.php?banner_id=100&url=/</a><br>_______________________________________________<br>
Nagios-devel mailing list<br>
<a href="mailto:Nagios-devel@lists.sourceforge.net">Nagios-devel@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/nagios-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/nagios-devel</a><br>
<br></blockquote></div><br></div>