Native Python AgentX client implementation to extend SNMP agents
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Looking for a New Maintainer

Please contact me if you are interested on maintaining the package!

Python AgentX Implementation

"pyagentx" is pure Python implementation of AgentX protocol (RFC 2741), it will allow you to extend SNMP agent (snmpd) by writing AgentX subagents, without modifying your original SNMP agent.

[RFC 2741: Agent Extensibility (AgentX) Protocol Version 1] (


Currently the code is capable of the following:

  • Open a session with AgentX master, e.g. net-snmpd snmpd, and register a new session.
  • Send Ping request.
  • Register multiple MIB regions.
  • Multiple MIB update classes with custom frequency for each.
  • Support snmpset operations.
  • Reconnect/Retry to master, in case the master restarted.


The package is registered on Python Package Index under the name "pyagentx"

You can install it by simply running:

pip install pyagentx

SNMP Agent Configuration

You need to make sure the SNMP agent (snmpd) will act as AgentX master:

master          agentx

Also make sure the SNMP agent accept requests for your MIB region:

view   systemview  included   .

NOTE: You need to change the OID to reflect your own OID.

Minimal Agent

To implement agent you need to provide one "Agent" class and one or more "Updater" classes, a sample code:

import pyagentx

# Updater class that set OID values
class NetSnmpPlaypen(pyagentx.Updater):
    def update(self):
        self.set_INTEGER('1.0', 1000)
        self.set_OCTETSTRING('3.0', 'String for NET-SNMP-EXAMPLES-MIB')

class MyAgent(pyagentx.Agent):
    def setup(self):
        # Register Updater class that responsd to
        # the tree under "netSnmpPlaypen":
        self.register('', NetSnmpPlaypen)

# Main
    a = MyAgent()
except Exception as e:
    print "Unhandled exception:", e
except KeyboardInterrupt:

To test:

snmpwalk -v 2c -c public localhost NET-SNMP-MIB::netSnmpPlaypen

Example Agent

To test the implementation I wrote an example agent that implement small parts of NET-SNMP-EXAMPLES-MIB including a table.

To run the sub agent:

sudo ./

Then from another terminal query the master SNMP agent.

Scalar example:

$ snmpwalk -v 2c -c public localhost NET-SNMP-EXAMPLES-MIB::netSnmpExampleScalars
NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 = INTEGER: 1000

Table example:

$ snmptable -v 2c -c public -Ci localhost NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable 

   index nsIETFWGChair1 nsIETFWGChair2
"group1"     "member 1"     "member 2"
"group2"     "member 1"     "member 2"

SNMP Set example:

$ snmpset -v 2c -c public localhost NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 i 10
# pass without errors, if not check snmpd.conf permissions

$ snmpset -v 2c -c public localhost NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger.0 i 200
# wrongValue error

$ snmpset -v 2c -c public localhost NET-SNMP-EXAMPLES-MIB::netSnmpExampleString.0 s "Test"
# notWritable error


What OID should I use for my agent?

If you are just playing and experminting you can put everything under "NET-SNMP-MIB::netSnmpPlaypen" OID "" tree, but you shouldn't use it for any public work.

If you need to publish your work you should apply for your own enterprise OID on the IANA PEN Application page, this will give you your own private tree, e.g. Net-Snmp uses, Google uses

So your company would have an OID

You also need to write your own MIB to allow your customer to use in thier Network Managment System (NMS):

Is there other ways to extend SNMP agent?

Some SNMP agents can be extended using many mechanisms, e.g. net-snmp can be extended using:

  • running external commands (exec, extend, pass)
  • loading new code dynamically (embedded perl, dlmod)
  • communicating with other agents (proxy, SMUX, AgentX)

Check "EXTENDING AGENT FUNCTIONALITY" in snmpd.conf man page for more details.

What's the difference between AgentX, SMUX and proxied SNMP?

Check the answer here

What is advatages of extending SNMP using agentx instead of something like "pass_perssist"?

I started pyagentx because I couldn't write a DateAndTime value using "pass_perssist" which can't handle binary data very well.

Another important reason is the decouple of master SNMP agent and its sub agents, which means you can start/stop one without affecting the other, and you don't have to change the snmpd.conf every time you want to add or remove a sub agent.

Why do I need sudo to run my agentx agent?

By default "snmpd" uses UNIX socket to communicate with agentx sub agents, it uses special permisssions to prevent unauthorized agents.

If you don't want to use "root" to run the agent you can use "agentXPerms" directive in snmpd.conf, check the man page for its options.

My agent connected to the master but I couldn't get result with snmpwalk?

First make sure you can get result from the agent, try something basic:

snmpwalk -v 2c -c public localhost .

If the command doesn't return anything double check your agent community and Access List.

If it works on standard OIDs but it doesn't work on your sub agent, make sure you include the correct OID view:

view   systemview  included   . 

How can I test it on Mac OSX?

SNMP agent from net-snmp is already installed on OSX, but first you need to load it:

sudo launchctl load -w /System/Library/LaunchDaemons/

Then you can start and stop it with these commands:

sudo launchctl start
sudo launchctl start

configuration file can be found on the default location "/etc/snmp/snmpd.conf".