Move IRC notifications to their own contact
authorTollef Fog Heen <tfheen@err.no>
Mon, 9 Dec 2013 19:59:02 +0000 (20:59 +0100)
committerTollef Fog Heen <tfheen@err.no>
Mon, 9 Dec 2013 19:59:02 +0000 (20:59 +0100)
In addition, add a simpler script to feed the IRC bot so it doesn't
have to parse Nagios mails.

config/static/bin/notify-irc [new file with mode: 0755]
config/static/commands.cfg [new file with mode: 0644]
config/static/objects/contacts.cfg

diff --git a/config/static/bin/notify-irc b/config/static/bin/notify-irc
new file mode 100755 (executable)
index 0000000..ca3db61
--- /dev/null
@@ -0,0 +1,67 @@
+#!/usr/bin/perl -wT
+
+# Copyright (c) 2005, 2006, 2007, 2008 Peter Palfrader <peter@palfrader.org>
+# Copyright (c) 2013 Tollef Fog Heen
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+
+use strict;
+use English;
+use File::Basename;
+
+my $ENVELOPE_FROM = 'nagios@debian.org';
+my $HEADER_FROM = 'nagios@debian.org';
+my $SENDMAIL = '/usr/sbin/sendmail';
+
+
+$ENV{'PATH'} = '/bin:/usr/bin';
+delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
+
+die ("Usage: $PROGRAM_NAME <project> <contact_email> <type> <host> <service> <state> <output>\n") unless (scalar @ARGV == 7);
+umask 077;
+
+my ($project, $bot_address, $type, $host, $service, $state, $info) = @ARGV;
+my $hosttype;
+
+$type =~ tr/A-Z/a-z/;
+$service = $host unless (defined $service and $service =~ /\S/);
+
+if ($state =~ m/CRITICAL|DOWN|UNREACHABLE/ ) {
+    $hosttype = "\ 35$host\ f";
+} elsif ($state =~ m/WARNING/) {
+    $hosttype = "\ 37$host\ f";
+} elsif ($state =~ m/OK|UP/ ) {
+    $hosttype = "\ 33$host\ f";
+} elsif ($state =~ m/UNKNOWN/) {
+    $hosttype = "\ 310$host\ f";
+} else {
+    $hosttype = "$type\@$host";
+}
+
+open(MAIL, "|$SENDMAIL -t -oi -f $ENVELOPE_FROM") or
+       die ("Cannot exec sendmail: $!\n");
+print MAIL "From: $HEADER_FROM\n";
+print MAIL "To: $BOT_ADDRESS\n";
+print MAIL "Subject: Announce $project\n";
+print MAIL "Precedence: junk\n";
+print MAIL "\n";
+print MAIL "[$hosttype] $service is $state: $info\n";
+close(MAIL);
diff --git a/config/static/commands.cfg b/config/static/commands.cfg
new file mode 100644 (file)
index 0000000..48fac74
--- /dev/null
@@ -0,0 +1,65 @@
+###############################################################################
+# COMMANDS.CFG - SAMPLE COMMAND DEFINITIONS FOR ICINGA
+# NOTES: This config file provides you with some example command definitions
+#        that you can reference in host, service, and contact definitions.
+#       
+#        You don't need to keep commands in a separate file from your other
+#        object definitions.  This has been done just to make things easier to
+#        understand.
+###############################################################################
+
+
+################################################################################
+# SAMPLE NOTIFICATION COMMANDS
+# These are some example notification commands.  They may or may not work on
+# your system without modification.  As an example, some systems will require 
+# you to use "/usr/bin/mailx" instead of "/usr/bin/mail" in the commands below.
+################################################################################
+
+
+# 'notify-host-by-email' command definition
+define command{
+       command_name    notify-host-by-email
+       command_line    /usr/bin/printf "%b" "***** Icinga *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
+       }
+
+# 'notify-service-by-email' command definition
+define command{
+       command_name    notify-service-by-email
+       command_line    /usr/bin/printf "%b" "***** Icinga *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
+       }
+
+define command{
+       command_name    notify-irc-host
+       command_line    /etc/icinga/bin/notify-irc "$CONTACTADDRESS1$" "$CONTACTEMAIL$" "$NOTIFICATIONTYPE$" "$HOSTNAME$" "" "$HOSTSTATE$" "$HOSTOUTPUT$"
+       }
+
+define command{
+       command_name    notify-irc-service
+       command_line    /etc/icinga/bin/notify-irc "$CONTACTADDRESS1$" "$CONTACTEMAIL$" "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$SERVICEDESC$" "$SERVICESTATE$" "$SERVICEOUTPUT$"
+       }
+
+
+################################################################################
+# SAMPLE PERFORMANCE DATA COMMANDS
+# These are sample performance data commands that can be used to send performance
+# data output to two text files (one for hosts, another for services).  If you
+# plan on simply writing performance data out to a file, consider using the 
+# host_perfdata_file and service_perfdata_file options in the main config file.
+################################################################################
+
+
+# 'process-host-perfdata' command definition
+define command{
+       command_name    process-host-perfdata
+       command_line    /usr/bin/printf "%b" "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /var/cache/icinga/host-perfdata.out
+       }
+
+
+# 'process-service-perfdata' command definition
+define command{
+       command_name    process-service-perfdata
+       command_line    /usr/bin/printf "%b" "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$\n" >> /var/cache/icinga/service-perfdata.out
+       }
+
+
index a487af1..57c45df 100644 (file)
@@ -221,6 +221,18 @@ define contact{
        host_notification_commands      notify-host-by-email
        email                           buildd-nagios@commit.noreply.org
        }
+define contact{
+       contact_name                    dsa-nsa
+       alias                           IRC bot for DSA notifications
+       service_notification_period     24x7
+       host_notification_period        24x7
+       service_notification_options    w,u,c,r
+       host_notification_options       d,r
+       service_notification_commands   notify-irc-service
+       host_notification_commands      notify-irc-host
+       address1                        dsa
+       email                           debian-nagios@commit.noreply.org
+       }
 define contact{
        contact_name                    christoph
        alias                           Christoph Egger
@@ -248,7 +260,7 @@ define contact{
 define contactgroup{
         contactgroup_name       dsa
         alias                   Debian System Administrators
-        members                 weasel, zobel, sgran, paravoid, tfheen, lfilipoz
+        members                 weasel, zobel, sgran, paravoid, tfheen, lfilipoz, dsa-nsa
         }
 
 define contactgroup{