OPNsense Forum

Archive => 18.1 Legacy Series => Topic started by: namezero111111 on January 22, 2018, 01:35:40 pm

Title: API Information
Post by: namezero111111 on January 22, 2018, 01:35:40 pm
Hello folks,

In our migration from pfsense, we are trying to replace old php monitoring scripts that used NRPE with API calls (https://docs.opnsense.org/development/how-tos/api.html)

However, the example isn't clear on how the URLs are constructed.
I found the following link, but it is an old post and has little information: https://forum.opnsense.org/index.php?topic=3027.0

For example, I would like to get information about:
- Gateway packet loss and gateway group status
- System logs
- Certificate expiration
- Openvpn status
- Traffic status / queue drops

Mostly stuff available via Dashboard.

The information is all on the WebGUI, so form what I understand it should be accessible via the API?

How are the URLs for the API built? Is that the wrong way to go on OPNsense?
Title: Re: API Information
Post by: franco on January 22, 2018, 03:58:30 pm
Hi there,

Hold on, this is not quite right.

1. We don't have NRPE integrated anywhere. It exists as a package for manual install, but that's it.

2. API yes, but it matters where. The code base is huge and we are still in the process of migration. Nearly all plugins do have an API, the majority of core components do not yet have an API. We built an API for Traffic Shaping, Firmware Updates, Intrusion Detection, Web Proxy, Routing and a few diagnostics tools.


Cheers,
Franco
Title: Re: API Information
Post by: namezero111111 on January 22, 2018, 05:12:50 pm
Ahh ok thanks for clarification; the documentation read as though everything could be managed that way already.

I meant from NRPE (now) to non-NRPE on OpnSense (future).

I found a few API calls, but I think for now it is easier to adjust the scrips we had and install nrpe3 from command line!

Title: Re: API Information
Post by: franco on January 22, 2018, 06:07:56 pm
Ah ok, thank you for the clarification. NRPE is a good solution for that and the migration work for the existing gathering script should be straightforward.

We still work up towards a documentation for the API which can be generated from the code and published alongside the docs, but it's not mission critical as we would rather spend the time to bring everyone e.g. the firewall rule API.

With that being said, general docs are going to be open source with 18.1 soon so the general direction is the right one. And the rest is just work + time. :)


Cheers,
Franco
Title: Re: API Information
Post by: namezero111111 on January 22, 2018, 07:10:45 pm
Thanks again for the quick reply.

Once I have spiked the scripts for OpnSense I will attach.
In the furture I will tyr to familiarize myself more with the API model and possibly convert some stuff.
Title: Re: API Information
Post by: fvanroie on January 22, 2018, 07:15:23 pm
The information is all on the WebGUI, so form what I understand it should be accessible via the API?

How are the URLs for the API built? Is that the wrong way to go on OPNsense?

From my experience you can look at the URI in the WebGUI and you'll notice that it either starts with /ui/modulename/... or it ends in *.php. The former is code using the new MVC model and it has APIs behind it. The latter (.php) pages are legacy code and do not have an API yet.

When there is an API behind the page it follows the syntax /api/<module>/<controller>/<command> and usually returns a json object. And indeed you can do pretty much the same as with the GUI. A comprehensive list can be found here (https://github.com/fvanroie/PS_OPNsense/wiki/API-Commands).

The only thing, like franco mentioned, is that not all parts have been converted to this model, but with every release more and more functions are reworked using the MVC model.