def test_default_profiles_events(self, setup_splunk):
     logger.info("Integration test for sc4snmp:event")
     search_string = """search index=netops | search "IF-MIB.ifAlias" AND "IF-MIB.ifAdminStatus" 
     AND "IF-MIB.ifDescr" AND "IF-MIB.ifName" sourcetype="sc4snmp:event" """
     result_count, metric_count = splunk_single_search(setup_splunk, search_string)
     assert result_count > 0
     assert metric_count > 0
 def test_smart_profiles_base(self, setup_splunk):
     logger.info("Integration test for fields base smart profiles")
     search_string_baseIF = (
         """| mpreview index=netmetrics| spath profiles | search profiles=BaseIF """
     )
     search_string_baseUpTime = """| mpreview index=netmetrics| spath profiles | search profiles=BaseUpTime """
     result_count, metric_count = splunk_single_search(
         setup_splunk, search_string_baseIF
     )
     assert result_count > 0
     assert metric_count > 0
     result_count, metric_count = splunk_single_search(
         setup_splunk, search_string_baseUpTime
     )
     assert result_count > 0
     assert metric_count > 0
 def test_enrich_works_for_IFMIB(self, setup_splunk):
     logger.info("Integration test for enrichment")
     search_string = """| mpreview index=netmetrics | search sourcetype="sc4snmp:metric" 
     | search "metric_name:sc4snmp.IF-MIB*if" 
     | search "ifDescr" AND "ifAdminStatus" AND "ifOperStatus" AND "ifPhysAddress" AND "ifIndex" """
     result_count, metric_count = splunk_single_search(setup_splunk, search_string)
     assert result_count > 0
     assert metric_count > 0
def run_retried_single_search(setup_splunk, search_string, retries):
    for i in range(retries):
        result_count, metric_count = splunk_single_search(setup_splunk, search_string)
        if result_count or metric_count:
            return result_count, metric_count
        logger.info("No results returned from search. Retrying in 2 seconds...")
        time.sleep(2)
    return 0, 0
 def test_poller_integration_event(self, setup_splunk):
     logger.info("Integration test for poller event")
     search_string = (
         """search index="netops" sourcetype="sc4snmp:event" earliest=-5m"""
     )
     result_count, events_count = splunk_single_search(setup_splunk, search_string)
     assert result_count > 0
     assert events_count > 0
def test_loading_mibs(request, setup_splunk):
    trap_external_ip = request.config.getoption("trap_external_ip")
    logger.info(f"I have: {trap_external_ip}")

    time.sleep(2)
    # send trap
    varbind1 = ("1.3.6.1.6.3.1.1.4.1.0", "1.3.6.1.4.1.15597.1.1.1.1.0.1")
    send_trap(trap_external_ip, 162, "1.3.6.1.4.1.15597.1.1.1.1", "SNMPv2-MIB",
              varbind1)

    # wait for the message to be processed
    time.sleep(2)

    search_query = """search index=netops "SNMPv2-MIB.snmpTrapOID.value"="AVAMAR-MCS-MIB::eventTrap"  """

    result_count, events_count = splunk_single_search(setup_splunk,
                                                      search_query)

    assert result_count == 1
def test_added_varbind(request, setup_splunk):
    trap_external_ip = request.config.getoption("trap_external_ip")
    logger.info(f"I have: {trap_external_ip}")

    time.sleep(2)
    # send trap
    varbind1 = ("1.3.6.1.2.1.1.1.0", OctetString("test_added_varbind"))
    send_trap(trap_external_ip, 162, "1.3.6.1.2.1.2.1", "SNMPv2-MIB", varbind1)

    # wait for the message to be processed
    time.sleep(2)

    search_query = (
        """search index="netops" "SNMPv2-MIB.sysDescr.value"="test_added_varbind" """
    )

    result_count, events_count = splunk_single_search(setup_splunk,
                                                      search_query)

    assert result_count == 1
def test_integration(request, setup_splunk):
    trap_external_ip = request.config.getoption("trap_external_ip")
    logger.info(f"I have: {trap_external_ip}")

    time.sleep(2)
    # send trap
    varbind1 = ("1.3.6.1.6.3.1.1.4.3.0", "1.3.6.1.4.1.20408.4.1.1.2")
    varbind2 = ("1.3.6.1.2.1.1.1.0", OctetString("my system"))
    send_trap(trap_external_ip, 162, "1.3.6.1.6.3.1.1.5.2", "SNMPv2-MIB",
              varbind1, varbind2)

    # wait for the message to be processed
    time.sleep(2)

    search_query = """search index="netops" sourcetype="sc4snmp:traps" earliest=-1m
                     | head 1"""

    result_count, events_count = splunk_single_search(setup_splunk,
                                                      search_query)

    assert result_count == 1
def test_trap_v3(request, setup_splunk):
    trap_external_ip = request.config.getoption("trap_external_ip")
    create_v3_secrets()
    update_file(["- secretv4"], "traps_secrets.yaml")
    upgrade_helm(["traps_secrets.yaml"])
    logger.info(f"I have: {trap_external_ip}")
    wait_for_pod_initialization()
    time.sleep(15)
    # send trap
    varbind1 = ("1.3.6.1.2.1.1.4.0", OctetString("test_trap_v3"))
    send_v3_trap(trap_external_ip, 162, "1.3.6.1.2.1.1.0", varbind1)

    # wait for the message to be processed
    time.sleep(2)

    search_query = (
        """search index=netops "SNMPv2-MIB.sysContact.value"="test_trap_v3"  """
    )

    result_count, events_count = splunk_single_search(setup_splunk,
                                                      search_query)

    assert result_count == 1
 def test_poller_integration_metric(self, setup_splunk):
     logger.info("Integration test for poller metric")
     search_string = "| mcatalog values(metric_name) where index=netmetrics AND metric_name=sc4snmp.* earliest=-5m"
     result_count, metric_count = splunk_single_search(setup_splunk, search_string)
     assert result_count > 0
     assert metric_count > 0