skip to main content
op5 Monitor API and CLI
  
op5 Monitor API and CLI
Introduction
op5 Monitor comes with a few API’s that can be used to The following API’s can be used.
Ninja API, GUI API
Nacoma API, Configure API
op5 Monitor Configuration CLI
 
GUI API
The GUI API is use to get the information that is used by op5 Monitor GUI. It can give you information about all objects used by the op5 monitor.
Widgets are one place where the GUI API will come handy.
There are only a briefly documentation about that API today. It is included in the product.
Let us say that your monitor server is called op5-monitor you can reach the documentation on the following location:
https://op5-monitor/monitor/Documentation/html/index.html
It is generated by doxygen and contains information like
namespaces
structures (classes and methods)
files
 
Configure API
The configure API is used to manipulate the object configuration used by op5 Monitor. It works against the configure database the same way as the op5 Monitor Configuration tool does.
You may use it to build integrations between op5 Monitor and other third party software.
Let us say that your monitor server is called op5-monitor you can reach the documentation on the following location:
https://op5-monitor/monitor/op5/nacoma/Documentation/html/index.html
It is generated by doxygen and contains information like classes and methods used in the op5 Monitor configuration tool.
op5 Monitor Configuration CLI
This is a tool used to edit the op5 Monitor object configuration.
You may use this one to add and remove
hosts
services
contacts
timeperiods.
 
You may also
list objects
save configuration
undo configuration (force import of the config files to the configure database).
Executing the op5 Monitor CLI
To execute the op5 Monitor CLI
1 Logon to the op5 Monitor server as root
2 Execute the following command:
php /opt/monitor/op5/nacoma/api/monitor.php
The above example will give you a description about how to use the op5 Monitor Configuration CLI
REST API
About
The REST-API let's you configure op5 Monitor by issuing regular HTTP requests.
Basically, you 'visit' an URI, which triggers op5 Monitor to do something, and you get a response telling you what happened.
For more information about the REST API go to https://your-op5-monitor/api/help/
Example
In this example we will create a new host called my_server with one ping service. The IP for my_server is 192.168.0.20
In this example the op5 server is called op5-server, the username is joe and joe’s password is joespassword.
By visiting the <monitor-installation>/api/help/config/host, you get information on how to create a host. This is what needs to be done in PHP:
 
<?php
$data = json_encode(array(
'address' => '192.168.0.20',
'alias' => 'My Server',
'host_name' => 'my_server'
));
$a_handle = curl_init('<monitor-installation>/api/config/host');
curl_setopt($a_handle, CURLOPT_USERPWD, 'joe:joespassword');
curl_setopt($a_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($a_handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($a_handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($a_handle, CURLOPT_SSL_VERIFYPEER, false);
$host = curl_exec($a_handle);
 
$data = json_encode(array(
'check_command' => 'check_ping',
'service_description' => 'ping',
'host_name' => 'my_server'
));
$a_handle = curl_init('op5-server/api/config/service');
curl_setopt($a_handle, CURLOPT_USERPWD, 'joe:joespassword');
curl_setopt($a_handle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($a_handle, CURLOPT_POSTFIELDS, $data);
curl_setopt($a_handle, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($a_handle, CURLOPT_SSL_VERIFYPEER, false);
$service = curl_exec($a_handle);
?>
 
Before the changes are applied, you need to confirm them and then save them so that they become part of your configuration. This can be done in two ways, either by Saving changes in the op5 Monitor GUI, or by adding an additional call via the REST API:
 
<?php
$a_handle = curl_init('op5-server/api/config/change');
curl_setopt($a_handle, CURLOPT_USERPWD, 'joe:joespassword');
curl_setopt($a_handle, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($a_handle, CURLOPT_SSL_VERIFYPEER, false);
$save = curl_exec($a_handle);
?>
Now, visiting op5-server/api/config/host/my_server in a browser should show you the live configuration.