Subagent

Subagent is a real SNMP Agent based on Twisted SNMP. It configures its own OIDs and listen for SNMP requests on configured port.

Most often this is a subagent contacted through a main SNMP agent configured with the proxy directive

subagent.createAgent(reactor, base_oid, regex_list, port=8001, host='127.0.0.1')

Initialize SNMP Agent.

Fill some OIDs of mib2.system with this SNMP Agent info. Then set additional OIDs with functions to retrieve specific regex attributes.

OIDs exposed are base_oid + “.” + one of the following indexes + <index of regex in regex_list + 1>:

  • 1 –> name (== label) as configured in regex_list
  • 2 –> regex as configured in regex_list
  • 3 –> exit_if_matched as configured in regex_list
  • 4 –> last_matched
  • 5 –> value (counter32: how many times regex matched)

In the end create the Agent object and let the reactor listen to specific UDP port for SNMP requests

Returns agent:created agentObject
Exceptions twisted_error.cannotlistenerror:
 if port is not available
subagent.main(reactor, regex_list, port=8001, host='0.0.0.0')

Initialize rector.

Parameters:
  • reactor (twisted.internet.reactor) – reactor to bound events to
  • regex_list (regex.RegexDictList) – regular expressions global registry
  • port (int) – port to bind syslog handler to (default = 8000)
  • host (string (ip address)) – ip address to bind syslog handler to (default = 0.0.0.0)
Returns None:
subagent.sysUpTime(oid, storage)
Determine uptime for our service in time-ticks
subagent.get_regex_by_oid(regex_list, oid)

Given an OID, retrieve regex object in regex_list

Parameters:
  • regex_list (regex.RegexDictList instance) – regular expression ordered dict as initialized in main program
  • oid (list compatible) – OID which holds index of regex in regex_list
Returns:

an instance of regex.BaseRegex

subagent.get_name(regex_list, oid, storage)

Retrieve regex label by oid

Returns:string
subagent.get_regex(regex_list, oid, storage)

Retrieve regex string by oid

Returns:string
subagent.get_exit_if_matched(regex_list, oid, storage)

Retrieve regex exit_if_matched flag status by oid

Returns:int
subagent.get_last_matched(regex_list, oid, storage)

Retrieve regex last_matched timestamp by oid

Returns:int
subagent.get_value(regex_list, oid, storage)

Retrieve regex match counter value by oid

Returns:pysnmp.proto.rfc1902.Counter32 instance

Previous topic

Syslog handler

Next topic

Regular expression management

This Page