Last Updated: 08 May 2024 Author: Christophe Lucas
Products Used: IBM Maximo Monitor
Disclaimer: This code is delivered as-is and is NOT formal IBM documentation in any way
- Introduction & Overview
- Prerequisites
- Get Ready !
- Overview of MAS Monitor API v2 & Anatomy of an API call
- Discover & Try Monitor API v2
- Play with 12 API calls using MAS Cloud Pak for Data
In this Tutorial, you will:
- GET READY to use Monitor API v2 by finding your MAS Monitor Environment required info & by creating sample Monitor Robot Devices and Alerts to test the calls.
- UNDERSTAND the Monitor API v2 structure and the anatomy of an API v2 call & πππ¦ππ’π©ππ₯ how to execute any call with Swagger & Postman.
- PLAY with 12 API v2 ready-to-use calls using a provided Jupyter Notebook, on your MAS Cloud Pak for Data instance.
To complete this tutorial, you need:
- an ID with Administrator Access to the Monitor Application of a MAS 811 instance
- Postman or an equivalent tool for running APIs. Postman can be downloaded here: Download Postman.
- Access to a Cloud Pak for Data Instance to run the Play with 12 API calls using MAS Cloud Pak for Data section.
This tutorial was built using a MAS 8.11.10 instance with Monitor 8.11.6 and IoT 8.8.7.
As per Monitor APIs documentation, in order to run Monitor API v2 calls, you will need:
- For GET calls:
X-api-key
,X-api-token
values. - For POST, PUT, or DELETE calls:
X-api-key
,X-api-token
+tenantId
andmam_user_email
values. - Your MAS
Monitor Server URL
.
Follow the below steps to get all those required values:
Get X-api-key & X-api-token values
There are 2 options/ways to get the X-api-key
, X-api-token
values:
-
Option 1 - Using Monitor as_apikey & as_apitoken (via MAS - Openshift Container Platform)
- From the OCP console, click
Project
. In theSearch by name
field, start typingmas-monitor
and locate e.g. themas-***-monitor
Project. Open the Project. - On the
Inventory
card, clickSecrets
. Search for and openmonitor-api
. - Copy and save
as_apikey
andas_token
- those are your requiredX-api-key
&X-api-token
values.
- From the OCP console, click
-
Option 2 - Using Watson IoT Platform API Key & Authentication Token
- From the Monitor Home menu, click
Open the IoT tool
to access the Watson IoT Platform. ClickApps
menu. - Click
Generate API Key
, Next and click expirationOff
. SelectStandard Application
role . Click Generate Key. - Copy and save
API key
andAuthentication token
- those are your requiredX-api-key
&X-api-token
values.
- From the Monitor Home menu, click
Get tenantId, mam_user_email
- To get your
tenantId
, look at your Monitor homepage URL, it should like thishttps://tenantId.monitor.domain.com/
. Example 1:https://mygeo.monitor.mygeomas.gtm-pat.com/
wheremygeomas.gtm-pat
is thedomain
andmygeo
is thetenantId
. Example 2:https://main.monitor.customer-poc.suite.maximo.com/
wherecustomer-poc.suite.maximo
is thedomain
andmain
is thetenantId
. Another simple way to get the value of yourtenantId
is to click theOpen the IoT tool
from Monitor home page, then copy (top-right) the value of your Watson IoT Platform ID. - To get your
mam_user_email
, jut click onManage your Profile
(top-right) and copy the value of your primary email - that will be yourmam_user_email
value.
Get Monitor Server URL
- Access the Monitor v2 API by clicking Monitor top-right
Help - API
menu. This will open a screen where you will note 4 distinct API sets. - Click any of these API sets, and notice top-left the
Server
box where theGenerated server url
will appear in plain sight. Copy it and use this as theyour-mas-monitor-server-url
in all below API v2 Postman (or CloudPakForData) calls.
The purpose of this section is to create standard ootb Monitor Robot
Device Type, Devices & Alerts that you will use to test all the API calls. Creating a Robot
Device Type will automatically create 5 Devices named 73000
, 73001
, 73002
, 73003
and 73004
, and data will keep flowing to them. All following sections will be based on a XY-Robot
Device Type - where XY
will be your initials (e.g. CL-Robot
for Christophe Lucas).
Create Sample Robot Device Type
- On Monitor Home screen, click
Create a device type
then selectSample robot type template
, name your Device TypeXY-Robot
(whereXY
are your initials), clickCreate
. - Go to the
Setup
menu and selectXY-Robot
. Notice how Monitor automatically created Devices73000
,73001
,73002
,73003
and73004
as well as data for those Devices in the past. It will keep creating new data in the future.
Create 2 Alert Types
- Click on the +
Batch data metric (calculated)
link on the left, selectAlerthHighValue
. Selectspeed
ininput_items
, setupper_threshold
to7
,Severity
toHigh
andStatus
toNew
. Click Next, call the output_itemsalert_speed_7
. UnclickAuto schedule
and enter5 Minutes
in theExecuting every
field, and7 Days
in theCalculating the last
field, clickCreate
. - Repeat 1. for
alert_torque_16
(withupper_threshold
=16
,Severity
=Medium
andStatus
=Validated
). - Wait minimum 5 minutes (take a longer break !) for the Analytics jobs to run. Observe how
alert_torque_16
andalert_speed_7
alerts are regularly created at an acceptable frequency (i.e. from a couple to a dozen to sometimes more per day).
The picture below highlights the steps you just completed.
The Monitor API v2 is very rich and contains dozens and dozens of calls. The best way to discover it is to first zig-zag through its content:
- To access the API, click Monitor top-right
Help - API
menu. This will open a screen where you will note 4 distinct API sets:Manage core resources
,Query data
,Query data for dashboards
,Manage images
(we will disregardManage Data Store Connector / FactoryTalk Integration
in this tutorial). - Click on each API set, and spend minimum 10 minutes looking at the descriptions of the calls.
- For
Manage core resources
,Query data
specifically, notice how the API set contains multiple Definitons (top-right drop-down list). Click one after the other and notice how each contains many different APIs available forDeviceType
,DeviceType -> Device
,DeviceType V2
,Organization
,Site
,Site -> Asset
,Site -> Location
etc.
The following image highlights the constitutive elements that must be considered to run any API call:
- Parameters: these are the INPUT parameters, either mandatory or optional.
- Call Type: each API call will have a GET, POST, PUT, DELETE type.
- Call URL: contains the URL of your Monitor instance required to execute the API call.
- Request Body: either mandatory or optional.
- Ouptut: the result (i.e. OUTPUT) of your API call execution.
[below images are taken from either the Swagger, the Postman or the Cloud Pak for Data interface that you will use to run the calls]
First, let's use the Monitor API Swagger Web UI which is available directly from within the Monitor application. We will use a simple Manage core resources DeviceType - Device Type Management
API call, which returns the list of all DeviceTypes in your Monitor environment:
- Click Monitor top-right
Help - API
menu. Open theManage core resources
API, select theDeviceType
definition (top right). On right-side of the screen, clickAuthorize
. - In the opened
Available authorizations
window, enter the value ofX-api-key
, clickAuthorize
, then repeat the same, one after the other, forX-api-token
,tenantId
andmam_user_email
that your retrieved in the Get Monitor {X-api-key, X-api-token, tenant, mam_user_email} & Server URL section. - Go to the
Device Type Management
section and open thePOST /api/v2/core/deviceTypes/search - Get Device types, filter by status, supports pagination
call. - Click
Try it out
and empty the wholeRequest body
content (that box should be blank). - Click
Execute
and observe the succesfull200
Server response code. - Observe the returned json in the
Response Body
. It should list all the MonitorDevice Types
within your Monitor system, including theXY-Robot
that you created in Create sample Robot Device Type, Devices & Alerts to test your API calls section. Find-copy theuuid
of yourXY-Robot
that we will use in the next section.
We will use a Query data - DeviceType definition -- Device Type Alert Management
API call to test an API call using Postman. This call returns the list of Alerts for a given DeviceType.
- Launch Postman desktop. Click the
+
button to create a new Collection, name itMy Monitor REST API v2 Collection
. Try to be well structured, so under that Collection, create folders and sub-folders (e.g.Query data
-DeviceType
-Device Type Alert Management
) that reflect the API structure as you observed it in Overview of the API v2 structure & definitions. - Under your
Query data
-DeviceType
-Device Type Alert Management
sub folder, click on the right...
andAdd request
. - Make sure your request is a
POST
. Name itapi/v2/datalake/deviceTypes/{deviceTypeId}/alerts/search
. In thePOST
field, enterhttps://your-mas-monitor-server-url/api/v2/datalake/deviceTypes/{deviceType}/alerts/search
where (1)your-mas-monitor-server-url
is the value you retrieved in Get Monitor {X-api-key, X-api-token, tenantId, mam_user_email} & Server URL and (2){deviceType}
is theuuid
value of yourXY-Robot
as returned in the previous section. - Go to the
Headers
tab and add 1 after the other 4 Keys:X-API-KEY
,X-API-TOKEN
,tenantId
&mam_user_email
, with the values you retrieved in the Get Monitor {X-api-key, X-api-token, tenantId, mam_user_email} & Server URL section. - Go to the
Body
tab, and the first time you run the call, leave it empty - this will return all the Alerts of yourXY-Robot
. The second time you run the call, fill theBody
section with this snippet where you update"tsBegin"
and"tsEnd"
values to the time range you want to list the Alerts for:
{
"search": "alert_speed_7",
"tsBegin": "2024-04-29T07:31:57.893Z",
"tsEnd": "2024-05-01T07:31:57.893Z"
}
In this section, you will download and re-use a sample Jupyter Notebook which contains 12 sample API calls. Each has a varying level of 'complexity' - try them all in the order set in the Notebook.
- Donwload the cl-mas-monitor-discover-api-cp4d-template.ipynb Jupyter Notebook provided with this tutorial.
- From your MAS Cloud Pak for Data instance home page, click
All Projects
from the left menu. ClickNew Project
. - Click
Create an empty project
, name itxy-mas-monitor-discover-api-cp4d
(wherexy
are your initials). ClickCreate
. - Once the project is created, click
New asset
, selectJupyter notebook editor
. Select the defaultPython 3.10
andRuntime 22.2 on Python 3.10
. - Go to the
From File
tab of the project. In theDrag and drop files here or upload
box, upload the Notebook you just downloaded. Name itxy-mas-monitor-discover-api-cp4d
. ClickCreate
.
Execute the cells in the just-imported cl-mas-monitor-discover-api-cp4d-template.ipynb
Notebook one after the other.
- In the
GET SET - Get & Set your MAS Monitor ENV Details
Notebook initial section, replaceX-api-key
,X-api-token
,tenantId
,mam_user_email
as you found them in Get Monitor {X-api-key, X-api-token, tenantId, mam_user_email} & Server URL. - Run all subsequent API calls in order, 1 by 1, by following the instructions which each include these details:
What this call does: Short explanation
Your action: What you need to do
Note: where applicable
Back to Table of Contents
Enjoy discovering the 12 calls (and don't hesitate to try out more) !