21820359 by Barry

Bug fixes for pinging.

1 parent aeb9e40a
No preview for this file type
......@@ -184,8 +184,8 @@ def search_google_images(query, animated=False):
def ping(hostname, timeout):
ping_response = subprocess.Popen(["/bin/ping", "-c1", "-w100", hostname], stdout=subprocess.PIPE).stdout.read()
log(ping_response)
matches = re.match('.*time=([0-9]+) ms.*', ping_response, re.DOTALL)
#log(ping_response)
matches = re.match('.*time=([0-9\.]+) ms.*', ping_response, re.DOTALL)
if matches:
return matches.group(1)
else:
......@@ -193,22 +193,22 @@ def ping(hostname, timeout):
def check_pings():
ping_list = data.db_get_pings()
new_ping = ping(ping_list[0].get('ip_address'), 1000)
for ping_row in data.db_get_pings():
new_ping = ping(ping_row.get('ip_address'), 1000)
if new_ping:
log("New Ping: {}".format(new_ping))
data.db_update_ping(ping_list[0].get('ping_id'), new_ping)
log("{} - New Ping: {}".format(ping_row.get('ip_address'), new_ping))
data.db_update_ping(ping_row.get('ping_id'), new_ping)
for channel in client.get_all_channels():
if channel.id == '193028170184785920': # Reflex channel
send_message(client, channel, "{} - {}ms Average: {}ms".format(ping_list[0].get('ip_address'), new_ping, ping_list[0].get('average_ping')))
send_message(client, channel, "{} - {}ms Average: {}ms".format(ping_row.get('ip_address'), new_ping, ping_row.get('average_ping')))
break
else:
for member in client.get_all_members():
if member.id == '122079633796497409':
send_message(client, member, "Outage! {} - {}ms Average: {}ms".format(ping_list[0].get('ip_address'), new_ping, ping_list[0].get('average_ping')))
break
# for member in client.get_all_members():
# if member.id == '122079633796497409':
# send_message(client, member, "Outage! {} - {}ms Average: {}ms".format(ping_row.get('ip_address'), new_ping, ping_row.get('average_ping')))
# break
data.db_update_ping(ping_list[0].get('ping_id'), False)
data.db_update_ping(ping_row.get('ping_id'), False)
def check_msg_queue(client):
......