API example code to get graphs

I am one of the co-founders of a peering fabric (Internet eXchange) in the San Francisco CA area. We wanted a way to pull daily and weekly graphs out of LibreNMS to display on our web site. I first ran rrdtool to create this on the LibreNMS box and then transferred these to the web site but found that a bit cumbersome. In drilling into the LibreNMS, I found I could get nearly everything I wanted via the API. Of course some of this is not documented so I had to dig through the code to find what I wanted.

One thing that was handy here was leveraging Libre’s concept of groups here to use this to identify ports I wanted to aggregate up. These are identified as “peering” in this script.

Additionally there doesn’t seem to be a way to add a title to a graph but I resolved that by using Imagemagick’s “convert” on the image I got via the API.

You can see the script at:

1 Like

I’m not sure if their’s a question in here or not :slight_smile:

However this API call gets your peering graphs: http://docs.librenms.org/API/API-Docs/#api-route-get_graph_by_portgroup

1 Like

No question. Just a post and pointer to a solution that we found for SFMIX. The code pointed to also shows some API arguments that are not (well) documented but are in the LibreNMS code that we found useful.

Your link is broken, I get a 404.

If you can improve the docs then please submit pull requests :slight_smile:

My apologies. That repro was private. It is now public.

Heh… Back in the FidoNet days. it was “Send code”. Will do.

This is an open source project and relies on people contributing to make it work :slight_smile:

How do you write your API request when a port is named with special characters ?

Here is a request on the “eth0” port that works:
curl -H ‘X-Auth-Token:a6ab915becafa4614deafb1624354c8e’ https://librenms.domain.fr/api/v0/devices/localhost/ports/**eth0**

And a request on port “1 \ / 2” of a switch?
curl -H ‘X-Auth-Token:a6ab915becafa4614deafb1624354c8e’ https://librenms.domain.fr/api/v0/devices/1/ports/???

Here are the ifnames of my ports:
“status”: “ok”,
“ports”: [
“ifName”: “1\ /1
“ifName”: “1\ /2

curl -H ‘X-Auth-Token:a6ab915becafa4614deafb1624354c8e’ https://librenms.univ-rennes2.fr/api/v0/devices/1/ports**/ 1%5C%2F1**
Not work too

Thank you :slight_smile:
PI : A similar post not resolve here :frowning: : API Port Graph urlencode

Solved :slight_smile:
curl -H ‘X-Auth-Token:a6ab915becafa4614deafb1624354c8e’ https://librenms.domain.fr/api/v0/devices/1/ports/ 1%2F1/port_errors > /tmp/test.png
And not 1 %5C %2F 1 pour 1 / 1

Hi - I’m new here and new to LibreNMS as well.
I’ve been asked to setup an API call to grab a disk usage graph once a week for one of the servers we are monitoring.
I’ve got as far as getting the graph -
curl -X GET -H ‘X-Auth-Token: xxxxx’ -i ‘http://librenms.ourdomain.net/api/v0/devices/16/graphs/health/device_storage

But I need to add a date range to this - ie, i want to get the information from the last week. Any help would be appriciaited :slight_smile:

I don’t think you can do that right now, it might just need this line removing: librenms/includes/html/api_functions.inc.php at master · librenms/librenms · GitHub

Then you should be able to use the inputs as per: Devices - LibreNMS Docs

Try that and see if it works.

1 Like

Actually, just try the example in the second link I sent first.

1 Like