hello,
please advice me how to check an output logfile for my backup in windows, i want nagios show me this backup finish successfully or no .
urgent please
check output logfile in nagios
Re: check output logfile in nagios
Do you want to see if Nagios ran a check? Or do you want to see the Nagios logs?
If you want to see the logs, they are usually located in /usr/local/nagios/var/nagios.log.
If you want to see the logs, they are usually located in /usr/local/nagios/var/nagios.log.
Re: check output logfile in nagios
noo i explain waht i need exactly , my server backup is in windows server 2008, so for every day i have to check the backup if its going fine ,so everyday i have to open the logfile and see it to be sure that everything working fine.now i need to check the output for these logfiles through nagios to make the daily check easy .my question is if there any specific plugin to check output files in nagios or any one has script for this matter .
thanks
thanks
Re: check output logfile in nagios
There's a nagios plugin called "check_log" which will check log files for specific strings or lengths. That one might be what you're looking for. It will check files or different types of log files.
Re: check output logfile in nagios
my case is different , because evry day on lof file generated , check_log its used to check between 2 files the new one and the old one ,but for me i need just to check the output file .if u have an example it will be better.
Re: check output logfile in nagios
Before I give you an example, does the log file have a different format, like a date on the file?
(like: mylogfile-01-01-2011.log)
I have a script that will work with changing log file days, which is a wrapper around check_log.
(like: mylogfile-01-01-2011.log)
I have a script that will work with changing log file days, which is a wrapper around check_log.
Re: check output logfile in nagios
my file is like : Daily-Bkp-Update-H 2011-05-10 020002.log , please tel me how
Re: check output logfile in nagios
Ok,
This script was written by an intern here, so there are things you can do differently for sure. It's not much, but here's what we use as a wrapper. these types of logs can be tricky depending on your logfile structure.
Here's how you run it from the command line: ./check_log_wrapper --filename=/opt/apache/logs/dispatcher_log -s "Connection timed out" -addtime
You will probably need to make some modifications for it to work. If you need help making those modifications, just let me know.
#!/usr/bin/perl
use strict;
use File::Basename;
use Getopt::Long;
use constant EXIT_OK => 0;
use constant EXIT_WARNING => 1;
use constant EXIT_CRITICAL => 2;
my $filename = '';
my $string = '';
my $addtime = 0;
my $html = 0;
my $return_val = EXIT_OK;
#my $logs_dir = '/home/nagios/old_logs'; #change this to where you want the logs dropped off at
my $logs_dir = '/tmp/tmp_logs';
my $output = '';
#my $check_log = '/home/nagios/bin/check_log';
my $check_log = '/home/nagios/bin/check_log';
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset,
$dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
my $debug = 0;
my $no_unknown = 0;
GetOptions(
"f|filename=s" => \$filename,
"s|string=s" => \$string,
"t|addtime" => \$addtime,
"html" => \$html,
"d|debug" => \$debug,
"nounknown" => \$no_unknown,
);
if ( ! defined($filename) || $filename eq '' ) {
print qq|No filename specified!\n|;
$return_val = EXIT_CRITICAL;
usage();
} elsif ( ! defined($string) || $string eq '' ) {
print qq|No string specified!\n|;
$return_val = EXIT_CRITICAL;
usage();
} elsif ( ! add_time_to_file($addtime) ) {
print qq|Failed to add time to the file\n|;
$return_val = EXIT_CRITICAL;
usage();
} else {
if ( ! -d $logs_dir ) {
write_line($debug, "Creating directory: $logs_dir");
system("/bin/mkdir -p $logs_dir");
}
my $oldfullname = $filename.".old";
write_line($debug, "Old full name = $oldfullname");
$oldfullname = basename($oldfullname);
write_line($debug, "Old full name basename = $oldfullname");
$oldfullname = "$logs_dir/$oldfullname";
write_line($debug, "New Old full name basename = $oldfullname");
my $cmd = '';
if ( ! -f $filename ) {
$output = "No log file found.\n";
$return_val = 0;
} else {
$cmd = qq|$check_log -F $filename -O $oldfullname -q "$string"|;
write_line($debug, "Command: $cmd");
$output = `$cmd`;
$return_val = $? >> 8;
}
if ( $return_val == 0 ) {
$output = "OK: $output";
} elsif ( $return_val == 1 ) {
$output = "WARNING: $output";
} elsif ( $return_val == 2 ) {
$output = "CRITICAL: $output";
} else {
$output = "UNKNOWN: $output";
if ($no_unknown) {
$return_val = 0;
}
}
write_line($debug, "Return Value: $return_val");
}
if ( $html ) {
print qq|<HTML><HEAD><TITLE>$filename Monitor</TITLE></HEAD><BODY>$output</BODY></HTML>\n|;
} else {
print qq|$output|;
}
exit $return_val;
#Caution, uses globals. However, you need to modify this section to match your log format
sub add_time_to_file {
################# Make your changes here #####################
if ( $addtime ) {
$month++;
$yearOffset+=1900;
$month = sprintf("%2d", $month);
$month =~ tr/ /0/;
$yearOffset = sprintf("%4d", $yearOffset);
$yearOffset =~ tr/ /0/;
$dayOfMonth = sprintf("%2d", $dayOfMonth);
$dayOfMonth =~ tr/ /0/;
$filename .= ".$yearOffset-$month-$dayOfMonth";
}
return 1;
}
sub usage {
print qq|\n\nUsage Instructions:\n|;
print qq| --f or --filename = Specifies the filename you are checking\n|;
print qq| --s or --string = Specifies the string you looking for\n|;
print qq| --a or --addtime = Adds a time/date stampe to the back of the file\n|;
print qq| --html = Spits out the items in html compatible format\n|;
print qq|Example usage: $0 --filename=testfoo --string="this is a test" --addtime\n|;
}
sub write_line {
my $dbg = shift;
my $line = shift;
if ( $dbg ) {
print qq|$line\n|;
}
}
This script was written by an intern here, so there are things you can do differently for sure. It's not much, but here's what we use as a wrapper. these types of logs can be tricky depending on your logfile structure.
Here's how you run it from the command line: ./check_log_wrapper --filename=/opt/apache/logs/dispatcher_log -s "Connection timed out" -addtime
You will probably need to make some modifications for it to work. If you need help making those modifications, just let me know.
#!/usr/bin/perl
use strict;
use File::Basename;
use Getopt::Long;
use constant EXIT_OK => 0;
use constant EXIT_WARNING => 1;
use constant EXIT_CRITICAL => 2;
my $filename = '';
my $string = '';
my $addtime = 0;
my $html = 0;
my $return_val = EXIT_OK;
#my $logs_dir = '/home/nagios/old_logs'; #change this to where you want the logs dropped off at
my $logs_dir = '/tmp/tmp_logs';
my $output = '';
#my $check_log = '/home/nagios/bin/check_log';
my $check_log = '/home/nagios/bin/check_log';
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset,
$dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
my $debug = 0;
my $no_unknown = 0;
GetOptions(
"f|filename=s" => \$filename,
"s|string=s" => \$string,
"t|addtime" => \$addtime,
"html" => \$html,
"d|debug" => \$debug,
"nounknown" => \$no_unknown,
);
if ( ! defined($filename) || $filename eq '' ) {
print qq|No filename specified!\n|;
$return_val = EXIT_CRITICAL;
usage();
} elsif ( ! defined($string) || $string eq '' ) {
print qq|No string specified!\n|;
$return_val = EXIT_CRITICAL;
usage();
} elsif ( ! add_time_to_file($addtime) ) {
print qq|Failed to add time to the file\n|;
$return_val = EXIT_CRITICAL;
usage();
} else {
if ( ! -d $logs_dir ) {
write_line($debug, "Creating directory: $logs_dir");
system("/bin/mkdir -p $logs_dir");
}
my $oldfullname = $filename.".old";
write_line($debug, "Old full name = $oldfullname");
$oldfullname = basename($oldfullname);
write_line($debug, "Old full name basename = $oldfullname");
$oldfullname = "$logs_dir/$oldfullname";
write_line($debug, "New Old full name basename = $oldfullname");
my $cmd = '';
if ( ! -f $filename ) {
$output = "No log file found.\n";
$return_val = 0;
} else {
$cmd = qq|$check_log -F $filename -O $oldfullname -q "$string"|;
write_line($debug, "Command: $cmd");
$output = `$cmd`;
$return_val = $? >> 8;
}
if ( $return_val == 0 ) {
$output = "OK: $output";
} elsif ( $return_val == 1 ) {
$output = "WARNING: $output";
} elsif ( $return_val == 2 ) {
$output = "CRITICAL: $output";
} else {
$output = "UNKNOWN: $output";
if ($no_unknown) {
$return_val = 0;
}
}
write_line($debug, "Return Value: $return_val");
}
if ( $html ) {
print qq|<HTML><HEAD><TITLE>$filename Monitor</TITLE></HEAD><BODY>$output</BODY></HTML>\n|;
} else {
print qq|$output|;
}
exit $return_val;
#Caution, uses globals. However, you need to modify this section to match your log format
sub add_time_to_file {
################# Make your changes here #####################
if ( $addtime ) {
$month++;
$yearOffset+=1900;
$month = sprintf("%2d", $month);
$month =~ tr/ /0/;
$yearOffset = sprintf("%4d", $yearOffset);
$yearOffset =~ tr/ /0/;
$dayOfMonth = sprintf("%2d", $dayOfMonth);
$dayOfMonth =~ tr/ /0/;
$filename .= ".$yearOffset-$month-$dayOfMonth";
}
return 1;
}
sub usage {
print qq|\n\nUsage Instructions:\n|;
print qq| --f or --filename = Specifies the filename you are checking\n|;
print qq| --s or --string = Specifies the string you looking for\n|;
print qq| --a or --addtime = Adds a time/date stampe to the back of the file\n|;
print qq| --html = Spits out the items in html compatible format\n|;
print qq|Example usage: $0 --filename=testfoo --string="this is a test" --addtime\n|;
}
sub write_line {
my $dbg = shift;
my $line = shift;
if ( $dbg ) {
print qq|$line\n|;
}
}
Re: check output logfile in nagios
thanks for your effort , but i dont understand that this script it resemble to the check_log script already in libexec directory , i can not understand why i need to make comparison between old file and new generated one,for my case i need just to check at time for example 2:00 am that the log file is generated and to let script read my output file for example let th script find one word in the file log for my case like "successful" and he will return me that the backup finished without error.i hope that you understand what i mean.im ready for any question
Re: check output logfile in nagios
Ok, I'd approach the problem using send_nsca and a cron job. Set up a passive alert in Nagios. Create a generic shell script to grep through your log file and if it finds the word "success" have it send an "OK" to Nagios. If it's in error, have it send an error to Nagios and alert people.ps2ali wrote:thanks for your effort , but i dont understand that this script it resemble to the check_log script already in libexec directory , i can not understand why i need to make comparison between old file and new generated one,for my case i need just to check at time for example 2:00 am that the log file is generated and to let script read my output file for example let th script find one word in the file log for my case like "successful" and he will return me that the backup finished without error.i hope that you understand what i mean.im ready for any question
Is that what you're looking for?
Also, if you haven't set up send_nsca before, I'll give you some tips on how to set it up.