Hi Folks,
this is the command line:
[root@monitor libexec]#./check_acc_bk.pl localhost 2
97 Files backed up in the last 2 days
this is the same command invoked by nagios:
[1349278228] EXTERNAL COMMAND: SCHEDULE_FORCED_SVC_CHECK;localhost;Check Account Backups;1349278227
[1349278238] SERVICE ALERT: localhost;Check Account Backups;CRITICAL;HARD;4;No files backed up in the previous 2 days
in nagios commands.cfg:
Code:
# 'check_acc_bk.pl' command definition
define command{
command_name check_acc_bk
command_line $USER1$/check_acc_bk.pl $HOSTADDRESS$ $ARG1$
}
then in local.cfg:
Code:
define service{
use local-service ; Name of service template to use
host_name localhost
service_description Check Account Backups
active_checks_enabled 1
check_interval 15
check_command check_acc_bk
notifications_enabled 0
}
and in check_acc_bk.pl:
Code:
#!/usr/bin/perl
use strict;
use File::Copy;
$|=1;
my $hostname = $ARGV[0] || die "Usage: (hostname) (days previous)\n";
my $delay = $ARGV[1] || '2' ;
my $status="3";
my $msg="warning failed to run properly \n";
my $retval="0";
$delay = $delay -1;
#my $newfiles = changedfiles($delay);
&changedfiles($delay);
#print "The number of files changed in $delay is $retval\n";
chomp($retval);
#print STDERR"***$retval****in $delay days ******";
if ($retval ne '0') {
$status=0;
$msg="$retval Files backed up in the last $delay days \n";
} else {
$delay = $delay +1;
&changedfiles($delay);
chomp($retval);
#print STDERR"***$retval****in $delay days ******";
#print "The number of files changed in $delay is $newfiles1 \n";
if ($retval ne '0') {
$status=1;
$msg="$retval files backed up in the last $delay days \n";
} else {
$status=2;
$msg="No files backed up in the previous $delay days \n";
}
}
#=================
# Status Processing
#=================
# 3 UNKNOWN
# 2 CRITICAL
# 1 WARNING
# 0 OK
print $msg;
exit ($status);
#print "======= subs =================\n";
sub changedfiles($delay)
{
# print"delay is $delay\n";
my $com = "sudo /usr/bin/find /root/accounting/backup/ -type f -mtime -$delay -print | wc -l";
my @lines = `$com`;
my $num;
foreach $num (@lines)
{
#print "the num = $num\n"; #put in for debugging
if ($num > 0) {
$retval = $num;
}
}
return $retval;
}
oh and nagios has sudo rights on /usr/bin/find with no password.
I have another almost identical perl script that checks database file backups and it works fine.
Please help me Obiwan you are my last chance