check output logfile in nagios

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
ps2ali
Posts: 11
Joined: Tue Apr 26, 2011 4:47 am

Re: check output logfile in nagios

Post by ps2ali »

exactly this my need , u can help me in that?
ps2ali
Posts: 11
Joined: Tue Apr 26, 2011 4:47 am

Re: check output logfile in nagios

Post by ps2ali »

yes thanks , please let me kno how i can do that
User avatar
niebais
Posts: 349
Joined: Tue Apr 13, 2010 2:15 pm

Re: check output logfile in nagios

Post by niebais »

Some things you'll need to set up on your systems, but I'll help you where I can. First you need to download nsca and install it on your system.
http://nagios.sourceforge.net/download/ ... _Setup.pdf


I'll hack up a quick script and post it here.

Also, make sure you read up on setting up Nagios XI passive alerts. You'll need to set one up for this type of alert.

I should be able to get that out to you tomorrow morning.
User avatar
niebais
Posts: 349
Joined: Tue Apr 13, 2010 2:15 pm

Re: check output logfile in nagios

Post by niebais »

Ok, I hope this is what you're looking for. Keep in mind that this is something that you'd normally have to come up with yourself if it didn't already exist.

Also note that this is a "quick and dirty script". It is written in perl and there are probably 1000 better ways to do this, but it returns an error if there is a problem. You'll need to set up the passive alert and then pipe the output to send_nsca.

If your system has any issues with it after running it, I am not liable or have no responsibility for any damages.
########################################################################

#!/usr/bin/perl

#------------------------------------------------------------------------------
# check_new_log
# returns a critical if a string is found in a logfile
#
#

use strict;
use Getopt::Long;

my $plugin_name = 'check_new_log';
my $VERSION = '0.01';

# nagios exit codes
use constant EXIT_OK => 0;
use constant EXIT_WARNING => 1;
use constant EXIT_CRITICAL => 2;
use constant EXIT_UNKNOWN => 3;

# parse cmd opts
my $filename = '';
my $help = '';
my $str = '';
my $message = '';
my $rv = EXIT_OK;

GetOptions(
'f|filename=s' => \$filename,
's|string=s' => \$str,
'h|help=s' => \$help,
);

if ( $help ) {
HELP_MESSAGE();
} elsif ( ! $filename ) {
$message = "No filename was supplied!\n";
$rv = EXIT_CRITICAL;
} elsif ( ! $str ) {
$message = "No search string was supplied!\n";
$rv = EXIT_CRITICAL;
} elsif ( ! -f $filename ) {
$message = "The filename: $filename does not exist!\n";
$rv = EXIT_CRITICAL;
} else {
$message = "OK: String: $str not found in file: $filename\n";
$rv = EXIT_OK;
open(FLE, "$filename") or die "Could not open filename: $filename\n";
while(<FLE>) {
if ( m/$str/ ) {
$message = "ERROR: String: $str found in file: $filename\n";
$rv = EXIT_CRITICAL;
last;
}
}
close FLE;
}

print "$message";
exit $rv;

sub HELP_MESSAGE {
print <<EOHELP
-h This help message
--filename {FILENAME}
--String {STRING}

EOHELP
;
}

sub VERSION_MESSAGE {
print "Version: $VERSION\n";
}
ps2ali
Posts: 11
Joined: Tue Apr 26, 2011 4:47 am

Re: check output logfile in nagios

Post by ps2ali »

thanks , but i read that NSCA is an addon that allows you to send passive check results from remote Linux/Unix hosts(not windows) to the
Nagios daemon running on the monitoring server?????? what do you think my friend?
User avatar
niebais
Posts: 349
Joined: Tue Apr 13, 2010 2:15 pm

Re: check output logfile in nagios

Post by niebais »

Try this for send_nsca:
http://exchange.nagios.org/directory/Ad ... nt/details

Almost everything in Nagios can be done in both windows and Linux.
Locked