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): ...@@ -184,8 +184,8 @@ def search_google_images(query, animated=False):
184 184
185 def ping(hostname, timeout): 185 def ping(hostname, timeout):
186 ping_response = subprocess.Popen(["/bin/ping", "-c1", "-w100", hostname], stdout=subprocess.PIPE).stdout.read() 186 ping_response = subprocess.Popen(["/bin/ping", "-c1", "-w100", hostname], stdout=subprocess.PIPE).stdout.read()
187 log(ping_response) 187 #log(ping_response)
188 matches = re.match('.*time=([0-9]+) ms.*', ping_response, re.DOTALL) 188 matches = re.match('.*time=([0-9\.]+) ms.*', ping_response, re.DOTALL)
189 if matches: 189 if matches:
190 return matches.group(1) 190 return matches.group(1)
191 else: 191 else:
...@@ -193,22 +193,22 @@ def ping(hostname, timeout): ...@@ -193,22 +193,22 @@ def ping(hostname, timeout):
193 193
194 194
195 def check_pings(): 195 def check_pings():
196 ping_list = data.db_get_pings() 196 for ping_row in data.db_get_pings():
197 new_ping = ping(ping_list[0].get('ip_address'), 1000) 197 new_ping = ping(ping_row.get('ip_address'), 1000)
198 if new_ping: 198 if new_ping:
199 log("New Ping: {}".format(new_ping)) 199 log("{} - New Ping: {}".format(ping_row.get('ip_address'), new_ping))
200 data.db_update_ping(ping_list[0].get('ping_id'), new_ping) 200 data.db_update_ping(ping_row.get('ping_id'), new_ping)
201 for channel in client.get_all_channels(): 201 for channel in client.get_all_channels():
202 if channel.id == '193028170184785920': # Reflex channel 202 if channel.id == '193028170184785920': # Reflex channel
203 send_message(client, channel, "{} - {}ms Average: {}ms".format(ping_list[0].get('ip_address'), new_ping, ping_list[0].get('average_ping'))) 203 send_message(client, channel, "{} - {}ms Average: {}ms".format(ping_row.get('ip_address'), new_ping, ping_row.get('average_ping')))
204 break 204 break
205 else: 205 else:
206 for member in client.get_all_members(): 206 # for member in client.get_all_members():
207 if member.id == '122079633796497409': 207 # if member.id == '122079633796497409':
208 send_message(client, member, "Outage! {} - {}ms Average: {}ms".format(ping_list[0].get('ip_address'), new_ping, ping_list[0].get('average_ping'))) 208 # send_message(client, member, "Outage! {} - {}ms Average: {}ms".format(ping_row.get('ip_address'), new_ping, ping_row.get('average_ping')))
209 break 209 # break
210 210
211 data.db_update_ping(ping_list[0].get('ping_id'), False) 211 data.db_update_ping(ping_row.get('ping_id'), False)
212 212
213 213
214 def check_msg_queue(client): 214 def check_msg_queue(client):
......