From 47b1a1504ca030df84f09b6daf8c8766ee81010e Mon Sep 17 00:00:00 2001 From: Kevin Lamontagne Date: Wed, 11 Jan 2012 15:20:48 -0500 Subject: [PATCH 1/2] Separate IMAP config --- .gitignore | 1 + localconfig.py.example | 12 ++++++++++++ nagios_email_handler.py | 9 +-------- 3 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 localconfig.py.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a77143 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +localconfig.py diff --git a/localconfig.py.example b/localconfig.py.example new file mode 100644 index 0000000..2fbe513 --- /dev/null +++ b/localconfig.py.example @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +# CMD file for Nagios +#CMD_FILE = '/usr/nagios/var/rw/nagios.cmd' +# for Icinga +#CMD_FILE = '/var/lib/icinga/rw/icinga.cmd' + +# IMAP server, username and password +IMAP_SERVER = 'imap.example.com' +IMAP_USER = 'username@example.com' +IMAP_PASS = 'your_password' + diff --git a/nagios_email_handler.py b/nagios_email_handler.py index 3862f23..30c2659 100755 --- a/nagios_email_handler.py +++ b/nagios_email_handler.py @@ -15,6 +15,7 @@ import re import sys import time +from localconfig import * __author__ = "Avleen Vig" @@ -32,14 +33,6 @@ # Global logging handler. LOGGER = None -# CMD file for Nagios -CMD_FILE = '/usr/nagios/var/rw/nagios.cmd' - -# IMAP server, username and password -IMAP_SERVER = 'imap.example.com' -IMAP_USER = 'username@example.com' -IMAP_PASS = 'your_password' - def do_sanity_checks(): """Do some sanity checks before anything else to make sure we're not going From e3f888b55ed28d92dfb5fbf102c0d165737460d6 Mon Sep 17 00:00:00 2001 From: Kevin Lamontagne Date: Sun, 15 Jan 2012 00:09:42 -0500 Subject: [PATCH 2/2] Handling mutiline "Subject:" header --- nagios_email_handler.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nagios_email_handler.py b/nagios_email_handler.py index 30c2659..a6167f2 100755 --- a/nagios_email_handler.py +++ b/nagios_email_handler.py @@ -95,9 +95,10 @@ def get_email_data(msg): else: from_p = re.compile('([\w\d._%+-]+@[\w\d.-]+\.[\w]{2,4})', re.IGNORECASE) - if subject_p.search(msg['Subject']): - alert_class = subject_p.search(msg['Subject']).group(1) - server_service = subject_p.search(msg['Subject']).group(2) + subjsearch = subject_p.search(msg['Subject'].replace('\r\n','')) + if not (subjsearch is None): + alert_class = subjsearch.group(1) + server_service = subjsearch.group(2) if alert_class.lower() == 'service': service = server_service.split('/')[1] server = server_service.split('/')[0]