Skip to content

Commit

Permalink
Cleaned up TODO's
Browse files Browse the repository at this point in the history
Edited gmail connectivity checker

Editied get_print_server_list (formatting too wide)
  • Loading branch information
Jelloeater committed Aug 14, 2014
1 parent 10ecdb9 commit b17d5e8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 33 deletions.
4 changes: 0 additions & 4 deletions Alerters/email_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ def generate_fail_table(fail_list_in, monitor_list_in):
service = fail_event[3]
time_stamp = str(fail_event[1])

# FIXME but it works fine for traditional urls (http://www.google.com)
# FIXME The issue we are having is that the host name that has been parsed out (127.0.0.1),
# FIXME is not being matched with the host name in the monitor list (https://127.0.0.1:808)

# Try to find note in
note_txt = ''
for monitor_item in monitor_list_in:
Expand Down
26 changes: 15 additions & 11 deletions Alerters/email_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,30 @@ def __init__(self):

def test_login(self):
""" Tests both if gmail is reachable, and if the login info is correct """
# FIXME Come up with better way to check for gmail being up
logging.debug('Testing login')
logging.debug('Testing site access')
http_response_code = 404
try:
http_response_code = urllib2.urlopen('http://www.google.com', timeout=3).code
http_response_code = urllib2.urlopen('http://www.gmail.com').code
except urllib2.URLError:
logging.critical('Cannot reach Gmail')
pass

if http_response_code == 200:
response_flag = True
else:
response_flag = False
logging.error('Cannot reach gmail.com')

try:
logging.debug(str(self.USERNAME) + str(self.PASSWORD))
gmail.GMail(username=self.USERNAME, password=self.PASSWORD)
login_flag = True
except smtplib.SMTPAuthenticationError:
logging.critical('Bad gmail login info, cannot send messages, exiting')
sys.exit(1)
logging.debug('Testing login')
if response_flag:
try:
logging.debug(str(self.USERNAME) + str(self.PASSWORD))
gmail.GMail(username=self.USERNAME, password=self.PASSWORD)
login_flag = True
except smtplib.SMTPAuthenticationError:
logging.critical('Bad gmail login info, cannot send messages, exiting')
sys.exit(1)
else:
login_flag = False

if login_flag and response_flag:
return True
Expand Down
1 change: 0 additions & 1 deletion Database/db_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class db_helper(db_access):
# db = postgresql.open(user = 'usename', database = 'datname', port = 5432)
# http://python.projects.pgfoundry.org/docs/1.1/

# TODO Maybe implement other mail providers
def __init__(self):
super(db_helper, self).__init__()

Expand Down
2 changes: 0 additions & 2 deletions Database/db_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def log_email_sent(to_list):

@staticmethod
def email_sent_x_minutes_ago():
#TODO Deal with empty table use case

try:
conn, cur = db_controller.db_access().open_connection()
cur.execute(
Expand Down
10 changes: 5 additions & 5 deletions Database/db_monitor_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ def check_for_valid_service_type():
def get_print_server_list():
x = db_helpers.monitor_list.get_server_list()
print("Servers:")
print("{0}{1}{2}{3}{4}".format("Index".ljust(8), "Hostname".ljust(50), "Port".ljust(8),
print("{0}{1}{2}{3}{4}".format("Index".ljust(8), "Hostname".ljust(30), "Port".ljust(8),
"Service".ljust(10), "Note".ljust(0)))

# TODO There's got to be a better way of doing this
for i in x:
if i[2] is None and i[4] is None:
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(50), str("").ljust(8),
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(30), str("").ljust(8),
i[3].ljust(10), str("").ljust(0))
if i[2] is not None and i[4] is None:
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(50), str(i[2]).ljust(8),
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(30), str(i[2]).ljust(8),
i[3].ljust(10), str("").ljust(0))
if i[2] is None and i[4] is not None:
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(50), str("").ljust(8),
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(30), str("").ljust(8),
i[3].ljust(10), str(i[4]).ljust(0))
if i[2] is not None and i[4] is not None:
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(50), str(i[2]).ljust(8),
print "{0}{1}{2}{3}{4}".format(str(i[0]).ljust(8), i[1].ljust(30), str(i[2]).ljust(8),
i[3].ljust(10), str(i[4]).ljust(0))

return x # Return the list, should come in handy
Expand Down
12 changes: 4 additions & 8 deletions Network_Monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@ def main():
" (http://github.com/Jelloeater/NetworkMonitor)",
version=__version__,
epilog="Please specify action")

multi_server_group = parser.add_argument_group('Multi Server Mode')
multi_server_group.add_argument("-m",
"--monitor",
help="Multi server watch mode",
action="store_true")
multi_server_group.add_argument("-e",
"--editServerList",
help="Edit the server watch list",
action="store_true")

report_group = parser.add_argument_group('Actions')
report_group.add_argument("-g",
Expand Down Expand Up @@ -80,21 +77,21 @@ def main():
action="store",
type=int,
default=60,
help="Wait x second between checks")
help="Wait x second between checks (60)")

parser.add_argument("-a",
"--alert_timeout",
action="store",
type=int,
default=15,
help="Wait x minutes between alerts")
help="Wait x minutes between alerts (15)")

parser.add_argument("-t",
"--host_timeout",
action="store",
type=int,
default=10,
help="Wait x seconds for failure")
help="Wait x seconds for failure (10)")

parser.add_argument("--debug",
action="store_true",
Expand Down Expand Up @@ -159,7 +156,6 @@ def __init__(self, sleep_delay, alert_timeout, host_timeout):
self.host_timeout = host_timeout
self.server_list = []

# TODO Load server List from JSON

def sleep(self):
try:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_server_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ def test_check_server_status_report_logic(self):
self.alert_timeout = 5
if db_helpers.email_log.email_sent_x_minutes_ago() < self.alert_timeout:
# report_generator.reports.generate_report()
pass
# TODO This is the root function for all reporting
pass

0 comments on commit b17d5e8

Please sign in to comment.