The Framework Instance

The Framework instance is the only argument that is supplied in the main function in the Jython script. This is an interface that can be used to retrieve information required to run the script (for example, information on trigger CIs and adapter parameters), and is also used to report on errors that occur during the script run. For details, see Data Flow Management API Reference.

The correct usage of Framework instance is to pass it as argument to each method that uses it.

Example:

def DiscoveryMain(Framework):
         OSHVResult = helperMethod (Framework)
            return OSHVResult
def helperMethod (Framework):
    .... 
     probe_name    = Framework.getDestinationAttribute('probe_name')
     ...
     return result

This section describes the most important Framework usages:

Framework.getTriggerCIData(String attributeName)

This API provides the intermediate step between the Trigger CI data defined in the adapter and the script.

Example of Retrieving Credential Information:

You request the following Trigger CI data information:

To retrieve the credential information from the task, use this API:

credId = Framework.getTriggerCIData('credentialsId')

Framework.createClient(credentialsId, props)

You make a connection to a remote machine by creating a client object and executing commands on that client. To create a client, retrieve the ClientFactory class. The getClientFactory() method receives the type of the requested client protocol. The protocol constants are defined in the ClientsConsts class. For details on credentials and supported protocols, see the Universal CMDB Discovery and Integrations Content Help.

Example of Creating a Client Instance for the Credentials ID:

To create a Client instance for the credentials ID:

properties = Properties()
codePage = Framework.getCodePage()
properties.put( BaseAgent.ENCODING, codePage)
client = Framework.createClient(credentailsID ,properties)

You can now use the Client instance to connect to the relevant machine or application.

Example of Creating a WMI Client and Running a WMI Query:

To create a WMI client and run a WMI query using the client:

wmiClient = Framework.createClient(credential)
resultSet = wmiClient. executeQuery("SELECT TotalPhysicalMemory
                                                       FROM    Win32_LogicalMemoryConfiguration")

Note: To make the createClient() API work, add the following parameter to the Trigger CI data parameters: credentialsId = ${SOURCE.credentials_id} in the Triggered CI Data pane. Or you can manually add the credentials ID when calling the function: wmiClient = clientFactory().createClient(credentials_id).

The following diagram illustrates the hierarchy of the clients, with their commonly-supported APIs:

For details on the clients and their supported APIs, see BaseClient, ShellClient, and QueryClient in the DFM Framework. These files are located in the following folder:

<UCMDB root directory>\UCMDBServer\deploy\ucmdb-docs\docs\eng\APIs\DDM_Schema\webframe.html

Framework.getParameter (String parameterName)

In addition to retrieving information on the Trigger CI, you often need to retrieve an adapter parameter value. For example:

Example of Retrieving the Value of the protocolType Parameter:

To retrieve the value of the protocolType parameter from the Jython script, use the following API:

protocolType = Framework.getParameterValue('protocolType')

Framework.reportError(String message) and Framework.reportWarning(String message)

Some errors (for example, connection failure, hardware problems, timeouts) can occur during a script run. When such errors are detected, Framework can report on the problem. The message that is reported reaches the server and is displayed for the user.

Example of a Report Error and Message:

The following example illustrates the use of the reportError(<Error Msg>) API:

try:
    client = Framework.createClient(Framework.getTriggerCIData(BaseClient.CREDENTIALS_ID))
except:
    strException = str(sys.exc_info()[1]).strip()
    Framework. reportError ('Connection failed: %s' % strException)

You can use either one of the APIs—Framework.reportError(String message), Framework.reportWarning(String message)—to report on a problem. The difference between the two APIs is that when reporting an error, the Probe saves a communication log file with the entire session's parameters to the file system. In this way you are able to track the session and better understand the error.

For details on error messages, see Error Messages.

Parent topic: Create Jython Code