Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Latest commit

 

History

History
80 lines (61 loc) · 2.45 KB

README.rst

File metadata and controls

80 lines (61 loc) · 2.45 KB

snormpy

A utility library for easier use of pysnmp4.

Utility functions

snormpy.add_mib_path(path)

This function adds a directory to the internal MIB search path.

snormpy.load_mibs(*modules)

This function loads one or more pysnmp-format MIBs. Beware that these are not standard MIB files, see libsmi2pysnmp(1), smidump(1) and build-pysnmp-mib(1) for all the details.

snormpy.nodeinfo(oid)

Returns a tuple with symbolic name information for the given object id.

snormpy.nodename(oid)

Returns the symbolic name for the object id.

snormpy.nodeid(name)

Returns the node id for the name as a tuple of integers.

The SnormpyClient class

This class wraps arround pysnmp's cmdgen.CommandGenerator to make it easier to address a SNMP agent.

snormpy.SnormpyClient(host, communities)

The constructor takes a hostname/ip address and a list of community info dicts. These dicts can have the following keys:

name
The security name to use. Almost always ignored, defaults to snormpy
community
The snmp community to use, defaults to public
version
The snmp version to use. Should be snormpy.V1 or snormpy.V2C (default)
port
The port the snmpd should listen on, defaults to 161

All communities in the list are tried until one succeeds. If none succeed, the created instance will have the 'alive' attribute set to False and should not be used.

snormpy.SnormpyClient.get(oid)

Takes a named oid, queries the server and returns the value of that oid on the server.

snormpy.SnormpyClient.set(oid, value)

Takes a named oid, queries the server and sets the value of that oid on the server to the given value.

snormpy.SnormpyClient.gettable(oid)

Takes a named oid, walks that table and returns a list of (oid, value) pairs in that table

snormpy.SnormpyClient.matchtables(index, tables)

Fetches all tables listed in tables and combines returned values according to the index table. If index is None, the index will be autogenerated from the tail of the table OID's. For example, to collect network interface data, one can use:

matchtables('IF-MIB::ifIndex', ('IF-MIB::ifDescr', 'IF-MIB::ifPhysAddress', 'IF-MIB::ifOperStatus'))