REST API
A RESTful interface is a web service conforming to the REST architectural style as described in RESTful Web Services. This section describes the RESTful interface for Meridian.
ReST URL
The base URL for REST calls is: http://opennmsserver:8980/opennms/rest/
For instance, http://localhost:8980/opennms/rest/alarms/ will give you the current alarms in the system.
Authentication
Use HTTP basic authentication to provide a valid username and password. By default you will not receive a challenge, so you must configure your REST client library to send basic authentication proactively.
Data Format
Jersey lets REST calls to be made using either XML or JSON. By default, returns a request to the API in XML. XML is delivered without namespaces.
If a namespace is added manually, in order to use a XML tool to validate against the XSD (like xmllint) it won’t be preserved when OpenNMS updates that file. The same applies to comments. |
To get JSON-encoded responses one has to send the following header with the request: Accept: application/json
.
Standard Parameters
The following are standard parameters available on most resources (noted below):
Parameter | Description |
---|---|
|
integer, limiting the number of results. This is particularly handy on events and notifications, where an accidental call with no limit could result in many thousands of results being returned, killing either the client or the server. If set to 0, then no limit applied. |
|
integer, being the numeric offset into the result set from which results should start being returned. For example, if there are 100 result entries, offset is 15, and limit is 10, then entries 15-24 will be returned. Used for pagination |
Filtering: All properties of the entity being accessed can be specified as parameters in either the URL (for GET) or the form value (for PUT and POST). If so, the value will be used to add a filter to the result. By default, the operation is equality, unless the |
|
|
Checks for equality |
|
Checks for non-equality |
|
Case-insensitive wildcarding ( |
|
Case-sensitive wildcarding ( |
|
Greater than |
|
Less than |
|
Greater than or equal |
|
Less than or equal |
If the value null
is passed for a given property, then the obvious operation will occur (comparator will be ignored for that property).
notnull
is handled similarly.
-
Ordering: If the parameter
orderBy
is specified, results will be ordered by the named property. Default is ascending, unless theorder
parameter is set todesc
(any other value will default to ascending)
Standard Filter Examples
Take /events
as an example.
Resource | Description |
---|---|
|
Returns the first 10 events with the rtc subscribe UEI, (10 being the default limit for events). |
|
Returns all the rtc subscribe events (potentially quite a few). |
|
Returns the first 10 events with an ID greater than 100. |
|
Returns the first 10 events that have a non-null Ack time (i.e., those that have been acknowledged). |
|
Returns the first 20 events that have a non-null Ack time and an ID greater than 100. Note that the notnull value causes the comparator to be ignored for eventAckTime. |
|
Returns the first 20 events that have were acknowledged after 28th July 2008 at 4:41 a.m. (+12:00), and an ID greater than 100. Note that the same comparator applies to both property comparisons. Also note that you must URL encode the plus sign when using GET. |
|
Returns the 10 latest events inserted (probably, unless you’ve been messing with the IDs). |
|
Returns the first 10 events associated with some node in location 'MINION' |
HTTP Return Codes
The following apply for OpenNMS Horizon 18 and newer.
-
DELETE requests return a 202 (ACCEPTED) if they are performed asynchronously, otherwise they return a 204 (NO_CONTENT) on success.
-
All the PUT requests return a 204 (NO_CONTENT) on success.
-
All the POST requests that can either add or update an entity return a 204 (NO_CONTENT) on success.
-
All the POST associated to resource addition return a 201 (CREATED) on success.
-
All the POST requests where it is required to return an object return a 200 (OK).
-
All the requests excepts GET for the requisitions end-point and the foreign sources definitions end-point return 202 (ACCEPTED). This is because all the requests are actually executed asynchronously and there is no way to know the status of the execution, or wait until the processing is done.
-
If a resource is not modified during a PUT request, a NOT_MODIFIED will be returned. A NO_CONTENT will be returned only on a success operation.
-
All GET requests return 200 (OK) on success.
-
All GET requests return 404 (NOT_FOUND) when a single resource does not exist, but will return 400 (BAD_REQUEST) if an intermediate resource doesn’t exist. For example, if a specific IP doesn’t exist on a valid node, return 404. But if the IP is valid and the node is not valid, because the node is an intermediate resource, a 400 will be returned.
-
If something not expected is received from the Service/DAO Layer when processing any HTTP request, like an exception, a 500 (INTERNAL_SERVER_ERROR) will be returned.
-
Any problem related to the incoming parameters, like validations, generates a 400 (BAD_REQUEST).
Identifying Resources
Some endpoints deal in resources, which are identified by resource IDs. Since every resource is ultimately parented under some node, identifying the node that contains a resource is the first step in constructing a resource ID. Two styles are available for identifying the node in a resource ID:
Style | Description | Example |
---|---|---|
|
Identifies a node by its database ID, which is always an integer |
|
|
Identifies a node by its foreign-source name and foreign-ID, joined by a single colon |
|
The node identifier is followed by a period, then a resource-type name and instance name. The instance name’s characteristics may vary from one resource-type to the next. A few examples:
Value | Description |
---|---|
|
Node-level (scalar) performance data for the node in question. This type is the only one where the instance identifier is empty. |
|
A layer two interface as represented by a row in the SNMP |
|
The root filesystem of a node running the Net-SNMP management agent. |
Putting it all together, here are a few well-formed resource IDs:
-
node[1].nodeSnmp[]
-
node[42].interfaceSnmp[eth0-04013f75f101]
-
node[Servers:115da833-0957-4471-b496-a731928c27dd].dskIndex[_root_fs]