diff --git a/splunk_connect_for_snmp_poller/manager/poller_utilities.py b/splunk_connect_for_snmp_poller/manager/poller_utilities.py index a35583d..688d7cb 100644 --- a/splunk_connect_for_snmp_poller/manager/poller_utilities.py +++ b/splunk_connect_for_snmp_poller/manager/poller_utilities.py @@ -32,6 +32,7 @@ is_valid_inventory_line_from_dict, should_process_inventory_line, ) +from splunk_connect_for_snmp_poller.utilities import multi_key_lookup logger = logging.getLogger(__name__) @@ -82,16 +83,14 @@ def parse_inventory_file(inventory_file_path, profiles): def get_frequency(agent, profiles, default_frequency): - if ( - profiles - and "profile" in agent - and agent["profile"] != "*" - and agent["profile"] in profiles["profiles"] - ): - return profiles["profiles"][agent["profile"]]["frequency"] - else: - logger.debug(f'Default frequency was assigned for agent = {agent.get("host")}') - return default_frequency + if "profile" in agent: + frequency = multi_key_lookup( + profiles, ("profiles", agent["profile"], "frequency") + ) + if frequency: + return frequency + logger.debug(f'Default frequency was assigned for agent = {agent.get("host")}') + return default_frequency def _extract_sys_uptime_instance( diff --git a/splunk_connect_for_snmp_poller/manager/profile_matching.py b/splunk_connect_for_snmp_poller/manager/profile_matching.py index 98d8a6f..81fc906 100644 --- a/splunk_connect_for_snmp_poller/manager/profile_matching.py +++ b/splunk_connect_for_snmp_poller/manager/profile_matching.py @@ -49,8 +49,8 @@ def get_profiles(server_config): result = {} merged_profiles = {} - - merged_profiles.update(mib_profiles["profiles"]) + if "profiles" in mib_profiles: + merged_profiles.update(mib_profiles["profiles"]) merged_profiles.update(server_config["profiles"]) result["profiles"] = merged_profiles diff --git a/tests/test_poller_utilities.py b/tests/test_poller_utilities.py index d5e35a9..93e18e3 100644 --- a/tests/test_poller_utilities.py +++ b/tests/test_poller_utilities.py @@ -77,3 +77,15 @@ def test_return_default_frequency_when_profile_matched_is_dynamic(self): profiles = {"profiles": {"some_profile": {"frequency": 20}}} result = get_frequency(agent, profiles, 60) self.assertEqual(result, 60) + + def test_return_default_frequency_when_frequency_is_missing(self): + agent = {"profile": "some_profile"} + profiles = {"profiles": {"some_profile_2": {}}} + result = get_frequency(agent, profiles, 60) + self.assertEqual(result, 60) + + def test_return_default_frequency_when_there_is_no_profiles(self): + agent = {"profile": "some_profile"} + profiles = {"profiles": {}} + result = get_frequency(agent, profiles, 60) + self.assertEqual(result, 60)