diff --git a/charts/splunk-connect-for-snmp/templates/inventory/job.yaml b/charts/splunk-connect-for-snmp/templates/inventory/job.yaml index 675b2defe..bc8f7dbe7 100644 --- a/charts/splunk-connect-for-snmp/templates/inventory/job.yaml +++ b/charts/splunk-connect-for-snmp/templates/inventory/job.yaml @@ -50,6 +50,8 @@ spec: value: {{ .Values.scheduler.tasksExpiryTime | quote }} - name: CONFIG_FROM_MONGO value: {{ quote .Values.UI.enable | default "false" }} + - name: ENABLE_FULL_WALK + value: {{ .Values.poller.enableFullWalk | default "false" | quote }} volumeMounts: - name: config mountPath: "/app/config" diff --git a/charts/splunk-connect-for-snmp/templates/ui/_helpers.tpl b/charts/splunk-connect-for-snmp/templates/ui/_helpers.tpl index b56314c55..8cd2a84bd 100644 --- a/charts/splunk-connect-for-snmp/templates/ui/_helpers.tpl +++ b/charts/splunk-connect-for-snmp/templates/ui/_helpers.tpl @@ -51,6 +51,8 @@ spec: value: {{ .Values.scheduler.logLevel | default "INFO" }} - name: CONFIG_FROM_MONGO value: {{ quote .Values.UI.enable | default "false" }} + - name: ENABLE_FULL_WALK + value: {{ .Values.poller.enableFullWalk | default "false" | quote }} volumeMounts: - name: config mountPath: "/app/config" diff --git a/charts/splunk-connect-for-snmp/values.yaml b/charts/splunk-connect-for-snmp/values.yaml index 95ee9a978..1a3023d13 100644 --- a/charts/splunk-connect-for-snmp/values.yaml +++ b/charts/splunk-connect-for-snmp/values.yaml @@ -226,6 +226,9 @@ poller: # https://splunk.github.io/splunk-connect-for-snmp/main/configuration/poller-configuration/#define-usernamesecrets usernameSecrets: [] + # flag to enable polling full walk tree for devices + enableFullWalk: false + # Here is where polling happens. Learn more on how to configure it here: # https://splunk.github.io/splunk-connect-for-snmp/main/configuration/poller-configuration/ diff --git a/integration_tests/splunk_test_utils.py b/integration_tests/splunk_test_utils.py index 000096f00..2071cd521 100644 --- a/integration_tests/splunk_test_utils.py +++ b/integration_tests/splunk_test_utils.py @@ -51,6 +51,13 @@ def splunk_single_search(service, search): inventory_template = """poller: + enableFullWalk: true + inventory: | + address,port,version,community,secret,security_engine,walk_interval,profiles,smart_profiles,delete +""" + +inventory_template_no_walk = """poller: + enableFullWalk: false inventory: | address,port,version,community,secret,security_engine,walk_interval,profiles,smart_profiles,delete """ @@ -77,6 +84,7 @@ def splunk_single_search(service, search): TEMPLATE_MAPPING = { "inventory.yaml": inventory_template, + "inventory2.yaml": inventory_template_no_walk, "profiles.yaml": profiles_template, "scheduler_secrets.yaml": poller_secrets_template, "traps_secrets.yaml": traps_secrets_template, diff --git a/integration_tests/test_poller_integration.py b/integration_tests/test_poller_integration.py index f74492e1b..e3ea437cc 100644 --- a/integration_tests/test_poller_integration.py +++ b/integration_tests/test_poller_integration.py @@ -379,12 +379,12 @@ def setup_small_walk(request): }, } update_profiles(profile) - update_file([f"{trap_external_ip},,2c,public,,,20,walk1,f,"], "inventory.yaml") - upgrade_helm(["inventory.yaml", "profiles.yaml"]) + update_file([f"{trap_external_ip},,2c,public,,,20,walk1,f,"], "inventory2.yaml") + upgrade_helm(["inventory2.yaml", "profiles.yaml"]) time.sleep(30) yield - update_file([f"{trap_external_ip},,2c,public,,,20,walk1,f,t"], "inventory.yaml") - upgrade_helm(["inventory.yaml"]) + update_file([f"{trap_external_ip},,2c,public,,,20,walk1,f,t"], "inventory2.yaml") + upgrade_helm(["inventory2.yaml"]) time.sleep(20) diff --git a/integration_tests/values.yaml b/integration_tests/values.yaml index b92b71770..663f02a91 100644 --- a/integration_tests/values.yaml +++ b/integration_tests/values.yaml @@ -65,6 +65,7 @@ scheduler: groups: | {} poller: + enableFullWalk: true usernameSecrets: - sv3poller # - sc4snmp-hlab-sha-aes diff --git a/rendered/manifests/tests/splunk-connect-for-snmp/templates/inventory/job.yaml b/rendered/manifests/tests/splunk-connect-for-snmp/templates/inventory/job.yaml index 40062ecdb..bbbb3fc46 100644 --- a/rendered/manifests/tests/splunk-connect-for-snmp/templates/inventory/job.yaml +++ b/rendered/manifests/tests/splunk-connect-for-snmp/templates/inventory/job.yaml @@ -48,6 +48,8 @@ spec: value: "60" - name: CONFIG_FROM_MONGO value: "false" + - name: ENABLE_FULL_WALK + value: "false" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml b/rendered/manifests/tests/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml index ce10d78b0..4b03ed67b 100644 --- a/rendered/manifests/tests/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml +++ b/rendered/manifests/tests/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml @@ -105,6 +105,12 @@ spec: value: "4" - name: PREFETCH_COUNT value: "30" + - name: RESOLVE_TRAP_ADDRESS + value: "false" + - name: MAX_DNS_CACHE_SIZE_TRAPS + value: "500" + - name: TTL_DNS_CACHE_TRAPS + value: "1800" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml b/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml index 40062ecdb..bbbb3fc46 100644 --- a/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml +++ b/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml @@ -48,6 +48,8 @@ spec: value: "60" - name: CONFIG_FROM_MONGO value: "false" + - name: ENABLE_FULL_WALK + value: "false" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml b/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml index dbd548386..058bde528 100644 --- a/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml +++ b/rendered/manifests/tests_autoscaling_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml @@ -104,6 +104,12 @@ spec: value: "4" - name: PREFETCH_COUNT value: "30" + - name: RESOLVE_TRAP_ADDRESS + value: "false" + - name: MAX_DNS_CACHE_SIZE_TRAPS + value: "500" + - name: TTL_DNS_CACHE_TRAPS + value: "1800" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/inventory/job.yaml b/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/inventory/job.yaml index 40062ecdb..bbbb3fc46 100644 --- a/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/inventory/job.yaml +++ b/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/inventory/job.yaml @@ -48,6 +48,8 @@ spec: value: "60" - name: CONFIG_FROM_MONGO value: "false" + - name: ENABLE_FULL_WALK + value: "false" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml b/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml index dbd548386..058bde528 100644 --- a/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml +++ b/rendered/manifests/tests_autoscaling_enabled_deprecated/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml @@ -104,6 +104,12 @@ spec: value: "4" - name: PREFETCH_COUNT value: "30" + - name: RESOLVE_TRAP_ADDRESS + value: "false" + - name: MAX_DNS_CACHE_SIZE_TRAPS + value: "500" + - name: TTL_DNS_CACHE_TRAPS + value: "1800" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/inventory/job.yaml b/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/inventory/job.yaml index 3134f724e..6230df48f 100644 --- a/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/inventory/job.yaml +++ b/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/inventory/job.yaml @@ -48,6 +48,8 @@ spec: value: "60" - name: CONFIG_FROM_MONGO value: "true" + - name: ENABLE_FULL_WALK + value: "false" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/ui/configmap-backend.yaml b/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/ui/configmap-backend.yaml index 78b8c4ba5..87d82d69c 100644 --- a/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/ui/configmap-backend.yaml +++ b/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/ui/configmap-backend.yaml @@ -53,6 +53,8 @@ data: value: INFO - name: CONFIG_FROM_MONGO value: "true" + - name: ENABLE_FULL_WALK + value: "false" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml b/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml index ce10d78b0..4b03ed67b 100644 --- a/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml +++ b/rendered/manifests/tests_enable_ui/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml @@ -105,6 +105,12 @@ spec: value: "4" - name: PREFETCH_COUNT value: "30" + - name: RESOLVE_TRAP_ADDRESS + value: "false" + - name: MAX_DNS_CACHE_SIZE_TRAPS + value: "500" + - name: TTL_DNS_CACHE_TRAPS + value: "1800" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_only_polling/splunk-connect-for-snmp/templates/inventory/job.yaml b/rendered/manifests/tests_only_polling/splunk-connect-for-snmp/templates/inventory/job.yaml index 40062ecdb..bbbb3fc46 100644 --- a/rendered/manifests/tests_only_polling/splunk-connect-for-snmp/templates/inventory/job.yaml +++ b/rendered/manifests/tests_only_polling/splunk-connect-for-snmp/templates/inventory/job.yaml @@ -48,6 +48,8 @@ spec: value: "60" - name: CONFIG_FROM_MONGO value: "false" + - name: ENABLE_FULL_WALK + value: "false" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_only_traps/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml b/rendered/manifests/tests_only_traps/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml index ce10d78b0..4b03ed67b 100644 --- a/rendered/manifests/tests_only_traps/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml +++ b/rendered/manifests/tests_only_traps/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml @@ -105,6 +105,12 @@ spec: value: "4" - name: PREFETCH_COUNT value: "30" + - name: RESOLVE_TRAP_ADDRESS + value: "false" + - name: MAX_DNS_CACHE_SIZE_TRAPS + value: "500" + - name: TTL_DNS_CACHE_TRAPS + value: "1800" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml b/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml index 40062ecdb..bbbb3fc46 100644 --- a/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml +++ b/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/inventory/job.yaml @@ -48,6 +48,8 @@ spec: value: "60" - name: CONFIG_FROM_MONGO value: "false" + - name: ENABLE_FULL_WALK + value: "false" volumeMounts: - name: config mountPath: "/app/config" diff --git a/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml b/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml index 6edf0e7bb..cef9e439e 100644 --- a/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml +++ b/rendered/manifests/tests_probes_enabled/splunk-connect-for-snmp/templates/worker/trap/deployment.yaml @@ -105,6 +105,12 @@ spec: value: "4" - name: PREFETCH_COUNT value: "30" + - name: RESOLVE_TRAP_ADDRESS + value: "false" + - name: MAX_DNS_CACHE_SIZE_TRAPS + value: "500" + - name: TTL_DNS_CACHE_TRAPS + value: "1800" volumeMounts: - name: config mountPath: "/app/config" diff --git a/splunk_connect_for_snmp/common/inventory_processor.py b/splunk_connect_for_snmp/common/inventory_processor.py index 5e8c3a4c2..9206315e5 100644 --- a/splunk_connect_for_snmp/common/inventory_processor.py +++ b/splunk_connect_for_snmp/common/inventory_processor.py @@ -1,5 +1,7 @@ import copy +import logging import os +import sys from contextlib import suppress from csv import DictReader from typing import List @@ -29,6 +31,20 @@ "security_engine", "securityEngine", ] +ENABLE_FULL_WALK = human_bool(os.getenv("ENABLE_FULL_WALK", "false").lower()) +from splunk_connect_for_snmp.common.customised_json_formatter import ( + CustomisedJSONFormatter, +) + +formatter = CustomisedJSONFormatter() +logger = logging.getLogger(__name__) +logger.setLevel("DEBUG") + +# writing to stdout +handler = logging.StreamHandler(sys.stdout) +handler.setLevel("DEBUG") +handler.setFormatter(formatter) +logger.addHandler(handler) def transform_key_to_address(target): @@ -88,10 +104,9 @@ def get_groups_keys(list_of_groups, group_name, inventory_group_port_mapping): class InventoryProcessor: - def __init__(self, group_manager: GroupsManager, logger, inventory_ui_collection): + def __init__(self, group_manager: GroupsManager, inventory_ui_collection): self.inventory_records: List[dict] = [] self.group_manager = group_manager - self.logger = logger self.hosts_from_groups: dict = {} self.inventory_group_port_mapping: dict = {} self.single_hosts: List[dict] = [] @@ -99,11 +114,11 @@ def __init__(self, group_manager: GroupsManager, logger, inventory_ui_collection def get_all_hosts(self): if CONFIG_FROM_MONGO: - self.logger.info("Loading inventory from inventory_ui collection") + logger.info("Loading inventory from inventory_ui collection") ir_reader = list(self.inventory_ui_collection.find({}, {"_id": 0})) else: with open(INVENTORY_PATH, encoding="utf-8") as csv_file: - self.logger.info(f"Loading inventory from {INVENTORY_PATH}") + logger.info(f"Loading inventory from {INVENTORY_PATH}") ir_reader = list(DictReader(csv_file)) for inventory_line in ir_reader: self.process_line(inventory_line) @@ -115,7 +130,7 @@ def get_all_hosts(self): if was_present is None: self.inventory_records.append(source_record) else: - self.logger.warning( + logger.warning( f"Record: {host} has been already configured in group. Skipping..." ) return self.inventory_records, self.inventory_group_port_mapping @@ -124,7 +139,7 @@ def process_line(self, source_record): address = source_record["address"] # Inventory record is commented out if address.startswith("#"): - self.logger.warning(f"Record: {address} is commented out. Skipping...") + logger.warning(f"Record: {address} is commented out. Skipping...") # Address is an IP address elif address[0].isdigit(): self.single_hosts.append(source_record) @@ -146,7 +161,7 @@ def get_group_hosts(self, source_object, group_name): if key in ALLOWED_KEYS_VALUES: host_group_object[key] = group_object[key] else: - self.logger.warning( + logger.warning( f"Key {key} is not allowed to be changed from the group level" ) address = str(group_object["address"]) @@ -156,19 +171,18 @@ def get_group_hosts(self, source_object, group_name): host_group_object["group"] = group_name self.inventory_records.append(host_group_object) else: - self.logger.warning( + logger.warning( f"Group {group_name} doesn't exist in the configuration. Treating {group_name} as a hostname" ) self.single_hosts.append(source_object) class InventoryRecordManager: - def __init__(self, mongo_client, periodic_objects_collection, logger): + def __init__(self, mongo_client, periodic_objects_collection): self.targets_collection = mongo_client.sc4snmp.targets self.inventory_collection = mongo_client.sc4snmp.inventory self.attributes_collection = mongo_client.sc4snmp.attributes self.periodic_object_collection = periodic_objects_collection - self.logger = logger def delete(self, target): address, port = transform_key_to_address(target) @@ -176,7 +190,7 @@ def delete(self, target): self.inventory_collection.delete_one({"address": address, "port": port}) self.targets_collection.delete_many({"address": target}) self.attributes_collection.delete_many({"address": target}) - self.logger.info(f"Deleting record: {target}") + logger.info(f"Deleting record: {target}") def update( self, inventory_record, new_source_record, runtime_profiles, expiry_time_changed @@ -191,13 +205,13 @@ def update( upsert=True, ) if status.matched_count == 0: - self.logger.info(f"New Record {inventory_record} {status.upserted_id}") + logger.info(f"New Record {inventory_record} {status.upserted_id}") elif status.modified_count == 1 and status.upserted_id is None: - self.logger.info(f"Modified Record {inventory_record}") + logger.info(f"Modified Record {inventory_record}") else: - self.logger.info(f"Unchanged Record {inventory_record}") + logger.info(f"Unchanged Record {inventory_record}") if expiry_time_changed: - self.logger.info( + logger.info( f"Task expiry time was modified, generating new tasks for record {inventory_record}" ) else: @@ -211,6 +225,8 @@ def update( def return_walk_profile(self, runtime_profiles, inventory_profiles): walk_profile = None + if ENABLE_FULL_WALK: + return None if inventory_profiles: walk_profiles = [ p @@ -221,4 +237,6 @@ def return_walk_profile(self, runtime_profiles, inventory_profiles): if walk_profiles: # if there's more than one walk profile, we're choosing the last one on the list walk_profile = walk_profiles[-1] + if not walk_profile: + walk_profile = "WalkProfile" return walk_profile diff --git a/splunk_connect_for_snmp/inventory/loader.py b/splunk_connect_for_snmp/inventory/loader.py index ef57b21d8..b8ad5ed35 100644 --- a/splunk_connect_for_snmp/inventory/loader.py +++ b/splunk_connect_for_snmp/inventory/loader.py @@ -183,12 +183,8 @@ def load(): new_groups = groups_manager.return_collection() inventory_ui_collection = mongo_client.sc4snmp.inventory_ui - inventory_processor = InventoryProcessor( - groups_manager, logger, inventory_ui_collection - ) - inventory_record_manager = InventoryRecordManager( - mongo_client, periodic_obj, logger - ) + inventory_processor = InventoryProcessor(groups_manager, inventory_ui_collection) + inventory_record_manager = InventoryRecordManager(mongo_client, periodic_obj) if CONFIG_FROM_MONGO: logger.info(f"Loading inventory from inventory_ui collection") else: diff --git a/splunk_connect_for_snmp/profiles/walk.yaml b/splunk_connect_for_snmp/profiles/walk.yaml new file mode 100644 index 000000000..7c701621b --- /dev/null +++ b/splunk_connect_for_snmp/profiles/walk.yaml @@ -0,0 +1,5 @@ +WalkProfile: + condition: + type: "walk" + varBinds: + - ['SNMPv2-MIB'] \ No newline at end of file diff --git a/test/common/test_inventory_processor.py b/test/common/test_inventory_processor.py index e4b337191..657a76c29 100644 --- a/test/common/test_inventory_processor.py +++ b/test/common/test_inventory_processor.py @@ -1,7 +1,11 @@ +import logging import os from unittest import TestCase, mock from unittest.mock import Mock, mock_open, patch +import pytest +from _pytest.logging import caplog + from splunk_connect_for_snmp.common.inventory_processor import ( InventoryProcessor, InventoryRecordManager, @@ -18,7 +22,8 @@ 0.0.0.0,,2c,public,,,1805,solo_profile1,False,False 0.0.0.0,1161,2c,public,,,1805,solo_profile2,False,False""" - +# TODO: write new test for walkProfile and full walk with flag +@pytest.mark.usefixtures("caplog") class TestInventoryProcessor(TestCase): profiles = { "test5": {"frequency": 6, "varBinds": [["IP-MIB"]]}, @@ -210,7 +215,7 @@ def test_get_group_hosts(self): "delete": "", }, ] - inventory_processor = InventoryProcessor(group_manager, Mock(), Mock()) + inventory_processor = InventoryProcessor(group_manager, Mock()) group_manager.return_element.return_value = [ { "group1": [ @@ -224,9 +229,13 @@ def test_get_group_hosts(self): inventory_processor.inventory_records, group_object_returned ) - def test_get_group_hosts_hostname(self): + # @mock.patch( + # "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + # True, + # ) + @mock.patch("splunk_connect_for_snmp.common.inventory_processor.logger") + def test_get_group_hosts_hostname(self, logger): group_manager = Mock() - logger = Mock() group_object = { "address": "ec2-54-91-99-115.compute-1.amazonaws.com", "port": "", @@ -239,7 +248,7 @@ def test_get_group_hosts_hostname(self): "SmartProfiles": "f", "delete": "", } - inventory_processor = InventoryProcessor(group_manager, logger, Mock()) + inventory_processor = InventoryProcessor(group_manager, Mock()) group_manager.return_element.return_value = [] inventory_processor.get_group_hosts( group_object, "ec2-54-91-99-115.compute-1.amazonaws.com" @@ -250,10 +259,14 @@ def test_get_group_hosts_hostname(self): self.assertEqual(inventory_processor.single_hosts, [group_object]) self.assertEqual(inventory_processor.inventory_records, []) - def test_process_line_comment(self): - logger = Mock() + # @mock.patch( + # "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + # True, + # ) + @mock.patch("splunk_connect_for_snmp.common.inventory_processor.logger") + def test_process_line_comment(self, logger): source_record = {"address": "#54.234.85.76"} - inventory_processor = InventoryProcessor(Mock(), logger, Mock()) + inventory_processor = InventoryProcessor(Mock(), Mock()) inventory_processor.process_line(source_record) logger.warning.assert_called_with( "Record: #54.234.85.76 is commented out. Skipping..." @@ -272,13 +285,13 @@ def test_process_line_comment(self): ) def test_process_line_host(self, m_inventory): source_record = {"address": "54.234.85.76"} - inventory_processor = InventoryProcessor(Mock(), Mock(), Mock()) + inventory_processor = InventoryProcessor(Mock(), Mock()) inventory_processor.get_all_hosts() self.assertEqual(inventory_processor.inventory_records, [source_record]) def test_process_line_group(self): source_record = {"address": "group1"} - inventory_processor = InventoryProcessor(Mock(), Mock(), Mock()) + inventory_processor = InventoryProcessor(Mock(), Mock()) inventory_processor.get_group_hosts = Mock() inventory_processor.process_line(source_record) inventory_processor.get_group_hosts.assert_called_with(source_record, "group1") @@ -307,7 +320,7 @@ def test_ignore_line_host_configured_in_group(self, m_load_element): ] group_manager = Mock() group_manager.return_element.return_value = returned_group - inventory_processor = InventoryProcessor(group_manager, Mock(), Mock()) + inventory_processor = InventoryProcessor(group_manager, Mock()) expected = [ { "address": "0.0.0.0", @@ -351,19 +364,23 @@ def test_ignore_line_host_configured_in_group(self, m_load_element): inventory_processor.get_all_hosts() self.assertEqual(expected, inventory_processor.inventory_records) + @mock.patch( + "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + True, + ) def test_return_walk_profile(self): inventory_profiles = ["walk1", "generic_switch"] - inventory_record_manager = InventoryRecordManager(Mock(), Mock(), Mock()) + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) self.assertEqual( inventory_record_manager.return_walk_profile( self.profiles, inventory_profiles ), - "walk1", + None, ) - def test_return_walk_profile_more_than_one(self): + def test_return_walk_profile_more_than_one_no_enable(self): inventory_profiles = ["walk1", "test_33", "generic_switch"] - inventory_record_manager = InventoryRecordManager(Mock(), Mock(), Mock()) + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) self.assertEqual( inventory_record_manager.return_walk_profile( self.profiles, inventory_profiles @@ -371,9 +388,13 @@ def test_return_walk_profile_more_than_one(self): "test_33", ) + @mock.patch( + "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + True, + ) def test_return_walk_profile_no_walk_in_inventory(self): inventory_profiles = ["generic_switch"] - inventory_record_manager = InventoryRecordManager(Mock(), Mock(), Mock()) + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) self.assertEqual( inventory_record_manager.return_walk_profile( self.profiles, inventory_profiles @@ -381,9 +402,13 @@ def test_return_walk_profile_no_walk_in_inventory(self): None, ) + @mock.patch( + "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + True, + ) def test_return_walk_profile_no_walk_in_config(self): inventory_profiles = ["generic_switch", "walk2"] - inventory_record_manager = InventoryRecordManager(Mock(), Mock(), Mock()) + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) self.assertEqual( inventory_record_manager.return_walk_profile( self.profiles, inventory_profiles @@ -391,22 +416,77 @@ def test_return_walk_profile_no_walk_in_config(self): None, ) + @mock.patch( + "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + True, + ) def test_return_walk_profile_no_config(self): inventory_profiles = ["generic_switch", "walk2"] - inventory_record_manager = InventoryRecordManager(Mock(), Mock(), Mock()) + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) self.assertEqual( inventory_record_manager.return_walk_profile({}, inventory_profiles), None ) + @mock.patch( + "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + True, + ) def test_return_walk_profile_no_config_no_inventory(self): inventory_profiles = [] - inventory_record_manager = InventoryRecordManager(Mock(), Mock(), Mock()) + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) self.assertEqual( inventory_record_manager.return_walk_profile({}, inventory_profiles), None ) + @mock.patch( + "splunk_connect_for_snmp.common.inventory_processor.ENABLE_FULL_WALK", + True, + ) def test_return_walk_profile_no_inventory(self): - inventory_record_manager = InventoryRecordManager(Mock(), Mock(), Mock()) + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) self.assertEqual( inventory_record_manager.return_walk_profile(self.profiles, []), None ) + + def test_return_walk_profile_no_enable(self): + inventory_profiles = ["walk1", "generic_switch"] + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) + self.assertEqual( + inventory_record_manager.return_walk_profile( + self.profiles, inventory_profiles + ), + "walk1", + ) + + def test_return_walk_profile_no_walk_in_inventory_no_enable(self): + inventory_profiles = ["generic_switch"] + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) + self.assertEqual( + inventory_record_manager.return_walk_profile( + self.profiles, inventory_profiles + ), + "WalkProfile", + ) + + def test_return_walk_profile_no_config_no_enable(self): + inventory_profiles = ["generic_switch", "walk2"] + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) + self.assertEqual( + inventory_record_manager.return_walk_profile({}, inventory_profiles), + "WalkProfile", + ) + + def test_return_walk_profile_no_config_no_inventory_no_enable(self): + inventory_profiles = [] + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) + self.assertEqual( + inventory_record_manager.return_walk_profile({}, inventory_profiles), + "WalkProfile", + ) + + def test_return_walk_profile_no_inventory_no_enable(self): + inventory_record_manager = InventoryRecordManager(Mock(), Mock()) + self.assertEqual( + inventory_record_manager.return_walk_profile(self.profiles, []), + "WalkProfile", + )