copyright | lastupdated | ||
---|---|---|---|
|
2019-06-18 |
{:new_window: target="_blank"} {:shortdesc: .shortdesc} {:screen: .screen} {:codeblock: .codeblock} {:pre: .pre} {:child: .link .ulchildlink} {:childlinks: .ullinks}
{: #python .reference}
Use the Python SDK to get started quickly with using the REST APIs of Maximo Asset Monitor. {:shortdesc}
Using the modules, you can interact with the REST APIs to:
- Manage entity types
- Manage dimensions
- Manage KPI functions
- Manage constants
- Load metric data
{: #modules .sectiontitle}
Description | Module | Input | Output | Script |
---|---|---|---|---|
Create an entity type using json payload | create_custom_entity_type |
|
None | Creating entities, adding functions, constants, dimensions script |
Read metric data for an existing entity type | load_metrics_data_from_csv |
|
None | Loading data from csv script |
Delete an entity type | remove_entity_type |
|
API response | Removing entity type, functions, constants, dimensions script |
Add KPI functions to an entity type | add_functions |
|
None | Creating entities, adding functions, constants, dimensions script |
Get all of the KPI functions of an entity type | get_functions |
|
List of dict with KPI functions (API response) | Getting functions, constants, and dimensions script |
Delete a KPI function of an entity type | remove_function |
|
API response | Removing entity type, functions, constants, dimensions script |
Register a constant globally | create_constants |
|
API response | None |
Get all of constants for a tenant | get_constants |
|
list of dict with constants information (API response) | Get functions, constants, and dimensions script |
Update constants for a tenant | update_constants |
|
API response | None |
Unregister constants by name | remove_constants |
|
API response | None |
Add dimension data to entities | add_dimensions_data |
|
API response | Creating entities, adding functions, constants, dimensions script |
Get all the dimensional data for an entity type | get_dimensions_data |
|
List of dict with dimension data information (API response) | Getting functions, constants, and dimensions script |
Update dimension data | update_dimensions_data |
|
API response | None |
Delete a dimension by name | remove_dimensions |
entity_type_name : Name of entity type in string format |
API response | Removing entity type, functions, constants, dimensions script |
Get all alerts using a json payload | get_alerts |
|
API response | Get alerts and update status and severity script |
Update the alert status using the alert ID | update_alert_status |
|
None | None |
Update the alert severity using alert ID | update_alert_severity |
|
None | None |
{: #install .sectiontitle}
Complete these steps to create a copy of the Python SDK and run it on your local system for development and testing purposes.
- Create a virtual environment
python3 -m venv env
- Activate virtual environment
source env/bin/activate
- Install sdk from GitHub
pip install git+https://github.com/ibm-watson-iot/maximo-asset-monitor-sdk.git
On a MAS OS X environment, if the IBM database (ibm_db) fails, complete these steps:
-
Activate the virtual environment to set up the
$VIRTUAL_ENV
variablesource env/bin/activate
-
Run the following command to download the driver:
pip install git+https://github.com/ibm-watson-iot/maximo-asset-monitor-sdk.git
-
Run the following command once to fix the driver:
bash ./dev_resources/mac_ibmdb_fix.sh
For more information about the workaround, see ibmdb/python-ibmdb#187 (comment)
{: #save-your-credentials-to-a-file .sectiontitle}
Important: The credentials file is used to run or test functions locally. Do not push this file to any external repository.
- Set credentials to connect to Analytics Service.
- Create a credentials.json file in the scripts folder in your working directory.
- On the user interface, go to the Services tab.
- Select Watson IoT Platform Analytics and click View Details.
- In the Environment Variables field, click Copy to Clipboard.
- Paste the contents of the clipboard into the credentials.json file.
- Load your credentials in your script. Add the following code to your script:
credentials_path=<path to credentials.json> with open(credentials_path, 'r') as F: credentials = json.load(F)