Updating default gateway if there are failures
This commit is contained in:
parent
610c61f9d1
commit
fbfe9e0afe
16
pinger.py
16
pinger.py
|
@ -35,6 +35,7 @@ from gi.repository import Gtk
|
||||||
from gi.repository import AppIndicator3 as appindicator
|
from gi.repository import AppIndicator3 as appindicator
|
||||||
# Timer
|
# Timer
|
||||||
from gi.repository import GObject as gobject
|
from gi.repository import GObject as gobject
|
||||||
|
import datetime
|
||||||
# Pinging
|
# Pinging
|
||||||
import subprocess
|
import subprocess
|
||||||
# Regex
|
# Regex
|
||||||
|
@ -161,6 +162,20 @@ class Pinger:
|
||||||
self.ping(self.host, self.host_log)
|
self.ping(self.host, self.host_log)
|
||||||
self.ping(self.router, self.router_log)
|
self.ping(self.router, self.router_log)
|
||||||
self.update_log_menu()
|
self.update_log_menu()
|
||||||
|
|
||||||
|
# If we have 5 router failures, try getting the default GW again
|
||||||
|
if (self.routerLastUpdated != None
|
||||||
|
and (datetime.datetime.now()-self.routerLastUpdated).seconds > 60):
|
||||||
|
|
||||||
|
if (len(self.router_log) > 5
|
||||||
|
and self.router_log[-1] == -1
|
||||||
|
and self.router_log[-2] == -1
|
||||||
|
and self.router_log[-3] == -1):
|
||||||
|
|
||||||
|
self.router = self.get_default_gateway_linux()
|
||||||
|
print "Updated router target to "+str(self.router)
|
||||||
|
self.routerLastUpdated = datetime.datetime.now()
|
||||||
|
|
||||||
gobject.timeout_add_seconds(self.timeout, self.ping_both)
|
gobject.timeout_add_seconds(self.timeout, self.ping_both)
|
||||||
|
|
||||||
def log_ping(self, log, value):
|
def log_ping(self, log, value):
|
||||||
|
@ -327,6 +342,7 @@ class Pinger:
|
||||||
if self.router == None:
|
if self.router == None:
|
||||||
self.router = default_router
|
self.router = default_router
|
||||||
print "Set router target to "+str(self.router)
|
print "Set router target to "+str(self.router)
|
||||||
|
self.routerLastUpdated = datetime.datetime.now()
|
||||||
|
|
||||||
# start the ping process
|
# start the ping process
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user