check_log not working properly

Jim Mozley jim.mozley at exponential-e.com
Fri Feb 13 10:29:37 CET 2004


Neil wrote:

> This was my pattern:
> if ( $syslogmsg =~ /down/ ) {
> I also tried $_ still didn't work.
> So how can the $* be read by the script.pl? One more, I also even tried 
> this pattern
> if ( $ARGV[0] =~ /down/ ) {

One needs to get @ARGV into one variable to match (see below), otherwise 
one is probably trying to match something like the month name.

> didn't work too.

This is really getting into perl, so in general I'd suggest the 
comp.land.perl.misc newsgroup for questions. But here is one way to do it...


This is from one script I have. First get all the arguments into one 
message string, then split it up using a regex to get the information 
you need such as host. Then use the info to make the decision on the 
service state.

The syslog message to be matched is below.

Oct 19 17:47:47 hostname %MPLS-I-LSPPATHSWITCH, LSP "backup path"
     switching to Primary Path "primary path".

# get @ARGV back to one syslog message
my $message = join(' ', @ARGV);

# When testing, the unix shell or perl removed quotes passed
# as ARGV so the quotes in the regex are optional. On further
# investigation I think it is syslog-ng doing this.
my ($switch, $type, $lsp, $msg) = $message =~
     /\s([a-z]{4}-[a-z]{2}-\d{2})\s    # Capture host name,
     %MPLS-I-
     ([A-Z]+)                          # type of MPLS message,
     ,\sLSP\s
     "?([-\w]+)"?                        # lsp
     \s(.*)                              # and the message.
     /x;


# Set nagios status code according to the type of syslog message
# and the contents of that message. Exit if its not something we are
# interested in
if ( $type eq 'LSPPATHSWITCH' ) {
     if ( $msg =~ /switching to Primary Path/ ) {
         $nagios_code = 0; # Ok
     }
     else { # switching to Secondary - so we have a problem
         $nagios_code = 2; # Critical
     }
}
elsif ( $type eq 'LSPUP' ) {
     $nagios_code = 0; # Ok
}
else {
     exit;
}

HTH,

Jim


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
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