Running Jython scripts

You can extend custom server and computer system templates by calling Jython scripts (.py extension) on a target system.

TADDM automatically detects the script language and passes the context of the custom server or computer system to the scripting language using a hashmap. This enables Jython to manipulate Java™ objects.

The detailed structure Fix Pack
8along with the sample script and its explanation is described in the Custom server extensions API section. However, initializing the sensor helper section is different for extensions of the custom server template and computer system template. The following sections provide description of these differences.

sensorhelper section of the Jython script
The Jython script that you use to extend the custom server and computer system templates contains the sensorhelper section. This section initializes the sensor tools Python module with information about the target of the discovery. Depending on which template you use to extend the discovery scope, it has the following form:
  • Initializing sensorhelper for a custom server:
    (os_handle, result, appserver, seed, log, env)=sensorhelper.init(targets)
  • Initializing sensorhelper for a computer system:
    (os_handle, result, computersystem, seed, log)=sensorhelper.init(targets)
Note: Do not change the order of the elements in this section of the script. Otherwise, it fails.
Target map objects for the custom server
The following table lists and describes the objects that are available in the targets map for the custom server.
Table 1. Target map objects for the custom server
Object Description
os_handle

This object is an implementation of the TADDM Os abstraction layer. You can use it to run remote commands.

The following method is available:
  • executeCommand(String cmd): Runs a command on the remote target and returns the output as a string.
result

The CustomAppServerResult object

The following methods are available:
  • getServer(): Returns the AppServer that is being discovered.
  • setServer(AppServer app): Sets the AppServer in the resulting object for persistence.
  • addExtendedResult(ModelObject mo): Adds a CDM ModelObject (or subclass) to the result object so that it can be persisted in the data store. This ModelObject does not need to be related to the target for which the sensor was started.
  • addConfig(AppConfig apconfig): Adds a configuration file to the result object for persistence.
appserver

The AppServer that is being discovered

The available methods are listed in the TADDM Data Dictionary. For details, see TADDM Data Dictionary.

seed

The CustomAppServerSeed object

The following methods are available:
  • getSessionIp(): Returns the IP address that TADDM used to connect to the computer system where the AppServer that is being discovered is running.
  • getPrimarySapIpAddr(): Returns the IP address to which the discovery target is bound. If it is bound to all interfaces, then the session IP is returned.
log

The object used for writing to sensor logs.

The following methods are available for various log levels, starting with most severe:
  • fatal
  • error
  • warning
  • info
  • debug
  • trace
env

The Java HashMap environment object. The keys are the processes environment variables. The values are those of the variables.

Target map objects for the computer system
The following table lists and describes the objects that are available in the targets map for the computer system.
Table 2. Target map objects for the computer system
Object Description
os_handle

This object is an implementation of the TADDM Os abstraction layer. You can use it to run remote commands.

The following method is available:
  • executeCommand(String cmd): Runs a command on the remote target and returns the output as a string.
result

The ComputerSystemResult object

The following methods are available:
  • getComputerSystem(): Returns the ComputerSystem being discovered.
  • setComputerSystem(): Sets the ComputerSystem in the result object for persistence.
  • addExtendedResult(ModelObject mo): Adds a CDM ModelObject (or subclass) to the result object so that it can be persisted in the data store. This ModelObject does not need to be related to the target for which the sensor was started.
computersystem

The ComputerSystem that is being discovered

The available methods are listed in the TADDM Data Dictionary. For details, see TADDM Data Dictionary.

seed

The ComputerSystemSeed object

The following method is available:
  • getIpAddress(): Returns the IP address that TADDM uses to discover the target.
log

The object used for writing to sensor logs.

The following methods are available for various log levels, starting with most severe:
  • fatal
  • error
  • warning
  • info
  • debug
  • trace
Running the script
To run the script, you must create the directive file, and include the name of the Jython script, for example:
SCRIPT:myscript.py

For more information about the format of the directive file, see Extending custom servers.

For example, you can run the Jython script myscript.py by including the following command in the directive file:

SCRIPT:myscript.py