Configuring Behavior

 



 

Overview

 

The most important part of the simulation is to set up the simulated environment. You can set up the desired environment by defining the behavior of the device, so that it will behaves like a real device. The behavior of devices is done through Jython scripts. For example, device values can be changed, rows can be dynamically added or deleted, Traps and Informs can be configured to be sent etc.

 

AdventNet Simulation Toolkit provides a ScriptInterface, which defines methods to perform simple operations, such as update, insert, and delete from a JPython script . The javadocs of the script API methods is provided in SNMP_TL1_SimScrIntf.html under the <simulator home>/examples/javadocs directory.

 

Enabling/Disabling Behavior Service

 

The SNMP Agent Simulator provides option to enable/disable the execution of  behavior scripts configured in the simulator, at agent runtime. If  behavior service is disabled, the agent will not check for script configurations before sending the response. Hence, you can use this option to improve the performance of the SNMP agent, if behavior scripts are not required to be executed.

 

By default, the service is enabled and the behavior scripts configured (if any), will be executed.  To disable the service,

Note: The options in the Initialize Services dialog will be disabled when the SNMP agent is started.

 

 

Configuring Behavior

 

The SNMP Agent Simulator provides an intuitive UI to configure Behavior scripts. To invoke the Behavior dialog, do the following :

The Configure Behavior dialog will list the configured scripts files and the defined conditions and actions to execute the script files. You can configure new Behavior, modify or delete an existing Behavior configuration, add new conditions and actions and modify existing conditions and actions, from this dialog.

 

Steps in Configuring Behavior

 

Step I : Configuring the Conditions to Execute the Script : Here, you will define when the script should be executed. Scripts can be executed based on three conditions. Scripts can be executed based on a request, based on a threshold condition and value, or timer based.

 

Step 2 and Step 3 is used for generating the script file from the UI, with the necessary actions to be executed and the conditions to execute the actions (if any). The conditions and actions are defined using the Script API methods.

 

Note:

 

Defining Step 2 and Step 3 is not required in the following cases
  • If you have defined your own script file with necessary conditions and actions, you can configure this script file in step 1 and can Finish 'Behavior Configuration'.

  • If your scope for defining the conditions and actions is beyond the current scope of our API , you have to write your own script. Configure this script file in step 1 and Finish 'Behavior Configuration'.

  • If you want to configure the script file available in the ./examples directory, you can specify this file in Step 1 and Finish 'Behavior Configuration'.

In all the above cases, the conditions and actions defined in the script file will be executed only when the condition to execute the script (specified in step 1) is satisfied.

 

Step 2 : Configuring the Conditions to Execute the Actions : In this step, you can define on what conditions the actions are to be executed. You can define any number of conditions.

 

Step 3 : Configuring the Actions to be Executed : In this step, you can define the actions to be executed, when the condition to execute the script and the condition to execute the action (if any) are satisfied.

 

Step 1: Configuring the Conditions to Execute the script

 

To configure conditions to execute the script, select the Add button in the Behavior Configuration dialog. Select any of the following conditions and configure the necessary details on the right-side of the dialog.

Request-Based Script

    1. Choose the Request Based icon that is displayed on the left of the wizard.

    2. Select the MIB node and instance based on which behavior will be configured.

    3. The name of the selected MIB node will be displayed as the script filename. You can also browse and select the required file, if it already exists.

    4. The option Copy script file to local directory will be enabled only if you browse and select the script file from the <Simulator_Home>/examples/scripting/snmp directory. Selecting this option will copy the script file into your configuration directory.

    5. To execute the script, one or more of the following conditions must be satisfied :

    6. Click Next in the wizard to proceed to Step 2 or click Finish to finish Behavior configuration and exit the dialog.

Threshold-Based Script

    1. Choose the Threshold Based icon that is displayed on the left of the wizard.

    2. Threshold based scripts can be configured only for leaf nodes. Select the leaf node and instance based on which behavior will be configured.

    3. The name of the selected node will be displayed as the script filename. You can also browse and select the required file, if it already exists.

    4. If you want the script to be copied on to the device directory, you can check the option Copy script file to local directory.

    5. To execute a script, you can specify any one of the following threshold conditions and value. When the condition and value is satisfied, the script will be executed.

    1. Specify the threshold value. For custom range, the lower threshold value and higher threshold value must be specified.

    2. Click Next in the wizard to proceed to Step 2 or click Finish to finish Behavior configuration and exit the dialog.

Timer-Based Script

    1. Choose the Timer Based icon that is displayed on the left of the wizard.

    2. The name of the script file will be displayed, based on the time specified to execute the script. You can also browse and select the required file, if it already exists.

    3. If you want the script to be copied on to the device directory, you can check the option Copy script file to local directory.

    1. You can specify when you want the scripts to get executed. The following options are provided:

    1. Specify a time interval between each script execution . Eg. Timer interval 1000 millisecs.

    2. The number of times you want the script to execute at the specified time. Eg: Number of times 5.

    3. Click Next in the wizard to proceed to Step 2 or click Finish to finish Behavior configuration and exit the dialog.

Example : You have configured Number of Times as 10 with a Timer Interval of 2 seconds and have chosen to periodically send it once in every 5 days. This configuration will execute the script 10 times with a time interval of 2 seconds, once in 5 days.

 

Step 2 : Configuring the Conditions to Execute the Action

 

In this step, you can define on what conditions you want the actions defined in the scripts to be executed. You can define any number of conditions.

    1. Click Add button that brings up the Configure Condition to be Checked dialog. This dialog displays all the methods available for the selected node.

    2. Select the desired method , for example, getCurrentInstance. The methods that start with getCurrent are applicable only to the selected agent. When you select these methods, the condition that you are specifying is for the agent. When you select other methods, such as getNodeValue, this is valid for all the network elements. You will see the select OID enabled and network elements listed in the drop-down box .

    3. Select the agent from the network and specify the OID and instance, if you wish to configure behavior across the network.

    4. Select the operator from the drop-down box. The list of operators are listed as follows :

Equal to ==

Not equal to !=

Lesser than <

Greater than >

Lesser than or equal to <=

Greater than or equal to >=

    1. After choosing the operator, you can specify the value to which the expression should be equated to.

    2. Click OK. You will see that the conditions that you have specified get added to the Conditions to execute actions list.

    3. Click Add to define another condition, (or) click Next to proceed to Step 3, or click Finish to finish Behavior configuration and exit the dialog.

    4. As already mentioned, you can specify as many conditions as you want . Hence you have to specify whether you want to

Step 3 : Configuring the Actions to be Executed

 

In this step, you can configure the actions to be performed when the condition to execute the script and the condition to execute the action (if any) are satisfied. Click Add to bring up the Configure Actions to be Performed dialog. Select a method from the drop-down list. Methods are listed below :

Update Value

        1. Select the update value method .

        2. When simulating behavior of devices across a network, the agents in the network are listed in the drop-down list. When you select the agent, the value will be updated in the specified agent.

        3. Select the OID and instance on which it should be updated. When selecting the OID and the instance, the details of the nodes are displayed.

        4. The syntax of the node is displayed along with the simulation type. You can choose the simulation type the node should have, and specify values for the simulation type.

        5. Click OK to add the action to the list.

          Example

          If you select the OID .1.3.6.1.2.1.1.6, the syntax would be Display String. The options that you have with this node are constant and random. If you choose the random option , you will see the range button being enabled. Specify value and click Add so that the value will be associated at random.

Get Node Value

        1. Select the GetNode value from the drop-down list.

        2. When simulating behavior of devices across a network, the agents in the network will be listed in the drop-down list. You will be able to select agent from the network.

        3. Select the OID and the instance.

        4. Now you have to specify a variable in the field that is displayed at the right corner.

        5. The value of the selected OID will get updated in the specified variable.

        6. Click OK for the action to be added to the list.

Insert Row To a Table :

        1. Select Insert Row to a table from the drop down list.

        2. When simulating behavior of devices across a network, the agents in the network will be listed in the drop-down list. You will be able to select agent from the network.

        3. Select a Table node and instance to insert row into the table.

        4. Click Add to add a row. ; You will see dialog coming up with details that contain

          • Column name

          • Simulation Type

          • Value

        5. You can make the desired changes to the row entries.

        6. Click OK to insert the selected row when the script is executed.

Delete a Row From Table.

        1. Select delete row from the table from the drop down list.

        2. When simulating behavior of devices across a network, the agents in the network will be listed in the drop down list. You will be able to select agent from the network.

        3. Specify the table OID and instance, that you want to delete from the table.

        4. Click Ok to delete table

Delete All Rows From Table

        1. Select delete all rows from the table from the drop-down list.

        2. When simulating behavior of devices across a network, the agents in the network will be listed in the drop-down list. You will be able to select agent from the network.

        3. Specify the table OID and instance. All rows from the specified table node will be deleted.

        4. Click OK.

Send Trap

 

There are three trap versions available :Sending a V1 trap, Sending a V2 trap and Sending a V3 trap.

 

Sending V1 Trap

        1. Select trap type as snmp V1.

        2. Manager name : Specify the manager name. by default it is given as localhost.

        3. Manager port : The port at which the manager is running. by default it is 162.

        4. The community string is set to public by default.

        5. You can choose from the generic types available.

          • Cold start

          • Warm start

          • Link down

          • Link up

          • Authentication failure

          • EgpNeighborloss

          • Enterprise specific : On selecting the enterprise specific type, you should also specify specific type for the trap.

        6. Specify the enterprise OID for this trap if the Generic type is Enterprise specific

Sending a V2c Trap

        1. Select trap type as snmp V2c.

        2. Manager name : Specify the manager name. by default it is given as localhost.

        3. Manager port : The port at which the manager is running. by default it is 162.

        4. The community string is set to public by default.

        5. Specify the SNMP Trap OID and click OK.

Sending a V3 Trap

        1. Select trap type as SNMP V3

        2. Manager name : Specify the manager name. by default it is given as localhost.

        3. Manager port : The port at which the manager is running. by default it is 162.

        4. The community string is set to public by default.

        5. You to provide a User name and Context Name for the snmp v3 trap. By default the values are provided User name has the value No Auth priv   and context name has the value No Auth.

        6. You can specify the trap OID.

        7. Click ok.

        Note: When you configure a Timer based SNMP V3 trap, the trap will be sent regardless of the manager's presence. You need the User name and the context name only to receive the traps. But when the SNMP v3 trap is configured as request based, the trap will not be sent unless the request is generated from the manager with the user name and context name.

 

 

Send Inform

        1. Select send inform from the drop-own list.

        2. Manager name : Specify the manager name. By default, it is given as localhost.

        3. Manager port : The port at which the manager is running. By default, it is 162.

        4. The community string is set to public by default.

        5. You have to specify the SysupTime and Enterprise OID.
          Example: SysupTime can take value of 1101101 and Enterprise OID can have take a value like 1.3.6.1.2162.2.1.1

Generate Random Numbers

 

To generate random numbers, specify minimum value and a maximum value so that random numbers will be generated within the specified range.

 

Minimum value can be 100 and maximum value can 200; random numbers will be generated within this range.

 

Delay action :

 

You can introduce a delay in the action. Specify the value in milliseconds and the script execution will be delayed by the specified time.

 

Terminate operation

 

This action can be configured before a GET/GETNEXT/SET. It will terminate the ongoing operation and send the corresponding error message specified. The error message can be specified from the drop down box. You can choose any one of the following error types.

        • tooBig

        • noSuchObject

        • noSuchInstance

        • endOfMibView

        • badvalue

        • readOnly

        • genErr

        • noAccess

Modifying and Deleting Script

 

To modify a script

To delete a script

Modifying and Deleting Condition for Action

 

If you require to change an existing condition.

You can delete a condition if it is no longer required.

Modifying and Deleting Action to Be Executed

 

To modify an action

To delete an action

Scripts in Examples Directory

 

1. DeleteAllRows.py

 

The script file uses the scriptAPI method deleteAllRows to delete all the entries in the ifTable. It takes the tableEntryOID as input.

 

Format :

    scriptinterface.deleteAllRows(String tableEntryOid)

2. DeleteRow.py

 

This script file uses the scriptAPI method deleteRow to delete the first entry in the ifTable.  It takes the tableEntryOID and the instance of the entry to be deleted, as input.

 

Format :

    scriptinterface.deleteRow(String tableEntryOid,String instance)

where

 

tableEntryOid is the Object Id of the table entry node

instance is the instance of the entry to be deleted

 

3. DeleteRowWithValue.py

 

This script uses the scriptAPI method deleteRowWithValue to delete a specific entry from a table when the value of the specified column matches the specified value.  It takes the tableEntryOID, the column name and value as input.

 

Format :

    scriptinterface.deleteRowWithValue(String tableEntryOid,String columnName String value)

where

 

tableEntryOid is the Object Id of the table entry node

columnName is the name of the column node in the table

value is the value of the specified column

 

4. GetAllTableValues.py

 

This script file uses the scriptAPI  method getAllTableValues to return the values of all the nodes for all the rows present in Table. It takes the tableEntryOID as input.

 

Format :

     scriptinterface.getAllTableValues(String tableEntryOid)

where

 

tableEntryOid is the Object Id of the table entry node

 

5. GetCurrentInstanceAndValue.py

 

This script file uses the scriptAPI method getCurrentInstance( ) and getCurrentValue( ) to return the instance and value of an incoming SET request. It should be configured for the condition "Before Processing Set" on a columnar node. This script gets the instance of the OID in the incoming SET request and its value and saves it in a text file named instance.txt

 

Format :

    scriptinterface.getCurrentInstance()

    scriptinterface.getCurrentValue()

6. GetInstances.py

 

This script file uses the scriptAPI method getInstances( ) to get all the instances in a table. It takes the tableOID as input and will return the instances in a Vector.

 

Format:

    scriptinterface.getInstances(String tableOid)

where

 

tableOid is the Object Id of the table node

 

7. GetNextInstance.py

 

This script file uses the scriptAPI method getNextInstance( ) to get the instance next to the one specified. It takes the Table OID and the instance of a table as input. This will return the value as a String

 

Format :

    scriptinterface.getNextInstance(String tableOid,String instance)

where

 

tableOid is the Object Id of the table node

instance is the instance of a row present in the table

 

8. GetNodeValue.py

 

This script file uses the method getNodeValue( ), to get the current value of a scalar or a table node. It takes the OID of the MIB node and the instance as input. This method will return the value as a String

 

Format :

    scriptinterface.getNodeValue(String objectId,String instance)

where

 

objectId is the object identifier (without the instance) of the MIB Node

instance is the instance of the node whose value should be obtained, for scalar nodes this should be ".0"

 

9. GetRowCount.py

 

This script files uses the method getRowCount( ) to get the total number of rows in a table. It takes the Table OID as input and returns an integer value.

 

Format :

    scriptinterface.getRowCount(String tableOid)

where

 

tableOid is the Object Id of the table node

 

10. InsertRow.py

 

This script file uses the insertrow( ) method is used to insert an entry in the Table . It takes the Table OID, the Object Id of the columns in the table, the values of each column and its simulation type as input.

 

Format :

    scriptinterface.insertRow(String tableOid, String[] objectId,String[] values String[] simTypes)

where

 

tableOid is the object id of the table node in which the entry has to be added

objectId is an array of the object Id of the columns in the table

values is an array of values for the columns in the table

simTypes is an array of the simulation types for the columns

 

11. MaskNode.py

 

This script file uses the method maskNode( ) to mask a MIB node from the Manager.

 

Format :

    scriptinterface.maskNode(String objectId,String instance,String maskValue).

12. UpdateColumnarValue.py and UpdateScalarValue.py

 

This script file uses the method updateValue( ) to update the value of a scalar node and columnar node. It takes the OID and instance of the MIB node for which the value should be updated, the value to be assigned and the simulation type.  

 

Format

    scriptinterface.updateValue(String objectId,String instance,String value,String simType)

where

 

objectId is the object identifier (without the instance) of the mib node whose value has to be updated

instance is the instance for which the value should be updated, for scalar nodes this should be ".0"

value is the value to be assigned to the node

simType is the type of simulation required

 

13. SendInform.py

 

This script file uses the method sendInform( ) to send an inform request with no extra varbinds. It takes the manager name, manager port, community, sysUpTime and SNMP Trap OID as input.

 

Format

    sendInform(String mgrName,String mgrPort,String community, String sysUpTime,String snmpTrapOid)

where

 

mgrName - the name of the manager to which the inform has to be sent

mgrPort - the port at which the manager is listening for incoming inform requests

community - the snmp community

sysUpTime - the System UpTime

snmpTrapOid - the value of the snmpTrapOid

 

14. SendInform_varbinds.py

 

This script file uses the scriptAPI method sendInform( ) to send an inform request with extra varbinds. The varbind for the inform is specified with the following information :

 

varbindOid is OID of the inform varbind

varbindTypes is the type of the varbind

varbindValues is the value of the varbinds.

 

Format

    sendInform(String mgrName,String mgrPort,String community,String sysUpTime,String snmpTrapOid,String[] varbindOid,String[] varbindTypes,String[] varbindValues)

15. SendV1Trap.py

 

This script file uses the scriptAPI method sendV1Trap( ) to send a v1 trap without varbinds. It takes the manager name, manager port, community, enterprise OID, generic type and specifi type as input.

 

Format

    sendV1Trap(String mgrName,int mgrPort,String community, String enterpriseOid,int genericType,int specificType)

where

 

mgrName - the name of the manager to which the trap has to be sent

mgrPort - the port at which the manager is listening for incoming traps

community - the snmp community

enterpriseOid - the Enterprise OID

genericType - the Generic Type

specificType - the Specific Type

 

16. SendV1Trap_varbinds.py

 

This script file uses the scriptAPI method sendv1Trap( ) to send a v1 trap with varbinds. It takes the manager name, manager port, community, enterprise OID, generic type, specific type, varbind OID, type and value as input.

 

Format

    sendV1Trap(String mgrName,int mgrPort,String community, String enterpriseOid,int genericType,int specificType,String[] varbindOid,String[] varbindTypes,String[] varbindValues)

where

 

mgrName - the name of the manager to which the trap has to be sent

mgrPort - the port at which the manager is listening for incoming traps

community - the snmp community

enterpriseOid - the Enterprise OID

genericType - the Generic Type

specificType - the Specific Type

varbindOid - oid of the varbind

varbindTypes - the type of the varbind

varbindValues - the value

 

17. SendV2Trap.py

 

This script file uses the sendv2Trap( ) method to send a v2 trap with no extra varbinds.

    sendV2Trap(String mgrName,int mgrPort,String community,String trapOID)

18. SendV2Trap_varbinds.py

 

This script file uses the sendv2Trap( ) method to send a v2 trap with extra varbinds. The varbinds for the trap is specified with the following information:

 

varbindOid - oid of the varbind

varbindTypes - the type of the varbind

varbindValues - the value

 

    sendV2Trap(String mgrName,int mgrPort,String community, String trapOID,String[] varbindOid,String[] varbindTypes,String[] varbindValues)

19. SendV3Trap.py

 

This script file uses the sendv3Trap( ) method to send a v3 trap with no extra varbinds.

    sendV3Trap(String mgrName,int mgrPort,String community, String trapOID,String userName,String contextName)

20. SendV3Trap_varbinds.py

 

This script file uses the sendV3Trap( ) method to send a v3 trap with extra varbinds. The varbinds for the trap is specified with the following information:

 

varbindOid is oid of the varbind

varbindTypes is the type of the varbind

varbindValues is the value

    sendV3Trap(String mgrName,int mgrPort,String community,String trapOID,String userName,String contextName,String[] varbindOid,String[] varbindTypes,String[] varbindValues)

21. TerminateOperation.py

 

This script file uses the scriptAPI method terminateOperation( ) for terminating the current operation i.e. a Get, GetNext or Set operation. The general format of the terminateOperation method is :

    scriptinterface.terminateOperation(int errorNumber)

where,

 

errorNumber is the error to be thrown on terminating the operation.

 

24. GetTotalColumns.py

 

This script file invokes the method getTotalColumns( ) and returns the total number of columns in a table.  It takes the table entry oid as input.

 

Format

    public int getTotalColumns(String tableEntryOid);

25. GetAllColumnByNames.py

    

This script file invokes the method getAllColumnByNames( ) and returns the name of all the columns in the table.  It takes the table entry oid as input.

 

Format

    public String[] getAllColumnByNames(String tableEntryOid);

26. getAllColumnByOids.py

 

This script file uses the method getAllColumnByOids( ) and returns the OID value of all the columns in the table.   It takes the table entry oid as input.

 

Format :

    public String[] getAllColumnByOids(String tableEntryOid);

27. GetAllIndices.py

 

This script file uses the method getAllIndices( ) to return the string array having name of all the indices defined in a table.  It takes the table entry oid as input.

 

Format :

    public String[] getAllIndices(String tableEntryOid);

28. SendTrap.py

 

This script file uses the scriptAPI method sendTrap( ) to send traps configured in the Trap Configuration dialog. It takes the associated variable as input.  The parameter 'associatedVariable' is the name with which the trap is configured  in 'TrapConfiguration' dialog .

 

The manager details and trap details will be taken as such configured in the 'TrapConfiguration' dialog.

 

Format :

    public void sendTrap(String associatedVariable);

29. SendTrapWithEnterpriseOid.py

 

The script file uses the method sendTrap( ) to send traps configured in the Trap Configuration dialog. It takes the associated variable as input.  The parameter 'associatedVariable' is the name with which the trap is configured  in 'TrapConfiguration' dialog . The 'enterpriceOid' is the one which is going to be sent in the trap.

 

The manager details and trap details will be taken as such configured in the 'TrapConfiguration' dialog. The enterpriceOid will be the one specified in the second argument irrespective of the one configured in 'TrapConfiguration' dialog.

 

Format :

    public void sendTrap(String associatedVariable, String enterpriseOid);

30. GetConfigDirectory.py

 

This script file uses the scriptAPI method getConfigDirectory( ) to get the current working directory name . It returns the directory name as a string.

 

Format :

    scriptinterface.getConfigDirectory();

31. SendV1TrapWhileAddingRow.py

 

This Script file will send the V1 Trap while adding the row in the tables. This Script file using the following Script API Methods:

32. SendV1TrapWithVarbindsWhileAddingRow.py

 

This Script file will send the V1 Trap with Varbinds while adding the row in the tables. This Script file uses the following Script API Methods:

33. StartSnmpAgent.py

 

This script file uses the scriptAPI method startAgent( ) to start an SNMP agent. This method is useful in the runtime to start any SNMP agent in the Network from any other agent. This file will work only for the Network Simulator and not for the SNMP Agent Simulator.

 

Format :

    scriptinterface.startAgent(java.lang.String networkName, java.lang.String ipAddress, java.lang.String snmpPort,java.lang.String tl1Port);

34. StopSnmpAgent.py

 

This script file uses the scriptAPI method stopAgent( ) to stop an SNMP agent. This method is useful in the runtime to stop any SNMP agent in the Network from any other agent. This file will work only for the Network Simulator and not for the SNMP Agent Simulator.

 

Format :

    scriptinterface.stopAgent(java.lang.String networkName, java.lang.String ipAddress, java.lang.String snmpPort,java.lang.String tl1Port) ;

Sample Scripts Defined

 

Script with Condition for Execution Alone

 

In this sample, the script DeleteAllRows.py will be executed, after a get request is made on the MIB node "ifDescr" in the ifTable of the RFC 1213 MIB, with instance as .1

    1. Select the Add button in the Behavior Configuration dialog.

    2. Choose the Request based icon that is displayed on the left of the wizard.

    3. Select the MIB node "ifDescr" in the ifTable of the RFC 1213 MIB. Specify the instance as .1

    4. The name of the selected MIB node will be displayed as the script filename. Browse and select the script file "DeleteAllRows.py" in the ./examples directory.

    5. Select the option "After processing Get" to execute the script.

    6. Click Finish to end Behavior configuration and exit from the dialog.

Script with Condition for Execution, Condition for Action, Action to Be Executed

 

In this sample, the script file, ifOutErrors.py will be executed, when a set request is made on the node ifOutErrors. The condition for action is "if current value of ifOutErrors is greater than 10", the action to be executed is "send a v2trap". Hence, the script will send a trap, when a set is made on ifOutErrors with value greater than 10. The steps given below, defines the above Behavior :

    1. Select the Add button in the Behavior Configuration dialog.

    2. Choose the Request based icon that is displayed on the left of the wizard.

    3. Select the MIB node "ifOutErrors" in the ifTable of the RFC 1213 MIB. Specify the instance as .1

    4. The name of the selected MIB node will be displayed as the script filename "ifOutErrors.py".

    5. Specify the condition to execute the script, by selecting the option "Before processing Set"

    6. Click Next button, to specify the condition for action.

    7. Click Add and select the method getCurrentValue, with operator as > and value as 10.

    8. Click OK to add the condition to list. Now, you will find the condition getCurrentValue() >10, added to the list.

    9. Click Next button, to specify the action to be executed.

    10. Click Add and select the method Send Trap, specify the version as Snmp v2c, with other options like Manager, Port and Community as default.

    11. Click OK to add the action to the list. Now, you will find the action Send a V2c trap to localhost and port 162, added to the list.

    12. Click Finish to end Behavior configuration. You will find the script ifOutErrors.py, added to the list with the defined conditions and actions, in the main dialog. Click Close to exit from the dialog.

The script file ifOutErrors.py is given below:

 

    # The Actions

     

    def actionfunc0():

    scriptinterface.sendV2Trap("localhost",162,"public",".1.3.6.1.2.1.11")

     

    # The end of the Actions

     

    # The Condition

     

    if(scriptinterface.getCurrentValue() > "10"):

    actionfunc0()

     

    # The end of Conditions

 

Script with Condition for Execution and Actions to Be Executed

 

In this sample, the script file, timer.py will be executed, when the agent is started. The following actions are configured to be executed at agent startup : Get the node value sysUpTime and store it in a variable., send v1Trap. The steps given below, defines the above Behavior :

    1. Select the Add button in the Behavior Configuration dialog.

    2. Choose the Timer based icon that is displayed on the left of the wizard.

    3. Specify the script filename as timer.py

    4. Select the option Execute Script while Agent Starts.

    5. Specify the Time Interval and Number of Times the script must be executed.

    6. Click Next. The dialog to define the condition for action will be displayed. In this sample, we are not defining any condition for action. Hence click Next, to go the next dialog.

    7. Click Add to add the action to the list. Select GetNodeValue, browse and select the OID as sysUpTime in System group of RFC 1213 MIB, specify the variable name as agentUpTime. The value of the node will be stored in this variable.

    8. Click OK. You will find the action GetValue of Node of oid .1.3.6.1.2.1.1.3 with Instance .0, added to the list.

    9. Click Add again, to add the second action. Select the method Send Trap, with other options like version, Manager, Port and Community as default.

    10. Click OK. You will find the second action Send a V1 trap to localhost and port 162, added to the list.

    11. Click Finish to end Behavior configuration. You will find the script timer.py, added to the list with the defined actions, the main dialog. Click Close to exit from the dialog.

The script file timer.py is given below:

 

    # The Actions

     

    def actionfunc0():

    agentUpTime = scriptinterface.getNodeValue(".1.3.6.1.2.1.1.3" , ".0")

    scriptinterface.sendV1Trap("localhost",162,"public",".1.3.6.1.2.1.11",1,0)

     

    # The end of the Actions

     

    # The Condition

    actionfunc0()

    # The end of Conditions

 

Script with Different Sets of Conditions for Action and Actions to Be Executed

 

In this sample, the script file, ifAdminStatus.py will be executed, when a get request is made on the node ifAdminStatus in ifTable of the RFC 1213 MIB. Two sets of conditions and actions are defined as given below:

The steps given below, defines the above Behavior :

    1. Select the Add button in the Behavior Configuration dialog.

    2. Choose the Request based icon that is displayed on the left of the wizard.

    3. Select the MIB node "ifAdminStatus" in the ifTable of the RFC 1213 MIB. Specify the instance as .1

    4. The name of the selected MIB node will be displayed as the script filename "ifAdminStatus.py".

    5. Specify the condition to execute the script, by selecting the option "After processing Get"

    6. Click Next button, to specify the condition for action.

    7. Click Add and select the method getNodeValue, to specify the OID, browse and select the ifTable, with operator as != and value as 1.

    8. Click OK to add the condition to list. Now, you will find the condition getNodeValue(".1.3.6.1.2.1.2.2.1.7", ".1") != 1 , added to the list.

    9. Click Next button, to specify the action to be executed.

    10. Click Add and select the method Send Trap, specify the version as Snmp v1, with other options like Manager, Port and Community as default.

    11. Click OK to add the action to the list. Now, you will find the action Send a V1 trap to localhost and port 162, added to the list.

    12. Click Finish.You will find the script ifAdminStatus.py added to the list, with the defined set of condition and actions, in the main dialog.

    13. To add the second set of condition and action to the list, click Add button .

    14. To add the second condition, click Add and select the method getRowCount, to specify the OID, browse and select the ifTable, with operator as < and value as 5.

    15. Click OK to add the condition to list. Now, you will find the condition getRowCount(".1.3.6.1.2.1.2.2") < 5 Insert a Row in the ifTable , added to the list.

    16. Click Next button, to specify the action to be executed.

    17. Click Add and select the method InsertRow, to specify the OID, browse and select the ifTable. To specify the values of the new row, click Add . The new row with default values will be displayed. Modify the ifIndex value as '2' and click OK.

    18. Click OK to add the action to the list. Now, you will find the action Insert a Row in the ifTable, added to the list.

    19. Click Finish to end Behavior configuration. Click Close to exit from the dialog.

The script file ifAdminStatus.py is given below:

 

    # Imports required for the scripts

    # to create an array the following lines should be in the script file

    from java.lang import String

    from jarray import array

    # The end of imports

    #############################################################################

    # Row values of Tables

     

    objectid1 = array([".1.3.6.1.2.1.2.2.1.1",".1.3.6.1.2.1.2.2.1.2",".1.3.6.1.2.1.2.2.1.3",".1.3.6.1.2.1.2.2.1.4",

    ".1.3.6.1.2.1.2.2.1.5", ".1.3.6.1.2.1.2.2.1.6",".1.3.6.1.2.1.2.2.1.7",".1.3.6.1.2.1.2.2.1.8",".1.3.6.1.2.1.2.2.1.9"

    ,".1.3.6.1.2.1.2.2.1.10",".1.3.6.1.2.1.2.2.1.11",".1.3.6.1.2.1.2.2.1.12",".1.3.6.1.2.1.2.2.1.13",

    ".1.3.6.1.2.1.2.2.1.14",".1.3.6.1.2.1.2.2.1.15",".1.3.6.1.2.1.2.2.1.16",".1.3.6.1.2.1.2.2.1.17",

    ".1.3.6.1.2.1.2.2.1.18",".1.3.6.1.2.1.2.2.1.19",".1.3.6.1.2.1.2.2.1.20",".1.3.6.1.2.1.2.2.1.21",

    ".1.3.6.1.2.1.2.2.1.22"],String)

    nodetypes1 = array(["CONST","CONST","CONST","CONST","CONST","CONST","CONST","CONST","CONST",

    "LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR","LINEAR",

    "LINEAR","CONST","CONST"],String)

    values1 = array(["2","Test Interface","32","1","1","ifPhysAddress","1","1","101010","1|1|0","1|1|0","1|1|0","1|1|0",

    "1|1|0","1|1|0","1|1|0","1|1|0","1|1|0","1|1|0","1|1|0","1",".1.3.6.1.2.1.2.2.1.22"],String)

    # The end of the varbinds

    #############################################################################

     

    # The Actions

    def actionfunc0():

    scriptinterface.sendV1Trap("localhost",162,"public",".1.3.6.1.2.1.11",0,0)

     

    def actionfunc1():

    scriptinterface.insertRow(".1.3.6.1.2.1.2.2",objectid1,values1,nodetypes1)

    # The end of the Actions

     

    # The Condition

    if(scriptinterface.getNodeValue(".1.3.6.1.2.1.2.2.1.7" , ".1") != "1"):

    actionfunc0()

     

    if(scriptinterface.getRowCount(".1.3.6.1.2.1.2.2") < 5):

    actionfunc1()

    # The end of Conditions

 

 



Copyright © 1996-2006, AdventNet Inc. All Rights Reserved.