#!/usr/bin/perl

# check remote nagios

use strict;
use Getopt::Long;

my ($host, $expires);

Getopt::Long::Configure ("bundling", "ignore_case_always");
my $result = GetOptions ("host|h=s"   => \$host,    
                         "expires|e=s"   => \$expires); 

if ( (!defined $host) ||
     (!defined $expires) ) {
  print "Usage: check_remote_nagios.pl -h <hostname or address> -e <expires>\n";
  print "Where expires is the minutes aging after which logfile is considered stale.\n";
  exit 3;
}

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =  localtime(time);
$mon++;
($year < 1900) && ($year += 1900);
my $cmd = "ssh  root\@$host \"/usr/local/nagios/libexec/check_nagios -e $expires -F /usr/local/nagios/var/status.dat -C /usr/local/nagios/bin/nagios\"";
my $res = `$cmd`;
chomp $res;
my $exitcode = $?;
($exitcode == 512) && ($exitcode == 2);
($exitcode == 256) && ($exitcode == 1);
print "$res";
exit $exitcode;
