Skip to content

Commit 779944c

Browse files
author
john
committed
Replaced send_trap code with Jan Breuer's pull-request (pief#45) version.
1 parent 7fc00db commit 779944c

File tree

8 files changed

+179
-194
lines changed

8 files changed

+179
-194
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ setup.py: setup.py.in
6666
chmod u+x setup.py
6767

6868
install: setup.py
69-
python setup.py install
69+
python3 setup.py install
7070

7171
.PHONY: ChangeLog
7272
ChangeLog:
@@ -129,13 +129,13 @@ dist/python-netsnmpagent.spec: dist python-netsnmpagent.spec.changelog python-ne
129129
@cat >>$@ python-netsnmpagent.spec.changelog
130130

131131
srcdist: setup.py ChangeLog dist/python-netsnmpagent.spec
132-
python setup.py sdist
132+
python3 setup.py sdist
133133
@echo Created source distribution archive as dist/netsnmpagent-$(VERSION).tar.gz
134134
@echo A suitable RPM .spec file can be found at dist/python-netsnmpagent.spec
135135

136136
upload: setup.py
137137
ifeq ($(TAGGED),1)
138-
python setup.py sdist upload
138+
python3 setup.py sdist upload
139139
else
140140
@echo "Upload not available for untagged versions!"
141141
endif
@@ -154,7 +154,7 @@ rpms: dist srcdist
154154

155155
clean:
156156
@[ -e "*.pyc" ] && rm *.pyc || true
157-
@[ -e setup.py ] && (python setup.py clean; rm setup.py) || true
157+
@[ -e setup.py ] && (python3 setup.py clean; rm setup.py) || true
158158
@[ -e ChangeLog ] && rm ChangeLog || true
159159
@[ -e build ] && rm -rf build || true
160160
@[ -e dist ] && rm -rf dist || true

examples/run_simple_agent_trap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ echo " snmpwalk -v 2c -c public -M+. localhost:5555 SIMPLE-MIB::simpleMIB"
152152
echo " snmptable -v 2c -c public -M+. -Ci localhost:5555 SIMPLE-MIB::firstTable"
153153
echo " snmpget -v 2c -c public -M+. localhost:5555 SIMPLE-MIB::simpleInteger.0"
154154
echo " snmpset -v 2c -c simple -M+. localhost:5555 SIMPLE-MIB::simpleInteger.0 i 123"
155+
echo " snmptrapd -f -Lo localhost:5556"
155156
echo ""
156157

157158
# Workaround to have CTRL-C not generate any visual feedback (we don't do any

examples/run_threading_agent_trap.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ echo ""
152152
echo " cd `pwd`"
153153
echo " snmpwalk -v 2c -c public -M+. localhost:5555 THREADING-MIB::threadingMIB"
154154
echo " snmpget -v 2c -c public -M+. localhost:5555 THREADING-MIB::threadingString.0"
155+
echo " snmptrapd -f -Lo localhost:5556"
155156
echo ""
156157

157158
# Workaround to have CTRL-C not generate any visual feedback (we don't do any

examples/simple_agent_trap.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,28 @@ def HupHandler(signum, frame):
249249
# there is flag set to skip sending trap on next check
250250
if sendTrap:
251251
print('Sending trap with simpleCounter32.value: {:}'.format(simpleCounter32.value()))
252-
trapOid = 'SNMPv2-MIB::sysDescr'
253-
trapData = [
254-
{ 'oid':'SNMPv2-MIB::sysDescr.0', 'val':'test state' },
255-
{ 'oid':'SIMPLE-MIB::simpleCounter32.0', 'val':simpleCounter32.value() },
256-
# { 'oid':'SIMPLE-MIB::simpleCounter64.0', 'val':simpleCounter64.value() },
257-
]
252+
253+
# trapOid = 'SNMPv2-MIB::sysDescr'
254+
# trapData = [
255+
# { 'oid':'SNMPv2-MIB::sysDescr.0', 'val':'test state' },
256+
# { 'oid':'SIMPLE-MIB::simpleCounter32.0', 'val':simpleCounter32.value() },
257+
# # { 'oid':'SIMPLE-MIB::simpleCounter64.0', 'val':simpleCounter64.value() },
258+
# ]
259+
# agent.send_trap(
260+
# oid = trapOid,
261+
# traps = trapData,
262+
# )
263+
264+
simpleUnsignedRO.update(simpleUnsignedRO.value() + 1)
265+
258266
agent.send_trap(
259-
oid = trapOid,
260-
traps = trapData,
261-
)
267+
trap='SIMPLE-MIB::simpleUnsignedROChange',
268+
varlist={
269+
'SNMPv2-MIB::sysDescr.0': agent.DisplayString('System'),
270+
'SIMPLE-MIB::simpleUnsignedRO.0': simpleUnsignedRO,
271+
'SIMPLE-MIB::simpleCounter64.0': simpleCounter64,
272+
}
273+
)
262274
sendTrap = False
263275
else:
264276
sendTrap = True

examples/threading_agent_trap.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def LogNetSnmpMsg(priority, msg):
128128
initval = "<No data available yet>"
129129
)
130130

131+
131132
def UpdateSNMPObjs():
132133
""" Function that does the actual data update. """
133134

@@ -156,13 +157,20 @@ def UpdateSNMPObjs():
156157

157158
# send trap
158159
global agent
160+
159161
trapOid = 'SNMPv2-MIB::sysDescr'
160-
trapData = [
161-
{ 'oid':'SNMPv2-MIB::sysDescr.0', 'val':'test threading agent trap' },
162-
]
163-
agent.send_trap(
164-
oid = trapOid,
165-
traps = trapData,
162+
trapData={
163+
'SNMPv2-MIB::sysDescr.0': agent.DisplayString('test threading agent trap'),
164+
}
165+
166+
# agent.send_trap(
167+
# trap = trapOid,
168+
# varlist = trapData,
169+
# )
170+
171+
agent.queue_trap(
172+
trap = trapOid,
173+
varlist = trapData,
166174
)
167175

168176
LogMsg("Data update done, exiting thread.")
@@ -238,5 +246,9 @@ def AlarmHandler(signum, frame):
238246
elif loop:
239247
LogMsg("net-snmp's check_and_process() returned (res={0}), doing another loop.".format(res))
240248

249+
if agent.num_queued_traps():
250+
LogMsg("Sending {} queued traps.".format(agent.num_queued_traps()))
251+
agent.send_queued_traps()
252+
241253
LogMsg("Terminating.")
242254
agent.shutdown()

0 commit comments

Comments
 (0)