mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-05 19:15:03 +00:00
Updated some REST documentation (#9013)
This commit is contained in:
parent
d884c9bc14
commit
4c1026f54d
7 changed files with 28 additions and 19 deletions
|
|
@ -1,4 +1,3 @@
|
|||
--
|
||||
-- (C) 2013-24 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
|
|
@ -6,7 +5,6 @@ package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
|||
package.path = dirs.installdir .. "/scripts/lua/modules/host/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/vulnerability_scan/?.lua;" .. package.path
|
||||
|
||||
|
||||
require "lua_utils"
|
||||
local rest_utils = require "rest_utils"
|
||||
local vs_utils = require "vs_utils"
|
||||
|
|
@ -17,6 +15,13 @@ if isEmptyString(host) then
|
|||
rest_utils.answer(rest_utils.consts.err.bad_content)
|
||||
end
|
||||
|
||||
local result = vs_utils.get_ports(host)
|
||||
-- Using pcall for error handling
|
||||
local success, result = pcall(function()
|
||||
return vs_utils.get_ports(host)
|
||||
end)
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, result)
|
||||
if success then
|
||||
rest_utils.answer(rest_utils.consts.success.ok, result)
|
||||
else
|
||||
rest_utils.answer(rest_utils.consts.err.internal_error, {error = tostring(result)})
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@ local rest_utils = require("rest_utils")
|
|||
local interface_alert_store = require"interface_alert_store".new()
|
||||
|
||||
--
|
||||
-- Read alerts data
|
||||
-- Get list of interfaces alerts
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/interface/alert/list.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ local rest_utils = require("rest_utils")
|
|||
|
||||
--
|
||||
-- Read information about the nprobes connected to an interface
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/interfacenprobes/data.lua
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/get/interface/nprobes/data.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
--
|
||||
-- (C) 2013-24 - ntop.org
|
||||
-- (C) 2013-25 - ntop.org
|
||||
--
|
||||
local dirs = ntop.getDirs()
|
||||
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
--
|
||||
-- Return all the actively monitored ntopng interfaces along with their ids
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/ntopng/interfaces.lua
|
||||
-- Return limits for the current ntopng license
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/ntopng/limits.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
--
|
||||
-- (C) 2019-24 - ntop.org
|
||||
-- (C) 2019-25 - ntop.org
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
|
|
@ -8,18 +8,19 @@ package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
|||
require "lua_utils"
|
||||
local json = require("dkjson")
|
||||
local syslog_utils = require "syslog_utils"
|
||||
|
||||
sendHTTPContentTypeHeader('application/json')
|
||||
local rest_utils = require("rest_utils")
|
||||
|
||||
local res = {}
|
||||
|
||||
local ifid = interface.getId()
|
||||
if tonumber(_GET["ifid"]) ~= nil then
|
||||
ifid = _GET["ifid"]
|
||||
local ifid = tonumber(_GET["ifid"])
|
||||
local rc = rest_utils.consts.success.ok
|
||||
|
||||
if ifid == nil then
|
||||
rest_utils.answer(rest_utils.consts.err.missing_parameters, {"Interface id (ifid) required"})
|
||||
end
|
||||
|
||||
if ifid ~= nil then
|
||||
res = syslog_utils.getProducers(ifid)
|
||||
end
|
||||
|
||||
print(json.encode(res))
|
||||
tprint(res)
|
||||
rest_utils.answer(rc, res)
|
||||
|
|
|
|||
|
|
@ -27,4 +27,8 @@ for _,iface in pairs(names) do
|
|||
end
|
||||
end
|
||||
|
||||
if #stats == 0 then
|
||||
stats = {"No flow collectors associated with ntopng"}
|
||||
end
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, stats)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ local rest_utils = require("rest_utils")
|
|||
|
||||
--
|
||||
-- Read system statistics
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/system/stats.lua
|
||||
-- Example: curl -u admin:admin -H "Content-Type: application/json" http://localhost:3000/lua/rest/v2/get/system/health/stats.lua
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue