Send to stderr all exceptions messages in arping check
Change-Id: I1d21c08ac650f0bbac511ca5ce059145e1273ec2
Related-bug: PROD-35728
diff --git a/telegraf/files/script/check_ovs_arping.py b/telegraf/files/script/check_ovs_arping.py
index 864131d..b6f8f2d 100644
--- a/telegraf/files/script/check_ovs_arping.py
+++ b/telegraf/files/script/check_ovs_arping.py
@@ -130,7 +130,8 @@
return packets
try:
data = soc.recv(PACKETSIZE)
- except OSError:
+ except OSError as e:
+ sys.stderr.write(str(e))
return packets
if len(data) == PACKETSIZE and ord(data[21]) == ARPREPLY:
ip_to = data[38:42]
@@ -148,20 +149,26 @@
soc = socket.socket(socket.PF_PACKET, socket.SOCK_RAW)
try:
soc.bind((interface, TYPEFRAME))
- except OSError:
+ except OSError as e:
+ sys.stderr.write(str(e))
return set(), ip_recvrs
+
for ip_recvr in ip_recvrs:
bc_packet = ARPSendPacket('ff:ff:ff:ff:ff:ff', mac_sedr, ip_sedr, mac_sedr, ip_recvr, '00:00:00:00:00:00')
try:
soc.send(bc_packet.__str__())
- except OSError:
+ except OSError as e:
+ sys.stderr.write(str(e))
return set(), ip_recvrs
+
packets = recv_arp_packets(soc, socket.inet_aton(ip_sedr), ip_recvrs, TIMEOUT)
res_addrs = set()
+
for packet in packets:
ip_from = packet[28:32]
mac_from = packet[6:12]
res_addrs.add((ip_from, mac_from))
+
for _ in range(args.arp_count - 1):
tmp_res_addrs = set()
str_ips = set()
@@ -172,18 +179,22 @@
uc_packet = ARPSendPacket(mac_str, mac_sedr, ip_sedr, mac_sedr, ip_str, mac_str)
try:
soc.send(uc_packet.__str__())
- except OSError:
+ except OSError as e:
+ sys.stderr.write(str(e))
return set(), ip_recvrs
packets = recv_arp_packets(soc, socket.inet_aton(ip_sedr), str_ips, TIMEOUT)
+
for packet in packets:
ip_from = packet[28:32]
mac_from = packet[6:12]
tmp_res_addrs.add((ip_from, mac_from))
res_addrs = tmp_res_addrs
+
ips = set()
for addr in res_addrs:
ips.add(socket.inet_ntoa(addr[0]))
soc.close()
+
return ips, ip_recvrs.difference(ips)
@@ -207,6 +218,7 @@
name = ""
mac = ""
addresses = []
+
for line in data.split('\n'):
m = re.match(r"(\d+):\s?(.+):", line)
if m:
@@ -220,6 +232,7 @@
m = re.match(r"\s+inet\s([0-9.]+)/(\d+)", line)
if m:
addresses.append((m.group(1), m.group(2)))
+
interfaces[name] = {"addresses": addresses, "mac": mac}
interfaces.pop("", None)
interfaces.pop("lo", None)
@@ -327,8 +340,10 @@
id = check["id"]
try:
passed, failed = check["result"].get()
- except IOError:
+ except IOError as e:
+ sys.stderr.write(str(e))
passed, failed = set(), check_map[id]
+
for ip in passed:
id_long = id + " " + ip
res = mapping[id_long]
@@ -339,6 +354,7 @@
'id': res['device_id'],
'success': "1"
}
+
for ip in failed:
id_long = id + " " + ip
res = mapping[id_long]
@@ -349,6 +365,8 @@
'id': res['device_id'],
'success': "0"
}
+
+
if __name__ == "__main__":
try:
gather()