Skip navigation
Share:|

BMC TrueSight 10 features a rich set of APIs that allow to interact with all the main aspects of the solution: Data, Events, Cis, Configuration.

This is the second of a series of posts on how to get familiar with those APIs and leverage them.

You can find the first post here: TrueSight Operations Management REST API for Event Management

 

For testing the APIs I suggest to use a Google Chrome app called Advanced REST client.

A valid alternative is another app/extension called Postman

 

Assumptions for using this tutorial:

TrueSight Operations Management 10.x installed and configured

  • TrueSight Presentation Server installed and configured for authentication with Atrium SSO
  • at least one TrueSight Infrastructure Management server installed and configured

 

Let's start setting up the Advanced REST client test environment:

 

 

The Central Monitoring Administration (CMA) API is exposed on the TS Presentation Server.

In order to be able to call any of the CMA APIs you need to obtain an authentication token calling the login API.


Here are the details needed for the login api

--------------------------------------------------------------------------------------------------------------

Url:

https://tsps:443/tsws/10.0/api/authenticate/login

 

Method: POST

 

Content-Type: application/json

 

Body:

 

{

    "username": "admin",

    "password": "admin12345",

    "tenantName": "BmcRealm"

}

 

------------------------------------------------------------------------------------------------------------------------

 

Calling the Login api in Advanced REST client:

cma_login_api_rest_client.png

more details here: Performing Central Monitoring Administration functions with web services - BMC TrueSight Operations Management 10.1 - BM…

 

Even though tokens expire, it is advised to release the token using the logout api when you are finished with the api calls.

 

 

 

List Policies

 

The CMA api allows to list policies

 

Here are the details needed for the list policies api:

--------------------------------------------------------------------------------------------------------------

 

url:

https://tsps.bmcswe.com:443/tsws/10.0/api/unifiedadmin/Policy/list?&responseType=basic

 

method: POST

 

Content-Type: application/json

 

Header: set Authorization header with the authtoken previously gotten.

Example:

Authorization: authtoken AQIC5wM2LY4SfcwdKU6v-5c6U-PtF1_x1qUlhw0CMjiiVKU.*AAJTSQACMDIAAlNLABM4NDE0Njc4NDQ2MDM4NTQ1MjA0AAJTMQACMDE.*

 

JSON body (sample) - Payload:

define an empty JSON body with just curly brackets

{}

 

Calling the list policies api in Advanced REST client:

cma_list_policy_api_rest_client.png

List Policy details

 

The CMA api allows to list policy details

 

Here are the details needed for the list policy details api:

--------------------------------------------------------------------------------------------------------------

 

url:

https://tsps:443/tsws/10.0/api/unifiedadmin/Policy/policy_Name/list?&responseType=basic

 

method: GET

 

Header: set Authorization header with the authtoken previously gotten.

Example:

Authorization: authtoken AQIC5wM2LY4SfcwdKU6v-5c6U-PtF1_x1qUlhw0CMjiiVKU.*AAJTSQACMDIAAlNLABM4NDE0Njc4NDQ2MDM4NTQ1MjA0AAJTMQACMDE.*

 

example:

https://tsps:443/tsws/10.0/api/unifiedadmin/Policy/PAR_ISM_PORTMON/list?&responseType=basic

 

 

Create Policies

 

The CMA api allows to create one or more policies. As you can notice the JSON body start and ends with square brackets, inside this section it is possible to define multiple events in blocks contained in curly brackets and separated by comma (",")

 

Here are the details needed for the create policy api:

--------------------------------------------------------------------------------------------------------------

 

url:

https://tsps:443/tsws/10.0/api/unifiedadmin/MonitoringPolicy/create

 

Content-Type: application/json


method: POST

 

Header: set Authorization header with the authtoken previously gotten.

Example:

Authorization: authtoken AQIC5wM2LY4SfcwdKU6v-5c6U-PtF1_x1qUlhw0CMjiiVKU.*AAJTSQACMDIAAlNLABM4NDE0Njc4NDQ2MDM4NTQ1MjA0AAJTMQACMDE.*

 

JSON body (sample policy for remote unix monitoring):

 

{

"monitoringPolicy": {

  "name" : "ZZZ-test-key-based-remote-unix-monitoring",

  "type" : "monitoring",

  "description" : "",

  "tenant" : {

    "name" : "bmcrealm",

    "id" : "bmcrealm"

  },

  "precedence" : 210,

  "agentSelectionCriteria" : "agentName STARTS_WITH \"agent_name\" ",

  "associatedUserGroup" : "Administrators",

  "owner" : "admin",

  "monitorConfiguration" : {

    "configurations" : [ {

      "solutionName" : "pukepd2",

      "solutionVersion" : "9.13.00",

      "monitoringProfile" : "REMOTE",

      "monitors" : [ {

        "monitorType" : "REMOTE_CONT",

        "configuration" : [ {

          "id" : "HOSTS",

          "value" : "remote_hostname_here",

          "details" : [ {

            "id" : "remHostName",

            "value" : "remote_hostname_here",

            "details" : null,

            "secure" : false,

            "mapDetails" : {

              "/remHostName" : "remote_hostname_here"

            }

          } ],

          "secure" : false,

          "mapDetails" : {

            "/HOSTS/remote_hostname_here/remHostName" : "remote_hostname_here"

          }

        }, {

          "id" : "HOSTS",

          "value" : "remote_hostname_here",

          "details" : [ {

            "id" : "remUserName",

            "value" : "root",

            "details" : null,

            "secure" : false,

            "mapDetails" : {

              "/remUserName" : "root"

            }

          } ],

          "secure" : false,

          "mapDetails" : {

            "/HOSTS/remote_hostname_here/remUserName" : "root"

          }

        }, {

          "id" : "HOSTS",

          "value" : "remote_hostname_here",

          "details" : [ {

            "id" : "remUsePwdAuth",

            "value" : "0",

            "details" : null,

            "secure" : false,

            "mapDetails" : {

              "/remUsePwdAuth" : "0"

            }

          } ],

          "secure" : false,

          "mapDetails" : {

            "/HOSTS/remote_hostname_here/remUsePwdAuth" : "0"

          }

        }, {

          "id" : "HOSTS",

          "value" : "remote_hostname_here",

          "details" : [ {

            "id" : "remPubKeyFilePath",

            "value" : "/home/patrol/.ssh/id_rsa.pub",

            "details" : null,

            "secure" : false,

            "mapDetails" : {

              "/remPubKeyFilePath" : "/home/patrol/.ssh/id_rsa.pub"

            }

          } ],

          "secure" : false,

          "mapDetails" : {

            "/HOSTS/remote_hostname_here/remPubKeyFilePath" : "/home/patrol/.ssh/id_rsa.pub"

          }

        }, {

          "id" : "HOSTS",

          "value" : "remote_hostname_here",

          "details" : [ {

            "id" : "remPrivKeyFilePath",

            "value" : "/home/patrol/.ssh/id_rsa",

            "details" : null,

            "secure" : false,

            "mapDetails" : {

              "/remPrivKeyFilePath" : "/home/patrol/.ssh/id_rsa"

            }

          } ],

          "secure" : false,

          "mapDetails" : {

            "/HOSTS/remote_hostname_here/remPrivKeyFilePath" : "/home/patrol/.ssh/id_rsa"

          }

        }, {

          "id" : "HOSTS",

          "value" : "remote_hostname_here",

          "details" : [ {

            "id" : "remPassPhrase",

            "value" : "f39/f39/f39/fwAAAAi2xZ3gZ7e7RgAAABD0Hxhh+szRH4B9PzNuO5KxAAAAFONPtuqt28Mo3Sj0zzzNC814OkdL",

            "details" : null,

            "secure" : true,

            "mapDetails" : {

              "/remPassPhrase" : "f39/f39/f39/fwAAAAi2xZ3gZ7e7RgAAABD0Hxhh+szRH4B9PzNuO5KxAAAAFONPtuqt28Mo3Sj0zzzNC814OkdL"

            }

          } ],

          "secure" : true,

          "mapDetails" : {

            "/HOSTS/remote_hostname_here/remPassPhrase" : "f39/f39/f39/fwAAAAi2xZ3gZ7e7RgAAABD0Hxhh+szRH4B9PzNuO5KxAAAAFONPtuqt28Mo3Sj0zzzNC814OkdL"

          }

        }, {

          "id" : "HOSTS",

          "value" : "remote_hostname_here",

          "details" : [ {

            "id" : "SudoMode",

            "value" : "1",

            "details" : null,

            "secure" : false,

            "mapDetails" : {

              "/SudoMode" : "1"

            }

          } ],

          "secure" : false,

          "mapDetails" : {

            "/HOSTS/remote_hostname_here/SudoMode" : "1"

          }

        } ]

      } ],

      "defaultMonitoring" : false

    } ]

  },

  "enabled" : false,

  "shared" : false

}

}

 

------------------------------------------------------------------------------------------------------------------------

The above policy configures monitoring for a new remote unix host with ssh key authentication. I highlighted in different colours the variable elements usually changed when adding remote hosts targets based on the same configuration. But there may be more attributes you may want to change according to your needs (sudo, etc.).

Calling the event Create api in Advanced REST client:

Screen Shot 2016-03-09 at 11.28.36.png

[...]

Screen Shot 2016-03-09 at 11.30.13.png

Sample response:

{

  "responseTimeStamp": "2016-03-09T11:28:32",

  "statusCode": "200",

  "statusMsg": "OK",

  "response": [{

       "resourceId": "031cf504-fd54-44f7-8d4f-ef5d684cc6b7",

       "resourceName": "ZZZ-test-key-based-remote-unix-monitoring",

       "resourceURI": null,

       "statusCode": "200",

       "statusMsg": "OK"

  }]

}

 

 

Delete a monitoring Policy

 

The CMA api allows to delete one or more policies.

 

Here are the details needed for the delete api:

--------------------------------------------------------------------------------------------------------------

Url:

http://tsps/tsws/10.0/api/unifiedadmin/Policy/policy203/delete?&idType=name

 

you can also delete a policy using policy Id so:  Idtype=id

 

method: DELETE (notice this is DELETE not POST as for the List and Create APIs)

 

Header: set Authorization header with the authtoken previously gotten.

Example:

Authorization: authtoken AQIC5wM2LY4SfcwdKU6v-5c6U-PtF1_x1qUlhw0CMjiiVKU.*AAJTSQACMDIAAlNLABM4NDE0Njc4NDQ2MDM4NTQ1MjA0AAJTMQACMDE.*

 

example:

https://tsps:443/tsws/10.0/api/unifiedadmin/Policy/PAR_ISM_PORTMON/delete?&idType=name

 

Being a DELETE, no JSON body is required.

 

Here is a sample response body:

 

{

    "response": [

        {

            "name": "PAR_ISM_PORTMON",

            "statusCode": "200",

            "statusMsg": "Successfully deleted policy",

            "resultHandle": "724"

        }

    ],

    "statusCode": "200",

    "statusMsg": "OK",

    "responseTimeStamp": "2016-04-29T16:33:20",

}

 

 

I plan to add more examples and attach some python scripts about CMA api with focus on policy management.

Filter Blog

By date:
By tag: