Skip to content

Commit

Permalink
fix: add communities for traps v1 [run-int-tests]
Browse files Browse the repository at this point in the history
  • Loading branch information
ajasnosz committed Dec 12, 2024
1 parent 627addb commit a63b3e1
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 8 deletions.
78 changes: 70 additions & 8 deletions integration_tests/test_trap_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
logger = logging.getLogger(__name__)


def send_trap(host, port, object_identity, mib_to_load, *var_binds):
def send_trap(
host, port, object_identity, mib_to_load, community, mp_model, *var_binds
):
iterator = sendNotification(
SnmpEngine(),
CommunityData("public", mpModel=0),
CommunityData(community, mp_model),
UdpTransportTarget((host, port)),
ContextData(),
"trap",
Expand Down Expand Up @@ -73,7 +75,37 @@ def send_v3_trap(host, port, object_identity, *var_binds):
logger.error(f"{error_indication}")


def test_integration(request, setup_splunk):
def test_trap_v1(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.4.0", OctetString("my contact"))
send_trap(
trap_external_ip,
162,
"1.3.6.1.6.3.1.1.5.2",
"SNMPv2-MIB",
"publicv1",
0,
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_v2(request, setup_splunk):
trap_external_ip = request.config.getoption("trap_external_ip")
logger.info(f"I have: {trap_external_ip}")

Expand All @@ -82,7 +114,14 @@ def test_integration(request, setup_splunk):
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
trap_external_ip,
162,
"1.3.6.1.6.3.1.1.5.2",
"SNMPv2-MIB",
"homelab",
1,
varbind1,
varbind2,
)

# wait for the message to be processed
Expand All @@ -103,7 +142,9 @@ def test_added_varbind(request, setup_splunk):
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)
send_trap(
trap_external_ip, 162, "1.3.6.1.2.1.2.1", "SNMPv2-MIB", "public", 1, varbind1
)

# wait for the message to be processed
time.sleep(2)
Expand All @@ -125,7 +166,15 @@ def test_many_traps(request, setup_splunk):
# send trap
varbind1 = ("1.3.6.1.2.1.1.1.0", OctetString("test_many_traps"))
for _ in range(5):
send_trap(trap_external_ip, 162, "1.3.6.1.2.1.2.1", "SNMPv2-MIB", varbind1)
send_trap(
trap_external_ip,
162,
"1.3.6.1.2.1.2.1",
"SNMPv2-MIB",
"public",
1,
varbind1,
)

# wait for the message to be processed
time.sleep(2)
Expand All @@ -148,7 +197,14 @@ def test_more_than_one_varbind(request, setup_splunk):
varbind1 = ("1.3.6.1.2.1.1.4.0", OctetString("test_more_than_one_varbind_contact"))
varbind2 = ("1.3.6.1.2.1.1.1.0", OctetString("test_more_than_one_varbind"))
send_trap(
trap_external_ip, 162, "1.3.6.1.2.1.2.1", "SNMPv2-MIB", varbind1, varbind2
trap_external_ip,
162,
"1.3.6.1.2.1.2.1",
"SNMPv2-MIB",
"public",
1,
varbind1,
varbind2,
)

# wait for the message to be processed
Expand All @@ -170,7 +226,13 @@ def test_loading_mibs(request, setup_splunk):
# 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
trap_external_ip,
162,
"1.3.6.1.4.1.15597.1.1.1.1",
"SNMPv2-MIB",
"public",
1,
varbind1,
)

# wait for the message to be processed
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ image:
traps:
replicaCount: 1
communities:
1:
- publicv1
2c:
- public
- homelab
Expand Down

0 comments on commit a63b3e1

Please sign in to comment.