doc/src/api/python/index.rst
ntopng provides a Python 3 API for querying the engine and retrieve traffic information by using the Python language.
The API is based on the ntopng REST API and it allows users to perform operations such as:
For each ntopng component there is a corresponding Python class (Host, Interface, Historical), and for each REST API call there is a corresponding method. The ntopng class is used to keep information about the ntopng configuration including IP address and credentials required to connect.
The API is using Pandas and NumPy for working with time series data, plotly and fpdf for generating reports in PDF format, and a few additional libraries.
.. code:: bash
pip3 install -r requirements.txt
For you convenience, ntop periodically builds pip packages. You can install the latest available package as:
.. code:: bash
pip3 install ntopng
A few sample applications are distributed with the ntopng source code and are available at https://github.com/ntop/ntopng/tree/dev/python/examples
All the examples require:
Some of the examples also require an ntopng interface ID (-i option) and additional parameters (e.g. host).
Example:
.. code:: bash
python3 alerts.py -n http://localhost:3000 -i admin -p password -i 0
This sample application is printing alert statistics, please see below a code snippet for achieving the same:
.. code:: python
my_ntopng = Ntopng(username, password, auth_token, ntopng_url)
my_historical = my_ntopng.get_historical_interface(iface_id)
data = my_historical.get_alerts_stats(epoch_begin, epoch_end)
print(data)
.. automodule:: ntopng :members:
.. automodule:: interface :members:
.. automodule:: host :members:
.. automodule:: historical :members: