REST API description: Difference between revisions

no edit summary
No edit summary
Line 1: Line 1:
== General ==
This page describes how to access and use the REST API. It allows to post-process data with 3rd party systems. The Allegro web interface is itself based on this REST API and all displayed statistics can be extracted from the Allegro with this API.


All Allegro Network Multimeter statistics are derived from HTTP requests and provided as JSON objects.
 
== General API Setup ==
 
=== REST API Interface ===
 
All Allegro Network Multimeter statistics are derived from HTTPS requests and provided as JSON objects.
The requests are stateless, i.e. there are no prerequisites and there is no fixed sequence of requests necessary.
The requests are stateless, i.e. there are no prerequisites and there is no fixed sequence of requests necessary.
Example requests related to a specific module and statistics can be seen in the web interface by opening
Example requests related to a specific module and statistics can be seen in the web interface by opening the browser development console (Ctrl+Shift+I for Chrome and Firefox, F12 for Edge).
the browser development console (Ctrl+Shift+I for Chrome and Firefox, F12 for Edge).
The credentials are the same as for the web interface. A non-admin user has read access to most of the statistics.


== Examples ==
=== credentials ===
 
The credentials are the same as for the web interface. The admin user allows to access all APIs. A non-admin user has read access to most of the statistics. If you have enabled the pcap role, the capture URL is also possible for the API.
 
Allegro recommend to set up a separate non-admin user with or without the pcap role for the REST API of only statistics shall be gathered. This will prevent to accidentally shut down or change any configuration by calling the REST API.
 
== Script parameters  ==
 
=== Curl ===
 
Most examples are written for curl [https://en.wikipedia.org/wiki/CURL]. Curl is available as for many operating systems like Linux or Windows. Curl needs a few parameters for the access of the Allegro Network Multimeter:
 
The parameter '''-u''' allows you to set a user name and password for the request.
 
The parameter '''-k''' will allow self-signed certificates.
 
The parameter '''-s''' or '''--silent''' mutes any debugging output.
 
The URL of the API call is the first argument. It is recommended to enclose the API call with the character ' to avoid replacing the argument ( unless you need to replace parts of it )
 
<code>curl --silent -k -u USER:PASSWORD 'https://allegro-mm-XXXX/...'</code>
 
=== PowerShell ===


In this section some examples are given using PowerShell and Linux curl and jq commands.
The Integrated Windows PowerShell can be used to access the REST API. This guide requires at least PowerShell v6.


==== SSL certificate errors ====
The command to call a REST API is '''Invoke-RestMethod''' [https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod].
Invoke-RestMethod on the PowerShell needs a few parameters for the access of the Allegro Network Multimeter:


If the default self-signed SSL certificate is used, curl and PowerShell will display error messages. You can either
To set the user name for basic authorization, use the '''-Headers''' parameter
install another SSL certificate or let the tools ignore the errors.
For curl it is:


<code>curl -k ...</code>
<code>-Headers @{Authorization = ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f 'USER', 'PASSWORD'))))}</code>


For PowerShell in recent versions (v6 and later) it is:
<code>((Invoke-RestMethod -Uri 'https://allegro-mm-XXXX/API/stats/modules/ip/ips_paged?sort=bytes&reverse=true&page=0&count=10&timespan=60&values=50' -Headers @{Authorization = ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f 'USER', 'PASSWORD'))))} -ContentType'application/json; charset=utf-8' -Method 'Get' -SkipCertificateCheck). displayedItems[0]).ip</code>


<code>Invoke-RestMethod -SkipCertificateCheck ...</code>
<code>Invoke-RestMethod -SkipCertificateCheck ...</code>
== Examples ==


==== MAC or IP address statistics ====
==== MAC or IP address statistics ====
404

edits