diff --git a/inventory_provider/db/ims.py b/inventory_provider/db/ims.py index dbf1c5f448ad1a501182a38e94a225e45faf79fa..29ab57a2d1c564a48cc1e334c1952b6320efe7e8 100644 --- a/inventory_provider/db/ims.py +++ b/inventory_provider/db/ims.py @@ -54,6 +54,10 @@ CITY_PROPERTIES = { EQUIP_DEF_PROPERTIES = { 'Nodes': 4096 } +# http://149.210.162.190:81/ImsVersions/20.1/html/6fd3a968-26e2-e40f-e3cd-c99afa34c3e6.htm +EXTRA_FIELD_VALUE_PROPERTIES = { + 'ExtraFieldValueObjectInfo': 64 +} # http://149.210.162.190:81/ImsVersions/4.19.9/html/f18222e3-e353-0abe-b89c-820db87940ac.htm # noqa INTERNAL_PORT_PROPERTIES = { 'Node': 8, diff --git a/inventory_provider/db/ims_data.py b/inventory_provider/db/ims_data.py index 838aed07bcd07a01ad91dc7a46ae94b0810591f6..2438ad84cd00b50ac736b9494f3a7c86e16cc59e 100644 --- a/inventory_provider/db/ims_data.py +++ b/inventory_provider/db/ims_data.py @@ -7,7 +7,7 @@ from itertools import chain from inventory_provider import environment from inventory_provider.db import ims from inventory_provider.db.ims import InventoryStatus, IMS, \ - CUSTOMER_RELATED_CONTACT_PROPERTIES + CUSTOMER_RELATED_CONTACT_PROPERTIES, EXTRA_FIELD_VALUE_PROPERTIES environment.setup_logging() logger = logging.getLogger(__name__) @@ -26,6 +26,17 @@ STATUSES_TO_IGNORE = \ [InventoryStatus.OUT_OF_SERVICE.value] +def get_non_monitored_circuit_ids(ds: IMS): + # note the id for the relevant field is hard-coded. I didn't want to use + # the name of the field as this can be changed by users + for d in ds.get_filtered_entities( + 'ExtraFieldValue', + 'extrafield.id == 2898 | value == 0', + EXTRA_FIELD_VALUE_PROPERTIES['ExtraFieldValueObjectInfo'] + ): + yield d['extrafieldvalueobjectinfo']['objectid'] + + def get_service_types(ds: IMS): for d in ds.get_filtered_entities( 'ComboBoxData', diff --git a/inventory_provider/routes/classifier.py b/inventory_provider/routes/classifier.py index 0b4b63c83ee130774d4661d7b46d4352b66b5524..40a20f3777ed2aa5ff8746cc19aea8561ff74aad 100644 --- a/inventory_provider/routes/classifier.py +++ b/inventory_provider/routes/classifier.py @@ -166,12 +166,17 @@ def get_interface_services_and_loc(ims_source_equipment, ims_interface, redis): f'ims:interface_services:{ims_source_equipment}:{ims_interface}') result = {} if raw_services: - result['services'] = json.loads(raw_services.decode('utf-8')) + result['services'] = [] contacts = set() - for s in result['services']: - contacts.update(set(s.pop('contacts', set()))) - _format_service(s) + for s in json.loads(raw_services.decode('utf-8')): + if s['monitored']: + contacts.update(set(s.pop('contacts', set()))) + _format_service(s) + result['services'].append(s) result['contacts'] = sorted(list(contacts)) + + # non-monitored related services are not added by the worker so don't + # need filtering out here result['related-services'] = list( get_related_services(ims_source_equipment, ims_interface, redis)) if not result['services']: diff --git a/inventory_provider/tasks/worker.py b/inventory_provider/tasks/worker.py index 358bae060653ad02e3693551495ca14fedac4881..a091838c33f5c74e97919b7ddf80934f8c8f20ac 100644 --- a/inventory_provider/tasks/worker.py +++ b/inventory_provider/tasks/worker.py @@ -474,6 +474,9 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): tls_names = list(ims_data.get_service_types(ds1)) customer_contacts = \ {k: v for k, v in ims_data.get_customer_service_emails(ds1)} + circuit_ids_not_to_monitor = \ + list(ims_data.get_non_monitored_circuit_ids(ds1)) + hierarchy = None port_id_details = defaultdict(list) port_id_services = defaultdict(list) @@ -516,6 +519,10 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): nonlocal hierarchy hierarchy = {} for d in ims_data.get_circuit_hierarchy(ds1): + if d['id'] in circuit_ids_not_to_monitor: + d['monitored'] = False + else: + d['monitored'] = True d['contacts'] = customer_contacts.get(d['customerid'], []) hierarchy[d['id']] = d logger.debug("hierarchy complete") @@ -565,6 +572,8 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): if c: def _is_tls(candidate): + if candidate['id'] in circuit_ids_not_to_monitor: + return False if candidate['product'] in tls_names: return True if candidate['speed'] == 'BGP': @@ -588,6 +597,10 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): return list(tls.values()) def _format_service(s): + if s['id'] in circuit_ids_not_to_monitor: + s['monitored'] = False + else: + s['monitored'] = True pd_a = port_id_details[s['port_a_id']][0] location_a = locations.get(pd_a['equipment_name'], None) if location_a: @@ -641,12 +654,19 @@ def update_circuit_hierarchy_and_port_id_services(self, use_current=False): [] ) ) - circ['fibre-routes'] = \ - [{ + circ['fibre-routes'] = [] + for x in set(_get_fibre_routes(circ['id'])): + c = { 'id': hierarchy[x]['id'], 'name': hierarchy[x]['name'], 'status': hierarchy[x]['status'] - } for x in set(_get_fibre_routes(circ['id']))] + } + if c['id'] in circuit_ids_not_to_monitor: + c['monitored'] = False + else: + c['monitored'] = True + circ['fibre-routes'].append(c) + circ['top-level-services'] = \ get_top_level_services(circ['id']) diff --git a/test/data/router-info.json b/test/data/router-info.json index 14ea174366273fcc32d990bac00d2abf6876aa09..5fabc42b2a241755fa0d476f41a5394bc27e2e14 100644 Binary files a/test/data/router-info.json and b/test/data/router-info.json differ