After you create an extension script, test it at the command line. The following example creates an OctetString extension on a UNIX system, tests its output, and then uses SNMP to return the value from the script.
To test the script
#!/bin/sh Script=$0 LeafNumber=$1 Operation=$2 SetValue=$3 if [ "$Operation" = "SET" ]; then echo $Script > /tmp/debugext_set.txt echo `date` >> /tmp/debugext_set.txt echo $LeafNumber >> /tmp/debugext_set.txt echo $Operation >> /tmp/debugext_set.txt echo $SetValue >> /tmp/debugext_set.txt echo $SetValue > /tmp/debugext_setvalue.txt #SET VALUE HERE echo $SetValue #You must echo back what was set fi # Override GETNEXT and just do GET if [ "$Operation" = "GETNEXT" ]; then Operation="GET" fi if [ "$Operation" = "GET" ]; then echo $Script > /tmp/debugext_get.txt echo `date` >> /tmp/debugext_get.txt echo $LeafNumber >> /tmp/debugext_get.txt echo $Operation >> /tmp/debugext_get.txt if [ ! -f /tmp/debugext_setvalue.txt ]; then echo "ERROR: do set first... Script:$Script LeafNumber:$LeafNumber Operation:$Operation" exit 0 fi cat /tmp/debugext_setvalue.txt #return SET VALUE fi
Note: This example tests an extension script that is an OctetString. It is valid for UNIX operating systems. On Windows systems, you must call the interpreter in your action script command. For example, enter perl.exe myscript.pl.
extension 1 OctetString ReadWrite /opt/CA/SystemEDGE/debugext.sh
Note: This example tests an extension script that is an OctetString. It is valid for UNIX operating systems. On Windows systems, you must call the interpreter in your action script command. For example, enter perl.exe myscript.pl.
echo "1.3.6.1.4.1.546.14.1.0 04 debugSetString" > myset.txt
You now have a file named myset.txt. You are setting the OctetString(04) “debugSetString” to the OID 1.3.6.1.4.1.546.14.1.0.
./snmpset -c private -h 127.0.0.1 < myset.txt
./snmpget -c public -h 127.0.0.1 -o 1.3.6.1.4.1.546.14.1.0
./debugext.sh 1 SET debugSetString2
This command should return the value as being set as output.
./debugext.sh 1 GET
This command should return the value as set in the earlier SET call.
Copyright © 2013 CA.
All rights reserved.
|
|