REST API description: Difference between revisions

no edit summary
No edit summary
Line 1: Line 1:
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.
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.


== General API Setup ==
== General API Setup ==
Line 34: Line 33:
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 )
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>
<pre>curl --silent -k -u USER:PASSWORD 'https://allegro-mm-XXXX/...'</pre>


Please note that you might need to use <code>curl.exe</code> in windows.
Please note that you might need to use <code>curl.exe</code> in windows.
Line 47: Line 46:
To set the user name for basic authorization, use the '''-Headers''' parameter:
To set the user name for basic authorization, use the '''-Headers''' parameter:


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


You also need to announce that you accept JSON as response with:
You also need to announce that you accept JSON as response with:


<code>-ContentType'application/json; charset=utf-8'</code>  
<pre>-ContentType'application/json; charset=utf-8'</pre>  


To disable the certificate check, use:
To disable the certificate check, use:


<code>-SkipCertificateCheck</code>
<pre>-SkipCertificateCheck</pre>


The URL must be passed with the parameter '''-Uri''', so the full command is:
The URL must be passed with the parameter '''-Uri''', so the full command is:


<code>Invoke-RestMethod -Uri 'https://allegro-mm-XXXX/...' -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</code>
<pre>Invoke-RestMethod -Uri 'https://allegro-mm-XXXX/...' -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</pre>


=== jq ===
=== jq ===


jq ( [https://stedolan.github.io/jq/] ) is a powerful tool to extract parameters from a json document. If called without parameters, jq formats the JSON output into a readable format with indenting and new lines. It also allows to select specific values and do basic operations like addition with this values.
jq ([https://stedolan.github.io/jq/]) is a powerful tool to extract parameters from a json document. If called without parameters, jq formats the JSON output into a readable format with indenting and new lines. It also allows to select specific values and do basic operations like addition with this values.
Please read the jq documentation for more information.
Please read the jq documentation for more information.


Line 237: Line 236:
This example shows IP address with the highest amount of traffic
This example shows IP address with the highest amount of traffic


<code>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/ip/ips_paged?sort=bps&reverse=true&page=0&count=1' | jq .displayedItems[0].ip</code>
<pre>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/ip/ips_paged?sort=bps&reverse=true&page=0&count=1' | jq .displayedItems[0].ip</pre>


This exampe shows up to 9999 peers of a specific IP address:
This exampe shows up to 9999 peers of a specific IP address:


<code>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/ip/ips/10.1.2.3/peers?sort=bytes&reverse=true&page=0&count=9999&timespan=60&values=100' | jq '.displayedItems[].ip'</code>
<pre>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/ip/ips/10.1.2.3/peers?sort=bytes&reverse=true&page=0&count=9999&timespan=60&values=100' | jq '.displayedItems[].ip'</pre>


=== Pcap extraction ===
=== Pcap extraction ===
Line 247: Line 246:
The Allegro Network Multimeter allows to extract the raw packets with the REST API with the special capture URI <code>/API/data/modules/capture</code>
The Allegro Network Multimeter allows to extract the raw packets with the REST API with the special capture URI <code>/API/data/modules/capture</code>


<code>curl -k -u USER:PASSWORD 'https://allegro-mm/API/data/modules/capture?expression=ip==10.1.2.3' > path_to/capture.pcap</code>
<pre>curl -k -u USER:PASSWORD 'https://allegro-mm/API/data/modules/capture?expression=ip==10.1.2.3' > path_to/capture.pcap</pre>


The available parameters are:
The available parameters are:
Line 261: Line 260:
Example to capture everything from now on:
Example to capture everything from now on:


<code>curl -k -u USER:PASSWORD 'https://allegro-mm/API/data/modules/capture' > path_to/capture.pcap</code>
<pre>curl -k -u USER:PASSWORD 'https://allegro-mm/API/data/modules/capture' > path_to/capture.pcap</pre>


Example to capture a specific IP of the last hour
Example to capture a specific IP of the last hour


<code>curl -k -u USER:PASSWORD "https://allegro-mm/API/data/modules/capture?expression=ip==10.1.2.3&starttime=$(date --date="1 hour ago" +%s)&endtime=$(date +%s)&fromCaptureBuffer=true" > path_to/capture.pcap</code>
<pre>curl -k -u USER:PASSWORD "https://allegro-mm/API/data/modules/capture?expression=ip==10.1.2.3&starttime=$(($(date --date="1 hour ago" +%s%N)/1000))&endtime=$(($(date +%s%N)/1000))&fromCaptureBuffer=true" > path_to/capture.pcap</pre>


Example to capture a specific IP of the last hour of the first parallel Pcap analysis slot
Example to capture a specific IP of the last hour of the first parallel Pcap analysis slot


<code>curl -k -u USER:PASSWORD "https://allegro-mm/API/data/modules/capture?expression=ip==10.1.2.3&starttime=$(date --date="1 hour ago" +%s)&endtime=$(date +%s)&fromCaptureBuffer=true&mm-id=:1" > path_to/capture.pcap</code>
<pre>curl -k -u USER:PASSWORD "https://allegro-mm/API/data/modules/capture?expression=ip==10.1.2.3&starttime=$(($(date --date="1 hour ago" +%s%N)/1000))&endtime=$(($(date +%s%N)/1000))&fromCaptureBuffer=true&mm-id=:1" > path_to/capture.pcap</pre>


=== Virtual Link Groups ===
=== Virtual Link Groups ===
Line 297: Line 296:
Extract the packets per second statistic of the MAC broadcast address
Extract the packets per second statistic of the MAC broadcast address


<code>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/mac/macs/ff:ff:ff:ff:ff:ff'</code>
<pre>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/mac/macs/ff:ff:ff:ff:ff:ff'</pre>


==== IP statistics ====
==== IP statistics ====


<code>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/ip/ips/10.1.2.3'</code>
<pre>curl --silent -k -u USER:PASSWORD 'https://allegro-mm/API/stats/modules/ip/ips/10.1.2.3'</pre>


==== Pretty displaying JSON output with jq ====
==== Pretty displaying JSON output with jq ====


<code>curl --silent -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/stats/modules/ip/ips/10.1.2.3' | jq</code>
<pre>curl --silent -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/stats/modules/ip/ips/10.1.2.3' | jq</pre>


==== Capture a specific IP ====
==== Capture a specific IP ====


<code>curl -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/data/modules/capture?expression=ip==10.1.2.3' > path_to/capture.pcap</code>
<pre>curl -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/data/modules/capture?expression=ip==10.1.2.3' > path_to/capture.pcap</pre>


==== Capture two IP addresses with ports on a specific Layer 4 protocol ====
==== Capture two IP addresses with ports on a specific Layer 4 protocol ====


<code>curl -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/data/modules/capture?expression=IP==10.1.2.3:62887 and IP==10.1.2.100:548 and l4Protocol==TCP' > path_to/capture.pcap</code>
<pre>curl -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/data/modules/capture?expression=IP==10.1.2.3:62887 and IP==10.1.2.100:548 and l4Protocol==TCP' > path_to/capture.pcap</pre>
340

edits