Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl use strict; use DBI; use DBD::mysql; sub SendMail($$$); my @monthnames = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)) +; my @msg; my @datetime; my ($rin, $nfound, $rout, $what, $dbh, $logtime, $logtable, $month); my $strSQL = ''; my $category = ''; my $catflag = ''; $dbh = DBI->connect("DBI:mysql:database=logger;host=localhost", "username", "password", {'RaiseError' => 1}); $rin=""; vec($rin,fileno(STDIN),1)=1; open (TTY, "> /dev/tty1"); while (1) { sleep 1; $nfound=select($rout=$rin,"","",1); $what = ($nfound) ? <> : ""; if ($what ne "") { $what = substr($what, index ($what, "MSWinEventLog")); @msg = split(/\t/, $what); @datetime = split(/ /, $msg[4]); for(0..11) { if ($monthnames[$_] eq $datetime[1]) {$month=++$_;} } $logtime = "$datetime[4]-$month-$datetime[2] $datetime[3]"; if ($msg[9] =~ "Error") { $logtable = 'error'; SendMail($msg[10], $msg[5], $msg[13]); }elsif ($msg[9] =~ "Warning") { $logtable = 'warning'; }else { $logtable = 'other'; $category = "\'$msg[9]\',"; $catflag='category, '; } $strSQL = "INSERT INTO $logtable ($catflag"."logtime, host, logt +ype, event_id," . " source, message) VALUES ($category \'$logtime\', \'$ +msg[10]\', " . "\'$msg[2]\', $msg[5], \'$msg[6]\', \'$msg[13]\')"; $dbh->do($strSQL); $category = $catflag = ''; } } #----------------- Send an email notification --------------------- sub SendMail($$$) { my ($host, $evnum, $msg) = @_; my $smtp = Net::SMTP->new(Host => 'smtp', Timeout => 30, Debug => 0); #Set to 0 in production ver +sion $smtp->mail('Windows System Event'); $smtp->to('admin'); $smtp->data(); $smtp->datasend("To: System Support\n"); $smtp->datasend("Subject: Error event $evnum on $host\n"); $smtp->datasend("\n"); $smtp->datasend("$msg\n"); $smtp->dataend(); $smtp->quit; } #-----------------------------------------------------------------

In reply to Win/Snare syslog message parser by bofh_of_oz

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2022-09-26 07:02 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (117 votes). Check out past polls.