Python inventory scripting

<< Click to Display Table of Contents >>

Raynet One > 1.1 > User Guide > Technical overview > Custom inventory scripting 

Python inventory scripting

The Python language is the recommended device inventory scripting language. Create powerful custom device inventory processes with this modern object-oriented programming language.

 

The IronPython language implementation is used. Default Python standard runtime libraries are excluded for robustness and increased security.

 

This chapter describes the provided API for Python script execution.

PythonConnector dictionary

This object contains all of the API functions for communication with both the inventory device and the runner. It is imported into every executed script by default for convenience.

Function PythonConnector.run(cmd: string [, redirect_error: boolean])

Requests the execution of a command on the remote system, the inventory device. The command is run with the same credentials as specified for this particular device. There is no further privilege elevation if not specified in the device credentials settings.

Parameter cmd (string)

The command to execute remotely on the inventory device.

Optional parameter redirect_error (boolean)

If true, error messages should be written to a device-local temporary error log file. On some platforms, the device command is amended with a shell-powered output redirection operator.

 

Default: False

Function PythonConnector.create_item(class_name: string, name: string [, create_custom_property: boolean])

Creates a new device inventory object of type InventoryItem and returns it. If create_custom_property is false, the value of class_name is used to categorize the inventory object for import. Otherwise, the object is not touched by the built-in device inventory import system at all. These objects are considered custom. They are exposed by API for self-built customer inventory processes (endpoint InventoryScriptResults).

 

The inventory object is not added to the device inventory process automatically. Use the PythonConnector.add_item function to add it.

 

If create_custom_property is false, the value of the name parameter is used internally only. Otherwise, the value is retrievable by API.

Parameter class_name (string)

The class name of the object for distinct categorization and property expectation. It gives the object meaning.

Parameter name (string)

The (internal) name of the object.

Optional parameter create_custom_property (boolean)

Decides whether the object should be excluded from built-in device inventory import logic or not.

 

Default: True

Function PythonConnector.add_property(key: string, value: string, item: InventoryItem)

Adds a property to a device inventory object. Two properties with the same key can be added.

Parameter key (string)

The value for the property's Name field.

Parameter value (string)

The value for the property's Value field.

Parameter item (InventoryItem)

The device inventory object to assign the property to.

Function PythonConnector.add_item(item: InventoryItem)

Adds the device inventory object pointed at by item to the device inventory process. As a result, the object is transfered to the system for import into the device inventory database.

Parameter item (InventoryItem)

The device inventory object to add.

Function PythonConnector.os_family()

Returns the string naming the device operating system category defined by the system for the inventory device.

 

Available operating system categories:

"Unknown"

"Solaris"

"HPUX"

"AIX"

"OSX"

"Linux"

"Windows"

Function PythonConnector.hostname()

Returns the hostname string related to the inventory device. If there is no hostname related to the inventory device or its retrieval has failed, the empty string is returned.

Function PythonConnector.critical(message: string)

Puts the message string as log entry of the critical category to the instrument log.

Parameter message (string)

The message to put into the log.

Function PythonConnector.error(message: string)

Puts the message string as log entry of the error category to the instrument log.

Parameter message (string)

The message to put into the log.

Function PythonConnector.warn(message: string)

Puts the message string as log entry of the warning category to the instrument log.

Parameter message (string)

The message to put into the log.

Function PythonConnector.info(message: string)

Puts the message string as log entry of the information category to the instrument log.

Parameter message (string)

The message to put into the log.

Function PythonConnector.debug(message: string)

Puts the message string as log entry of the debug category to the instrument log.

Parameter message (string)

The message to put into the log.

Script debugging

Set the instrument log level of the runner to Verbose and view the executing instrument logs of inventory devices. There should be log lines related to the PythonScanner runner component.

clip0138

 

The instrument log of a device which executed the program in the distributed device command execution use-case. There are many log lines. At some point, the PythonScanner runner software component is mentioned. You can see the line with the content "Collected ping inventory". This is the information-level log entry as output by the Python inventory script. Use log lines to reconstruct or trace the script's path of execution.