Device details report¶
The device-report helper collects the standard objects from the
SNMPv2-MIB::system group and walks SNMPv2-MIB::sysORTable in one
operation. It returns a DeviceReport containing:
description(sysDescr.0)vendor_oid(sysObjectID.0)uptime(sysUpTime.0, in centiseconds)contact,name,locationandservicesimplemented_mibs, a list ofSysOREntryrows
Unavailable scalar objects are represented by None. The table walk is
bounded to the four sysORTable columns, so objects following the table in
the agent’s MIB view are never reported as capabilities.
Asynchronous use¶
The asyncio API returns the report directly from a coroutine:
"""
Device report
+++++++++++++
Query a device via SNMP and print a structured report of its system
information, including description, vendor OID, uptime, contact, name,
location, services, and implemented MIB modules (sysORTable).
Functionally similar to:
| $ snmpget -v2c -c public demo.pysnmp.com SNMPv2-MIB::sysDescr.0 \\
SNMPv2-MIB::sysObjectID.0 SNMPv2-MIB::sysUpTime.0
| $ snmpwalk -v2c -c public demo.pysnmp.com SNMPv2-MIB::sysORTable
""" #
import asyncio
from pysnmp.hlapi.asyncio import (
CommunityData,
ContextData,
SnmpEngine,
UdpTransportTarget,
get_device_report,
)
async def run():
report = await get_device_report(
SnmpEngine(),
CommunityData("public"),
UdpTransportTarget(("demo.pysnmp.com", 161)),
ContextData(),
)
print("=== Device Report ===")
print(f"Description : {report.description}")
print(f"Vendor OID : {report.vendor_oid}")
print(f"Uptime : {report.uptime} centiseconds")
print(f"Contact : {report.contact}")
print(f"Name : {report.name}")
print(f"Location : {report.location}")
print(f"Services : {report.services}")
if report.implemented_mibs:
print("\nImplemented MIBs (sysORTable):")
for mib in report.implemented_mibs:
print(f" [{mib.index}] {mib.or_id}")
print(f" {mib.or_descr}")
print(f" uptime: {mib.or_uptime}")
else:
print("\nNo sysORTable entries found.")
asyncio.run(run())
Synchronous use¶
The default pysnmp.hlapi facade provides the same operation as a
blocking function:
from pysnmp.hlapi import (
CommunityData,
ContextData,
SnmpEngine,
UdpTransportTarget,
get_device_report,
)
report = get_device_report(
SnmpEngine(),
CommunityData("public"),
UdpTransportTarget(("demo.pysnmp.com", 161)),
ContextData(),
)
print(report.name, report.vendor_oid)
The helper uses GETNEXT for sysORTable so the same API works with SNMPv1,
SNMPv2c and SNMPv3 credentials. The legacy spelling getDeviceReport is
retained as an alias.
API reference¶
- async pysnmp.hlapi.asyncio.get_device_report(snmpEngine: Any, authData: Any, transportTarget: Any, contextData: Any, **options: Any) DeviceReport¶
Query standard system objects and
sysORTablefrom an SNMP agent.Unavailable scalar objects are represented by
None. Transport and protocol errors also produce a partial report rather than raising.lookupMibis passed through to the underlying HLAPI commands.
- class pysnmp.hlapi.DeviceReport(description: str | None, vendor_oid: str | None, uptime: int | None, contact: str | None, name: str | None, location: str | None, services: int | None, implemented_mibs: list[SysOREntry])¶
Structured device details gathered from SNMPv2-MIB.
Create new instance of DeviceReport(description, vendor_oid, uptime, contact, name, location, services, implemented_mibs)
- implemented_mibs: list[SysOREntry]¶
Alias for field number 7