Started fixing rest Documentation and postman collection creation (#8987)

This commit is contained in:
GabrieleDeri 2025-02-24 11:46:44 +01:00 committed by GitHub
parent 4c611cf661
commit fe18eff11d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 147 additions and 44 deletions

View file

@ -10,8 +10,6 @@ require "lua_utils"
local json = require "dkjson"
local rest_utils = require "rest_utils"
sendHTTPContentTypeHeader('application/json')
--
-- Test ntopng reachability and authentication (used by Python API)
-- Example: curl -u admin:admin http://localhost:3000/lua/rest/v2/connect/test.lua

View file

@ -12,7 +12,7 @@ local rest_utils = require("rest_utils")
--
-- Get a new ntopng user session (Cookie)
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"username": "simone"}' http://localhost:3000/lua/rest/v1/create/ntopng/api_token.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"username": "Mario"}' http://localhost:3000/lua/rest/v2/create/ntopng/api_token.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -12,7 +12,7 @@ local rest_utils = require("rest_utils")
--
-- Get a new ntopng user session (Cookie)
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"username": "mario"}' http://localhost:3000/lua/rest/v2/get/ntopng/session.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"username": "Mario", "auth_session_duration": 30}' http://localhost:3000/lua/rest/v2/create/ntopng/session.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -13,7 +13,7 @@ local rest_utils = require("rest_utils")
local host_alert_store = require "host_alert_store".new()
--
-- Read alerts data
-- Delete host alerts for the given interface
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/delete/host/alerts.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login

View file

@ -10,7 +10,7 @@ local rest_utils = require("rest_utils")
local asset_utils = require("asset_utils")
--
-- Read alerts data
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/delete/host/alerts.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/delete/host/asset.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -16,30 +16,29 @@ local host = _GET["host"]
local scan_type = _GET["scan_type"]
local delete_all_scan_hosts = _GET["delete_all_scan_hosts"]
tprint(host)
tprint(scan_type)
tprint(delete_all_scan_hosts)
tprint("--------")
if not delete_all_scan_hosts then
if isEmptyString(host) or isEmptyString(scan_type) then
rest_utils.answer(rest_utils.consts.err.bad_content)
end
if isEmptyString(host) or isEmptyString(scan_type) then
rest_utils.answer(rest_utils.consts.err.bad_content)
end
local function delete_host_to_scan(ip, scan_type)
return vs_utils.delete_host_to_scan(ip, scan_type, false)
end
local function delete_all_hosts_to_scan()
return vs_utils.delete_host_to_scan(nil, nil, true)
end
local del_result = 0
if not delete_all_scan_hosts then
del_result = delete_host_to_scan(host,scan_type)
if delete_all_scan_hosts then
-- Delete all hosts to scan
del_result = vs_utils.delete_host_to_scan(nil, nil, true)
else
del_result = delete_all_hosts_to_scan()
-- Only delete a host and a scan type
del_result = vs_utils.delete_host_to_scan(host, scan_type, false)
end
if del_result then
rest_utils.answer(rest_utils.consts.success.ok)
rest_utils.answer(rest_utils.consts.success.ok)
else
rest_utils.answer(rest_utils.consts.err.internal_error)
rest_utils.answer(rest_utils.consts.err.internal_error)
end

View file

@ -13,7 +13,7 @@ local auth = require "auth"
--
-- Enable User Script
-- Example: curl -u admin:admin http://localhost:3000/lua/rest/v2/disable/check.lua
-- Example: curl -u admin:admin http://localhost:3000/lua/rest/v2/enable/check.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -12,7 +12,7 @@ local auth = require "auth"
--
-- Read alerts data
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/host/alert/list.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/all/alert/list.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -16,7 +16,7 @@ local auth = require "auth"
--
-- Read alerts count by time
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/host/alert/ts.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/all/alert/ts.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -15,7 +15,7 @@ local auth = require "auth"
--
-- Read alerts count by time
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{ }' http://localhost:3000/lua/rest/v2/get/active_monitoring/alert/ts.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/am_host/alert/ts.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -1,5 +1,5 @@
--
-- (C) 2013-21 - ntop.org
-- (C) 2013-25 - ntop.org
--
local dirs = ntop.getDirs()
@ -10,8 +10,8 @@ local json = require "dkjson"
local rest_utils = require "rest_utils"
--
-- Read all the L4 protocols
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/l4/protocol/consts.lua
-- Get info for a specific ASN
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/asn/asn_info.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -1,5 +1,5 @@
--
-- (C) 2013-21 - ntop.org
-- (C) 2013-25 - ntop.org
--
local dirs = ntop.getDirs()
@ -9,8 +9,8 @@ require "lua_utils"
local rest_utils = require "rest_utils"
--
-- Read all the L4 protocols
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/l4/protocol/consts.lua
-- Get AS Name from IP
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/asn/asn_name.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -1,5 +1,5 @@
--
-- (C) 2013-24 - ntop.org
-- (C) 2013-25 - ntop.org
--
dirs = ntop.getDirs()
@ -10,6 +10,13 @@ local rest_utils = require "rest_utils"
local json = require("dkjson")
require "lua_utils"
--
-- Get AS Name from IP
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/asn/get_as_data.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--
-- Get from redis the throughput type bps or pps
local ts_enabled = areASTimeseriesEnabled(interface.getId())
local throughput_type = getThroughputType()

View file

@ -13,7 +13,7 @@ local rest_utils = require("rest_utils")
--
-- Read checks configuration
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/scripts/config.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/checks/config.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -0,0 +1,37 @@
--
-- (C) 2019-25 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local json = require("dkjson")
local checks = require("checks")
local rest_utils = require "rest_utils"
local auth = require "auth"
-- Return all checks subdirs supported by ntopng for checks
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/checks/subdirs.lua
--
local rc = rest_utils.consts.success.ok
if not auth.has_capability(auth.capabilities.checks) then
rest_utils.answer(rest_utils.consts.err.not_granted)
return
end
local subdirs = {}
for _, subdir in pairs(checks.listSubdirs()) do
subdirs[#subdirs + 1] = subdir.id
end
local subdirs_list = {
checks_subdirs = subdirs
}
rest_utils.answer(rc, subdirs_list)

View file

@ -1,5 +1,5 @@
--
-- (C) 2013-21 - ntop.org
-- (C) 2013-25 - ntop.org
--
local dirs = ntop.getDirs()
@ -10,8 +10,8 @@ local rest_utils = require "rest_utils"
local country_codes = require "country_codes"
--
-- Read all the L4 protocols
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/l4/protocol/consts.lua
-- Get country name from id
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/country/country_name.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -13,7 +13,7 @@ local dashboard_utils = require "dashboard_utils"
--
-- Get list of components for a dashboard template
-- Example: curl -u admin:admin "http://localhost:3000/lua/pro/rest/v2/get/dashboard/template/data.lua?template=default"
-- Example: curl -u admin:admin "http://localhost:3000/lua/rest/v2/get/dashboard/template/data.lua?template=default"
--
local template_id = _GET["template"]

View file

@ -13,7 +13,7 @@ local dashboard_utils = require "dashboard_utils"
--
-- Get list of dashboard templates
-- Example: curl -u admin:admin "http://localhost:3000/lua/pro/rest/v2/get/dashboard/template/list.lua"
-- Example: curl -u admin:admin "http://localhost:3000/lua/rest/v2/get/dashboard/template/list.lua"
--
local page = "dashboard"

View file

@ -1,5 +1,5 @@
--
-- (C) 2013-24 - ntop.org
-- (C) 2013-25 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
@ -13,7 +13,7 @@ local alert_store_instances = alert_store_utils.all_instances_factory()
--
-- Read alerts data
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/flow/alert/list.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/flow/alert/alert_details.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -11,7 +11,7 @@ local rest_utils = require("rest_utils")
--
-- Read number of active flows per protocol
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/flow/l7/counters.lua
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/flow/l7/iec104.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

View file

@ -10,7 +10,7 @@ require "lua_utils"
local rest_utils = require("rest_utils")
--
-- Read list of active flows
-- Get Traffic stats
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/flow/traffic_stats.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login

View file

@ -0,0 +1,62 @@
--
-- (C) 2019-25 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local json = require("dkjson")
local alert_consts = require("alert_consts")
local checks = require("checks")
local rest_utils = require "rest_utils"
local auth = require "auth"
-- Return all checks scripts keys, used to identify a check in ntopng
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/scripts/key.lua
--
local rc = rest_utils.consts.success.ok
if not auth.has_capability(auth.capabilities.checks) then
rest_utils.answer(rest_utils.consts.err.not_granted)
return
end
local subdirs = {}
local result = {}
for _, subdir in pairs(checks.listSubdirs()) do
subdirs[#subdirs + 1] = subdir.id
end
local config_set = checks.getConfigset()
for _, subdir in ipairs(subdirs) do
local script_type = checks.getScriptType(subdir)
if(script_type == nil) then
traceError(TRACE_ERROR, TRACE_CONSOLE, "Bad subdir: " .. subdir)
return
end
-- ################################################
local scripts = checks.load(getSystemInterfaceId(), script_type, subdir, {return_all = false})
for script_name, script in pairs(scripts.modules) do
if script.gui and script.gui.i18n_title and script.gui.i18n_description then
result[#result + 1] = script_name
end
::continue::
end
end
local scripts_keys = {
scripts_keys = result
}
rest_utils.answer(rc, scripts_keys)