mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
53 lines
2.6 KiB
Python
53 lines
2.6 KiB
Python
#
|
|
#
|
|
# (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("----------------------------")
|