#!/usr/bin/perl use Win32::EventLog; use MIME::Lite::TT::HTML; use strict; my $Tabelle = ""; #---------------------------------------------------------------------------# sub GetEvents { my ($recs, $base, $off, $hashRef, $Event, $Status); my $handle=Win32::EventLog->new("Application", $ENV{ComputerName}); $handle->GetNumber($recs); $handle->GetOldest($base); $off = $recs - 1; while ($off >= 0) { $handle->Read(EVENTLOG_BACKWARDS_READ | EVENTLOG_SEEK_READ, $base + $off, $hashRef); if ($hashRef->{Source} eq "p2fService") { Win32::EventLog::GetMessageText($hashRef); my $Msg = $hashRef->{Message}; my $Event = $hashRef->{EventID} & 1073741823; if ($Event == 1018) { my @lines = split /\n/, $Msg; open (MAIL, ">Mail.txt"); foreach my $line (@lines) { if ($line =~ /^[A-Z]{3}/) { $Status = ""; if ($line =~ /ERR (.*)./) { $Status = 'Fehler'; } elsif ($line =~ /LIC (.*)./) { $Status = 'Lizenzfehler'; } elsif ($line =~ /PRT (.*)./) { $Status = 'Druckerfehler'; } elsif ($line =~ /SPC (.*)./) { $Status = 'Debug'; } elsif ($line =~ /INT (.*)./) { $Status = 'Eingriff erforderlich'; } elsif ($line =~ /JAM (.*)./) { $Status = 'Papierstau'; } elsif ($line =~ /PAP (.*)./) { $Status = 'Kein Papier'; } elsif ($line =~ /TON (.*)./) { $Status = 'Tonerstand niedrig'; } elsif ($line =~ /OFL (.*)./) { $Status = 'Nicht betriebsbereit'; } elsif ($line =~ /COV (.*)./) { $Status = 'Abdeckung offen'; } elsif ($line =~ /NET (.*)./) { $Status = 'Netzwerkfehler'; } elsif ($line =~ /FUL (.*)./) { $Status = 'Ausgabefach voll'; } if ($Status ne "") { $Tabelle .= '' . $Status . '' . $1 . "\n"; printf MAIL "%-21.21s %s\n", $Status, $1; } } } close (MAIL); return ($Tabelle eq "") ? 0 : 1; } } $off--; } return 0; } #---------------------------------------------------------------------------# chdir ("C:\\Users\\Public\\Documents\\SPE Systemhaus GmbH\\print2forms\\p2fScript"); if (GetEvents ()) { my %params = (Tabelle => $Tabelle); my %options = (die_on_bad_params => 0); my $msg = MIME::Lite::TT::HTML->new(From => 'p2f@spe-systemhaus.de', To => 'spe@spe-systemhaus.de', Subject => 'Statusänderung Client / Gateway-Service', Encoding => 'quoted-printable', Template => { html => "Mail.html", text => "Mail.txt" }, Charset => 'iso8859-1', TmplOptions => \%options, TmplParams => \%params); MIME::Lite->send('smtp', "10.1.1.9", Timeout=>60); $msg->send; } exit 0;