diff --git a/Changelog.md b/Changelog.md index 9bedbb59c62ba3997a36f1f4f1641ba2435ec8ab..eaaa81f543aa7f4e15584cb10a873974603204ab 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,8 @@ # Changelog All notable changes to this project will be documented in this file. +## [0.10] - 2024-05-07 +- Poll netconf only once for both brian and error counters ## [0.9] - 2024-05-06 - DBOARD3-900: Add report-interface-errors script diff --git a/brian_polling_manager/interface_stats/cli.py b/brian_polling_manager/interface_stats/cli.py index 74d9ee89e302b458f8b97fcedbd1386aae860de8..6b32276458f2f661a8737eaa9588c98754339e4f 100644 --- a/brian_polling_manager/interface_stats/cli.py +++ b/brian_polling_manager/interface_stats/cli.py @@ -24,7 +24,7 @@ DEFAULT_INTERFACES_URL = "/poller/interfaces/" class PointGroup(enum.Enum): BRIAN = ("brian", "brian-counters", vendors.brian_points) - ERRORS = ("errors", "error-counters", vendors.error_points) + ERRORS = ("error", "error-counters", vendors.error_points) def config_params(self, app_params: dict): return app_params[self.value[1]] @@ -154,16 +154,15 @@ def _get_interfaces_for_router( def process_router( router_fqdn: str, vendor: Vendor, + document: Any, + timestamp: datetime, interfaces: Optional[List[str]], app_config_params: dict, output: OutputMethod, point_group: PointGroup, ): - ssh_params = vendor.config_params(app_config_params) - document = vendor.get_netconf(router_name=router_fqdn, ssh_params=ssh_params) - timestamp = datetime.now() - influx_params = point_group.config_params(app_config_params)["influx"] + points = list( _points( router_fqdn=router_fqdn, @@ -176,7 +175,7 @@ def process_router( ) ) - _log_interface_points_sorted(points, point_kind="error") + _log_interface_points_sorted(points, point_kind=str(point_group)) output.write_points(points, influx_params=influx_params) @@ -226,6 +225,9 @@ def main( if not app_config_params.get(vendor_str): raise ValueError(f"'{vendor_str}' ssh params are required") + ssh_params = vendor.config_params(app_config_params) + netconf = vendor.get_netconf(router_name=router_fqdn, ssh_params=ssh_params) + timestamp = datetime.now() for point_group in PointGroup: logger.info(f"Processing {str(point_group).capitalize()} points...") @@ -240,6 +242,8 @@ def main( process_router( router_fqdn=router_fqdn, vendor=vendor, + document=netconf, + timestamp=timestamp, interfaces=check_interfaces, app_config_params=app_config_params, output=output, diff --git a/setup.py b/setup.py index 3aba6ebfeacffaf724a345e99563fd8dac554367..7d889e797d086c33ec0957431e3db92a6b782759 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='brian-polling-manager', - version="0.9", + version="0.10", author='GEANT', author_email='swd@geant.org', description='service for managing BRIAN polling checks', diff --git a/test/interface_stats/test_interface_stats.py b/test/interface_stats/test_interface_stats.py index f6195b6ea5f19391d539853c8fdad56f80c0cb90..e132e31011482252dfe2dc6a927f6e33f44ee386 100644 --- a/test/interface_stats/test_interface_stats.py +++ b/test/interface_stats/test_interface_stats.py @@ -208,15 +208,17 @@ def test_main_for_all_juniper_routers( def mocked_load_inventory(): with patch.object(cli, "load_inventory_json") as mock: mock.return_value = [ - {"router": "router1", "name": "ifc1"}, - {"router": "router1", "name": "ifc2"}, - {"router": "router2", "name": "ifc3"}, + {"router": "mx1.ams.nl.geant.net", "name": "ifc1"}, + {"router": "mx1.ams.nl.geant.net", "name": "ifc2"}, + {"router": "mx1.lon.uk.geant.net", "name": "ifc3"}, ] yield mock @patch.object(cli, "process_router") -def test_main_with_some_interfaces(process_router, mocked_load_inventory): +def test_main_with_some_interfaces( + process_router, mocked_load_inventory, mocked_get_netconf +): config = { "juniper": {"some": "params"}, "inventory": ["some-inprov"], @@ -225,7 +227,7 @@ def test_main_with_some_interfaces(process_router, mocked_load_inventory): } cli.main( config, - "router1", + "mx1.ams.nl.geant.net", Vendor.JUNIPER, interfaces=["ifc1"], ) @@ -234,7 +236,7 @@ def test_main_with_some_interfaces(process_router, mocked_load_inventory): @patch.object(cli, "process_router") def test_main_with_all_interfaces_and_inprov_hosts( - process_router, mocked_load_inventory + process_router, mocked_load_inventory, mocked_get_netconf ): config = { "juniper": {"some": "params"}, @@ -242,20 +244,20 @@ def test_main_with_all_interfaces_and_inprov_hosts( "brian-counters": {}, "error-counters": {}, } - cli.main(config, "router1", Vendor.JUNIPER) + cli.main(config, "mx1.ams.nl.geant.net", Vendor.JUNIPER) assert process_router.call_args[1]["interfaces"] == ["ifc1", "ifc2"] @patch.object(cli, "process_router") def test_main_with_all_interfaces_no_inprov_hosts( - process_router, mocked_load_inventory + process_router, mocked_load_inventory, mocked_get_netconf ): config = { "juniper": {"some": "params"}, - "brian-counters": {}, - "error-counters": {}, + "brian-counters": {"influx": None}, + "error-counters": {"influx": None}, } - cli.main(config, "router1", Vendor.JUNIPER) + cli.main(config, "mx1.ams.nl.geant.net", Vendor.JUNIPER) assert process_router.call_args[1]["interfaces"] is None @@ -274,7 +276,7 @@ def test_loads_interfaces_from_endpoint(point_group, url, mocked_load_inventory) "error-counters": {"inventory-url": "/error/endpoint"}, } cli.load_interfaces( - "router1", + "mx1.ams.nl.geant.net", interfaces=cli.ALL_, app_config_params=config, point_group=point_group,