Skip to content

Conversation

j123b567
Copy link
Contributor

@j123b567 j123b567 commented Sep 9, 2020

Inspired by #22 but done completely differently. It is not using pdu so it is not affected by incompatibility introduced in Net-SNMP v5.8.

Function parameters are different and simplified. You can just send numeric trap for SNMPv1 or OID trap for SNMPv2c and SNMPv3.

Actual version of the trap is configured via snmpd.conf.

Variables are not send by raw values but must be encapsulated in variable type. This help serializing with already defined code.

To send trap, you can reuse already registred variables

simpleUnsignedRO = agent.Unsigned32(
	oidstr   = "SIMPLE-MIB::simpleUnsignedRO",
	writable = False
)

...

agent.send_trap(
	trap='SIMPLE-MIB::simpleUnsignedROChange',
	varlist={
		'SIMPLE-MIB::simpleUnsignedRO.0': simpleUnsignedRO,
	}
)

Or send completely unrelated new value

agent.send_trap(
	trap='SIMPLE-MIB::simpleUnsignedROChange',
	varlist={
		'SIMPLE-MIB::simpleUnsignedRO.0': agent.Unsigned32(123456),
	}
)

Function read_objid is extracted, because it is used many times. This function can handle correctly numeric OID representations like ".1.3.6.1.2.1.1.3.0" so there is no need to reimplement this in python. This is the reason, why this part is heavily simplified.

jbize pushed a commit to jbize/python-netsnmpagent that referenced this pull request Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant