Problem with check_by_ssh...

Dmitriy Kropivnitskiy jeld at bnl.gov
Wed Nov 12 18:49:14 CET 2003


After fighting with check_by_ssh for a while, I have given up and wrote 
my own. It is easy to use, and doesn't require you to copy your plugins 
to all the hosts.
You will need to install Net::SSH::Perl though. Change the private key 
location and plugin directory location, add your public key to 
authorized_keys and you should be good to go.
Any bugfixes/features welcome.


-----------------------------------------

#!/usr/bin/perl -w

use strict;
use warnings;

use Net::SSH::Perl;
use Getopt::Long;
Getopt::Long::Configure("bundling");

my $SCRIPTDIR = '/usr/nagios/custom/';
my @KEYS = ('/etc/nagios/nagios.key');

my ($opt_H, $opt_s, $opt_u, $opt_a);
my ($out, $err, $code);
my $ssh;

GetOptions(
    'H=s' => \$opt_H, 'host=s' => \$opt_H,
    's=s' => \$opt_s, 'script=s' => \$opt_s,
    'u=s' => \$opt_u, 'user=s' => \$opt_u,
    'a=s' => \$opt_a, 'args=s' => \$opt_a,);

if (!$opt_H || !$opt_s) { print "Usage: check_by_ssh -H hostname -s 
script_name [-u username] [-a args]\n"; exit 1; }

$ENV{'HOME'} = '/home/nagios'; # Otherwise Net::SSH::Perl gets confused 
about file locations

my %args;
$args{identity_files} = \@KEYS;
$args{privileged} = 0;
$args{compression} = 1;
$args{use_pty} = 0;
$args{interactive} = 0;
$args{protocol} = '2';
#$args{user_known_hosts} = '/home/nagios/.ssh/known_hosts2';
#$args{debug} = 1;
eval { $ssh = Net::SSH::Perl->new($opt_H, %args); };
print $@ if $@;

$opt_u ? $opt_u : $opt_u = 'root';

eval { $ssh->login($opt_u); };
print $@ if $@;

my $script = $SCRIPTDIR . $opt_s;
if (! -e $script) { print "Script $script doesn't exist\n"; exit 1; }

open my($fh), $script;
($out, $err, $code) = $ssh->cmd('perl - ' . $opt_a, join("", <$fh>));
close $fh;

if ($err) { print "Error occured processing $opt_s. $err"; exit $code; }

print $out;
exit $code;




-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Nagios-users mailing list
Nagios-users at 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





More information about the Users mailing list