def test_modify_frequency_field(self, request, setup_splunk):
     trap_external_ip = request.config.getoption("trap_external_ip")
     profile = {
         "test_modify": {
             "frequency": 7,
             "varBinds": [yaml_escape_list(sq("UDP-MIB"))],
         },
     }
     update_profiles(profile)
     update_file(
         [f"{trap_external_ip},,2c,public,,,600,test_modify,f,t"], "inventory.yaml"
     )
     upgrade_helm(["inventory.yaml", "profiles.yaml"])
     time.sleep(60)
     update_file(
         [f"{trap_external_ip},,2c,public,,,600,test_modify,f,"], "inventory.yaml"
     )
     upgrade_helm(["inventory.yaml", "profiles.yaml"])
     time.sleep(30)
     search_string = """| mpreview index=netmetrics earliest=-30s | search profiles=test_modify frequency=7 """
     result_count, metric_count = run_retried_single_search(
         setup_splunk, search_string, 8
     )
     assert result_count > 0
     assert metric_count > 0
def setup_smart_profiles(request):
    trap_external_ip = request.config.getoption("trap_external_ip")
    logger.info("Integration test for fields smart profiles")
    profile = {
        "smart_profile_field": {
            "frequency": 3,
            "condition": {
                "type": "field",
                "field": "SNMPv2-MIB.sysDescr",
                "patterns": [".*zeus.*"],
            },
            "varBinds": [
                yaml_escape_list(sq("IP-MIB"), sq("icmpOutDestUnreachs"), 0),
                yaml_escape_list(sq("IP-MIB"), sq("icmpOutEchoReps"), 0),
            ],
        }
    }
    update_profiles(profile)
    upgrade_helm(["inventory.yaml", "profiles.yaml"])
    time.sleep(60)
    update_file([f"{trap_external_ip},,2c,public,,,600,,t,"], "inventory.yaml")
    upgrade_helm(["inventory.yaml", "profiles.yaml"])
    time.sleep(30)
    yield
    update_file([f"{trap_external_ip},,2c,public,,,600,,t,t"], "inventory.yaml")
    upgrade_helm(["inventory.yaml"])
    time.sleep(20)
def setup_profiles(request):
    trap_external_ip = request.config.getoption("trap_external_ip")
    profile = {
        "new_profile": {"frequency": 7, "varBinds": [yaml_escape_list(sq("IP-MIB"))]},
        "generic_switch": {
            "frequency": 5,
            "varBinds": [yaml_escape_list(sq("UDP-MIB"))],
        },
    }
    update_profiles(profile)
    upgrade_helm(["profiles.yaml"])
    time.sleep(60)
    update_file(
        [f"{trap_external_ip},,2c,public,,,600,new_profile;generic_switch,,"],
        "inventory.yaml",
    )
    upgrade_helm(["inventory.yaml", "profiles.yaml"])
    time.sleep(30)
    yield
    update_file(
        [f"{trap_external_ip},,2c,public,,,600,new_profile;generic_switch,,t"],
        "inventory.yaml",
    )
    upgrade_helm(["inventory.yaml"])
    time.sleep(20)
def setup_small_walk(request):
    trap_external_ip = request.config.getoption("trap_external_ip")
    profile = {
        "walk1": {
            "condition": {"type": "walk"},
            "varBinds": [yaml_escape_list(sq("IP-MIB"))],
        },
    }
    update_profiles(profile)
    upgrade_helm(["inventory.yaml", "profiles.yaml"])
    time.sleep(60)
    update_file([f"{trap_external_ip},,2c,public,,,20,walk1,f,"], "inventory.yaml")
    upgrade_helm(["inventory.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"])
    time.sleep(20)
 def test_modify_varBinds_field(self, request, setup_splunk):
     trap_external_ip = request.config.getoption("trap_external_ip")
     profile = {
         "test_modify": {
             "frequency": 7,
             "varBinds": [
                 yaml_escape_list(sq("TCP-MIB")),
                 yaml_escape_list(sq("IP-MIB"), sq("icmpOutDestUnreachs"), 0),
                 yaml_escape_list(sq("UCD-SNMP-MIB"), sq("laIndex")),
             ],
         },
     }
     update_profiles(profile)
     update_file(
         [f"{trap_external_ip},,2c,public,,,600,test_modify,f,t"], "inventory.yaml"
     )
     upgrade_helm(["inventory.yaml", "profiles.yaml"])
     time.sleep(60)
     update_file(
         [f"{trap_external_ip},,2c,public,,,600,test_modify,f,"], "inventory.yaml"
     )
     upgrade_helm(["inventory.yaml", "profiles.yaml"])
     time.sleep(20)
     search_string = """| mpreview index=netmetrics earliest=-15s | search profiles=test_modify TCP-MIB """
     result_count, metric_count = run_retried_single_search(
         setup_splunk, search_string, 3
     )
     assert result_count > 0
     assert metric_count > 0
     search_string = """| mpreview index=netmetrics  earliest=-15s | search profiles=test_modify | search icmpOutDestUnreachs """
     result_count, metric_count = run_retried_single_search(
         setup_splunk, search_string, 3
     )
     assert result_count > 0
     assert metric_count > 0
     search_string = """| mpreview index=netmetrics earliest=-20s | search  laIndex | dedup metric_name:sc4snmp.UCD-SNMP-MIB.laIndex """
     result_count, metric_count = run_retried_single_search(
         setup_splunk, search_string, 3
     )
     assert result_count == 3
     assert metric_count == 3
 def test_disable_one_profile_and_reload(self, request, setup_splunk):
     trap_external_ip = request.config.getoption("trap_external_ip")
     logger.info("Integration test for deleting one profile and reloading")
     profile = {
         "new_profile": {
             "frequency": 7,
             "varBinds": [yaml_escape_list(sq("IP-MIB"))],
         }
     }
     update_profiles(profile)
     update_file(
         [f"{trap_external_ip},,2c,public,,,600,new_profile,,"], "inventory.yaml"
     )
     upgrade_helm(["inventory.yaml", "profiles.yaml"])
     time.sleep(70)
     search_string = """| mpreview index=netmetrics| spath profiles | search profiles=generic_switch earliest=-20s """
     result_count, metric_count = run_retried_single_search(
         setup_splunk, search_string, 3
     )
     assert result_count == 0
     assert metric_count == 0
def setup_profile(request):
    trap_external_ip = request.config.getoption("trap_external_ip")
    profile = {
        "generic_switch": {
            "frequency": 5,
            "varBinds": [
                yaml_escape_list(sq("TCP-MIB")),
                yaml_escape_list(sq("IF-MIB"), sq("ifType"), 1),
            ],
        }
    }
    update_profiles(profile)
    upgrade_helm(["profiles.yaml"])
    time.sleep(60)
    update_file(
        [f"{trap_external_ip},,2c,public,,,600,generic_switch,,"], "inventory.yaml"
    )
    upgrade_helm(["inventory.yaml", "profiles.yaml"])
    time.sleep(30)
    yield
    upgrade_helm([f"{trap_external_ip},,2c,public,,,600,generic_switch,,t"])
    time.sleep(20)
def setup_modify_profile(request):
    trap_external_ip = request.config.getoption("trap_external_ip")
    profile = {
        "test_modify": {
            "frequency": 5,
            "varBinds": [yaml_escape_list(sq("UDP-MIB"))],
        },
    }
    update_profiles(profile)
    upgrade_helm(["inventory.yaml", "profiles.yaml"])
    time.sleep(60)
    update_file(
        [f"{trap_external_ip},,2c,public,,,600,test_modify,f,"], "inventory.yaml"
    )
    upgrade_helm(["inventory.yaml", "profiles.yaml"])
    time.sleep(30)
    yield
    update_file(
        [f"{trap_external_ip},,2c,public,,,600,test_modify,f,t"], "inventory.yaml"
    )
    upgrade_helm(["inventory.yaml"])
    time.sleep(20)