Getting Started with APIs
Introduction
Overview
OpsRamp provides REST APIs to:
Get information about managed resources from OpsRamp.
Send information about managed resources to OpsRamp.
Configure OpsRamp to take management actions.
Authentication
OpsRamp APIs use OAuth 2.0 based authentication.
API URL
OpsRamp supports the following API URLs:
For Partner Users:
If partner is custom branded, use partner custom branded API URL – https://<partner_name>.api.opsramp.com. For example, if partner name is Alpha, provide https://alpha.api.opsramp.com as the API URL.
If partner is NOT custom branded, use https://api.opsramp.com as the API URL.
For Client Users:
If client and partner are custom branded, use client custom branded API URL – https://<client_name>.api.opsramp.com. For example, if client name is Logix, provide https://logix.api.opsramp.com as the API URL.
If client is custom branded, but partner is NOT custom branded, use https://api.opsramp.com as the API URL.
Each API request has the following header format:
Header
Value
Accept
application/json
Content-Type
application/json
Authorization
Bearer {accessToken} or Basic base64_encode(loginName:password)
API Request Throttling
API throttling limits the number of requests an API server accepts within a time period. The API server rejects requests that exceed the limit and will return 429 Too Many Requests status code.
OpsRamp throttles API requests to ensure a better quality of service. The following limits apply for each tenant (service provider, partner, and client). API requests made after a throttling limit will fail with a 429 status code error.
Throttling Limits
API Category
GET (non-paginated) (requests/minute)
GET (paginated) (requests/minute)
POST/DELETE/PUT (requests/minute)
Note: The API rate limits may change to ensure better performance and service, hence it is advisable to use HTTP headers while making API requests.
Response headers include usage against limits
API response headers include information on usage against throttling limits so that application making API request can self-regulate their requests.
HTTP Header
Description
Example
X-RateLimit-Limit
Number of requests the user is allowed to make per minute.
X-RateLimit-Limit: 500
X-RateLimit-Remaining
Number of requests remaining in the current rate limit window.
X-RateLimit-Remaining: 14
X-RateLimit-Reset
The time at which the current rate limit window resets. Time in UTC epoch seconds.
X-RateLimit-Reset: 1491397260
Sample Error Response
Below is the sample response generated if the API requests exceed the rate limit.
Return Status Codes
Each API call returns one of the following return codes.
Status
Message
Details
200
Success
The request has succeeded.
400
Bad Request
Unable to authenticate.
401
Unauthorized
The system/user is not authorized to use the API.
404
Not found
The requested resource was not found.
405
Method not allowed
The HTTP action is not allowed for the requested REST API, or it is not supported by any API.
407
Proxy Authentication Required
Token is expired.
410
Gone
Tenant is unavailable or deactivated.
429
Too Many Requests
API rate limit is reached and request made after the rate limit fails.
500
Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request.
Generate API Requests
Prior to initiating an API request install the integration, obtain the access token and then generate the API request.
Step 1: Install Integration
This integration is the channel through which the API communicates with OpsRamp.
Each integration has an OAuth Key and Secret, which is used to obtain an OAuth Access Token.
Step 2: Generate an Access Token
Prior to making API requests, obtain an access token using the OAuth Key and Secret.
Steps to obtain OAuth Key and Secret.
Click Setup.
Click Integrations on the left-hand side panel and then click Integrations. Integrations page appears.
Click Available Integrations and then click on the required integration.
Click Install to install the integration.
Select authentication type OAUTH2 and then click Save.
Capture the Key and Secret for the integration.
Authenticate with OpsRamp using auth API as below
Curl
Python
Java
Capture OAuth authorization token from response
Note:
Validity period of the access token is 2 hours.
Repeat above instructions if the token expires.
Appendix – Generating API Requests
Example: Get inventory of managed resources within a client
Below are the sample codes to make an API request to get the inventory details of resources within a client.
Get list of Devices.
Curl
Search device details by name.
Curl
Search devices by UUID.
Curl
Python
Java
Example: Get time series metric data for a managed resource
Below are the sample codes to generate an API request to get metric data for a managed resource.
Get resource ID and resource type using Search Devices API.
Curl
curl -k -H "Authorization: Bearer be1eb787-9994-4de8-b060-4d1b201eb570" -H "Content-Type: application/json" -H "Accept:application/json" -X GET "https://<api-url>/api/v2/tenants/client_622733/devices/search?queryString=hostName:prod-Test-01"
Capture resource ID and resource type from the response.
Get metric name from the list of available metrics on a device.
Curl
curl -k -H "Authorization: Bearer be1eb787-9994-4de8-b060-4d1b201eb570" -H "Content-Type: application/json" -H "Accept:application/json" -X GET "https://<api-url>/api/v2/metric/tenants/client_622733/rtypes/DEVICE/resources/i-4cf5c094/metrics"
Capture metric from response Get the time series response for the resource ID, resource type and metric (startTime and endTime are UNIX timestamps).
Curl
curl -k -H "Authorization: Bearer be1eb787-9994-4de8-b060-4d1b201eb570" -H "Content-Type: application/json" -H "Accept:application/json" -X GET "https://<api-url>/api/v2/metric/search?tenant=client_622733&rtype=DEVICE&resource=i-4cf5c094&metric=system.cpu.utilization&startTime=1444973469&endTime=1445002269"
Sample metric and start/end times are
metric=system.cpu.utilization&startTime=1444973469&endTime=1463772116049
Note:
Start/end dates from the curl from Linux
date +%s #Current time
date -d “1 hour ago” +%s #1 Hour ago
date -d “1 day ago” +%s #1 Day ago
date -d “1 month ago” +%s #1 Month ago
Start/end dates from the curl from OS X
date +%s #Current time
date -v-1H +%s #1 Hour ago
date -v-1d +%s #1 Day ago
date -v-1m +%s #1 Month ago
Python
Java
Example: Post a metric against a resource
Below are the sample codes to generate an API request to post a metric on a resource.
Curl
curl -k https://<api-url>/api/v2/metric/tenants/client_622733/rtypes/DEVICE/resources/i-4cf5c094/metrics -H "Authorization: Bearer be1eb787-9994-4de8-b060-4d1b201eb570" -H "Content-Type: application/json" -H "Accept: application/json" -d '[{"metricName" : "system.cpu.utilization","instanceName" : "system.cpu.utilization","instanceVal" : "13.50","ts" : "1448274610"}]' -X POSTPython
Java
Example: Get open alerts
Below are the sample codes to generate an API request to get the list of open alerts.
Curl
curl -k -H “Authorization: Bearer be1eb787-9994-4de8-b060-4d1b201eb570” -H “Content-Type: application/json” -H “Accept:application/json” -X GET “https://<partner_name>.api.ospramp.com/api/v2/tenants/client_622733/alerts/search?queryString=actions:OPEN”
Python
Java
Example: Post an alert against a resource
Below are the sample codes to generate an API request to post alerts on a resource.
Curl
curl -k https://<api-url>/api/v2/tenants/client_622733/alert -H "Authorization: Bearer be1eb787-9994-4de8-b060-4d1b201eb570" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"serviceName": "CPU","device":{"hostName":"Think-pad","resourceUUID":"DEV0000011767","providerUUID":"11767","systemUUID":"11767","macAddress":"2E:8B:EB:32:7A:F9","ipAddress":"172.2.229.109"},"subject":"Test API Alert for car", "alertTime":"2014-11-05 11:26:00","currentState":"CRITICAL", "app":"OPSRAMP","alertType":"Maintenance","component": "C","description":"api calls","monitorName":"test"}'Python
Java
Example: Assign schedule maintenance to a device
Below are the sample codes to generate an API request to manage the schedule maintenance window.
Create a schedule maintenance window.
Curl
curl -k -H "Authorization: Bearer be1eb787-9994-4de8-b060-4d1b201eb570" -H "Content-Type: application/json" -H "Accept:application/json" -X POST https://<api-url>/api/v2/tenants/client_622733/scheduleMaintenances -d
Search for a scheduled maintenance window by name.
Curl
Suspend a scheduled maintenance window.
Curl
Resume a scheduled maintenance window.
Curl
Delete a scheduled maintenance window.
Curl
Below are the sample codes of Python and Java to manage a schedule maintenance window.
Python
Java
Last updated
Was this helpful?