[omd-commits] OMD Git: omd: added tt notification script

git version control git at mathias-kettner.de
Sat Dec 3 20:06:47 CET 2011


Module:   omd
Branch:   master
Commit:   13cfb5f8af098cf3b64645cdcb61f2d14c834ea9
URL:      http://omdistro.org/projects/omd/repository/revisions/13cfb5f8af098cf3b64645cdcb61f2d14c834ea9

Author:   Sven Nierlein <sven at nierlein.de>
Date:     Sat Dec  3 15:46:29 2011 +0100
Commiter: Sven Nierlein <sven at nierlein.de>
Date:     Sat Dec  3 20:06:15 2011 +0100

added tt notification script

---

 Makefile                                           |    3 +-
 .../nagios/skel/etc/nagios/conf.d/templates.cfg    |    4 +-
 packages/notifications-tt/Makefile                 |   16 +++++
 packages/notifications-tt/notify-by-email.pl       |   65 ++++++++++++++++++++
 .../etc/mail-templates/notify-by-email.host.tpl    |   24 +++++++
 .../etc/mail-templates/notify-by-email.service.tpl |   26 ++++++++
 .../etc/nagios/conf.d/notification_commands.cfg    |   40 ++++++++++++
 7 files changed, 175 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index bf1bdc0..458fe2d 100644
--- a/Makefile
+++ b/Makefile
@@ -30,7 +30,8 @@ PACKAGES=perl-modules \
          gearmand \
          mod-gearman \
          patch \
-         nail
+         nail \
+         notifications-tt
 
 include Makefile.omd
 
diff --git a/packages/nagios/skel/etc/nagios/conf.d/templates.cfg b/packages/nagios/skel/etc/nagios/conf.d/templates.cfg
index 677c379..98008fe 100644
--- a/packages/nagios/skel/etc/nagios/conf.d/templates.cfg
+++ b/packages/nagios/skel/etc/nagios/conf.d/templates.cfg
@@ -5,8 +5,8 @@ define contact{
   host_notification_period        24x7                    ; host notifications can be sent anytime
   service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
   host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
-  service_notification_commands   notify-service-by-email ; send service notifications via email
-  host_notification_commands      notify-host-by-email    ; send host notifications via email
+  service_notification_commands   service-notify-by-email ; send service notifications via email
+  host_notification_commands      host-notify-by-email    ; send host notifications via email
   register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
 }
 
diff --git a/packages/notifications-tt/Makefile b/packages/notifications-tt/Makefile
new file mode 100644
index 0000000..f7692ef
--- /dev/null
+++ b/packages/notifications-tt/Makefile
@@ -0,0 +1,16 @@
+include ../../Makefile.omd
+
+NAME     = notifications-tt
+VERSION  = 1
+
+.PHONY: skel
+
+build:
+
+install:
+	mkdir -p $(DESTDIR)$(OMD_ROOT)/lib/nagios/plugins
+	install -m 755 notify-by-email.pl $(DESTDIR)$(OMD_ROOT)/lib/nagios/plugins/notify-by-email.pl
+
+skel:
+
+clean:
diff --git a/packages/notifications-tt/notify-by-email.pl b/packages/notifications-tt/notify-by-email.pl
new file mode 100755
index 0000000..ea5d770
--- /dev/null
+++ b/packages/notifications-tt/notify-by-email.pl
@@ -0,0 +1,65 @@
+#!/usr/bin/perl
+#
+# Notification Script used by OMD
+# Joerg Linge 2011
+#
+#
+use strict;
+use warnings;
+use Getopt::Long;
+use Template;
+
+my %macro;
+my $template = '';
+my $data     = '';
+my $output   = '';
+my $mail     = $ENV{'OMD_ROOT'}.'/bin/mail -t';
+my $verbose  = 0;
+
+GetOptions (
+	'option|o=s'   => \%macro,
+	'type=s'       => \%macro,
+	'template=s'   => \$template,
+	'mail=s'       => \$mail,
+	'verbose'      => \$verbose,
+	);
+
+if ( $template eq '' ){
+	print "Template not given\n";
+	usage();
+	exit 3;
+}
+if ( ! -e $template ){
+	print "Template \"$template\" not found\n";
+	exit 3;
+}
+process_template();
+exit;
+
+sub process_template {
+	open FILE, $template or die "Couldn't open file: $!";
+	while (<FILE>) {
+		#chomp;
+		next if ( /^#/ );
+		$data .= "$_";
+	}
+	close FILE;
+	my $template = Template->new({PRE_CHOMP => 1, POST_CHOMP => 0});
+	$template->process(\$data, \%macro, \$output);
+	print $output if $verbose;
+	send_mail();
+}
+
+sub send_mail {
+	open (MAIL,"|$mail $macro{'CONTACTEMAIL'}") || die("Couldn't open $mail: $!");
+	print MAIL $output;
+	close MAIL;
+}
+
+sub usage {
+	print "
+Usage:
+$0 --template=<path to template> -o <MACRO>=<VALUE> -o ....
+
+";
+}
diff --git a/packages/notifications-tt/skel/etc/mail-templates/notify-by-email.host.tpl b/packages/notifications-tt/skel/etc/mail-templates/notify-by-email.host.tpl
new file mode 100644
index 0000000..f520577
--- /dev/null
+++ b/packages/notifications-tt/skel/etc/mail-templates/notify-by-email.host.tpl
@@ -0,0 +1,24 @@
+#
+# Mail Template used for Host Notifications
+#
+#
+# Mail starts here --->
+SUBJECT: *** [% NOTIFICATIONTYPE %] *** [% HOSTNAME %] is [% HOSTSTATE %]
+TO: [% CONTACTEMAIL %]
+#FROM: omd at domain.com
+#REPLY-TO: support at domain.com
+
+--HOST-ALERT----------------------
+- Hostname:    [% HOSTNAME %]
+- Hostaddress: [% HOSTADDRESS %]
+- - - - - - - - - - - - - - - - -
+- State:       [% HOSTSTATE %]
+- Date:        [% SHORTDATETIME %]
+- Output:      [% HOSTOUTPUT %]
+-              [% LONGHOSTOUTPUT %]
+[% IF NOTIFICATIONTYPE == 'ACKNOWLEDGEMENT' %]
+----------------------------------
+- Author:      [% ACKAUTHOR %]
+- Comment:     [% ACKCOMMENT %]
+[% END %]
+----------------------------------
diff --git a/packages/notifications-tt/skel/etc/mail-templates/notify-by-email.service.tpl b/packages/notifications-tt/skel/etc/mail-templates/notify-by-email.service.tpl
new file mode 100644
index 0000000..b1c6665
--- /dev/null
+++ b/packages/notifications-tt/skel/etc/mail-templates/notify-by-email.service.tpl
@@ -0,0 +1,26 @@
+#
+# Mail Template used for Service Notifications
+#
+#
+# Mail starts here --->
+SUBJECT: *** [% NOTIFICATIONTYPE %] *** [% HOSTNAME %] / [% SERVICEDESC %] is [% SERVICESTATE %]
+TO: [% CONTACTEMAIL %]
+#FROM: omd at domain.com
+#REPLY-TO: support at domain.com
+
+--SERVICE-ALERT-------------------
+-
+- Hostaddress: [% HOSTADDRESS %]
+- Hostname:    [% HOSTNAME %]
+- Service:     [% SERVICEDESC %]
+- - - - - - - - - - - - - - - - -
+- State:       [% SERVICESTATE %]
+- Date:        [% SHORTDATETIME %]
+- Output:      [% SERVICEOUTPUT %]
+-              [% LONGSERVICEOUTPUT %]
+[% IF NOTIFICATIONTYPE == 'ACKNOWLEDGEMENT' %]
+----------------------------------
+- Author:      [% ACKAUTHOR %]
+- Comment:     [% ACKCOMMENT %]
+[% END %]
+----------------------------------
diff --git a/packages/notifications-tt/skel/etc/nagios/conf.d/notification_commands.cfg b/packages/notifications-tt/skel/etc/nagios/conf.d/notification_commands.cfg
new file mode 100644
index 0000000..521e49e
--- /dev/null
+++ b/packages/notifications-tt/skel/etc/nagios/conf.d/notification_commands.cfg
@@ -0,0 +1,40 @@
+#
+# Generic Notification Commands
+#
+#
+define command {
+	command_name host-notify-by-email
+	command_line /usr/bin/perl $USER1$/notify-by-email.pl \
+		--template=$USER4$/etc/mail-templates/notify-by-email.host.tpl \
+		-o NOTIFICATIONTYPE='$NOTIFICATIONTYPE$' \
+		-o HOSTNAME='$HOSTNAME$' \
+		-o HOSTSTATE='$HOSTSTATE$' \
+		-o CONTACTEMAIL='$CONTACTEMAIL$' \
+		-o HOSTADDRESS='$HOSTADDRESS$' \
+		-o SHORTDATETIME='$SHORTDATETIME$' \
+		-o HOSTOUTPUT='$HOSTOUTPUT$' \
+		-o LONGHOSTOUTPUT='$LONGHOSTOUTPUT$' \
+		-o ACKAUTHOR='$HOSTACKAUTHOR$' \
+		-o ACKCOMMENT='$HOSTACKCOMMENT$' \
+		-o DURATION='$HOSTDURATION$'
+}
+
+define command {
+	command_name service-notify-by-email
+	command_line /usr/bin/perl $USER1$/notify-by-email.pl \
+		--template=$USER4$/etc/mail-templates/notify-by-email.service.tpl  \
+		-o NOTIFICATIONTYPE='$NOTIFICATIONTYPE$' \
+		-o HOSTNAME='$HOSTNAME$' \
+		-o HOSTSTATE='$HOSTSTATE$' \
+		-o CONTACTEMAIL='$CONTACTEMAIL$' \
+		-o HOSTADDRESS='$HOSTADDRESS$' \
+		-o SHORTDATETIME='$SHORTDATETIME$' \
+		-o SERVICEDESC='$SERVICEDESC$' \
+		-o SERVICESTATE='$SERVICESTATE$' \
+		-o SERVICEOUTPUT='$SERVICEOUTPUT$' \
+		-o LONGSERVICEOUTPUT='$LONGSERVICEOUTPUT$' \
+		-o ACKAUTHOR='$SERVICEACKAUTHOR$' \
+		-o ACKCOMMENT='$SERVICEACKCOMMENT$' \
+		-o DURATION='$SERVICEDURATION$'
+}
+



More information about the omd-commits mailing list