Getting a token via the API
If you need to generate tokens programmatically, you can request a token through the API with your username and password. All future requests can then be performed using the returned token.
If the user generating the token has Multi Factor Authentication enabled, you cannot use this method and must create the token via the web UI.
Deleting a token via the API
API tokens can be deleted via the API or through the web UI.
In this example, the tokens are different but they can be the same if you want to delete the token you’re accessing the API with.
Getting a token via the UI
As well as programmatically, it's also possible to create tokens manually within your user interface.
- Log in to your Server Density account.
- Click your name in the top left, then click Security.
- Under API tokens, enter a name for the API application you're building so you can easily recognise it in the future e.g. "Llama Script".
- Press Enter and your API token will be shown as a 32 character ID.
Pagination
Our API will not return more than 400 JSON objects in a single request. Therefore we provide pagination to access more data conveniently. For data where pagination is required additional headers will be included in the response.
Response Headers
x-total-number Gives the total number of results availablex-first-page Gives the URL for the first page of paginated resultsx-last-page Gives the URL for the last page of paginated resultsx-previous-page Gives the URL for the previous page of paginated resultsx-next-page Gives the URL for the next page of paginated results
Pagination is designed to work with any API endpoint that returns are large amount of data. Simply append the pagination options to your endpoint URL.
Creating a device
You can create new devices via the API, useful if you want to automatically provision new devices and start monitoring automatically.
This API method is used by our Puppet manifest, Chef cookbook and installer shell script to automatically create devices during the agent installation.
Deleting a device
Delete a device from your account. Device deletion is an irreversible process when carried out by the API.
Listing all devices
List each device on your account, along with the meta data.
The deleted field can be either set to true or false. If a cloud-synced device is deleted using the web front end it will still appear in the api call, but with deleted set to true.
Searching for a device
There is a single resources endpoint that will search the entire inventory. This can be used to search for services too.
The response will either be an empty JSON array, or a list of the devices that match the filter. These will be in the same format and with the same fields as without the filter.
Searching for a service
There is a single resources endpoint that will search the entire inventory. This can be used to search for devices too.
View service errors
Filter options
code - This filter option will search and return all errors with a match of your desired status code in the error description.location_name - This filter option will search and return all errors from the specified monitoring location.error - This filter option will search and return all errors with the specified error message in the error description.
Creating an alert
Create new alerts on devices or services, at an item or group level.
Comparisons
| Comparison | Explanation |
|---|---|
lt |
less than |
gt |
greater than |
lte |
less than or equal to |
gte |
greater than or equal to |
eq |
equal to |
neq |
not equal to |
c |
contains |
nc |
does not contain |
re |
matches regex |
nre |
does not match regex |
ex |
does exist |
nex |
does not exist |
Parameters: Recipients
| Parameters | Required | Type | Description |
|---|---|---|---|
| type | Yes | string | The type of recipient: user, pagerduty or webhook |
| id | Yes | string | The ID of the recipient e.g. user ID or webhook ID |
| actions | depends | string | The notification types to send, not required for pagerduty, webhook, slack or hipchat types |
You can list all of your recipients with the List Recipients endpoint. You can also Create Recipients too. If you're using a webhook recipient you might want to familiarise yourself with the webhook payload format
Parameters: Wait
| Parameters | Required | Type | Description |
|---|---|---|---|
| seconds | Yes | string | The number of seconds to wait. |
| enabled | Yes | string | Whether the wait configuration is enabled or not |
| displayUnits | Yes | string | Hint for the UI, always s (may change in future releases) |
Parameters: Repeat
| Parameters | Required | Type | Description |
|---|---|---|---|
| seconds | Yes | string | The number of seconds to wait. |
| enabled | Yes | string | Whether the wait configuration is enabled or not |
| displayUnits | Yes | string | Hint for the UI, always s (may change in future releases) |
Updating alerts
Update existing alerts on devices or services, at an item or group level.
Comparisons
| Comparison | Explanation |
|---|---|
lt |
less than |
gt |
greater than |
lte |
less than or equal to |
gte |
greater than or equal to |
eq |
equal to |
neq |
not equal toc - contains |
nc |
does not contain |
re |
matches regex |
nre |
does not match regex |
Parameters: Recipients
| Parameters | Required | Type | Description |
|---|---|---|---|
| type | Yes | string | The type of recipient: user, pagerduty or webhook |
| id | Yes | string | The ID of the recipient e.g. user ID or webhook ID |
| actions | depends | string | The notification types to send, not required for pagerduty or webhook types` |
Parameters: Wait
| Parameters | Required | Type | Description |
|---|---|---|---|
| seconds | Yes | string | The number of seconds to wait. |
| enabled | Yes | string | Whether the wait configuration is enabled or not |
| displayUnits | Yes | string | Hint for the UI, always s (may change in future releases) |
Parameters: Repeat
| Parameters | Required | Type | Description |
|---|---|---|---|
| seconds | Yes | string | The number of seconds to wait. |
| enabled | Yes | string | Whether the wait configuration is enabled or not |
| displayUnits | Yes | string | Hint for the UI, always s (may change in future releases) |
Pausing & resuming alerts
Pausing and resuming existing alerts on devices or services, at an item or group level.
Triggered alerts
Get a list of all triggered alerts on your account, per subject (device or service) or per alert config.
Additional Headers
This endpoint also returns the following headers:
X-Total-Closed:X-Total-Filter:X-Total-Open:X-User-Closed:X-User-Id:X-User-Open:
Filter Options
Some filter options are not present in the returned data or the config:limit - Use this to limit the total results returned, defaults to 100dateFrom - Use this to limit the returned triggered alerts by date.
You can filter on any of the config options in a similar fashion to below.config.subjectId - Use this to limit by subjectId (including group names).config.subjectType - Use this to limit by subject typeconfig.field - Use this to filter by field, e.g loadAvrg
Example Filter
{"limit":10,"dateFrom":"2016-06-20T15:45:57+00:00","fixed":true, "config.subjectId":"websites", "config.subjectType":"deviceGroup", "config.field":"loadAvrg"}
Listing device alert metrics
Devices and services have different alert metrics which you can configure in the ui. The section correspond to the top-level of the alert metric whereas field corresponds to the subsection of the given section.
Listing service alert metrics
Devices and services have different alert metrics which you can configure in the ui. The section correspond to the top-level of the alert metric whereas field corresponds to the subsection of the given section.
Listing recipients
Get a list of non-user recipients for alerts including Slack, HipChat, PagerDuty and WebHooks
Creating a recipient
Create recipients for your alert notifications
If you're using a webhook recipient you might want to familiarise yourself with the webhook payload format
Listing costs
Get the alerts history items limited by the given filter. If configId filter is set, then the results contains all events for that alert configuration. In any other case, the results are aggregated by itemId and configId including the following derived values:
durationthe sum of event durations.triggeredCountthe number of events for that alert in that item.costthe HumanOps cost in seconds. For more information please check our support docs
When the query is aggregated, the non-derived fields are from the document whose startDate is the newest. In addition to this, an unique id is generated by concatenating the itemId and the configId.
Viewing costs
Get the alerts history items limited by the given filter and the itemId. If configId filter is set, then the results contains all events for that alert configuration. In any other case, the results are aggregated by itemId and configId including the following derived values:
durationthe sum of event durations.triggeredCountthe number of events for that alert in that item.costthe HumanOps cost in seconds. For more information please check our support docs
When the query is aggregated, the non-derived fields are from the document whose startDate is the newest. In addition to this, an unique id is generated by concatenating the itemId and the configId.
Available Metrics
Determine which metrics are available to return historical data for. Metrics can be returned for the whole account, a specific item (device or service), or the scope can be narrowed using a filter.
You can define the scope of the query using the scope list in your filter. It has the format type: id where type is one of the following
item
The ObjectId string which uniquely identifies the item
{"item": "5a79e996b03e85b1378b456f"}
group
A list of item identifiers
{"group": ["5a79e996b03e85b1378b456f", "5a79e996b03e85b1378b456d"]}
filter
A list of search terms, searching the inventory
{"filter":"web*"}
serviceGroup
A service group name string
{"serviceGroup": "services"}
deviceGroup
a device group name string
{"deviceGroup": "devices"}
You can further define the scope by specifying the metrics to be returned in your filter. Metrics can be searched by exact match, or by regex. This has the format {'type': 'eq|re', 'value': 'val'} with eq meaning exact match and re meaning regex.
Examples are provided above.
Get metrics
Returns historical metrics data, for a specific subject (device or service) over a specific time range. Wildcards are supported with metric names, allowing you to query multiple metrics with a simple request.
Note that data is stored in a particular retention policy which will return minute and hourly data points depending on the time range. If the query ranges over 1 day, hourly data points will be returned, otherwise you will get a data point for every minute. The 1 minute data points are only stored for the last 5 days.
Dynamic metrics
Return historical metrics data, for a devices and/or services that match a search or regex style inventory filter search over a specific time range.
Creating a postback
You can use this method to post data back to Server Density without using the agent, for example using your own scripts or to integrate in something custom you are doing. You will still be restricted to posting back once per minute using this method, as you would be using the agent.
Creating a widget
Types of Widget
| Widget | Description |
|---|---|
| cloudStatus | Status of some cloud vendors |
| graph | Graph widget with time series data |
| openAlerts | Open alerts from the selected device/service/group |
| rss | RSS feed |
| serviceStatus | Display the current status of one of your service checks |
| latestValue | The latest value for a selected metric |
Configuring a widget
Widget json objects have a config field where the widget configuration is stored. The configuration depends on the widget type. This different configuration variants are described in this document.
This widget type shows the status of some cloud vendors
cloudStatus Parameters
| Parameters | Description |
|---|---|
| providerId | Name of the provider |
amazon |
|
digitalOcean |
|
google |
|
joyent |
|
linode |
|
rackspace |
|
salesforce |
|
softlayer |
|
windowsAzure |
|
| feedUrl | Url of the news feed. The feed needs to be one of the specified on the Cloud status widget feed url list page. If the feed you wish to use is not in this list you should use an RSS widget, which can be configured with any feed. |
Example Configuration
{
"providerId": “amazon”,
"feedUrl": "http://status.aws.amazon.com/rss/cloudfront.rss"
}
This widget shows time series data
graph Parameters
| Parameters | Required | Type | Description |
|---|---|---|---|
| requests | No | list of dicts | Each dict in the list can contain the scope, metric, and tags fields.The scope field will contain the id(s) of the subject device/service or the regex filter to be used on the device/service list. The metric filed will contain the name of the metric being displayed. The tags field will contain the tagged instances that will be displayed for the selected metric |
| filter | Yes | dict | Object containing the metrics to be graphed. The JSON representation to the left would graph all available apache stats. |
| type | Yes | string | "line" for line a line graph. "area" for a stacked area graph. |
| tall | No | bool | True makes the maximized view of the graph extra tall. |
| seriesStatesv3 | No | dict | Contains the series configuration of a graph such as assigning series to the left or right axis or disabling them completely. |
Example Configuration
"requests": [
{
"scope": [
{
"filter": "[1|2]"
}
],
"metric": "system.processes.number"
},
{
"scope": [
{
"item": "5ad9d132b03e85d53165456a"
}
],
"tags": {
"device_name": "*"
},
"metric": "system.disk.in_use"
},
],
"type": "line"
This widget shows the last entries from the specified RSS feed
rss Parameters
| Parameters | Required | Type | Description |
|---|---|---|---|
| feedUrl | Yes | string | Url of the RSS news feed. |
Example Configuration
{
"feedUrl": "http://status.aws.amazon.com/rss/fps.rss"
}
This widget shows the current status of one of your service checks
Config Parameters
| Parameters | Required | Type | Description |
|---|---|---|---|
| serviceId | Yes | string | Id of the service this widget will display information from. |
Example Configuration
{
"serviceId": "5457a1ff95fe35c63174751f"
}
This widget shows the number of open alerts
openAlerts Parameters
entity Is a dictionary which is the definition of the subset of entities from which to count alerts.
Within entity the following parameters can be used.
| Parameters | Type | Description |
|---|---|---|
| id | string | Id of the device or service or the name of the group. Use all for the whole account |
| name | string | Name of the device or group |
| type | string | What type it is. See the following types. |
| type > device | string | The id is from a device |
| type > deviceGroup | string | The id is from a deviceGroup |
| type > service | string | The id is from a service |
| type > serviceGroup | string | The id is from a service group |
| isGroup | bool | Depending if the ID is from a group. |
Example Configurations
- openAlerts - account
- openAlerts - single device
- openAlerts - single service
- open alerts - device group
- openAlerts - service group
{
"entity": {
"id": "all",
"name": "The entire account",
"type": "all",
"isGroup": false
}
}
{
"id": "5458c45276d3776004900000",
"name": "test",
"type": "device",
"isGroup": false
}
{
"id": "5358f95f76d377e876000000",
"name": "www.serverdensity.com",
"type": "service",
"isGroup": false
}
{
"id": "test_group",
"name": "test_group",
"type": "deviceGroup",
"isGroup": true
}
{
"id": "Monitored websites",
"name": "Monitored websites",
"type": "serviceGroup",
"isGroup": true
}
