mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
parent
1f24dec3e3
commit
b117e8a23a
178 changed files with 6639 additions and 124 deletions
51
scripts/lua/rest/v2/import/active_monitoring/config.lua
Normal file
51
scripts/lua/rest/v2/import/active_monitoring/config.lua
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/import_export/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local plugins_utils = require("plugins_utils")
|
||||
local am_import_export = plugins_utils.loadModule("active_monitoring", "am_import_export")
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require "rest_utils"
|
||||
local import_export_rest_utils = require "import_export_rest_utils"
|
||||
|
||||
--
|
||||
-- Import Active Monitoring configuration
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local modules = import_export_rest_utils.unpack(_POST["JSON"])
|
||||
|
||||
if not modules then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
if not modules["active_monitoring"] then
|
||||
rest_utils.answer(rest_utils.consts.err.configuration_file_mismatch)
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
local am_import_export = am_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "active_monitoring",
|
||||
conf = modules["active_monitoring"],
|
||||
instance = am_import_export
|
||||
}
|
||||
|
||||
import_export_rest_utils.import(items)
|
||||
|
||||
43
scripts/lua/rest/v2/import/all/config.lua
Normal file
43
scripts/lua/rest/v2/import/all/config.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/import_export/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local all_import_export = require "all_import_export"
|
||||
local rest_utils = require "rest_utils"
|
||||
local import_export_rest_utils = require "import_export_rest_utils"
|
||||
|
||||
--
|
||||
-- Import all configurations
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local modules = import_export_rest_utils.unpack(_POST["JSON"])
|
||||
|
||||
if not modules or not modules["all"] then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
local all_ie = all_import_export:create()
|
||||
items[#items+1] = { name = "all",
|
||||
conf = modules["all"],
|
||||
instance = all_ie
|
||||
}
|
||||
|
||||
import_export_rest_utils.import(items)
|
||||
|
||||
50
scripts/lua/rest/v2/import/checks/config.lua
Normal file
50
scripts/lua/rest/v2/import/checks/config.lua
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/import_export/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local checks_import_export = require "checks_import_export"
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require "rest_utils"
|
||||
local import_export_rest_utils = require "import_export_rest_utils"
|
||||
|
||||
--
|
||||
-- Import scripts configuration
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local modules = import_export_rest_utils.unpack(_POST["JSON"])
|
||||
|
||||
if not modules then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
if not modules["scripts"] then
|
||||
rest_utils.answer(rest_utils.consts.err.configuration_file_mismatch)
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
local scripts_ie = checks_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "scripts",
|
||||
conf = modules["scripts"],
|
||||
instance = scripts_ie
|
||||
}
|
||||
|
||||
import_export_rest_utils.import(items)
|
||||
|
||||
51
scripts/lua/rest/v2/import/infrastructure/config.lua
Normal file
51
scripts/lua/rest/v2/import/infrastructure/config.lua
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
--
|
||||
-- (C) 2020 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/pro/scripts/lua/enterprise/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/import_export/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local plugins_utils = require("plugins_utils")
|
||||
local infrastructure_import_export = require("infrastructure_import_export")
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require "rest_utils"
|
||||
local import_export_rest_utils = require "import_export_rest_utils"
|
||||
local auth = require "auth"
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
if not ntop.isEnterpriseL() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local modules = import_export_rest_utils.unpack(_POST["JSON"])
|
||||
|
||||
if not modules then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
if not modules["infrastructure"] then
|
||||
rest_utils.answer(rest_utils.consts.err.configuration_file_mismatch)
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
local infrastructure_import_export = infrastructure_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "infrastructure",
|
||||
conf = modules["infrastructure"],
|
||||
instance = infrastructure_import_export
|
||||
}
|
||||
|
||||
import_export_rest_utils.import(items)
|
||||
50
scripts/lua/rest/v2/import/notifications/config.lua
Normal file
50
scripts/lua/rest/v2/import/notifications/config.lua
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/import_export/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local notifications_import_export = require "notifications_import_export"
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require "rest_utils"
|
||||
local import_export_rest_utils = require "import_export_rest_utils"
|
||||
|
||||
--
|
||||
-- Import Notification Endpoint and Recipient configuration
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local modules = import_export_rest_utils.unpack(_POST["JSON"])
|
||||
|
||||
if not modules then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
if not modules["notifications"] then
|
||||
rest_utils.answer(rest_utils.consts.err.configuration_file_mismatch)
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
local notifications_ie = notifications_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "notifications",
|
||||
conf = modules["notifications"],
|
||||
instance = notifications_ie
|
||||
}
|
||||
|
||||
import_export_rest_utils.import(items)
|
||||
|
||||
93
scripts/lua/rest/v2/import/pool/config.lua
Normal file
93
scripts/lua/rest/v2/import/pool/config.lua
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/import_export/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local snmp_import_export = require "snmp_import_export"
|
||||
local plugins_utils = require("plugins_utils")
|
||||
local am_import_export = plugins_utils.loadModule("active_monitoring", "am_import_export")
|
||||
local notifications_import_export = require "notifications_import_export"
|
||||
local checks_import_export = require "checks_import_export"
|
||||
local pool_import_export = require "pool_import_export"
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require "rest_utils"
|
||||
local import_export_rest_utils = require "import_export_rest_utils"
|
||||
local auth = require "auth"
|
||||
|
||||
--
|
||||
-- Import Pool configuration
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not auth.has_capability(auth.capabilities.pools) then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local modules = import_export_rest_utils.unpack(_POST["JSON"])
|
||||
|
||||
if not modules then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
local expected_modules = { "snmp", "active_monitoring", "notifications", "scripts", "pool" }
|
||||
local missing_modules = {}
|
||||
for _, m in ipairs(expected_modules) do
|
||||
if not modules[m] then
|
||||
rest_utils.answer(rest_utils.consts.err.configuration_file_mismatch)
|
||||
missing_modules[#missing_modules+1] = m
|
||||
end
|
||||
end
|
||||
|
||||
if #missing_modules > 0 then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, "Failure importing configuration due to missing modules: " .. table.concat(missing_modules, ", "))
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
local snmp_ie = snmp_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "snmp",
|
||||
conf = modules["snmp"],
|
||||
instance = snmp_ie
|
||||
}
|
||||
|
||||
local am_ie = am_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "active_monitoring",
|
||||
conf = modules["active_monitoring"],
|
||||
instance = am_ie
|
||||
}
|
||||
|
||||
local notifications_ie = notifications_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "notifications",
|
||||
conf = modules["notifications"],
|
||||
instance = notifications_ie
|
||||
}
|
||||
|
||||
local scripts_ie = checks_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "scripts",
|
||||
conf = modules["scripts"],
|
||||
instance = scripts_ie
|
||||
}
|
||||
|
||||
local pool_ie = pool_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "pool",
|
||||
conf = modules["pool"],
|
||||
instance = pool_ie
|
||||
}
|
||||
|
||||
import_export_rest_utils.import(items)
|
||||
|
||||
74
scripts/lua/rest/v2/import/pool/host_pool/members.lua
Normal file
74
scripts/lua/rest/v2/import/pool/host_pool/members.lua
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local auth = require "auth"
|
||||
local rest_utils = require "rest_utils"
|
||||
local host_pools = require "host_pools"
|
||||
local pools_rest_utils = require "pools_rest_utils"
|
||||
|
||||
--- Import Host Pool members by reading file content
|
||||
local pool_id = _POST["pool"]
|
||||
local members_file_content = _POST["host_pool_members"]
|
||||
|
||||
if not auth.has_capability(auth.capabilities.pools) then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
if not pool_id or not members_file_content then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
local s = host_pools:create()
|
||||
local members = split(members_file_content, "\n")
|
||||
|
||||
host_pools:start_transaction()
|
||||
|
||||
for _, member in ipairs(members) do
|
||||
-- TODO: add the member to the right host pool using pools_rest_utils
|
||||
|
||||
-- Expected format
|
||||
-- 00:11:22:33:44:55
|
||||
-- 192.168.1.10/32@10
|
||||
|
||||
-- Note IPv6 not handled for now
|
||||
|
||||
if(member ~= "") then
|
||||
if((not member:find("^%d+%.%d+%.%d+%.%d+"))
|
||||
and (not member:find("^%w+:%w+:%w+:%w+:%w+:%w+:%w+:%w+"))
|
||||
and (not member:find("^%w+:%w+:%w+:%w+:%w+:%w+$"))) then
|
||||
traceError(TRACE_WARNING, TRACE_CONSOLE, "Pool import: skipping "..member)
|
||||
else
|
||||
if(string.find(member, ":") == nil) then
|
||||
-- This is not a MAC address
|
||||
local cidr_idx = string.find(member, "/")
|
||||
if(cidr_idx == nil) then
|
||||
local vlan_idx = string.find(member, "@")
|
||||
if(vlan_idx == nil) then
|
||||
member = member.."/32"
|
||||
else
|
||||
member = member:sub(0, vlan_idx-1) .."/32"..member:sub(vlan_idx)
|
||||
end
|
||||
end
|
||||
|
||||
local vlan_idx = string.find(member, "@")
|
||||
if(vlan_idx == nil) then
|
||||
member = member.."@0"
|
||||
end
|
||||
end
|
||||
|
||||
res,err = s:bind_member_if_not_already_bound(member, pool_id)
|
||||
--ntop.setMembersCache("ntopng.prefs.host_pools.members."..pool_id, member)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
host_pools:end_transaction()
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok)
|
||||
50
scripts/lua/rest/v2/import/snmp/config.lua
Normal file
50
scripts/lua/rest/v2/import/snmp/config.lua
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
--
|
||||
-- (C) 2019-21 - ntop.org
|
||||
--
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/import_export/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
|
||||
local snmp_import_export = require "snmp_import_export"
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require "rest_utils"
|
||||
local import_export_rest_utils = require "import_export_rest_utils"
|
||||
|
||||
--
|
||||
-- Import SNMP configuration
|
||||
--
|
||||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
if not isAdministratorOrPrintErr() then
|
||||
rest_utils.answer(rest_utils.consts.err.not_granted)
|
||||
return
|
||||
end
|
||||
|
||||
-- ################################################
|
||||
|
||||
local modules = import_export_rest_utils.unpack(_POST["JSON"])
|
||||
|
||||
if not modules then
|
||||
rest_utils.answer(rest_utils.consts.err.invalid_args)
|
||||
return
|
||||
end
|
||||
|
||||
if not modules["snmp"] then
|
||||
rest_utils.answer(rest_utils.consts.err.configuration_file_mismatch)
|
||||
return
|
||||
end
|
||||
|
||||
local items = {}
|
||||
|
||||
local snmp_ie = snmp_import_export:create()
|
||||
items[#items+1] = {
|
||||
name = "snmp",
|
||||
conf = modules["snmp"],
|
||||
instance = snmp_ie
|
||||
}
|
||||
|
||||
import_export_rest_utils.import(items)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue