ntopng/scripts/lua/rest/v2/delete/all/alerts.lua
2024-01-12 11:44:18 +01:00

48 lines
1.2 KiB
Lua

--
-- (C) 2013-24 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
package.path = dirs.installdir .. "/scripts/lua/modules/alert_store/?.lua;" .. package.path
local alert_utils = require "alert_utils"
local alert_consts = require "alert_consts"
local alert_entities = require "alert_entities"
local rest_utils = require("rest_utils")
local alert_store_utils = require "alert_store_utils"
--
-- Read alerts data
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{"ifid": "1"}' http://localhost:3000/lua/rest/v2/delete/all/alerts.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--
local rc = rest_utils.consts.success.ok
local res = {}
-- Checking root privileges
if not isAdministrator() then
rest_utils.answer(rest_utils.consts.err.not_granted)
return
end
local ifid = _GET["ifid"]
if isEmptyString(ifid) then
rc = rest_utils.consts.err.invalid_interface
rest_utils.answer(rc)
return
end
interface.select(ifid)
local all_instances = alert_store_utils.all_instances_factory()
for _, instance in pairs(all_instances) do
instance:add_request_filters(true)
instance:delete()
end
rest_utils.answer(rc)