File: send-trap.py

package info (click to toggle)
python-pysnmp4 7.1.21-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,564 kB
  • sloc: python: 33,654; makefile: 166; javascript: 4
file content (34 lines) | stat: -rw-r--r-- 996 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import asyncio
from pysnmp.hlapi.v3arch.asyncio import *


async def run():
    snmpEngine = SnmpEngine()
    # Example of how you might update sysUpTime
    mibBuilder = snmpEngine.get_mib_builder()
    (sysUpTime,) = mibBuilder.import_symbols("__SNMPv2-MIB", "sysUpTime")
    sysUpTime.syntax = TimeTicks(12345)  # Set uptime to 12345

    errorIndication, errorStatus, errorIndex, varBinds = await send_notification(
        snmpEngine,
        CommunityData("public", mpModel=0),
        await UdpTransportTarget.create(("demo.pysnmp.com", 162)),
        ContextData(),
        "trap",
        NotificationType(
            ObjectIdentity("NET-SNMP-EXAMPLES-MIB", "netSnmpExampleNotification")
        ).add_varbinds(
            ObjectType(
                ObjectIdentity("NET-SNMP-EXAMPLES-MIB", "netSnmpExampleHeartbeatRate"),
                1,
            )
        ),
    )

    if errorIndication:
        print(errorIndication)

    snmpEngine.close_dispatcher()


asyncio.run(run())