Using scripts to extend custom server extensions to run in script and asynchronous mode
You can use shell scripts or Jython scripts to extend a custom server template (CST).
When these are used, then script-based discovery is performed where TADDM copies
the user-defined scripts (ASDMAINSCRIPT/ASDSCRIPT) to the target system, run the scripts, and
returns the output files to the TADDM server. The output generated by these script files needs to be
parsed by a Jython script file, that must be created by the user which will be configured via the
SCRIPT tag in the directive file. Only the model objects if any, created and returned by this script
file will get stored.
In the case of Asynchronous discovery mode (ASD), the user can generate a request package and these scripts configured with ASDMainScript and ASDScript tags, will get bundled in it. Users can then run the package at target and get a result file generated like the ASD process for other sensors. This result file will be copied to the asdd directory on the TADDM server by the user, and then when ASD discovery is invoked via the Discovery Management Console, it will process these files. The Jython script (tagged with SCRIPT tag) mentioned in the directive file will process the output result and will generate result objects as per user coding in that Jython script. Hence, in this mode of extension define one main script (ASDMAINSCRIPT) for a given custom server template. If required, more than one additional scripts (ASDSCRIPT) that are used by the main script can be defined as well. Along with these, define another Jython script (SCRIPT), that will parse the outputs of the scripts run on targets and create model objects and return them for storage.

To start a custom server template using a script, define one main script for a given custom server template. If required, you can define one or more additional scripts which are used by the main script.
Definition of CST extended with scripts
- ASDMAINSCRIPT
- This command specifies the main script file name. It specifies the script to be copied and started on the target system.
- ASDSCRIPT
- This command specifies additional script file names if required. It specifies scripts to be copied and used by the main script on the target system.
SCRIPT
- This command specifies the Jython script file name. It specifies the script that parses the
outputs of scripts run on targets and creates model objects as well. Only the model objects, if any,
created and returned by the Jython script file will get stored.
For Asynchronous discovery, the directive filename or the custom server template name must not have space in its name.
Command syntax
- ASDMAINSCRIPT:os_discriminator:script_relative_path
- The variable os_discriminator defines the operating
system where you can run the script. The following values are valid:
- AIX
- LINUX
- SOLARIS
- UNIX
- WINDOWS
- ALL: Use this value to indicate all operating systems.
- ASDSCRIPT:os_discriminator:script_relative_path
- The same definitions as described previously also apply to the ASDSCRIPT command.
Example of a command file
A script set is a set of scripts defined with the same os_discriminator attribute. Each script set must have one main script (ASDMAINSCRIPT) and can have if required one or more additional scripts (ASDSCRIPT). The CST extended by scripts chooses the most specific script set for the discovered operating system.
The following example shows a command file for a CST extended with scripts:
ASDMAINSCRIPT:AIX:etc/templates/commands/scripts/scriptAix.sh
ASDSCRIPT:AIX:etc/templates/commands/scripts/myTest3.sh
ASDMAINSCRIPT:UNIX:etc/templates/commands/scripts/scriptUnix.sh
ASDSCRIPT:UNIX:etc/templates/commands/scripts/myTest.sh
ASDSCRIPT:UNIX:etc/templates/commands/scripts/myTest2.sh
SCRIPT: etc/templates/commands/scripts/myOutputParser.py
This
command file defines two script sets: one for AIX® only, and
one for UNIX and similar operating systems.In the ASDMAINSCRIPT file, to invoke the other script for example,
myTest.sh
,
follow the pattern as used in the normal script sensors, for example, echo
SCRIPT:myTest.sh
, only the file name must be mentioned without any directory
path.
Script generated files
TADDM copies the defined scripts to the target system and runs the main script. The main script is started in the root system directory, but it is located in a temporary directory. To get the actual script location, use the dirname $0 command.
The scripts and files generated by the script, which are stored in the temporary location on the target system, are returned to the TADDM server. The files are placed in the $COLLATION_HOME/var/asdd/{runId}/{targetIp}/{sensorOsgiId} directory. The sensorOsgiId name consists of the custom application server sensor (CustomAppSever) identifier and the template name. For example, com.ibm.cdb.discover.sensor.app.customappserver_7.1.0.JavaServer for a JavaServer CST.
Add a Jython extension to a CST extended with scripts
To parse data gathered by a CST extended with scripts, you can call Jython scripts (.py extension) automatically during a discovery. To add a Jython extension to a script file, you must add the following command to the directive file:- SCRIPT:jythonscript_relative_path
- The directive file must have the same name as the CST and must be stored in the following directory: $COLLATION_HOME/etc/templates/commands
- outputs - the List
<OutputDataSet>
object - systeminfo - the system information object
- seed - the CustomAppServerSeed object
- result - the CustomAppServerResult object
- environment - the Java HashMap environment object
containing the Map
<String, String>
object
...
log = LogFactory.getLogger("com.ibm.cdb.discover.sensor.CustomAppServerScriptSensor")
result = scripttargets.get("result")
seed = scripttargets.get("seed");
env = scripttargets.get("environment")
systeminfo = scripttargets.get("systeminfo")
outputDataSetList = scripttargets.get("outputs")
# just print the content of output data set list
for outputDataSet in outputDataSetList:
if not outputDataSet.isValid():
log.error("Not valid output data set")
continue
for outputData in outputDataSet.iterator():
if not outputData.isValid():
log.error("Not valid output data")
try:
log.info(outputData.getValue())
except ExecutionException, e:
log.error("ExecutionException", e)
...
For information on how to create model objects using extensions, refer to Creating new objects and relationships through custom server extensions.