no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | monitors:winevtmsgs.pl [2010/08/24 01:40] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== WinEvtMsgs ====== | ||
+ | |||
+ | ^ Author | [[ dbaldwin@users.sf.net|David Baldwin ]] | | ||
+ | ^ Compatibility | Xymon 4.2 | | ||
+ | ^ Requirements | Perl, rsyslog/ | ||
+ | ^ Download | None | | ||
+ | ^ Last Update | 2010-08-17 | | ||
+ | |||
+ | ===== Description ===== | ||
+ | |||
+ | Report on Windows Event logs forwarded with SNARE | ||
+ | |||
+ | note: xymon/ | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | ===== Installation ===== | ||
+ | === Client side === | ||
+ | Each Windows server needs the appropriate version of Snare installed (Vista/2008 different from older versions of Windows). | ||
+ | |||
+ | === Server side === | ||
+ | Install on central syslog server. Assumed this is the same as Xymon server (need to use bb-hosts ' | ||
+ | |||
+ | Can also report on cluster nodes and cluster resources (e.g. SQL or Exchange) - in such cases each cluster node forwards all events for all nodes. | ||
+ | |||
+ | bb-hosts example for SQL instances: | ||
+ | < | ||
+ | 10.0.0.22 c2n1 # evt | ||
+ | 10.0.0.23 c2n2 # evt | ||
+ | 10.0.0.24 c2n3 # evt | ||
+ | 10.0.0.26 sql1 # evt=10.0.0.22 | ||
+ | 10.0.0.27 sql2 # evt=10.0.0.22 | ||
+ | 10.0.0.28 sql3 # evt=10.0.0.22 | ||
+ | </ | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | Sample / | ||
+ | note: " | ||
+ | note: " | ||
+ | <code perl> | ||
+ | # $ModLoad immark # provides --MARK-- message capability | ||
+ | $ModLoad imudp # provides UDP syslog reception | ||
+ | $UDPServerAddress * # this MUST be before the $UDPServerRun directive! | ||
+ | $UDPServerRun 514 | ||
+ | $ModLoad imtcp # provides TCP syslog reception | ||
+ | $InputTCPServerRun 514 | ||
+ | $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) | ||
+ | $ModLoad imklog # provides kernel logging support (previously done by rklogd) | ||
+ | |||
+ | $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat | ||
+ | |||
+ | # | ||
+ | |||
+ | $umask 0000 | ||
+ | $DirOwner root | ||
+ | $DirGroup logview | ||
+ | $DirCreateMode 0750 | ||
+ | $FileOwner root | ||
+ | $FileGroup logview | ||
+ | $FileCreateMode 0640 | ||
+ | $template DynFile,"/ | ||
+ | |||
+ | :source , !isequal , " | ||
+ | </ | ||
+ | |||
+ | Add to hobbitlaunch.cfg | ||
+ | < | ||
+ | # " | ||
+ | |||
+ | [winevt] | ||
+ | ENVFILE / | ||
+ | NEEDS hobbitd | ||
+ | CMD $BBHOME/ | ||
+ | LOGFILE $BBSERVERLOGS/ | ||
+ | INTERVAL 5m | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Source ===== | ||
+ | ==== winevtmsgs.pl ==== | ||
+ | Install in server/ext directory | ||
+ | |||
+ | <hidden onHidden=" | ||
+ | <code perl> | ||
+ | # | ||
+ | #CHKHOSTS evt | ||
+ | # | ||
+ | # winevtmsgs.pl | ||
+ | # | ||
+ | # Report on Windows Event logs forwarded with SNARE | ||
+ | # | ||
+ | # note: xymon/ | ||
+ | # | ||
+ | # SNARE is a Windows event log forwarder over syslog. | ||
+ | # http:// | ||
+ | # | ||
+ | =begin rsyslog | ||
+ | # rsyslog or syslog-ng can be used on a central syslog server to accumulate logs for each host in a separate directory | ||
+ | # | ||
+ | # http:// | ||
+ | # Sample / | ||
+ | # note: " | ||
+ | # note: " | ||
+ | # (rsyslog V3) | ||
+ | |||
+ | # $ModLoad immark # provides --MARK-- message capability | ||
+ | $ModLoad imudp # provides UDP syslog reception | ||
+ | $UDPServerAddress * # this MUST be before the $UDPServerRun directive! | ||
+ | $UDPServerRun 514 | ||
+ | $ModLoad imtcp # provides TCP syslog reception | ||
+ | $InputTCPServerRun 514 | ||
+ | $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) | ||
+ | $ModLoad imklog # provides kernel logging support (previously done by rklogd) | ||
+ | |||
+ | $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat | ||
+ | |||
+ | # | ||
+ | |||
+ | $umask 0000 | ||
+ | $DirOwner root | ||
+ | $DirGroup logview | ||
+ | $DirCreateMode 0750 | ||
+ | $FileOwner root | ||
+ | $FileGroup logview | ||
+ | $FileCreateMode 0640 | ||
+ | $template DynFile,"/ | ||
+ | |||
+ | :source , !isequal , " | ||
+ | |||
+ | =cut | ||
+ | |||
+ | my $xymonlib; | ||
+ | BEGIN { $xymonlib = $ENV{BBHOME} && " | ||
+ | |||
+ | use strict; | ||
+ | use lib $xymonlib; | ||
+ | use POSIX; | ||
+ | use Fcntl; | ||
+ | use DB_File; | ||
+ | use XymonExt; | ||
+ | use Getopt:: | ||
+ | |||
+ | use Data:: | ||
+ | |||
+ | $|=1; | ||
+ | my $debug = 0; # 0 = none 1 = low | ||
+ | |||
+ | # config | ||
+ | my $logdir = "/ | ||
+ | |||
+ | my $test = " | ||
+ | my $bbtest = " | ||
+ | my $topredlim = 5; | ||
+ | |||
+ | # end of test config | ||
+ | my ($bbstatus, | ||
+ | my $filedump = 0; | ||
+ | my $exit_status = 0; | ||
+ | my $addr = ''; | ||
+ | my $complete = 0; | ||
+ | my $previous = 0; | ||
+ | my %cluster; | ||
+ | my $evthf = " | ||
+ | my %logsp; | ||
+ | tie(%logsp, ' | ||
+ | or die " | ||
+ | |||
+ | # Global status variables - don't forget to initialiase in main loop below to clear before checking new host ... | ||
+ | # | ||
+ | |||
+ | while ( $ARGV[0] && $ARGV[0] =~ /^-/ ) { | ||
+ | if ( $ARGV[0] eq ' | ||
+ | $debug++; | ||
+ | shift @ARGV; | ||
+ | next; | ||
+ | } | ||
+ | if ( $ARGV[0] eq ' | ||
+ | $filedump++; | ||
+ | shift @ARGV; | ||
+ | next; | ||
+ | } | ||
+ | if ( $ARGV[0] eq ' | ||
+ | shift @ARGV; | ||
+ | if ( ! $ARGV[0] ) { &usage; exit 5; } | ||
+ | $addr = $ARGV[0]; | ||
+ | shift @ARGV; | ||
+ | next; | ||
+ | } | ||
+ | if ( $ARGV[0] eq ' | ||
+ | $complete++; | ||
+ | shift @ARGV; | ||
+ | next; | ||
+ | } | ||
+ | if ( $ARGV[0] eq ' | ||
+ | $previous++; | ||
+ | shift @ARGV; | ||
+ | next; | ||
+ | } | ||
+ | exit 5; | ||
+ | } | ||
+ | if ( $ARGV[0] ) { | ||
+ | die " | ||
+ | } | ||
+ | |||
+ | # | ||
+ | |||
+ | my %tests = do "/ | ||
+ | |||
+ | sub match { | ||
+ | my ($val, | ||
+ | return 0 unless defined $val; | ||
+ | if(ref $match eq " | ||
+ | return $val =~ $match; | ||
+ | } else { | ||
+ | return $val eq $match; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | my %dbgc = (); | ||
+ | |||
+ | sub reportline { | ||
+ | my $line = shift; | ||
+ | my $rephost = shift; | ||
+ | my %fields = (); | ||
+ | @fields{qw{date evt eid src ser tsp evn cat usr na typ hst n1 n2 msg n3}} = split /# | ||
+ | my ($host) = ($fields{date} =~ / | ||
+ | print " | ||
+ | return if lc $rephost ne lc $fields{hst}; | ||
+ | my $lcol = ""; | ||
+ | MATCH: foreach my $tk ((grep {$_ ne " | ||
+ | print " | ||
+ | my %tr = %{$tests{$tk}}; | ||
+ | next if defined($tr{host}) && ! match($host, | ||
+ | print "DBG: matched $host in test $tk\n" if $debug && ! $dbgc{$host}{$tk}++; | ||
+ | if(defined $tr{ignore}) { | ||
+ | foreach my $ik (keys %{$tr{ignore}}) { | ||
+ | my %ti = %{$tr{ignore}{$ik}}; | ||
+ | my $im = scalar keys %ti; | ||
+ | foreach my $ikt (keys %ti) { | ||
+ | $im &&= match($fields{$ikt}, | ||
+ | } | ||
+ | if($im) { | ||
+ | print " | ||
+ | return; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | foreach my $col (qw{red yellow green}) { | ||
+ | TEST: foreach my $ik (keys %{$tr{$col}}) { | ||
+ | print "DBGD: testing $host in $col test $ik\n" if $debug && ! $dbgc{111}{$host}{$col}{$ik}++; | ||
+ | my %ti = %{$tr{$col}{$ik}}; | ||
+ | foreach my $ikt (keys %ti) { | ||
+ | print " | ||
+ | next TEST unless match($fields{$ikt}, | ||
+ | } | ||
+ | print "DBG: matched $col in test $ik group $tk\n" if $debug; | ||
+ | $lcol = $col; | ||
+ | last MATCH; # exit on first match - otherwise default may override specific match - do we need priority also? | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | return if $lcol eq ""; | ||
+ | my $msg = $fields{msg} || $fields{n1} || ""; | ||
+ | my $evtmsg = "& | ||
+ | $topred .= $evtmsg if $lcol eq " | ||
+ | $bbmsg .= $evtmsg; | ||
+ | XymonExt-> | ||
+ | } | ||
+ | |||
+ | ### Main loop | ||
+ | my @dflist = (); | ||
+ | if (length $addr == 0 || ! $debug) { | ||
+ | @dflist = XymonExt-> | ||
+ | } else { | ||
+ | @dflist = ($addr); | ||
+ | } | ||
+ | if($debug) { | ||
+ | printf "** DEBUG Host list ** %s\n", | ||
+ | } | ||
+ | my @testtime = localtime(time - 300 - $previous*24*60*60); | ||
+ | if($filedump) { | ||
+ | my $logdate = strftime " | ||
+ | foreach my $f (keys %logsp) { | ||
+ | my $old = $f =~ / | ||
+ | print "$f: $logsp{$f} : $old\n"; | ||
+ | if($filedump> | ||
+ | delete $logsp{$f}; | ||
+ | } | ||
+ | } | ||
+ | exit; | ||
+ | } | ||
+ | foreach my $bbhost (@dflist) { | ||
+ | my ($shrephost) = split / | ||
+ | my $ipaddr = XymonExt-> | ||
+ | my $altipaddr = XymonExt-> | ||
+ | print " | ||
+ | if( my ($ip) = ($altipaddr =~ / | ||
+ | if( $ip =~ / | ||
+ | $ipaddr = $ip; | ||
+ | } else { | ||
+ | push @{$cluster{$1}}, | ||
+ | } | ||
+ | } | ||
+ | XymonExt-> | ||
+ | $bbmsg = ""; | ||
+ | $topred = ""; | ||
+ | $topredcnt = 0; | ||
+ | my $c = 0; | ||
+ | my $newsp = 0; | ||
+ | my $prevsp = 0; | ||
+ | my $logfile = strftime " | ||
+ | print " | ||
+ | if(open LF, | ||
+ | if(exists $logsp{$logfile} && ! $complete) { | ||
+ | $prevsp = $logsp{$logfile}; | ||
+ | print "DBG: logfile SP: $prevsp\n" | ||
+ | my $seeksts = seek LF, $prevsp, 0; | ||
+ | print " | ||
+ | } else { | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | my $tspat = strftime "^%b %e %H: | ||
+ | $tspat =~ s/ | ||
+ | $tspat =~ s/ | ||
+ | $tspat .= ": | ||
+ | print "DBG: tspat: / | ||
+ | my $tsre = qr{$tspat}; | ||
+ | while(my $ll = <LF>) { | ||
+ | print $ll if $debug > 1; | ||
+ | reportline($ll, | ||
+ | if( $ll =~ /$tsre/) { | ||
+ | print " | ||
+ | unless( $newsp ) { | ||
+ | $newsp = $prevsp; | ||
+ | print "DBG: set new SP: $newsp\n" | ||
+ | } | ||
+ | $c++; | ||
+ | } | ||
+ | $prevsp = tell(LF) unless $newsp; | ||
+ | } | ||
+ | close LF; | ||
+ | print "DBG: $c\n" if $debug; | ||
+ | print "DBG: new logfile SP: $newsp\n" | ||
+ | $logsp{$logfile} = $newsp if $newsp > 0; | ||
+ | my $scol = XymonExt-> | ||
+ | my $warn = $scol eq " | ||
+ | my $redcnt = $topredcnt > $topredlim && $topredlim || $topredcnt; | ||
+ | my $redmsg = $topredcnt ? "< | ||
+ | $bbmsg = " | ||
+ | } else { | ||
+ | $bbmsg = " | ||
+ | if($testtime[2]*60+$testtime[1] > 15) { # allow 15 minutes after midnight for SOMETHING to be logged | ||
+ | XymonExt-> | ||
+ | } else { | ||
+ | XymonExt-> | ||
+ | } | ||
+ | } | ||
+ | # | ||
+ | if ($debug) { | ||
+ | print "BB: $bbhost.$bbtest sts: " | ||
+ | } else { | ||
+ | XymonExt-> | ||
+ | } | ||
+ | |||
+ | |||
+ | } # end main loop | ||
+ | exit $exit_status; | ||
+ | |||
+ | # | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== winevtmsgs.cfg ==== | ||
+ | |||
+ | Install in / | ||
+ | |||
+ | <hidden onHidden=" | ||
+ | <code perl> | ||
+ | # | ||
+ | # | ||
+ | # winevtmsgs.pl config file (/ | ||
+ | # | ||
+ | # Field values can be defined as exact string match (plain string) or regexp (qr//). | ||
+ | # | ||
+ | # Rules must have unique key (name) - default is always processed last | ||
+ | # host field is matched against host name from syslog file line (generated by SNARE) | ||
+ | # matching rules use key: ignore, red, yellow, green | ||
+ | # | ||
+ | # | ||
+ | # other fields for matching purposes are from Event log line (* = displayed in report): | ||
+ | # date = syslog date/time stamp | ||
+ | # evt = " | ||
+ | # eid = " | ||
+ | # * src = Security, Application, | ||
+ | # ser = event number (sequence) | ||
+ | # * tsp = time/date stamp (from Windows host) | ||
+ | # * evn = event ID | ||
+ | # * cat = category/ | ||
+ | # * usr = account/ | ||
+ | # na = " | ||
+ | # * typ = Warning, Error, Information, | ||
+ | # hst = Windows host name or cluster node/ | ||
+ | # ? n1 = sometimes message (e.g. Exchange), often " | ||
+ | # n2 = "" | ||
+ | # * msg = event message (sometime blank - e.g. Exchange) | ||
+ | # n3 = another sequence number? | ||
+ | # | ||
+ | # Reporting line format is: | ||
+ | # | ||
+ | # (if msg is blank, n1 is reported instead - e.g. some Exchange messages) | ||
+ | # | ||
+ | # Tune as required based on " | ||
+ | # | ||
+ | # sample rule: | ||
+ | # DCs (Domain Controllers) | ||
+ | # host name specified by regexp | ||
+ | # ignore System: | ||
+ | # yellow on System:KDC 26 messages (often Error, but not that significant) | ||
+ | # green on System: | ||
+ | # | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # }, | ||
+ | # }, | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # }, | ||
+ | # }, | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # " | ||
+ | # }, | ||
+ | # }, | ||
+ | # }, | ||
+ | |||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | "WSUS replica" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | |||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | }, | ||
+ | }, | ||
+ | # | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | ===== Known Bugs and Issues ===== | ||
+ | |||
+ | ===== To Do ===== | ||
+ | |||
+ | ===== Credits ===== | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * **2010-08-17** | ||
+ | * Initial release | ||