mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-01 00:19:33 +00:00
Added ndpi application rest
This commit is contained in:
parent
899e557c19
commit
cd460f2f75
1 changed files with 57 additions and 0 deletions
57
scripts/lua/rest/v2/get/ntopng/applications.lua
Normal file
57
scripts/lua/rest/v2/get/ntopng/applications.lua
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
--
|
||||
-- (C) 2013-23 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local protos_utils = require("protos_utils")
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
-- Table parameters
|
||||
local ifid = _GET["ifid"] or interface.getId()
|
||||
local proto_filter = _GET["l7proto"]
|
||||
local category_filter = _GET["category"]
|
||||
|
||||
local sortPrefs = "ndpi_application_category"
|
||||
local custom_protos = protos_utils.parseProtosTxt()
|
||||
local proto_to_num_rules = {}
|
||||
local applications = interface.getnDPIProtocols()
|
||||
|
||||
for proto, rules in pairs(custom_protos) do
|
||||
proto_to_num_rules[proto] = #rules
|
||||
end
|
||||
|
||||
local function makeApplicationHostsList(appname)
|
||||
local hosts_list = {}
|
||||
|
||||
for _, rule in ipairs(custom_protos[appname] or {}) do
|
||||
hosts_list[#hosts_list + 1] = rule.value
|
||||
end
|
||||
|
||||
return table.concat(hosts_list, ",")
|
||||
end
|
||||
|
||||
interface.select(ifid)
|
||||
|
||||
local categories = interface.getnDPICategories()
|
||||
|
||||
local result = {}
|
||||
|
||||
for app_name, app_id in pairs(applications) do
|
||||
local record = {}
|
||||
local category = ntop.getnDPIProtoCategory(tonumber(app_id))
|
||||
record["application_id"] = app_id
|
||||
record["category_id"] = category_id
|
||||
record["application"] = app_name
|
||||
record["num_hosts"] = proto_to_num_rules[app_name] or 0
|
||||
record["custom_rules"] = makeApplicationHostsList(app_name)
|
||||
record["is_custom"] = ntop.isCustomApplication(tonumber(app_id))
|
||||
record["category"] = getCategoryLabel(category.name, category.id)
|
||||
--record["custom_rule"] = ''
|
||||
|
||||
result[#result + 1] = record
|
||||
end
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, result)
|
||||
Loading…
Add table
Add a link
Reference in a new issue