SNMP Configuration
| Horizon has been updated to move SNMP Configuration into the database. Please see SNMP Configuration (Legacy) for the legacy REST API. Generally speaking you should avoid that legacy API and use the new API instead, but if you have a use case that requires the legacy API, that page describes how to use it. |
This is the new REST API for SNMP configuration. It is used by the SNMP Configuration UI in the OpenNMS web interface, but it can also be used by external applications to manage SNMP configuration in OpenNMS directly.
You can use this API to manage SNMP configuration for individual IP addresses, for example to edit the community string, SNMP version, etc. for an IP address or range.
If you make a change that would overlap with any existing configurations, the system will automatically create groups of definition entries as necessary.
If a configuration matches the defaults, then no definition entry is created.
The following operations are supported.
The base URL for the API is http://localhost:8980/opennms/api/v2 (substitute your protocol, OpenNMS host and port as necessary).
GETs (reading data)
| Parameter | Description |
|---|---|
/snmp-config |
Get the entire SNMP configuration in JSON format. |
/snmp-config/lookup?ipAddress={ipaddress}&location={location} |
Get the SNMP configuration for a given IP address at a given monitoring location.
If Example: |
/snmp-config/download?format={format} |
Download the entire SNMP configuration in JSON or XML format as a file.
Example: |
PUT (modifying data)
| Parameter | Description |
|---|---|
/snmp-config/definition |
Add or update an SNMP configuration definition, in JSON format. See below for the SNMP Definition schema.
This can be used to apply configurations to individual IP addresses or ranges, or use |
POST (modifying data)
| Parameter | Description |
|---|---|
/snmp-config/defaults |
Save SNMP default override configuration, in JSON format. See below for the SNMP Configuration schema.
For each configuration item, the system has some default values.
However, you can use this API to override those defaults with your own values.
For example, if you want to change the default SNMP read community string from |
/snmp-config/profile |
Add or update an SNMP configuration profile, in JSON format. See below for the SNMP Profile schema. |
/snmp-config/upload |
Upload an entire SNMP configuration, in JSON format. See below for the schema. |
/snmp-config/upload/xml |
Upload an entire SNMP configuration, in XML format. See below for the schema. |
DELETE (removing data)
| Parameter | Description |
|---|---|
/snmp-config/definition?specifics={specifics}&ranges={ranges}&ipmatches={ipLike}&location={location} |
Remove an SNMP configuration definition.
This in effect resets the SNMP configuration for the specified IP address(es) and/or range(s) and/or You can supply any combination of the following parameters to specify which definition(s) to remove. You can use commas to separate individual values for each parameter. Example: would remove the definition for IP address 10.0.0.1. would remove both ranges. The system will automatically reconfigure SNMP configuration as necessary. |
/snmp-config/profile?label={label} |
Remove an SNMP configuration profile with the given |
API Schema
While the older XML configuration format is still supported, we recommend using the new JSON format for SNMP configuration, as it is more flexible and easier to work with.
The following table shows all supported attributes for SNMP Configuration. It also shows the version limitations, default values, and the restrictions, if any:
| Attribute | Default Value | Restricted to SNMP Version | Restrictions |
|---|---|---|---|
version |
v1 |
None |
|
port |
161 |
None |
Integer > |
retries |
1 |
None |
Integer > |
timeout |
3000 |
None |
Integer > |
maxVarsPerPdu |
10 |
None |
Integer > |
maxRepetitions |
2 |
None |
Integer > |
maxRequestSize |
65535 |
None |
Integer > |
ttl |
Blank |
None |
Integer > |
proxyHost |
Blank |
None |
None |
readCommunity |
public |
v1, v2c |
None |
writeCommunity |
private |
v1, v2c |
None |
securityName |
opennmsUser |
v3 |
None |
securityLevel |
noAuthNoPriv |
v3 |
Integer value, which can be |
authPassPhrase |
0p3nNMSv3 |
v3 |
None |
authProtocol |
MD5 |
v3 |
Only |
privPassPhrase |
0p3nNMSv3 |
v3 |
None |
privProtocol |
DES |
v3 |
Only |
engineId |
Blank |
v3 |
None |
contextEngineId |
Blank |
v3 |
None |
contextName |
Blank |
v3 |
None |
enterpriseId |
Blank |
v3 |
None |
| In the JSON examples below, the commented sections are explanatory only and are not part of the actual JSON body that you would send in a request. |
{
"maxRepetitions": 2, (1)
"maxRequestSize": 65535,
"readCommunity": "public123",
"definition": [
{
"range": [
{
"begin": "10.0.0.0",
"end": "10.0.0.9"
}
],
"readCommunity": "myReadCommunityFor10Net" (2)
},
{
"specific": [
"10.9.9.9", "10.11.12.13"
]
(2)
},
{
"ipMatch": [
"10.0.0.*", "192.168.*.*"
]
(2)
}
],
"profiles": {
"profile": [
{
"label": "datacenter1",
"filter": "filter expression 1"
(3)
},
{
"label": "datacenter2",
"filter": "filter expression 2"
(3)
}
]
}
}
| 1 | Any fields from the table above can go here, these are the default overrides, if any.
They can be omitted or null to use the system defaults |
| 2 | Any fields from the table above can go here, to override the defaults for this definition, specific or ipMatch. |
| 3 | Any fields from the table above can go here, to override the defaults for this profile. |
When updating a Definition or Profile, use the JSON body that’s inside the definition or profile array, respectively.
{
"maxRepetitions": 2, (1)
"maxRequestSize": 65535,
"readCommunity": "public123",
"range": [
{
"begin": "10.0.0.0",
"end": "10.0.0.9"
}
]
}
| 1 | Any fields from the table above can go here, these are the overrides for this definition. |
{
"maxRepetitions": 2, (1)
"maxRequestSize": 65535,
"readCommunity": "public123",
"label": "myProfileLabel",
"filter": "myFilterExpression"
}
| 1 | Any fields from the table above can go here, these are the overrides for this profile. |
curl Examples
curl -v -u admin:admin -X PUT -H "Content-Type: application/json" \
-d @./your-data-file.json \
http://localhost:8980/opennms/api/v2/snmp-config/definition
Creates or updates a definition entry, with configuration in the given local JSON file.
curl -v -u admin:admin -X PUT \
-H "Content-Type: application/json" \
-d \
'{
"readCommunity": "public-123",
"timeout": 2000,
"range": [
{
"begin": "10.0.0.0",
"end": "10.0.0.9"
}
],
"ipMatch": ["10.9.9.9"]
}' \
'http://localhost:8980/opennms/api/v2/snmp-config/definition'
Creates or updates a definition entry, with configuration inline.
curl -v -u admin:admin http://localhost:8980/opennms/api/v2/snmp-config
curl -v -u admin:admin http://localhost:8980/opennms/api/v2/snmp-config/download
curl -v -u admin:admin http://localhost:8980/opennms/api/v2/snmp-config/download?format=xml
curl -v -u admin:admin \
'http://localhost:8980/opennms/api/v2/snmp-config/lookup?ipAddress=10.0.0.2&location=Default'