More exception handling and some logging fixes.
This commit is contained in:
parent
f531e89a2f
commit
81e72aa7fa
1 changed files with 14 additions and 9 deletions
23
uplink
23
uplink
|
|
@ -110,7 +110,7 @@ def get_data(config, inc):
|
||||||
password=config["database_password"],
|
password=config["database_password"],
|
||||||
database=config["database"])
|
database=config["database"])
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(RED + "ERROR: Database connection failed!" + str(err) + END)
|
logger.error("ERROR: Database connection failed!" + str(err))
|
||||||
# see https://stackoverflow.com/questions/1489669/how-to-exit-the-entire-application-from-a-python-thread
|
# see https://stackoverflow.com/questions/1489669/how-to-exit-the-entire-application-from-a-python-thread
|
||||||
# maybe the following is better. need to evaluate:
|
# maybe the following is better. need to evaluate:
|
||||||
# thread.interrupt_main()
|
# thread.interrupt_main()
|
||||||
|
|
@ -138,10 +138,10 @@ def get_data(config, inc):
|
||||||
|
|
||||||
if fc.is_connected:
|
if fc.is_connected:
|
||||||
status = "UP"
|
status = "UP"
|
||||||
logger.info(GREEN + config["uplinks"][inc]["provider"] + " " + status + END)
|
|
||||||
else:
|
else:
|
||||||
status = "DOWN"
|
status = "DOWN"
|
||||||
logger.info(RED + config["uplinks"][inc]["provider"] + " " + status + END)
|
|
||||||
|
logger.info(config["uplinks"][inc]["provider"] + " " + status)
|
||||||
|
|
||||||
sql = 'INSERT INTO log (timestamp, date, time, uptime, internal_ip, external_ip, external_ipv6, is_linked, ' \
|
sql = 'INSERT INTO log (timestamp, date, time, uptime, internal_ip, external_ip, external_ipv6, is_linked, ' \
|
||||||
'is_connected, str_transmission_rate_up, str_transmission_rate_down, str_max_bit_rate_up, ' \
|
'is_connected, str_transmission_rate_up, str_transmission_rate_down, str_max_bit_rate_up, ' \
|
||||||
|
|
@ -194,15 +194,20 @@ if __name__ == "__main__":
|
||||||
handler2.setFormatter(formatter)
|
handler2.setFormatter(formatter)
|
||||||
root_logger.addHandler(handler2)
|
root_logger.addHandler(handler2)
|
||||||
|
|
||||||
if args.stdout or args.logfile:
|
#if args.stdout or args.logfile:
|
||||||
root_logger.setLevel(args.loglevel)
|
root_logger.setLevel(args.loglevel)
|
||||||
|
|
||||||
config_path = args.config
|
config_path = args.config
|
||||||
with open(config_path, 'r') as configfile:
|
try:
|
||||||
config_data = configfile.read()
|
with open(config_path, 'r') as configfile:
|
||||||
_config = json.loads(config_data)
|
config_data = configfile.read()
|
||||||
|
_config = json.loads(config_data)
|
||||||
|
except Exception as err:
|
||||||
|
logger.error("ERROR: Reading configuration file '" + config_path + "' failed!: " + str(err))
|
||||||
|
exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run(_config)
|
run(_config)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.info(RED + "uplink terminated!" + END)
|
logger.info("uplink terminated!")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue