Quickstart
Build and run your first SNMP agent in 5 minutes.
Prerequisites
- Python 3.14+
- Net-SNMP installed and configured
Ubuntu/Debian
sudo apt install snmpd snmp libsnmp-devConfigure snmpd
Enable AgentX in /etc/snmp/snmpd.conf:
# Enable AgentX
master agentx
agentXSocket /var/agentx/masterRestart snmpd:
sudo systemctl restart snmpdCreate Your Agent
my_agent.py
import snmpkit
from snmpkit.agent import Agent, Updater
class SystemInfoUpdater(Updater):
"""Provides system information via SNMP."""
async def update(self):
# OID suffix -> value
self.set_OCTETSTRING("1.0", "My Application")
self.set_OCTETSTRING("2.0", "1.0.0")
self.set_INTEGER("3.0", 42)
async def main():
agent = Agent(agent_id="my-app")
# Register under enterprise OID 1.3.6.1.4.1.12345
agent.register("1.3.6.1.4.1.12345", SystemInfoUpdater())
print("Agent starting...")
await agent.start()
snmpkit.run(main())Run the Agent
pip
python my_agent.pyQuery with snmpwalk
In another terminal:
snmpwalk -v2c -c public localhost 1.3.6.1.4.1.12345Expected output:
iso.3.6.1.4.1.12345.1.0 = STRING: "My Application"
iso.3.6.1.4.1.12345.2.0 = STRING: "1.0.0"
iso.3.6.1.4.1.12345.3.0 = INTEGER: 42Understanding the Code
Agent
agent = Agent(agent_id="my-app")Creates an agent that will connect to /var/agentx/master by default. The agent_id identifies your agent to the master.
Updater
class SystemInfoUpdater(Updater):
async def update(self):
self.set_OCTETSTRING("1.0", "My Application")The update() method is called periodically (default: every 10 seconds). Use set_* methods to provide values:
set_INTEGER(oid, value)- 32-bit signed integerset_OCTETSTRING(oid, value)- String or bytesset_COUNTER32(oid, value)- 32-bit counterset_GAUGE32(oid, value)- 32-bit gaugeset_TIMETICKS(oid, value)- Time in centisecondsset_COUNTER64(oid, value)- 64-bit counterset_IPADDRESS(oid, value)- IPv4 address stringset_OBJECTIDENTIFIER(oid, value)- OID string
Registration
agent.register("1.3.6.1.4.1.12345", SystemInfoUpdater())Registers the updater for the OID subtree. The OID suffixes in set_* calls are appended to this base OID.
The register() method takes an instance, not a class. This lets you pass configuration to your updater’s constructor.
Next Steps
- Updater - Learn all Updater methods
- SET Handler - Handle SNMP SET requests
- Examples - More patterns and use cases
Last updated on