op5 Monitor comes with a few API’s that can be used to The following API’s can be used.
•HTTP-API
•op5 Monitor Configuration CLI
HTTP-API
About
The HTTP-API let's you configure, get status information and report data from 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/
HTTP Status API
The HTTP Status API is used to get the information from op5 Monitor Status GUI. It can give you information about all objects used by the op5 monitor.
Widgets are one place where the HTTP Status 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
HTTP Configuration 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.
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 https://op5monitor.example.com/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('https://op5monitor.example.com/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.
REST and LDAP
When you have more than one auth module, for example "Local" and "LDAP", you need to specify which to authenticate against. This is done with the dollar character ('$').
Thus, this regular call:
curl -u user:password https://op5monitor.example.com/api/status/host [^]
becomes
curl -u 'user$LDAP:password' https://op5monitor.example.com/api/status/host [^]
or
curl -u 'user$Local:password' https://op5monitor.example.com/api/status/host [^]
Notice how the dollar sign ('$') needs quoting depending on the environment (in bash, it will always need to be quoted).
The first way of calling the API:
curl -u user:password https://op5monitor.example.com/api/status/host [^]
will still work, provided that you want to authenticate against the default driver. The default driver can always be specified from within the GUI: Configure -> Auth Modules.
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