use Time::localtime; #use Net::SMTP; use Win32::EventLog; #$serveur_mail="mail_server"; #$destinataire="name\@adress"; $server=shift; # server_name $typeERR=shift; # Securité, Application, Système $chaine=shift; # "McLog"; if ($chaine eq "") { die "Usage : $0 \\server {Application,Security,System} \"string to search for\" "; } # $ENV{ComputerName} $handle=Win32::EventLog->new($typeERR, $server) or die "Can't open $typeERR EventLog on $server \n"; $handle->GetNumber($recs) or die "Can't get number of EventLog records\n"; $handle->GetOldest($base) or die "Can't get number of oldest EventLog record\n"; ($nowsec,$nowmin,$nowhour,$nowmday,$nowmon,$nowyear,$nowwday,$nowyday,$nowisdst) = localtime(time()); $x =0; while ($x < $recs ) { $handle->Read(EVENTLOG_FORWARDS_READ|EVENTLOG_SEEK_READ, $base+$x, $hashRef) or die "Can't read EventLog entry #$x\n"; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($hashRef->{'TimeGenerated'}); # if ( $nowyear == $year && $nowmday == $mday && $nowmon == $mon ) # { # if ($hashRef->{Source} eq "Networker") { Win32::EventLog::GetMessageText($hashRef); $myresult=$hashRef->{'Strings'}; print "$x = $hashRef->{Source}\n--->\n$hashRef->{Data}\n---\n$myresult\n<---\n" if $hashRef->{Data}=~/$chaine/ || $hashRef->{Strings}=~/$chaine/ || $hashRef->{Source}=~/$chaine/; # } # } $x++; } #$smtp = Net::SMTP->new($serveur_mail); #$smtp->mail($ENV{USER}); #$smtp->to($destinataire); #$smtp->data(); #$smtp->datasend("From: $destinataire\n"); #$smtp->datasend("To: $destinataire\n"); #$smtp->datasend("Subject: text subject.\n"); #$smtp->datasend("\n $myresult\n"); #$smtp->dataend(); #$smtp->quit;