Back to OP5 Monitor FAQ

Using the REST API with PHP

Purpose Copied

The purpose of this document is designed for those who want to get started with developing communications between your own application and the op5 Monitor REST API.

The REST API was introduced in op5 Monitor 5.7.0.

Prerequisites Copied

op5 Monitor 5.7.0 or higher is required

OP5 Monitor - Using the REST API with PHP

/etc/op5/http_api.yml

---
report:
  limit: 1000
auth_method:
  ninja: true
basic_auth: true

PHP must be compiled with cURL-support

You can verify if PHP is compiled with cURL by running the following in the terminal. The output should tell you whether cURL is enabled or not)

## php -i | grep "cURL support"
cURL support => enabled

The code Copied

In particular, the brief code example below will get a list of all services on a specific host and output their states. The desired result is to list services that are in an OK, WARNING, CRITICAL or an UNKNOWN state.

  1. Download and save this file (api_example.php), and upload it to a server where you can reach the file with your preferred web browser. Make sure that the server you upload the code to can communicate with the op5 Monitor server you set in the $host variable. Please note that you are required to change the following variables in the code, since they need to reflect the settings in your environment:

As a quick test, you can upload the example code to /var/www/html/. This will make the code accessible in a web browser through the URL https://<YOUR_OP5_SERVER/api_example.php.

  1. Once you are done with saving the file, use your browser to navigate to api_example.php webpage you have created/modified. you will then be presented with a list of all services of the host you entered in step 1.

OP5 Monitor - Using the REST API with PHP

WRAP UP

This is a how-to for users who are new to the op5 Monitor API. Hopefully this how-to has kick-started your knowledge in regards to how to use the API to your advantage; and we’d love to see more customers using the API and start integrating your own customized solutions with it.

["Geneos"] ["FAQ"]

Was this topic helpful?