summaryrefslogtreecommitdiffstats
path: root/app/monitoring/checks
diff options
context:
space:
mode:
authorKoren Lev <korenlev@gmail.com>2017-12-18 19:16:16 +0200
committerKoren Lev <korenlev@gmail.com>2017-12-18 19:16:16 +0200
commit98c3ac7c859e34fe60d061b9ca591aba429e4118 (patch)
tree3ff2629def8938b12c0a0147e463e74e475c9032 /app/monitoring/checks
parent4709d96cc240c0c4c5308d40361ca3c3da1152fd (diff)
release 1.2 + new tagging
Change-Id: I1e876451ec4a330f458dd57adadb15e39969b225 Signed-off-by: Koren Lev <korenlev@gmail.com>
Diffstat (limited to 'app/monitoring/checks')
-rw-r--r--app/monitoring/checks/check_instance_communictions.py85
-rw-r--r--app/monitoring/checks/check_vconnector.py50
2 files changed, 135 insertions, 0 deletions
diff --git a/app/monitoring/checks/check_instance_communictions.py b/app/monitoring/checks/check_instance_communictions.py
new file mode 100644
index 0000000..d3a94b7
--- /dev/null
+++ b/app/monitoring/checks/check_instance_communictions.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python3
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
+
+# find status of instance network
+# For each instance vNIC - take the MAC address
+# For each vService in the same network as the instance,
+# use local_service_id attribute in the following command in the network node:
+# "ip netns exec <local_service_id> arp -n"
+# look for the instance vNIC's mac_address to appear in the response
+# for each mac_address:
+# - if Flag 'C' = 'Complete' - mark result OK for that instance,
+# - 'I' = 'Incomplete' - mark as 'warn',
+# - no mac_address mark as 'error'
+
+import sys
+import subprocess
+
+from binary_converter import binary2str
+
+
+arp_headers = ['Address', 'HWtype', 'HWaddress', 'Flags', 'Mask', 'Iface']
+arp_mac_pos = arp_headers.index('HWaddress')
+arp_flags_pos = arp_headers.index('Flags')
+
+
+def check_vnic_tuple(vnic_and_service: str):
+ tuple_parts = vnic_and_service.split(',')
+ local_service_id = tuple_parts[0]
+ mac_address = tuple_parts[1]
+ check_output = None
+ try:
+ netns_cmd = 'ip netns exec {} arp -n'.format(local_service_id)
+ check_output = 'MAC={}, local_service_id={}\n'\
+ .format(mac_address, local_service_id)
+ netns_out = subprocess.check_output([netns_cmd],
+ stderr=subprocess.STDOUT,
+ shell=True)
+ netns_out = binary2str(netns_out)
+ check_output += '{}\n'.format(netns_out)
+ netns_lines = netns_out.splitlines()
+ if not netns_lines or \
+ netns_lines[0].endswith('No such file or directory'):
+ check_rc = 2
+ else:
+ mac_found = False
+ flags = None
+ for l in netns_lines:
+ line_parts = l.split()
+ line_mac = line_parts[arp_mac_pos]
+ if len(line_parts) > arp_mac_pos and line_mac == mac_address:
+ mac_found = True
+ flags = line_parts[arp_flags_pos]
+ break
+ if mac_found:
+ check_rc = 1 if flags == 'I' else 0
+ else:
+ check_rc = 2
+ except subprocess.CalledProcessError as e:
+ check_output = str(e)
+ check_rc = 2
+ return check_rc, check_output
+
+
+if len(sys.argv) < 2:
+ print('usage: ' + sys.argv[0] +
+ ' <vService local_service_id>,<MAC>[;<>,<>]...')
+ exit(1)
+
+rc = 0
+output = ''
+vnics = str(sys.argv[1]).split(';')
+for vnic_tuple in vnics:
+ tuple_ret, out = check_vnic_tuple(vnic_tuple)
+ rc = min(rc, tuple_ret)
+ output += out
+print(output)
+exit(rc)
diff --git a/app/monitoring/checks/check_vconnector.py b/app/monitoring/checks/check_vconnector.py
new file mode 100644
index 0000000..237a195
--- /dev/null
+++ b/app/monitoring/checks/check_vconnector.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+###############################################################################
+# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
+# and others #
+# #
+# All rights reserved. This program and the accompanying materials #
+# are made available under the terms of the Apache License, Version 2.0 #
+# which accompanies this distribution, and is available at #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+###############################################################################
+
+# find status of vconnector
+# vconnector object name defines name of bridge
+# use "brctl showmacs <bridge>", return ERROR if 'No such device' is returned
+
+import sys
+import subprocess
+
+from binary_converter import binary2str
+
+
+if len(sys.argv) < 2:
+ print('usage: ' + sys.argv[0] + ' <bridge>')
+ exit(1)
+bridge_name = str(sys.argv[1])
+
+rc = 0
+
+cmd = None
+out = ''
+try:
+ cmd = "brctl showmacs {}".format(bridge_name)
+ out = subprocess.check_output([cmd],
+ stderr=subprocess.STDOUT,
+ shell=True)
+ out = binary2str(out)
+ lines = out.splitlines()
+ if not lines or lines[0].endswith('No such device'):
+ rc = 2
+ else:
+ print(out)
+except subprocess.CalledProcessError as e:
+ rc = 2
+ out = str(e)
+
+if rc != 0:
+ print('Failed to find vConnector {}:\n{}\n'
+ .format(bridge_name, out))
+
+exit(rc)