Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Perl Script to parse Windows Event Logs

by kar_thik82 (Novice)
on Dec 07, 2012 at 09:43 UTC ( #1007701=perlquestion: print w/ replies, xml ) Need Help??
kar_thik82 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I am developing a log parsing agent in perl to send windows Event logs to Zenoss Monitoring tool. Using Win32::EventLog i can able to get the Event messages but only one Eventype eg Application or System could able to parse at a time. Can you please help to how to open mutiple eventlogs at a time I need to get the total number of events combining all these event types. Below is my code which i tried

my @log_type =("Application", "Security", "Setup", "System", "Forwarde +d Events"); foreach $logs_type (@log_type){ #print "$logs_type\n"; Win32::EventLog::Open($EventLog, $logs_type,'') or die "Could not open System log:$^E\n"; $EventLog->Win32::EventLog::GetNumber($numevents); print "$EventLog->Win32::EventLog::GetNumber($numevents)\n" +; }

Comment on Perl Script to parse Windows Event Logs
Download Code
Re: Perl Script to parse Windows Event Logs
by brap (Pilgrim) on Dec 07, 2012 at 14:19 UTC

    Hi kar_thik82,

    What about keeping a running count of each event log, and then printing the total?

    my @log_type =("Application", "Security", "Setup", "System", "Forwarde +d Events"); my $total_events = 0; foreach $logs_type (@log_type) { #print "$logs_type\n"; Win32::EventLog::Open($EventLog, $logs_type,'') or die "Could not open System log:$^E\n"; $EventLog->Win32::EventLog::GetNumber($numevents); $total_events += $numevents; # print "$EventLog->Win32::EventLog::GetNumber($numevents)\n"; } print "Total number of events: $total_events\n";

    Not exactly tested, but hopefully enough to illustrate the point.

      Thanks Brap It works for me.

Re: Perl Script to parse Windows Event Logs
by Anonymous Monk on Dec 08, 2012 at 03:38 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007701]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-04-23 20:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (554 votes), past polls