Allow reporting over backup interface if report in-band fails
Change-Id: If5dfdd555c1962f43e9969023318d672aa228365
diff --git a/VERSION b/VERSION
index c006218..879be8a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.7.6
+0.7.7
diff --git a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
index c9d362b..680643f 100755
--- a/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
+++ b/edge-monitoring/agent_modem/edge_monitoring_agent_modem.py
@@ -429,22 +429,43 @@
logging.info("Number of cycles since modem restart %i",cycles)
try:
+ interface = None
+ report_via_modem = "report_in_band" in CONF._fields and CONF.report_in_band and \
+ "iface" in CONF.modem._fields and CONF.modem.iface
+ report_via_given_iface = "report_iface" in CONF._fields and CONF.report_iface
+
c = pycurl.Curl()
c.setopt(pycurl.URL, CONF.report_url)
c.setopt(pycurl.POST, True)
c.setopt(pycurl.HTTPHEADER, ['Content-Type: application/json'])
c.setopt(pycurl.TIMEOUT, 10)
c.setopt(pycurl.POSTFIELDS, json.dumps(report))
- if "report_in_band" in CONF._fields and CONF.report_in_band and \
- "iface" in CONF.modem._fields and CONF.modem.iface:
- c.setopt(pycurl.INTERFACE, CONF.modem.iface)
- elif "report_iface" in CONF._fields and CONF.report_iface:
- c.setopt(pycurl.INTERFACE, CONF.report_iface)
c.setopt(pycurl.WRITEFUNCTION, lambda x: None) # don't output to console
- c.perform()
+
+ if report_via_modem: # report in-band
+ interface = CONF.modem.iface
+ c.setopt(pycurl.INTERFACE, interface)
+ elif report_via_given_iface: # report over given interface
+ interface = CONF.report_iface
+ c.setopt(pycurl.INTERFACE, interface)
+ # else, reports over default interface
+
+ try:
+ c.perform()
+ logging.info("Report sent via " + interface + "!")
+ except Exception as e:
+ if report_via_modem and report_via_given_iface:
+ logging.warning("Sending report via modem failed. Attempting to send report via " + str(CONF.report_iface) + ".")
+ interface = CONF.report_iface
+ c.setopt(pycurl.INTERFACE, interface)
+ c.perform()
+ logging.info("Report sent via " + interface + "!")
+ else:
+ logging.error("Failed to send report: " + str(e))
c.close()
except Exception as e:
logging.error("Failed to send report: " + str(e))
+ c.close()
time.sleep(CONF.report_interval)