/usr/lib/mon/mon.d/local-syslog.monitor is in mon 1.2.0-4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | #!/usr/bin/perl
#
# A syslog monitor for mon, with support for Cisco router messages
#
# $Id: local-syslog.monitor,v 1.1.2.1 2007/06/03 13:43:35 trockij Exp $
#
# Copyright (C) 2001-2006, Jon Meek, meekj at ieee.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
=head1 NAME
B<local-syslog.monitor> - syslog monitor for mon
=head1 DESCRIPTION
Watch local syslog log files and alert when a regular expression is matched.
Include router interface descriptions for logs generate by a Cisco router.
=head1 SYNOPSIS
When the regular expression is matched, an alert is triggered. The alert
details contain the actual log entries that matched. An optional additional
description can be added to the details for an IP address / Interface Name
pair if the log entry comes from a Cisco router.
A common usage involves having other systems send their syslog information
to this mon server so they can be watched by this monitor.
=head1 OPTIONS
=over 5
=item B<-c>
Configuration file
=item B<-d>
Debug/Test. Useful for manual command line use.
=back
=head1 CONFIGURATION FILE
=item B<Strings>
Regular expression that will trigger an alarm when there is a match.
=item B<BaseDir>
The top of the directory tree where the syslog files are kept.
=item B<File>
Syslog files are usually specified on the command line, but can be
listed in the config file as well.
=item B<Extended Name>
IP Address / Interface Name pairs can be expanded in the details
section of an alert. These lines consist of an IP address followed by
whitespace, then the interface name followed by whitespace, then a
description of the interface. This is added to the alert if the log
entry is found to match the output generated from a Cisco router.
Example:
Strings %BGP-5|%LINEPROTO-5-UPDOWN|%LINK-3-UPDOWN
BaseDir /d2/logs/remotesyslog
#File exnetmon-gv/cisco.log
#File ot-gv/cisco.log
192.168.56.1 FastEthernet0/0 To Extranet Switch
192.168.56.1 Serial0/0 Frame-Relay DHEC266467 DLCI 612
192.168.56.1 FastEthernet0/1 Inside Interface
192.168.56.1 Serial0/1 T-1 to ICO DHEC397828
=head1 MON CONFIGURATION EXAMPLE
hostgroup remote-syslog exnetmon-wl/cisco.log ot-wl/cisco.log
watch remote-syslog
service syslog
interval 15m
monitor local-syslog.monitor -c /usr/local/mon/syslog.cfg
period wd {Sun-Sat}
alert mail.alert meekj-at-ieee.org
=head1 AUTHOR
Jon Meek, meekj at ieee.org
=cut
use Getopt::Std;
#use File::Basename;
#use Time::HiRes qw( gettimeofday tv_interval );
$BaseDir = '';
@Failures = (); # Initialize failure list
$TimeOfDay = time; # Current time
getopts ("dc:");
if (defined $ENV{MON_STATEDIR}) { # Are we running under mon?
$STATE_DIR = $ENV{MON_STATEDIR};
$RunningUnderMon = 1;
} else {
$RunningUnderMon = 0;
}
if ($opt_c) { # Read configuration file
$ConfigFile = $opt_c;
if (open(C, $ConfigFile)) {
while ($in = <C>) {
last if ($in =~ /^Exit/i);
next if ($in =~ /^\#/); # Comments
chomp $in;
if ($in =~ /^BaseDir/i) {
($tag, $BaseDir) = split(' ', $in, 2);
next;
}
if ($in =~ /^File/i) {
($tag, $file) = split(' ', $in, 2);
push(@Files, $file);
next;
}
if ($in =~ /^Strings/i) {
($tag, $data) = split(' ', $in, 2);
$RegEx .= $data;
next;
}
if ($in =~ /^[0-9\.]+/) {
($router_ip, $interface_name, $description) = split(' ', $in, 3);
# print "$router_ip - $interface_name - $description\n" if $opt_d;
$RouterInterfaceDescription{"$router_ip $interface_name"} = $description;
next;
}
if ($in =~ /^RouterList/i) {
($tag, $RouterListFile) = split(' ', $in, 2);
next;
}
if ($in =~ /^StateDir/i) { # If the mon environment variable needs to be overriden
($tag, $STATE_DIR) = split(' ', $in, 2);
next;
}
}
} else {
print "local-syslog.monitor: Couldn't open $ConfigFile configuration file\n";
exit 1;
}
}
push (@Files, @ARGV); # Get file names from the command line
foreach $File (@Files) {
$FullPath = "$BaseDir/$File";
if (!-e $FullPath) { # File does not exist
print "**** $FullPath does not exist\n" if $opt_d;
next;
}
$StateFile = $FullPath;
$StateFile =~ s/\//-/g; # Change / to - to make filename
$StateFile =~ s/^-//;
$StateFile = "$STATE_DIR/$StateFile";
#
# Read the previous file sizes if the State File exists
#
if (-e $StateFile) {
print "Existing $StateFile\n" if $opt_d;
open(F, $StateFile);
$in = <F>;
($t, $last_size) = split(' ', $in);
close F;
$StateFileExists = 1; # Remember that there is a existing State File
} else {
$StateFileExists = 0; # or not
$last_size = 0;
print "No Existing $StateFile\n" if $opt_d;
}
#
# Get file information
#
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
$atime, $mtime, $ctime, $blksize, $blocks) = stat($FullPath);
# $basename = basename($SmartAlarm); # Get the path to the module
# $dirname = dirname($SmartAlarm);
print "$StateFile Last size: $last_size Size - : $size\n" if $opt_d;
next if ($size == $last_size); # File has not changed since last check (may want to check time too)
$FailureDetail{$File} = '';
open(F, $FullPath);
if ($size > $last_size) { # Position to read new lines only
seek(F, $last_size, 0);
}
while ($in = <F>) {
chomp $in;
if ($in =~ /$RegEx/o) { # Check the master regular expression
#
# see if we have a description on the router/interface (from cisco)
#
if ($in =~ /^(\w{3}\s+\d{1,2}\s+\d{2}:\d{2}:\d{2})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) {
$router_ip = $2;
$in =~ /\s+Interface\s+([\w\/\.]+)/;
$interface_name = $1;
# print "*** $router_ip $interface_name\n";
if (exists $RouterInterfaceDescription{"$router_ip $interface_name"}) {
$in .= ' [' . $RouterInterfaceDescription{"$router_ip $interface_name"} . ']';
}
}
$HaveFailureData{$File}++;
$FailureDetail{$File} .= "$in\n";
print "$in\n" if $opt_d;
}
}
$CurrentPosition = tell(F);
print "Final Position: $CurrentPosition\n" if $opt_d;
close F;
# Write new state file
print "Writing a new $StateFile\n" if $opt_d;
open(F, ">$StateFile");
print F "$TimeOfDay $CurrentPosition\n";
close F;
}
foreach $k (sort keys %HaveFailureData) {
push(@Failures, $k);
}
if (@Failures == 0) { # Indicate "all OK" to mon
exit 0;
}
#
# Otherwise we have one or more failures
#
print "@Failures\n";
foreach $k (@Failures) {
print "$k $FailureDetail{$k}\n";
}
print "\n";
exit 1; # Indicate failure to mon
|