forked from etingof/pysnmp
-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
384 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from pysnmp.hlapi.asyncio import * | ||
|
||
@pytest.mark.asyncio | ||
async def test_send_notification(): | ||
snmpEngine = SnmpEngine() | ||
errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( | ||
snmpEngine, | ||
CommunityData('public', mpModel=0), | ||
UdpTransportTarget(('demo.pysnmp.com', 162)), | ||
ContextData(), | ||
"trap", | ||
NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")).addVarBinds( | ||
("1.3.6.1.6.3.1.1.4.3.0", "1.3.6.1.4.1.20408.4.1.1.2"), | ||
("1.3.6.1.2.1.1.1.0", OctetString("my system")), | ||
), | ||
) | ||
assert errorIndication is None | ||
assert errorStatus == 0 | ||
assert errorIndex == 0 | ||
assert varBinds == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from pysnmp.hlapi import * | ||
from pysnmp.hlapi.asyncio.ntforg import sendNotification | ||
from pysnmp.hlapi.asyncio.transport import UdpTransportTarget | ||
from pysnmp.proto.errind import RequestTimedOut | ||
|
||
@pytest.mark.asyncio | ||
async def test_send_v3_inform_notification(): | ||
errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( | ||
SnmpEngine(), | ||
UsmUserData('usr-md5-des', 'authkey1', 'privkey1'), | ||
UdpTransportTarget(('demo.pysnmp.com', 162)), | ||
ContextData(), | ||
'inform', | ||
NotificationType( | ||
ObjectIdentity('1.3.6.1.6.3.1.1.5.2') | ||
).addVarBinds( | ||
('1.3.6.1.2.1.1.1.0', OctetString('my system')) | ||
) | ||
) | ||
|
||
assert isinstance(errorIndication, RequestTimedOut) | ||
assert errorStatus == 0 | ||
assert errorIndex == 0 | ||
assert varBinds == [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
SNMPv1 | ||
++++++ | ||
Send SNMP GET request using the following options: | ||
* with SNMPv1, community 'public' | ||
* over IPv4/UDP | ||
* to an Agent at demo.pysnmp.com:161 | ||
* for an instance of SNMPv2-MIB::sysDescr.0 MIB object | ||
* Based on asyncio I/O framework | ||
Functionally similar to: | ||
| $ snmpgetnext -v1 -c public demo.pysnmp.com SNMPv2-MIB::sysDescr.0 | ||
"""# | ||
import asyncio | ||
import pytest | ||
from pysnmp.hlapi.asyncio.slim import Slim | ||
from pysnmp.smi.rfc1902 import ObjectIdentity, ObjectType | ||
|
||
@pytest.mark.asyncio | ||
async def test_v1_next(): | ||
slim = Slim(1) | ||
errorIndication, errorStatus, errorIndex, varBinds = await slim.next( | ||
'public', | ||
'demo.pysnmp.com', | ||
161, | ||
ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), | ||
) | ||
|
||
assert errorIndication is None | ||
assert errorStatus == 0 | ||
assert errorIndex == 0 | ||
assert len(varBinds) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[tox] | ||
envlist = py37, py38, py39, py310, py311, py312 | ||
|
||
[testenv] | ||
deps = | ||
pytest | ||
pytest-asyncio | ||
commands = | ||
pytest tests |