Skip to content

Commit 7fc00db

Browse files
author
john
committed
Update example scripts to explicitly use python3.
Also update simple_agent to catch exceptions for invalid test calls.
1 parent 3ed03fb commit 7fc00db

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

examples/run_callback_agent.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ stty -echo
9494

9595
# Now start the callback example agent
9696
echo "* Starting the callback example agent..."
97-
python callback_agent.py -m $TMPDIR/snmpd-agentx.sock -p $TMPDIR/
97+
python3 callback_agent.py -m $TMPDIR/snmpd-agentx.sock -p $TMPDIR/

examples/run_simple_agent.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ stty -echo
9494

9595
# Now start the simple example agent
9696
echo "* Starting the simple example agent..."
97-
python simple_agent.py -m $TMPDIR/snmpd-agentx.sock -p $TMPDIR/
97+
python3 simple_agent.py -m $TMPDIR/snmpd-agentx.sock -p $TMPDIR/

examples/run_simple_agent_trap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ echo ""
160160

161161
# Now start the simple example agent
162162
echo "* Starting the simple example agent..."
163-
python simple_agent_trap.py -m $AGENTX_SOCK -p $TMPDIR/
163+
python3 simple_agent_trap.py -m $AGENTX_SOCK -p $TMPDIR/
164164

165165
# Debug mode
166166
#gdb python -ex "run simple_agent_trap.py -m $AGENTX_SOCK -p $TMPDIR/"

examples/run_threading_agent.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ stty -echo
9292

9393
# Now start the threading agent
9494
echo "* Starting the threading agent..."
95-
python threading_agent.py -m $TMPDIR/snmpd-agentx.sock -p $TMPDIR/
95+
python3 threading_agent.py -m $TMPDIR/snmpd-agentx.sock -p $TMPDIR/

examples/run_threading_agent_trap.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ do
3838
fi
3939
done
4040
if [ -z "$SNMPTRAPD_BIN" ] ; then
41-
echo "snmptrapd executable not found -- net-snmp not installed?"
41+
echo "snmptrapd executable not found -- snmptrapd not installed?"
4242
exit 1
4343
fi
4444

@@ -160,7 +160,7 @@ stty -echo
160160

161161
# Now start the threading agent
162162
echo "* Starting the threading agent..."
163-
python threading_agent_trap.py -m $AGENTX_SOCK -p $TMPDIR/
163+
python3 threading_agent_trap.py -m $AGENTX_SOCK -p $TMPDIR/
164164

165165
# Debug mode
166166
# Remember to comment out 'stty -echo' few lines above

examples/simple_agent.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ def HupHandler(signum, frame):
273273
# handler above changes the "loop" variable.
274274
print("{0}: Serving SNMP requests, send SIGHUP to dump SNMP object state, press ^C to terminate...".format(prgname))
275275

276+
table1Row1Cell3Val = 55
277+
276278
loop = True
277279
while (loop):
278280
# Block and process SNMP requests, if available
@@ -298,24 +300,42 @@ def HupHandler(signum, frame):
298300
#
299301
# As a workaround, Table.setRowColumn(row, col, data) was created to traverse rows from the table each time.
300302
try:
303+
# Incorrect indexing
301304
firstTable.setRowColumn(1, 3, agent.Integer32(555))
302305
except Exception as e:
303306
print('Error from firstTable.setRowColumn: {:}'.format(e))
304307

305-
firstTable.setRowColumn(['aa'], 3, agent.Integer32(444))
308+
# Valid indexing
309+
firstTable.setRowColumn(['ab'], 2, agent.DisplayString('Gotham'))
310+
306311

307-
# Another (better?) solution is to re-retrieve first row to mitigarte memory error
312+
# Another (better?) solution is to re-retrieve first row to mitigate memory error
308313
# Verify likely calling scenarios don't fail:
314+
315+
# The following getRow() calls use incorrect indexing
309316
try:
310317
firstTableRow1 = firstTable.getRow(1)
311318
except Exception as e:
312319
print('Error from firstTable.getRow({:}): {:}'.format(1, e))
313320

314-
firstTableRow1 = firstTable.getRow(agent.DisplayString("aa"))
315-
firstTableRow1 = firstTable.getRow([agent.DisplayString("aa")])
316-
firstTableRow1 = firstTable.getRow(['aa'])
321+
try:
322+
firstTableRow1 = firstTable.getRow(agent.DisplayString("aa"))
323+
except Exception as e:
324+
print('Error from firstTable.getRow(agent.DisplayString("{:}")): {:}'.format("aa", e))
325+
326+
try:
327+
firstTableRow1 = firstTable.getRow([agent.DisplayString("aa")])
328+
except Exception as e:
329+
print('Error from firstTable.getRow([agent.DisplayString("{:}")]): {:}'.format("aa", e))
330+
331+
332+
table1Row1Cell3Val = table1Row1Cell3Val + 1
333+
# Valid Syntaxes:
317334
firstTableRow1 = firstTable.getRow('aa')
318-
firstTableRow1.setRowCell(3, agent.Integer32(77))
335+
firstTableRow1 = firstTable.getRow(['aa'])
336+
337+
firstTableRow1.setRowCell(3, agent.Integer32(table1Row1Cell3Val))
338+
319339

320340
print('-------------- end of update --------------')
321341

0 commit comments

Comments
 (0)