Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
localconfig.py
12 changes: 12 additions & 0 deletions localconfig.py.example
Original file line number Diff line number Diff line change
@@ -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'

16 changes: 5 additions & 11 deletions nagios_email_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import re
import sys
import time
from localconfig import *


__author__ = "Avleen Vig"
Expand All @@ -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
Expand Down Expand Up @@ -102,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]
Expand Down