From 9baf12ce9165945c4206e38df7dc20008cfcf31b Mon Sep 17 00:00:00 2001 From: Karl Newell Date: Mon, 18 Mar 2019 15:43:24 -0700 Subject: [PATCH] Update main.py, ui/index.html, ui/ui.js Add VRF and table support to Flow Configuration reporting --- main.py | 76 +++++++++++++++++++++++++++++++++------------------ ui/index.html | 1 + ui/ui.js | 5 ++++ 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index 2a51199..4fb528e 100644 --- a/main.py +++ b/main.py @@ -331,8 +331,7 @@ def loadFlowRouteConfig(self): # Junos 14.1RX does not support json so let's go with XML here -# if int(version[0]) <= 14 and int(version[1]) <= 1: - if True: + if int(version[0]) <= 14 and int(version[1]) <= 1: # Retrieving all routing-options so we can get both v4 and v6. Might also work for VRFs data = dev.rpc.get_config(options={'format': 'xml'}, filter_xml='routing-options') @@ -391,33 +390,58 @@ def loadFlowRouteConfig(self): return True, self.flow_config else: + options = dev.rpc.get_config(options={'format': 'json'}, filter_xml='routing-options') + instances = dev.rpc.get_config(options={'format': 'json'}, filter_xml='routing-instances') + + data = options['configuration'] + data.update(instances['configuration']) + + for vrf in self.vrfs: + if vrf == 'default': + _vrf_data = data['routing-options'] + else: + for instance in data['routing-instances']['instance']: + if instance['name'] == vrf: + _vrf_data = instance['routing-options'] + + for table in ['inet', 'inet6']: + if table == 'inet6': + _data = _vrf_data['rib'][0]['flow'] + vrf_table = '(v6)' + else: + _data = _vrf_data['flow'] + vrf_table = '(v4)' + + for route in _data['route']: + _action = dict() - data = dev.rpc.get_config(options={'format': 'json'}) - - if 'route' in data['configuration']['routing-options']['flow']: - - for route in data['configuration']['routing-options']['flow']['route']: - _action = dict() - - for key, value in route['then'].iteritems(): + for key, value in route['then'].iteritems(): - if value[0]: - _action[key] = {'value': value} + if value[0]: + _action[key] = {'value': value} + else: + _action[key] = {'value': None} + + self.flow_config[route['name']] = { + 'vrf': '{} {}'.format(vrf, vrf_table), + 'protocol': route['match']['protocol'] if 'protocol' in route['match'] else None, + 'dstPort': route['match']['destination-port'] if 'destination-port' in route[ + 'match'] else None, + 'srcPort': route['match']['source-port'] if 'source-port' in route['match'] else None, + 'action': _action + } + if table == 'inet6': + self.flow_config[route['name']].update({ + 'dstPrefix': route['match']['destination']['prefix'] if 'destination' in route['match'] else None, + 'srcPrefix': route['match']['source']['prefix'] if 'source' in route['match'] else None + }) else: - _action[key] = {'value': None} - - self.flow_config[route['name']] = { - 'dstPrefix': route['match']['destination'] if 'destination' in route['match'] else None, - 'srcPrefix': route['match']['source'] if 'source' in route['match'] else None, - 'protocol': route['match']['protocol'] if 'protocol' in route['match'] else None, - 'dstPort': route['match']['destination-port'] if 'destination-port' in route[ - 'match'] else None, - 'srcPort': route['match']['source-port'] if 'source-port' in route['match'] else None, - 'action': _action} - return True, self.flow_config - - else: - return False, self.flow_config + self.flow_config[route['name']].update({ + 'dstPrefix': route['match']['destination'] if 'destination' in route['match'] else None, + 'srcPrefix': route['match']['source'] if 'source' in route['match'] else None + }) + + return True, self.flow_config def save_settings(self, dev_user=None, dev_pw=None, routers=None, age_out_interval=None): diff --git a/ui/index.html b/ui/index.html index a330eda..d7ef832 100644 --- a/ui/index.html +++ b/ui/index.html @@ -78,6 +78,7 @@

Monitoring BGP Flow Name + VRF Destination Prefix Source Prefix Protocol diff --git a/ui/ui.js b/ui/ui.js index 718e380..7169898 100644 --- a/ui/ui.js +++ b/ui/ui.js @@ -61,6 +61,7 @@ $(document).ready(function () { return_data.push({ 'name': name, + 'vrf': flow.vrf, 'dstPrefix': flow.dstPrefix, 'dstPort': flow.dstPort, 'srcPrefix': flow.srcPrefix, @@ -77,6 +78,10 @@ $(document).ready(function () { "data": "name", "defaultContent": "" }, + { + "data": "vrf", + "defaultContent": "" + }, { "data": "dstPrefix", "defaultContent": ""