OpsView RESTful API Tips

Recently I’ve had the displeasure of building scripts that interact with the OpsView API, which is the only way to programmatically change settings in OpsView. The API itself seems to be quite well designed, however, it’s very poorly documented. Below are a few of the things I couldn’t figure out how to do via Google.

Change A User’s Password

JSON:

{
  "id": 1,
  "password": "plaintext_password"
}

Command:

/usr/local/nagios/bin/opsview_rest \
  --data-format=json \
  --username=admin \
  --password=initial \
  --content-file=/path/to/your/json/file.json \
  PUT config/contact/1

The important part here is the path, which is /rest/config/contact/#ID.

Modify A User

Same as above.

JSON:

{
  "id": 1,
  "name": "username",
  "variables": [{"name": "EMAIL", "value": "[email protected]"}]
}

Command:

/usr/local/nagios/bin/opsview_rest \
  --data-format=json \
  --username=admin \
  --password=initial \
  --content-file=/path/to/your/json/file.json \
  PUT config/contact/1

The important part here is the path, which isĀ /rest/config/contact/#ID.

If you want to see all of the fields available to change, just issue a GET request to that URL:

/usr/local/nagios/bin/opsview_rest \
  --data-format=json \
  --username=admin \
  --password=initial \
  --pretty \
  GET config/contact/1

Get All Users

Pretty obvious.

/usr/local/nagios/bin/opsview_rest \
  --data-format=json \
  --username=admin \
  --password=initial \
  --pretty GET config/contact

Add A Host

Refer to the OpsView documentation for a list of fields you can set.

JSON:

{
  "alias": "Totally Sweet Web Server",
  "ip": "hostname.example.com",
  "name": "SweetWebServer",
  "hostgroup": { "name": "Some Host Group" },
  "hosttemplates": [{ "name": "OS - Unix Base" }],
  "icon": { "name": "SYMBOL - Server", "path": "/images/logos/server_small.png" }
}

Command:

/usr/local/nagios/bin/opsview_rest \
  --data-format=json \
  --username=admin \
  --password=initial \
  --content-file=/path/to/your/json/file.json \
  PUT config/host

Add A Host Group

JSON:

{
  "name": "Production Servers"
}

Command:

/usr/local/nagios/bin/opsview_rest \
  --data-format=json \
  --username=admin \
  --password=initial \
  --content-file=/path/to/your/json/file.json \
  PUT config/hostgroup

 

Leave a Reply