Support multiple IPs for agent to ping, use 0s instead of nulls for speedtest
Change-Id: I68290906d808f652b324bccc44f6935ea662b7e2
diff --git a/edge-monitoring/agent_modem/config.json b/edge-monitoring/agent_modem/config.json
index 00bb652..efd0139 100644
--- a/edge-monitoring/agent_modem/config.json
+++ b/edge-monitoring/agent_modem/config.json
@@ -5,7 +5,10 @@
"baud": 115200,
"ip_addr": "192.168.0.1"
},
- "ping_to": "1.1.1.1",
+ "ips": {
+ "user_plane_ping_test": "8.8.8.8",
+ "speedtest_ping_dns": "8.8.8.8"
+ },
"report_url": "https://monitoring.aetherproject.org/edges",
"report_interval": 180,
"log_file": "/var/log/edge_monitoring_agent.log"
diff --git a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
index 0744304..757d622 100755
--- a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
+++ b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
@@ -26,7 +26,7 @@
from collections import namedtuple
'''
-Simple script that checks Aether network operational status periodically
+"Simple" script that checks Aether network operational status periodically
by controlling the attached 4G/LTE modem with AT commands and
report the result to the central monitoring server.
'''
@@ -182,7 +182,7 @@
def get_user_plane_state(modem):
- resp = os.system("ping -c 3 " + CONF.ping_to + ">/dev/null 2>&1")
+ resp = os.system("ping -c 3 " + CONF.ips.user_plane_ping_test + ">/dev/null 2>&1")
return State.connected if resp is 0 else State.disconnected, None
@@ -192,10 +192,10 @@
Input: IP to ping, # times to ping
Returns: dict of the min/avg/max/stddev numbers from the ping command result
'''
- result = {'min': None,
- 'avg': None,
- 'max': None,
- 'stddev': None}
+ result = {'min': 0.0,
+ 'avg': 0.0,
+ 'max': 0.0,
+ 'stddev': 0.0}
try:
pingResult = subprocess.check_output(
"ping -c " + str(count) + " " + ip + \
@@ -217,7 +217,7 @@
2) # TODO: Performs ping to device on network.
'''
speedtest_ping = {}
- speedtest_ping['dns'] = run_ping_test("8.8.8.8", 10)
+ speedtest_ping['dns'] = run_ping_test(CONF.ips.speedtest_ping_dns, 10)
return speedtest_ping
@@ -247,11 +247,12 @@
logging.error("Failed to connect the modem for %s", e)
sys.exit(1)
- success = os.system("sudo ip route replace {}/32 via {}".format(
- CONF.ping_to, CONF.modem.ip_addr))
- if success is not 0:
- logging.error("Failed to add test routing.")
- sys.exit(1)
+ for ip in CONF.ips:
+ success = os.system("sudo ip route replace {}/32 via {}".format(
+ ip, CONF.modem.ip_addr))
+ if success is not 0:
+ logging.error("Failed to add test routing to " + ip)
+ sys.exit(1)
while True:
cp_state, cp_msg = get_control_plane_state(modem)