Add : (Denis GERMAIN) check_shinken plugin and interface in the arbiter to get data.
[shinken.git] / libexec / sendmailservices.pl
blobab5464cfc4147321c7473375e7bbfa3c98026860
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 $SERVICEDESC=$ARGV[1];
8 $HOSTNAME=$ARGV[2];
9 $HOSTADDRESS=$ARGV[3];
10 $SERVICESTATE=$ARGV[4];
11 $SHORTDATETIME=$ARGV[5];
12 $SERVICEOUTPUT=$ARGV[6];
13 $TO=$ARGV[7];
14 #$HOSTNAME=$ARGV[8];
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";
29 $color="blue";
30 $colorstate="black";
32 if ($NOTIFICATIONTYPE =~ /RECOVERY/ | $NOTIFICATIONTYPE =~ ACKNOWLEDGEMENT) {
33 $color="#339933";
34 if ($SERVICESTATE =~ /OK/){
35 $colorstate="#339933";
39 if ($NOTIFICATIONTYPE =~ /PROBLEM/) {
40 $color="#FF0000";
42 if ($SERVICESTATE =~ /CRITICAL/) {
43 $colorstate="#FF0000";
45 if ($SERVICESTATE =~ /WARNING/) {
46 $colorstate="#FF9900";
48 if ($SERVICESTATE =~ /UNKNOWN/) {
49 $colorstate="#999999";
53 $SERVICEOUTPUT =~ s/=/&#61;/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";
70 %mail = (
71 from => 'Monitoring Agent <monitor-agent@invaliddomain.org>',
72 to => $TO,
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);
81 $html = $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;
90 $boundary
91 Content-Type: text/plain; charset="utf-8"
92 Content-Transfer-Encoding: quoted-printable
94 $plain
96 $boundary
97 Content-Type: text/html; charset="utf-8"
98 Content-Transfer-Encoding: quoted-printable
100 <html>$html</html>
101 $boundary--
102 END_OF_BODY
104 sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";