Ad Widget

Collapse

External checks that call SSH don't work when run by proxy

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davethehedgehog
    Junior Member
    • Oct 2014
    • 3

    #1

    External checks that call SSH don't work when run by proxy

    Hi,

    I have a really simple check that runs an SSH command.

    #!/usr/bin/perl

    use strict;
    use warnings;

    #open(my $fh, '>>', 'log.txt') or die "Could not open file log.txt $!";

    #print `ssh $ARGV[1]\@$ARGV[0] < sx20.txt`;

    my @output = `ssh $ARGV[1]\@$ARGV[0] < sx20.txt`;

    #say $fh @output;

    #close $fh;
    my $line;
    my $result = 'UnRegistered';

    foreach $line (@output) {
    if ($line=~/: Registered/) {
    $result='Registered';
    }
    }

    system ("echo $result");


    Really simple. It works perfectly when logged in as Zabbix from command-line, but for some reason when running as an external check in Zabbix the SSH doesn't work and returns UnRegistered.

    I've set the correct rights on the script and on the directory as a whole. I've seen some posts saying to use a wrapper script to set up environmental variables, but I can't find a good example anywhere. Anyone have any pointers as to what I'm doing wrong or missing?
  • BDiE8VNy
    Senior Member
    • Apr 2010
    • 680

    #2
    Does it work in general, e.g.:
    Code:
    system ("/bin/touch /tmp/foobar");
    Did you make sure that the host the external check is assigned to is indeed configured to use the respective Zabbix proxy?

    Comment

    • davethehedgehog
      Junior Member
      • Oct 2014
      • 3

      #3
      Thanks for your help! Yep, works fine normally. Works fine if I su to Zabbix user too. Also the host is definitely assigned to the proxy. The script is running, because it's returning the default "UnRegistered" result in Zabbix, but it's returning the incorrect result because the SSH process isn't spawning. I've got around this in the past by using Net::SSH:Expect, but it's overkill really. I have a feeling this is a rights/environment thing.

      Comment

      • davethehedgehog
        Junior Member
        • Oct 2014
        • 3

        #4
        Never mind, I sorted. Thanks for your help!

        For others who may come across this post. My issue was indeed environmental I think. I needed to give the full path to my ssh and to my associated input file.

        Comment

        Working...