mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Improved Python API
This commit is contained in:
parent
f8f97a5af8
commit
f3a2f2e31b
4 changed files with 138 additions and 9 deletions
53
python/flow.py
Normal file
53
python/flow.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#
|
||||
#
|
||||
# (C) 2022 - ntop.org
|
||||
#
|
||||
# flow class
|
||||
# https://www.ntop.org/guides/ntopng/api/rest/api_v2.html
|
||||
#
|
||||
|
||||
import requests
|
||||
import json
|
||||
from requests.auth import HTTPBasicAuth
|
||||
from ntopng import ntopng
|
||||
|
||||
class flow:
|
||||
def __init__(self, ntopng_obj):
|
||||
self.ntopng_obj = ntopng_obj
|
||||
self.rest_v2_url = "/lua/rest/v2"
|
||||
self.rest_pro_v2_url = "/lua/pro/rest/v2"
|
||||
|
||||
def get_active_flows_paginated(self, ifid, currentPage, perPage):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/flow/active.lua", {"ifid": ifid, "currentPage": currentPage, "perPage": perPage}))
|
||||
|
||||
def get_active_host_flows_paginated(self, ifid, host, vlan, currentPage, perPage):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/flow/active.lua", {"ifid": ifid, "host": host, "vlan": vlan, "currentPage": currentPage, "perPage": perPage}))
|
||||
|
||||
def get_active_l4_proto_flow_counters(self, ifid):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/flow/l4/counters.lua", {"ifid": ifid }))
|
||||
|
||||
def get_active_l7_proto_flow_counters(self, ifid):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/flow/l7/counters.lua", {"ifid": ifid }))
|
||||
|
||||
def get_historical_flows(self, ifid, epoch_begin, epoch_end, max_hits, where_clause):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_pro_v2_url + "/get/db/flows.lua", {"ifid": ifid, "begin_time_clause": epoch_begin, "end_time_clause": epoch_end, "maxhits_clause": max_hits, "where_clause": where_clause }))
|
||||
|
||||
def get_historical_topk_flows(self, ifid, epoch_begin, epoch_end, max_hits, where_clause):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_pro_v2_url + "/get/db/topk_flows.lua", {"ifid": ifid, "begin_time_clause": epoch_begin, "end_time_clause": epoch_end, "maxhits_clause": max_hits, "where_clause": where_clause }))
|
||||
|
||||
|
||||
|
||||
def self_test(self, ifid):
|
||||
print("----------------------------")
|
||||
print(self.get_active_flows_paginated(ifid, 1, 100))
|
||||
print("----------------------------")
|
||||
print(self.get_active_host_flows_paginated(ifid, "192.168.1.1", 0, 1, 100))
|
||||
print("----------------------------")
|
||||
print(self.get_active_l4_proto_flow_counters(ifid))
|
||||
print("----------------------------")
|
||||
print(self.get_active_l7_proto_flow_counters(ifid))
|
||||
print("----------------------------")
|
||||
print(self.get_historical_flows(ifid, 1641042000, 1735736400, 10, None))
|
||||
print("----------------------------")
|
||||
print(self.get_historical_topk_flows(ifid, 1641042000, 1735736400, 10, None))
|
||||
print("----------------------------")
|
||||
Loading…
Add table
Add a link
Reference in a new issue