Fix : fix hot module under windows test. (at leat I hope...)
[shinken.git] / libexec / sendmailhost.pl
blob51e85670dffd294685799495e0ec633b833b837a
1 #!/usr/bin/perl
2 use MIME::QuotedPrint;
3 use HTML::Entities;
4 use Mail::Sendmail 0.75; # doesn't work with v. 0.74!
6 $NOTIFICATIONTYPE=$ARGV[0];
7 $HOSTNAME=$ARGV[1];
8 $HOSTSTATE=$ARGV[2];
9 $HOSTADDRESS=$ARGV[3];
10 $HOSTOUTPUT=$ARGV[4];
11 $SHORTDATETIME=$ARGV[5];
12 $TO=$ARGV[6];
13 #$HOSTNAME=$ARGV[7];
14 #$DOWNTIME=$ARGV[8];
16 $boundary = "====" . time() . "====";
18 $text = "***** Notification Shinken *****\n\n"
19 . "Notification : $NOTIFICATIONTYPE\n\n"
20 . "Host : $HOSTNAME\n\n"
21 . "Address : $HOSTADDRESS\n"
22 . "State : $HOSTSTATE\n\n"
23 . "Date/Time : $SHORTDATETIME\n\n"
24 . "Host output : $HOSTOUTPUT";
26 $texthtml = " <center><table border='11><th><strong>***** Notification Shinken *****</strong></th></table></center>\n";
28 $color="blue";
29 if ($NOTIFICATIONTYPE =~ /RECOVERY/) {
30 $color="#339933";
32 if ($NOTIFICATIONTYPE =~ /PROBLEM/) {
33 $color="#FF0000";
36 $HOSTOUTPUT =~ s/=/&#61;/g;
38 $texthtml = $texthtml . "<strong>Notification type : <span style='ccolor:$color> $NOTIFICATIONTYPE </span></strong>\n\n";
40 if ($DOWNTIME != 0) {
41 $color="#3333FF";
42 $texthtml = $texthtml . "<strong><i><span style='ccolor:$color>This device is actually in maintenance.</span></i></strong>\n\n";
45 if ($HOSTSTATE =~ /DOWN/) {
46 $color="#FF0000";
48 if ($HOSTSTATE =~ /UP/) {
49 $color="#339933";
51 if ($HOSTSTATE =~ /UNREACHABLE/) {
52 $color="#00CCCC";
55 $texthtml = $texthtml . "<strong>Impacted host</strong> : $HOSTNAME\n"
56 . "<strong>Address</strong> : <i>$HOSTADDRESS</i> \n"
57 . "<strong>Host State : <span style='ccolor:$color> $HOSTSTATE </span></strong>\n"
58 . "<strong>Date/Time</strong> : <i>$SHORTDATETIME</i> \n\n"
59 . "<strong>Host Output</strong> : $HOSTOUTPUT \n\n\n\n";
62 %mail = (
63 from => 'Monitoring Agent <monitor-agent@invaliddomain.org>',
64 to => $TO,
65 subject => "$HOSTNAME is $HOSTSTATE !",
66 'content-type' => "multipart/alternative; boundary=\"$boundary\"",
67 'Auto-Submitted' => "auto-generated"
70 $plain = encode_qp $text;
72 #$html = encode_entities($texthtml);
73 $html = $texthtml;
74 $html =~ s/\n\n/\n\n<p>/g;
75 $html =~ s/\n/<br>\n/g;
76 $html = "<p>" . $html . "</p>";
78 $boundary = '--'.$boundary;
80 $mail{body} = <<END_OF_BODY;
81 $boundary
82 Content-Type: text/plain; charset="utf-8"
83 Content-Transfer-Encoding: quoted-printable
85 $plain
87 $boundary
88 Content-Type: text/html; charset="utf-8"
89 Content-Transfer-Encoding: quoted-printable
91 <html>$html</html>
92 $boundary--
93 END_OF_BODY
95 sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";