Previous Topic: Extension ScriptsNext Topic: Using Extension Variables with Your Management Software


Example Script Test

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

  1. Create a file executable file named /opt/CA/SystemEDGE/debugext.sh with the following information:
    #!/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.

  2. Add the following line to sysedge.cf:
    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.

  3. Enter the following at the command line to create a file named myset.txt:
    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.

  4. Issue the SNMP Set by entering the following:
    ./snmpset -c private -h 127.0.0.1 < myset.txt
    
  5. Retrieve the value of your debugSetString by entering the following:
    ./snmpget -c public -h 127.0.0.1 -o 1.3.6.1.4.1.546.14.1.0
    
  6. Test the setup by entering the following at the command line:
    ./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.