Jython Libraries and Utilities

Several utility scripts are used widely in adapters. These scripts are part of the AutoDiscovery package and are located under: C:\UCMDB\DataFlowProbe\runtime\probeManager\discoveryScripts with the other scripts that are downloaded to the Probe.

Note The discoveryScript folder is created dynamically when the Probe begins working.

To use one of the utility scripts, add the following import line to the import section of the script:

import <script name>

The AutoDiscovery Python library contains Jython utility scripts. These library scripts are considered DFM's external library. They are defined in the jythonGlobalLibs.xml file (located in the Configuration Files folder).

Each script that appears in the jythonGlobalLibs.xml file is loaded by default at Probe startup, so there is no need to use them explicitly in the adapter definition.

This section includes the following topics:

logger.py

The logger.py script contains log utilities and helper functions for error reporting. You can call its debug, info, and error APIs to write to the log files. Log messages are recorded in C:\UCMDB\DataFlowProbe\runtime\log.

Messages are entered in the log file according to the debug level defined for the PATTERNS_DEBUG appender in the C:\UCMDB\DataFlowProbe\conf\log\probeMgrLog4j.properties file. (By default, the level is DEBUG.) For details, see Error Severity Levels.

#####################################################################
################         PATTERNS_DEBUG log                  ####################
#####################################################################
log4j.category.PATTERNS_DEBUG=DEBUG, PATTERNS_DEBUG
log4j.appender.PATTERNS_DEBUG=org.apache.log4j.RollingFileAppender
log4j.appender.PATTERNS_DEBUG.File=C:\UCMDB\DataFlowProbe\runtime\log/probeMgr-patternsDebug.log
log4j.appender.PATTERNS_DEBUG.Append=true
log4j.appender.PATTERNS_DEBUG.MaxFileSize=15MB
log4j.appender.PATTERNS_DEBUG.Threshold=DEBUG
log4j.appender.PATTERNS_DEBUG.MaxBackupIndex=10
log4j.appender.PATTERNS_DEBUG.layout=org.apache.log4j.PatternLayout
log4j.appender.PATTERNS_DEBUG.layout.ConversionPattern=<%d> [%-5p] [%t] - %m%n
log4j.appender.PATTERNS_DEBUG.encoding=UTF-8

The info and error messages also appear in the Command Prompt console.

There are two sets of APIs:

  • logger.<debug/info/warn/error>

  • logger.<debugException/infoException/warnException/errorException>

The first set issues the concatenation of all its string arguments at the appropriate log level and the second set issues the concatenation as well as issuing the stack trace of the most recently-thrown exception, to provide more information, for example:

logger.debug('found the result')
logger.errorException('Error in discovery')

modeling.py

The modeling.py script contains APIs for creating hosts, IPs, process CIs, and so on. These APIs enable the creation of common objects and make the code more readable. For example:

ipOSH= modeling.createIpOSH(ip)
host = modeling.createHostOSH(ip_address)
member1 = modeling.createLinkOSH('member', ipOSH, networkOSH)

netutils.py

The netutils.py library is used to retrieve network and TCP information, such as retrieving operating system names, checking if a MAC address is valid, checking if an IP address is valid, and so on. For example:

dnsName = netutils.getHostName(ip, ip)
isValidIp = netutils.isValidIp(ip_address)
address = netutils.getHostAddress(hostName)

shellutils.py

The shellutils.py library provides an API for executing shell commands and retrieving the end status of an executed command, and enables running multiple commands based on that end status. The library is initialized with a Shell Client, and uses the client to run commands and retrieve results. For example:

ttyClient = Framework.createClient(Framework.getTriggerCIData(BaseClient.CREDENTIALS_ID), Props)
clientShUtils = shellutils.ShellUtils(ttyClient)
if (clientShUtils.isWinOs()):
        logger.debug ('discovering Windows..')