From fb1f93b19c4574c25efab874d9d926f280ece1c9 Mon Sep 17 00:00:00 2001 From: Jan Tomsa Date: Wed, 6 Apr 2022 10:10:29 +0200 Subject: [PATCH] fix: fix error for interfaces without ip addresses (#200) --- prometheuspvesd/discovery.py | 2 +- prometheuspvesd/test/fixtures/fixtures.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/prometheuspvesd/discovery.py b/prometheuspvesd/discovery.py index e778fa5..8070cb0 100644 --- a/prometheuspvesd/discovery.py +++ b/prometheuspvesd/discovery.py @@ -68,7 +68,7 @@ class Discovery(): if type(networks) is list: for network in networks: - for ip_address in network["ip-addresses"]: + for ip_address in network.get("ip-addresses", []): if ip_address["ip-address-type"] == "ipv4" and not ipv4_address: ipv4_address = self._validate_ip(ip_address["ip-address"]) elif ip_address["ip-address-type"] == "ipv6" and not ipv6_address: diff --git a/prometheuspvesd/test/fixtures/fixtures.py b/prometheuspvesd/test/fixtures/fixtures.py index f6e0370..6949dc0 100644 --- a/prometheuspvesd/test/fixtures/fixtures.py +++ b/prometheuspvesd/test/fixtures/fixtures.py @@ -350,6 +350,10 @@ def networks(): "tx-packets": 14423878 } }, + { + "hardware-address": "ba:97:85:bd:9a:a5", + "name": "eth1" + }, ]