Added workaround for empty 'mac_addr' element in nodewatcher data.

Signed-off-by: Steffen Pankratz <kratz00@gmx.de>
This commit is contained in:
Steffen Pankratz 2016-05-16 12:17:49 +02:00
parent 1d05ab544b
commit c42dc9b92f
2 changed files with 7 additions and 1 deletions

View File

@ -315,7 +315,6 @@ def parse_nodewatcher_xml(xml):
interface = {
"name": netif.xpath("name/text()")[0],
"mtu": int(netif.xpath("mtu/text()")[0]),
"mac": netif.xpath("mac_addr/text()")[0].lower(),
"traffic": {
"rx_bytes": int(netif.xpath("traffic_rx/text()")[0]),
"tx_bytes": int(netif.xpath("traffic_tx/text()")[0]),
@ -329,6 +328,10 @@ def parse_nodewatcher_xml(xml):
interface["ipv6_addrs"].append(ipv6_addr.lower().split("/")[0])
with suppress(IndexError):
interface["ipv4_addr"] = netif.xpath("ipv4_addr/text()")[0]
with suppress(IndexError):
interface["mac"] = ""
interface["mac"] = netif.xpath("mac_addr/text()")[0].lower()
router_update["netifs"].append(interface)
visible_neighbours = 0

View File

@ -117,6 +117,9 @@ def humanize_bytes(num, suffix='B'):
@filters.app_template_filter('mac2fe80')
def mac_to_ipv6_linklocal(mac):
if not mac:
return ''
# Remove the most common delimiters; dots, dashes, etc.
mac_bare = re.sub('[%s]+' % re.escape(' .:-'), '', mac)
mac_value = int(mac_bare, 16)