Searching the Help
To search for information in the Help, type a word or phrase in the Search box. When you enter a group of words, OR is inferred. You can use Boolean operators to refine your search.
Results returned are case insensitive. However, results ranking takes case into account and assigns higher scores to case matches. Therefore, a search for "cats" followed by a search for "Cats" would return the same number of Help topics, but the order in which the topics are listed would be different.
Search for | Example | Results |
---|---|---|
A single word | cat
|
Topics that contain the word "cat". You will also find its grammatical variations, such as "cats". |
A phrase. You can specify that the search results contain a specific phrase. |
"cat food" (quotation marks) |
Topics that contain the literal phrase "cat food" and all its grammatical variations. Without the quotation marks, the query is equivalent to specifying an OR operator, which finds topics with one of the individual words instead of the phrase. |
Search for | Operator | Example |
---|---|---|
Two or more words in the same topic |
|
|
Either word in a topic |
|
|
Topics that do not contain a specific word or phrase |
|
|
Topics that contain one string and do not contain another | ^ (caret) |
cat ^ mouse
|
A combination of search types | ( ) parentheses |
|
- Create Jython Code
- Use External Java JAR Files within Jython
- Execution of the Code
- Modifying Out-of-the-Box Scripts
- Structure of the Jython File
- Results Generation by the Jython Script
- The Framework Instance
- Finding the Correct Credentials (for Connection Adapters)
- Handling Exceptions from Java
- Troubleshooting Migration from Jython Version 2.1 to 2.5.3
Structure of the Jython File
The Jython file is composed of three parts in a specific order:
-
Imports
-
Main Function - DiscoveryMain
-
Functions definitions (optional)
The following is an example of a Jython script:
# imports section from appilog.common.system.types import ObjectStateHolder from appilog.common.system.types.vectors import ObjectStateHolderVector # Function definition def foo: # do something # Main Function def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() ## Write implementation to return new result CIs here... return OSHVResult
Imports
Jython classes are spread across hierarchical namespaces. In version 7.0 or later, unlike in previous versions, there are no implicit imports, and so every class you use must be imported explicitly. (This change was made for performance reasons and to enable an easier understanding of the Jython script by not hiding necessary details.)
-
To import a Jython script:
import logger
-
To import a Java class:
from appilog.collectors.clients import ClientsConsts
Main Function – DiscoveryMain
Each Jython runnable script file contains a main function: DiscoveryMain.
The DiscoveryMain
function is the main entry into the script; it is the first function that runs. The main function may call other functions that are defined in the scripts:
def DiscoveryMain(Framework):
The Framework argument must be specified in the main function definition. This argument is used by the main function to retrieve information that is required to run the scripts (such as information on the Trigger CI and parameters) and can also be used to report on errors that occur during the script run.
You can create a Jython script without any main method. Such scripts are used as library scripts that are called from other scripts.
Functions Definition
Each script can contain additional functions that are called from the main code. Each such function can call another function, which either exists in the current script or in another script (use the import
statement). Note that to use another script, you must add it to the Scripts section of the package:
Example of a Function Calling Another Function:
In the following example, the main code calls the doQueryOSUsers(..)
method which calls an internal method doOSUserOSH(..)
:
def doOSUserOSH(name): sw_obj = ObjectStateHolder('winosuser') sw_obj.setAttribute('data_name', name) # return the object return sw_obj def doQueryOSUsers(client, OSHVResult): _hostObj = modeling.createHostOSH(client.getIpAddress()) data_name_mib = '1.3.6.1.4.1.77.1.2.25.1.1,1.3.6.1.4.1.77.1.2.25.1.2,string' resultSet = client.executeQuery(data_name_mib) while resultSet.next(): UserName = resultSet.getString(2) ########## send object ############## OSUserOSH = doOSUserOSH(UserName) OSUserOSH.setContainer(_hostObj) OSHVResult.add(OSUserOSH) def DiscoveryMain(Framework): OSHVResult = ObjectStateHolderVector() try: client = Framework.createClient(Framework.getTriggerCIData(BaseClient.CREDENTIALS_ID)) except: Framework.reportError('Connection failed') else: doQueryOSUsers(client, OSHVResult) client.close() return OSHVResult
If this script is a global library that is relevant to many adapters, you can add it to the list of scripts in the jythonGlobalLibs.xml
configuration file, instead of adding it to each adapter (Adapter Management > Resources Pane > AutoDiscoveryContent > Configuration Files).
We welcome your comments!
To open the configured email client on this computer, open an email window.
Otherwise, copy the information below to a web mail client, and send this email to cms-doc@microfocus.com.
Help Topic ID:
Product:
Topic Title:
Feedback: