my $maxlen_msg = $maxlen * 4;
my $maxenv = 1;
-my ( $attr, $env, $input, $text, $body, $content, $r, $file, $lockfile, $i, $mail, $part );
+my ( $attr, $env, $input, $text, $body, $content, $r, $file, $lockfile, $i, $mail, $part, $html_body );
my (@Rcpts);
# Ausgabe des Environments vorbereiten
exit 0 unless $input;
$body = undef;
+$html_body = undef;
-# Mail zerpflücken und den plain-text-Teil heraussuchen
+# Mail zerpflücken und den plain-text-Teil sowie HTML-Teil heraussuchen
$mail = Email::Simple->new($input);
if ( $mail->header("content-type") =~ m#multipart/alternative#i ) {
foreach $part ( @{ $mail->{'parts'} } ) {
if ( $part->header("content-type") =~ m#text/plain#i ) {
$body = $part->body();
- last;
+ }
+ elsif ( $part->header("content-type") =~ m#text/html#i ) {
+ $html_body = $part->body();
}
}
- # Es gab keinen plain-text-Teil, dann den gesamten Mailtext nehmen
- $body = $mail->body_raw() unless $body;
+ # Es gab keinen plain-text-Teil, dann den HTML-Teil oder den gesamten Mailtext nehmen
+ unless ( $body ) {
+ $body = $html_body ? $html_body : $mail->body_raw();
+ }
} ## end if ( $mail->header("content-type"...
else {
$body = $mail->body();
}
+$body =~ s/^\s+//s;
+$body =~ s/\s+$//s;
+print "Meldungs-Text:\n----------------\n$body\n-------------\n" if $verbose > 1;
+
+if ( $html_body ) {
+ $html_body =~ s/^[\s\n\r]+//s;
+ $html_body =~ s/[\s\n\r]+$//s;
+ print "HTML-Text:\n----------------\n$html_body\n-------------\n" if $verbose > 1;
+}
+
##############################
# SMS-Text zusammemsetzen
Messages mit Fehlern
&red Fehler: [2006 Nov 12 01:33:50 CET +0100] na2702 [daemon.err] [na2702: asup.smtp.unreach:error]: Autosupport mail was not sent because the system cannot reach any of the mail hosts from the autosupport.mailhost option. (WEEKLY_LOG)
+
+smc.msgs down (red) 12:44: Meldungen mit Fehlern.|>|>
+<h2>Meldungen mit Fehlern.</h2>
+
+<pre>
+<img align="middle" src="skins/Strato/red.gif" alt="red" title="red" border=0> 2007-01-22 12:42:59 kern.err rmclomv rmclomv: [ID 544949 kern.error] DISK @ HDD0 has been removed.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:23 user.info bsagent bsagent[master 235]: Test mit PID 11409 (Test ssh, Node 'Nexus', Item 'ssh') unsachgemaess verstorben.
+
=cut
-if ( $text =~ /^(\w+.msgs\s+down\s+\(\w+\)\s+\d+:\d+(?::\d+)?:\s+[\s\w]+)\|.*[\n\r]+\&\w+\s+Fehler:\s+(.*)/is ) {
+if ( $text =~ /^(\w+\.msgs\s+down\s+\(\w+\)\s+\d+:\d+(?::\d+)?:\s+[\s\w\.]+)\|/ ) {
+
+ my $anfang = $1;
+
+ warn "msgs-Meldung gefunden.\n" if $verbose;
+
+ if ( $text =~ /[\n\r]\&\w+\s+Fehler:\s+(.*)/is ) {
+
+ warn "msgs-Meldung Variante 1 gefunden.\n" if $verbose;
+
+ $text = $anfang . "\n" . $1;
+ $text =~ s/\&(red|yellow|green)/$1/isg;
+
+ }
+ elsif ( $html_body and $html_body =~ m#<h2>Meldungen\s+mit\s+Fehlern\.</h2>\s+<pre>(.*)</pre>#is ) {
+
+ warn "msgs-Meldung Variante 2 gefunden.\n" if $verbose;
+
+ my $msgs = $1;
+
+ $msgs =~ s/^[\s\n\r]+//s;
+ $msgs =~ s/[\s\n\r]+$//s;
+ $msgs =~ s#<img\s[^>]+/(red|yellow|green)[^>]+>#$1#isg;
+ $msgs =~ s#[\r\s]+green\s+.*##is;
+
+ $text = $anfang . "\n" . $msgs;
- $text = $1 . "\n" . $2;
+ }
# Text trimmen und auf Länge stutzen
$text = substr( $text, 0, $maxlen_msg );
}
+print "Meldung:\n---------\n$text\n" if $verbose;
+exit 0;
+
# Bestätigungs-Mail rausjagen, falls nicht untersagt ..
unless ($nomail) {
__END__
+=head2 Moegliche Fehler-Mails zu C<msgs>:
+
+=over 4
+
+=item Variante 1 (alt):
+
+Received: from TECTEX02.berlin.strato.de ([172.30.3.55]) by STRATOEX01.berlin.strato.de with Microsoft SMTPSVC(6.0.3790.1830);
+ Tue, 2 Jan 2007 11:47:24 +0100
+Received: from SPAMFILTER.berlin.strato.de ([172.30.3.61]) by TECTEX02.berlin.strato.de with Microsoft SMTPSVC(6.0.3790.1830);
+ Tue, 2 Jan 2007 11:47:24 +0100
+Received: from mx.berlin.strato.de ([172.31.8.8]) by SPAMFILTER.berlin.strato.de with Microsoft SMTPSVC(6.0.3790.1830);
+ Tue, 2 Jan 2007 11:47:23 +0100
+Received: from smc.technik.berlin.strato.de (StratoGateway [192.166.201.59])
+ by mx2.berlin.strato.de (Postfix) with ESMTP id 6F32E176E7
+ for <brehm@strato.de>; Tue, 2 Jan 2007 11:47:23 +0100 (CET)
+Received: by smc.technik.berlin.strato.de (Postfix)
+ id 608853569; Tue, 2 Jan 2007 11:47:19 +0100 (CET)
+Delivered-To: brehm@smc.technik.berlin.strato.de
+Received: by smc.technik.berlin.strato.de (Postfix, from userid 1984)
+ id 54028371A; Tue, 2 Jan 2007 11:47:19 +0100 (CET)
+Subject: Imperia.msgs down (red) 11:43: Messages mit Fehlern|>&red Fehler: [2007 Jan 2 11:40:38 CET
+To: <alarm@smc.technik.berlin.strato.de>
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="----=_NextPart_"
+Message-Id: <20070102104719.54028371A@smc.technik.berlin.strato.de>
+Date: Tue, 2 Jan 2007 11:47:19 +0100 (CET)
+From: bs@smc.technik.berlin.strato.de (BigSister user)
+Return-Path: bs@smc.technik.berlin.strato.de
+X-OriginalArrivalTime: 02 Jan 2007 10:47:23.0908 (UTC) FILETIME=[62DFBC40:01C72E5B]
+
+This is a multi-part message in MIME format. If you see
+this message your mailer probably does not support this
+message format. Please contact your Big Sister administrator
+then.
+
+------=_NextPart_
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Transfer-Encoding: 8bit
+
+Status Imperia.msgs -> down (red) um Tue Jan 2 11:43:11 2007.
+Messages mit Fehlern
+&red Fehler: [2007 Jan 2 11:40:38 CET +0100] imperia [auth.crit] su: [ID 810491 auth.crit] \'su root\' failed for rene on /dev/pts/1
+
+------=_NextPart_
+Content-Type: text/html; charset="iso-8859-1"
+Content-Transfer-Encoding: 8bit
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title>Big Sister Statusbenachrichtigung für Imperia.msgs</title>
+</head>
+<body bgcolor="#ffffff">
+Der Status von<br /><br />
+
+<table border="0" cellspacing="2" cellpadding="3">
+ <tbody>
+ <tr>
+ <td>
+ </td>
+ <td bgcolor="#d8d8ff">
+ <strong>Host</strong></td>
+ <td bgcolor="#d8d8d8">
+ Imperia (Imperia)</td>
+ </tr><tr>
+ <td></td>
+ <td bgcolor="#d8d8d8">
+ <strong>Gegenstand</strong></td>
+ <td bgcolor="#d8d8ff">
+ msgs</td>
+ </tr>
+ </tbody>
+
+</table>
+<br /><br />
+
+hat sich um Tue Jan 2 11:43:11 2007 auf down (Status red) geändert.<br /><br />
+
+Der Statustext lautet:<br /><br />
+
+<table border="0" cellspacing="6" cellpadding="6">
+ <tbody>
+ <tr>
+ <td bgcolor="#ffffd8">
+<pre>Messages mit Fehlern<BR><img align="middle" src="skins/Strato/red.gif" alt="red" title="red" border=0> Fehler: [2007 Jan 2 11:40:38 CET +0100] imperia [auth.crit] su: [ID 810491 auth.crit] \'su root\' failed for rene on /dev/pts/1</pre></td>
+ </tr>
+ </tbody>
+
+</table>
+
+</body>
+</html>
+
+=item Variante 2 (neu):
+
+Received: from TECTEX02.berlin.strato.de ([172.30.3.54]) by STRATOEX01.berlin.strato.de with Microsoft SMTPSVC(6.0.3790.1830);
+ Mon, 22 Jan 2007 12:49:25 +0100
+Received: from SPAMFILTER.berlin.strato.de ([172.30.3.61]) by TECTEX02.berlin.strato.de with Microsoft SMTPSVC(6.0.3790.1830);
+ Mon, 22 Jan 2007 12:49:25 +0100
+Received: from mx.berlin.strato.de ([172.31.8.5]) by SPAMFILTER.berlin.strato.de with Microsoft SMTPSVC(6.0.3790.1830);
+ Mon, 22 Jan 2007 12:49:25 +0100
+Received: from smc.technik.berlin.strato.de (StratoGateway [192.166.201.59])
+ by mx1.berlin.strato.de (Postfix) with ESMTP id DEE0B1B9C9
+ for <brehm@strato.de>; Mon, 22 Jan 2007 12:49:10 +0100 (CET)
+Received: by smc.technik.berlin.strato.de (Postfix)
+ id B14ED3BBD; Mon, 22 Jan 2007 12:49:11 +0100 (CET)
+Delivered-To: brehm@smc.technik.berlin.strato.de
+Received: by smc.technik.berlin.strato.de (Postfix, from userid 1984)
+ id 8C92A3C69; Mon, 22 Jan 2007 12:49:11 +0100 (CET)
+Subject: smc.msgs down (red) 12:44: Meldungen mit Fehlern.|>|>
+To: <alarm@smc.technik.berlin.strato.de>
+MIME-Version: 1.0
+Content-Type: multipart/alternative;
+ boundary="----=_NextPart_"
+Message-Id: <20070122114911.8C92A3C69@smc.technik.berlin.strato.de>
+Date: Mon, 22 Jan 2007 12:49:11 +0100 (CET)
+From: bs@smc.technik.berlin.strato.de (BigSister user)
+Return-Path: bs@smc.technik.berlin.strato.de
+X-OriginalArrivalTime: 22 Jan 2007 11:49:25.0439 (UTC) FILETIME=[5D574CF0:01C73E1B]
+
+This is a multi-part message in MIME format. If you see
+this message your mailer probably does not support this
+message format. Please contact your Big Sister administrator
+then.
+
+------=_NextPart_
+Content-Type: text/plain; charset="iso-8859-1"
+Content-Transfer-Encoding: 8bit
+
+Status smc.msgs -> down (red) um Mon Jan 22 12:44:39 2007.
+Meldungen mit Fehlern.
+
+
+
+------=_NextPart_
+Content-Type: text/html; charset="iso-8859-1"
+Content-Transfer-Encoding: 8bit
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<html><head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title>Big Sister Statusbenachrichtigung für smc.msgs</title>
+</head>
+<body bgcolor="#ffffff">
+Der Status von<br /><br />
+
+<table border="0" cellspacing="2" cellpadding="3">
+ <tbody>
+ <tr>
+ <td>
+ </td>
+ <td bgcolor="#d8d8ff">
+ <strong>Host</strong></td>
+ <td bgcolor="#d8d8d8">
+ smc (smc)</td>
+ </tr><tr>
+ <td></td>
+ <td bgcolor="#d8d8d8">
+ <strong>Gegenstand</strong></td>
+ <td bgcolor="#d8d8ff">
+ msgs</td>
+ </tr>
+ </tbody>
+
+</table>
+<br /><br />
+
+hat sich um Mon Jan 22 12:44:39 2007 auf down (Status red) geändert.<br /><br />
+
+Der Statustext lautet:<br /><br />
+
+<table border="0" cellspacing="6" cellpadding="6">
+ <tbody>
+ <tr>
+ <td bgcolor="#ffffd8">
+<pre>Meldungen mit Fehlern.<BR></pre><h2>Meldungen mit Fehlern.</h2>
+
+<pre>
+<img align="middle" src="skins/Strato/red.gif" alt="red" title="red" border=0> 2007-01-22 12:42:59 kern.err rmclomv rmclomv: [ID 544949 kern.error] DISK @ HDD0 has been removed.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:23 user.info bsagent bsagent[master 235]: Test mit PID 11409 (Test ssh, Node 'Nexus', Item 'ssh') unsachgemaess verstorben.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:17 user.info bsagent bsagent[master 235]: Test mit PID 11386 (Test SNMP-Test, Node 'Na2701', Item 'snmp') unsachgemaess verstorben.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:16 user.info bsagent bsagent[disk-win-67 11375]: SNMP-Typ 'hrStorageVirtualMemory' fuer 'Virtual' ist nicht 'hrStorageFixedDisk'.
+
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:16 user.info bsagent bsagent[disk-win-67 11375]: SNMP-Typ 'hrStorageCompactDisc' fuer 'D:\' ist nicht 'hrStorageFixedDisk'.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:16 user.info bsagent bsagent[disk-win-67 11375]: SNMP-Typ 'hrStorageRemovableDisk' fuer 'A:\' ist nicht 'hrStorageFixedDisk'.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:15 user.info bsagent bsagent[disk-win-11 11273]: SNMP-Typ 'hrStorageVirtualMemory' fuer 'Virtual' ist nicht 'hrStorageFixedDisk'.
+
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:14 user.info bsagent bsagent[disk-win-11 11273]: SNMP-Typ 'hrStorageCompactDisc' fuer 'G:\' ist nicht 'hrStorageFixedDisk'.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:09 auth.info sshd sshd[11329]: [ID 800047 auth.info] Did not receive identification string from 127.0.0.1
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:06 user.info bsagent bsagent[disk-win-11 11273]: SNMP-Typ 'hrStorageRemovableDisk' fuer 'A:\' ist nicht 'hrStorageFixedDisk'.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:03 user.info bsagent bsagent[master 73]: Test mit PID 11281 (Test ping, Node 'Zero', Item 'conn') unsachgemaess verstorben.
+
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:43:02 user.info bsagent bsagent[master 235]: Test mit PID 11268 (Test SNMP-Test, Node 'Gordon', Item 'snmp') unsachgemaess verstorben.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:14 user.info bsagent bsagent[master 235]: Test mit PID 11031 (Test ssh, Node 'Slim', Item 'ssh') unsachgemaess verstorben.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:14 user.info bsagent bsagent[master 235]: Test mit PID 11026 (Test smtp, Node 'Mx1', Item 'smtp') unsachgemaess verstorben.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:14 user.info bsagent bsagent[master 235]: Test mit PID 11030 (Test SNMP-Test, Node 'Slim', Item 'snmp') unsachgemaess verstorben.
+
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:09 user.info bsagent bsagent[disk-win-67 11002]: SNMP-Typ 'hrStorageVirtualMemory' fuer 'Virtual' ist nicht 'hrStorageFixedDisk'.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:09 user.info bsagent bsagent[disk-win-67 11002]: SNMP-Typ 'hrStorageCompactDisc' fuer 'D:\' ist nicht 'hrStorageFixedDisk'.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:09 user.info bsagent bsagent[disk-win-67 11002]: SNMP-Typ 'hrStorageRemovableDisk' fuer 'A:\' ist nicht 'hrStorageFixedDisk'.
+
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:09 user.info bsagent bsagent[disk-win-11 10895]: SNMP-Typ 'hrStorageVirtualMemory' fuer 'Virtual' ist nicht 'hrStorageFixedDisk'.
+<img align="middle" src="skins/Strato/green.gif" alt="green" title="green" border=0> 2007-01-22 12:40:08 user.info bsagent bsagent[disk-win-11 10895]: SNMP-Typ 'hrStorageCompactDisc' fuer 'G:\' ist nicht 'hrStorageFixedDisk'.
+Weitere 73 Meldungen ...
+</pre><pre>
+<b>Scriptinfo:</b> bsagent@smc.technik.berlin.strato.de:/var/opt/bsagent/agent/bin/bsagent.pl <i>[Test msgs-mysql, Node 'Smc', Item 'msgs']</i>
+
+<!-- Ermittlungszeit: 1.117176 Sekunden -->
+<!-- Modulversion: 1.2.1843 --></pre></td>
+ </tr>
+ </tbody>
+</table>
+
+</body>
+</html>
+
+=back
+
+=cut