new-klecker is on buster
[mirror/dsa-nagios.git] / config / static / bin / notify-irc
1 #!/usr/bin/perl -wT
2
3 # Copyright (c) 2005, 2006, 2007, 2008 Peter Palfrader <peter@palfrader.org>
4 # Copyright (c) 2013 Tollef Fog Heen
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
13 #
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25
26 use strict;
27 use English;
28 use File::Basename;
29
30 my $ENVELOPE_FROM = 'nagios@debian.org';
31 my $HEADER_FROM = 'nagios@debian.org';
32 my $SENDMAIL = '/usr/sbin/sendmail';
33
34
35 $ENV{'PATH'} = '/bin:/usr/bin';
36 delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
37
38 die ("Usage: $PROGRAM_NAME <project> <contact_email> <type> <host> <service> <state> <output>\n") unless (scalar @ARGV == 7);
39 umask 077;
40
41 my ($project, $bot_address, $type, $host, $service, $state, $info) = @ARGV;
42 my $hosttype;
43
44 $type =~ tr/A-Z/a-z/;
45 $service = $host unless (defined $service and $service =~ /\S/);
46
47 if ($state =~ m/CRITICAL|DOWN|UNREACHABLE/ ) {
48     $hosttype = "\ 35$host\ f";
49 } elsif ($state =~ m/WARNING/) {
50     $hosttype = "\ 37$host\ f";
51 } elsif ($state =~ m/OK|UP/ ) {
52     $hosttype = "\ 33$host\ f";
53 } elsif ($state =~ m/UNKNOWN/) {
54     $hosttype = "\ 310$host\ f";
55 } else {
56     $hosttype = "$type\@$host";
57 }
58
59 open(MAIL, "|$SENDMAIL -t -oi -f $ENVELOPE_FROM") or
60         die ("Cannot exec sendmail: $!\n");
61 print MAIL "From: $HEADER_FROM\n";
62 print MAIL "To: $bot_address\n";
63 print MAIL "Subject: Announce $project\n";
64 print MAIL "Precedence: junk\n";
65 print MAIL "\n";
66 print MAIL "[$hosttype] $service is $state: $info\n";
67 close(MAIL);