4 use Mail
::Sendmail
0.75; # doesn't work with v. 0.74!
6 $NOTIFICATIONTYPE=$ARGV[0];
10 $SERVICESTATE=$ARGV[4];
11 $SHORTDATETIME=$ARGV[5];
12 $SERVICEOUTPUT=$ARGV[6];
16 $boundary = "====" . time() . "====";
18 $text = "***** Notification Shinken *****\n\n"
19 . "Notification : $NOTIFICATIONTYPE\n\n"
20 . "Impacted service : $SERVICEDESC\n"
21 . "State : $SERVICESTATE\n\n"
22 . "Related host : $HOSTNAME\n"
23 . "Address : $HOSTADDRESS\n"
24 . "Date/Time : $SHORTDATETIME\n\n"
25 . "Service output : $SERVICEOUTPUT";
27 $texthtml = " <center><table border='11><th><strong>***** Shinken Notification *****</strong></th></table></center>\n";
32 if ($NOTIFICATIONTYPE =~ /RECOVERY/ | $NOTIFICATIONTYPE =~ ACKNOWLEDGEMENT
) {
34 if ($SERVICESTATE =~ /OK/){
35 $colorstate="#339933";
39 if ($NOTIFICATIONTYPE =~ /PROBLEM/) {
42 if ($SERVICESTATE =~ /CRITICAL/) {
43 $colorstate="#FF0000";
45 if ($SERVICESTATE =~ /WARNING/) {
46 $colorstate="#FF9900";
48 if ($SERVICESTATE =~ /UNKNOWN/) {
49 $colorstate="#999999";
53 $SERVICEOUTPUT =~ s/=/=/g;
55 if ($NOTIFICATIONTYPE =~ /RECOVERY/){
56 if ($SERVICESTATE =~ /OK/){
57 $colorstate="#339933";
61 $texthtml = $texthtml . "<strong>Notification : <span style='ccolor:$color>$NOTIFICATIONTYPE</span></strong>\n\n"
62 . "<strong>Impacted service : <i>$SERVICEDESC</i></strong>\n"
63 . "<strong>State : <span style='ccolor:$colorstate>$SERVICESTATE</span></strong>\n\n";
65 $texthtml = $texthtml . "<strong>Host</strong> : $HOSTNAME\n"
66 . "<strong>Address</strong> : <i>$HOSTADDRESS</i>\n"
67 . "<strong>Date/Time</strong> : <i>$SHORTDATETIME</i>\n\n"
68 . "<strong>Service output</strong> : $SERVICEOUTPUT\n\n\n\n";
71 from
=> 'Monitoring Agent <monitor-agent@invaliddomain.org>',
73 subject
=> "$SERVICEDESC $SERVICESTATE on $HOSTNAME",
74 'content-type' => "multipart/alternative; boundary=\"$boundary\"",
75 'Auto-Submitted' => "auto-generated"
78 $plain = encode_qp
$text;
80 #$html = encode_entities($texthtml);
82 $html =~ s/\n\n/\n\n<p>/g;
83 $html =~ s/\n/<br>\n/g;
84 $html = "<p>" . $html . "</p>";
86 $boundary = '--'.$boundary;
89 $mail{body
} = <<END_OF_BODY;
91 Content-Type: text/plain; charset="utf-8"
92 Content-Transfer-Encoding: quoted-printable
97 Content-Type: text/html; charset="utf-8"
98 Content-Transfer-Encoding: quoted-printable
104 sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";