mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 07:59:35 +00:00
Improved Python API
This commit is contained in:
parent
f8f97a5af8
commit
f3a2f2e31b
4 changed files with 138 additions and 9 deletions
|
|
@ -13,19 +13,85 @@ from ntopng import ntopng
|
|||
|
||||
class host:
|
||||
def __init__(self, ntopng_obj):
|
||||
self.ntopng_obj = ntopng_obj
|
||||
self.rest_v2_url = "/lua/rest/v2"
|
||||
|
||||
self.ntopng_obj = ntopng_obj
|
||||
self.rest_v2_url = "/lua/rest/v2"
|
||||
self.rest_pro_v2_url = "/lua/pro/rest/v2"
|
||||
|
||||
def get_active_hosts(self, ifid):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/host/active.lua", {"ifid": ifid}))
|
||||
|
||||
|
||||
def get_active_hosts_paginated(self, ifid, currentPage, perPage):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/host/active.lua", {"ifid": ifid, "currentPage": currentPage, "perPage": perPage}))
|
||||
|
||||
|
||||
def get_host_interfaces(self, host):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/host/interfaces.lua", { "host": host }))
|
||||
|
||||
def get_host_data(self, ifid, host):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/host/data.lua", { "ifid": ifid, "host": host }))
|
||||
|
||||
def get_host_l7_stats(self, ifid, host, vlan):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/host/l7/stats.lua", { "ifid": ifid, "host": host, "vlan": vlan, "breed": True, "ndpi_category": True, "collapse_stats": False }))
|
||||
|
||||
def get_host_dscp_stats(self, ifid, host, vlan, direction_rcvd):
|
||||
if(direction_rcvd):
|
||||
direction = "recvd"
|
||||
else:
|
||||
direction = "sent"
|
||||
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/host/dscp/stats.lua", { "ifid": ifid, "host": host, "vlan": vlan, "direction": direction }))
|
||||
|
||||
def get_top_local_talkers(self, ifid):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_pro_v2_url + "/get/interface/top/local/talkers.lua", { "ifid": ifid }))
|
||||
|
||||
def get_top_remote_talkers(self, ifid):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_pro_v2_url + "/get/interface/top/remote/talkers.lua", { "ifid": ifid }))
|
||||
|
||||
def get_alert_types(self):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/alert/type/consts.lua", None))
|
||||
|
||||
def get_alert_severities(self):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/alert/severity/consts.lua", None))
|
||||
|
||||
def get_historical_alert_type_counters(self, ifid, epoch_begin, epoch_end):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/alert/type/counters.lua", { "ifid": ifid, "status": "historical", "epoch_begin": epoch_begin, "epoch_end": epoch_end }))
|
||||
|
||||
def get_historical_flows_type_counters(self, ifid, epoch_begin, epoch_end):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/alert/type/counters.lua", { "ifid": ifid, "status": "historical", "epoch_begin": epoch_begin, "epoch_end": epoch_end }))
|
||||
|
||||
def get_historical_alert_severity_counters(self, ifid, epoch_begin, epoch_end):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/alert/severity/counters.lua", { "ifid": ifid, "status": "historical", "epoch_begin": epoch_begin, "epoch_end": epoch_end }))
|
||||
|
||||
def get_historical_flows_severity_counters(self, ifid, epoch_begin, epoch_end):
|
||||
return(ntopng.request(self.ntopng_obj, self.rest_v2_url + "/get/alert/severity/counters.lua", { "ifid": ifid, "status": "historical", "epoch_begin": epoch_begin, "epoch_end": epoch_end }))
|
||||
|
||||
|
||||
def self_test(self, ifid):
|
||||
print("----------------------------")
|
||||
print(self.get_active_hosts(ifid))
|
||||
print("----------------------------")
|
||||
print(self.get_active_hosts_paginated(ifid, 1, 100))
|
||||
print("----------------------------")
|
||||
|
||||
print(self.get_host_interfaces("192.168.1.1"))
|
||||
print("----------------------------")
|
||||
print(self.get_host_data(ifid, "192.168.1.1"))
|
||||
print("----------------------------")
|
||||
print(self.get_host_l7_stats(ifid, "192.168.1.1", 0))
|
||||
print("----------------------------")
|
||||
print(self.get_host_dscp_stats(ifid, "192.168.1.1", 0, True))
|
||||
print("----------------------------")
|
||||
print(self.get_top_local_talkers(ifid))
|
||||
print("----------------------------")
|
||||
print(self.get_top_remote_talkers(ifid))
|
||||
print("----------------------------")
|
||||
print(self.get_alert_types())
|
||||
print("----------------------------")
|
||||
print(self.get_alert_severities())
|
||||
print("----------------------------")
|
||||
print(self.get_historical_alert_type_counters(ifid, 1641042000, 1735736400))
|
||||
print("----------------------------")
|
||||
print(self.get_historical_flows_type_counters(ifid, 1641042000, 1735736400))
|
||||
print("----------------------------")
|
||||
print(self.get_historical_alert_severity_counters(ifid, 1641042000, 1735736400))
|
||||
print("----------------------------")
|
||||
print(self.get_historical_flows_severity_counters(ifid, 1641042000, 1735736400))
|
||||
print("----------------------------")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue