You are here

Blog

Using the Opsview API

Every version of Opsview ships with a public REST API that allows full control over your Opsview configuration.  This technical blog post is going to highlight some of the ways we can use the API to automate certain tasks.

You can use /usr/local/nagios/bin/opsview_rest to communicate with the REST API. For example:

opsview_rest --username=admin --password=initial GET config/host/1

This will return back the full configuration of host ‘1’.   

You can find out the value of your host by going to SETTINGS > HOSTS  and hover over the host you want to find the value of. 

Opsview API

You can get the output to edit and put back again:

We can use 'sed' to replace the name of our servers, for example, we want to replace ‘ukirpops’ servers 05-09 as ‘ukirtops’ as they are becoming test servers.  

sed -r '/ukirpops0[5-9]/s/ukirpops([0-9]{2})/ukirtops\1/' all.json

opsview_rest --username=admin --password=initial --content-file=host.json --data-format=json --pretty PUT config/host/1

To show all performance statistics for 'unix swap' metric:

opsview_rest --username=admin --password=initial --pretty GET /rest/status/performancemetric/?servicename=Unix\ Swap  

To show all performance statistics for host 'opsview'

opsview_rest --username=admin --password=initial --pretty GET /rest/status/performancemetric/?hostname=opsview 

To show metric 'load average' from host 'opsview':

opsview_rest --username=admin --password=initial --pretty GET '/rest/status/performancemetric?order=metricname&order=hostname&metricname=load1&hostname=opsview'  

To perform a reload of Opsview:

opsview_rest --username=admin --password=initial --pretty POST 'reload'

Find out more about using Opsview REST API on our docs site.

Get unified insight into your IT operations with Opsview Monitor

webteam's picture
by Opsview Team,
Administrator
Opsview is passionately focused on monitoring that enables DevOps teams to deliver smarter business services, faster.

More like this

Extending Puppet into your Monitoring Environment
Oct 03, 2017
Blog
By John Hashem, Technical Pre-sales

Opsview has introduced the Opsview Puppet Module, which automatically registers compute instances for monitoring within Opsview Monitor. 

Jun 06, 2012
Blog
By Opsview Team, Administrator

This blog post takes a deep-dive into monitoring Microsoft SQL Server 2008 with Opsview V4. In order to monitor SQL server (known hereon as SQL2K8...

Oct 14, 2015
Blog
By Adam Such, Integrations Lead

With each new version release of Opsview Monitor, new and improved features are delivered as we continue to enhance our monitoring solution to fit...