Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
fix: add some restrictions for getting profiles from mib server (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
omrozowicz-splunk authored Oct 11, 2021
1 parent 9b728d6 commit 3c690a5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
19 changes: 9 additions & 10 deletions splunk_connect_for_snmp_poller/manager/poller_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions splunk_connect_for_snmp_poller/manager/profile_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/test_poller_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 3c690a5

Please sign in to comment.