REST API description: Difference between revisions

(added csv examples)
Line 335: Line 335:
==== Output Connection Table as CSV file ====
==== Output Connection Table as CSV file ====
<pre>curl -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/stats/modules/ip/globalConnections/csv?csv=true' > path_to/file.csv</pre>
<pre>curl -k -u USER:PASSWORD 'https://allegro-mm-XXXX/API/stats/modules/ip/globalConnections/csv?csv=true' > path_to/file.csv</pre>
==== Multi-device Capture Python Script Example ====
<pre>
#! /usr/bin/python3
""" This example script starts a parallel download-capture for each 'multi-device' of a given allegro packets multimeter. """
import requests
import threading
import datetime
import shutil
def start_capture_download(host: str, device: dict, duration: int):
    start = datetime.datetime.now()
    end = start + datetime.timedelta(seconds=duration)
    file = device["host"] + start.strftime("%m-%d-%Y_%H-%M-%S") + ".pcap"
    params = {
        "mm-id": device["id"],
        "endTime": int(end.timestamp() * 1000000),
    }
    with session.get(host + "/API/data/modules/capture", params=params, stream=True) as resp:
        with open(file, "wb") as fh:
            shutil.copyfileobj(resp.raw, fh)
host = "https://allegro-mm-xxxx"
session = requests.Session()
session.auth = ("user", "password")
# session.verify = False  # disable ssl verification
with session.get(host + "/API/system/multidevice/devices") as resp:
    devices = resp.json()
active_devices = []
for device in devices:
    if device["active"]:
        active_devices.append(device)
threads = []
for device in active_devices:
    t = threading.Thread(target=start_capture_download, args=(host, device, 30))
    t.start()
    threads.append(t)
for t in threads:
    t.join()
</pre>
inactive
67

edits