mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
refactor for endpoints and recipients (#4707)
This commit is contained in:
parent
06161556ac
commit
15772bd0fe
24 changed files with 129 additions and 117 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/notifications/?.lua;" .. package.path
|
||||
require "lua_utils"
|
||||
local ts_utils = require("ts_utils")
|
||||
local info = ntop.getInfo()
|
||||
|
|
@ -12,8 +13,8 @@ local alerts_api = require("alerts_api")
|
|||
local format_utils = require("format_utils")
|
||||
|
||||
local plugins_utils = require "plugins_utils"
|
||||
local notification_configs = require("notification_configs")
|
||||
local notification_recipients = require("notification_recipients")
|
||||
local endpoints = require("endpoints")
|
||||
local recipients_module = require("recipients")
|
||||
|
||||
sendHTTPContentTypeHeader('text/html')
|
||||
|
||||
|
|
@ -31,19 +32,19 @@ local res
|
|||
-- TEST ENDPOINT CONFIGS --
|
||||
---------------------------
|
||||
|
||||
res = notification_configs.reset_configs()
|
||||
res = endpoints.reset_configs()
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_configs.delete_config("nonexisting_config_name")
|
||||
res = endpoints.delete_config("nonexisting_config_name")
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_config_not_existing")
|
||||
|
||||
res = notification_configs.add_config("nonexisting", nil, nil)
|
||||
res = endpoints.add_config("nonexisting", nil, nil)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_not_existing")
|
||||
|
||||
res = notification_configs.add_config("email", nil, nil)
|
||||
res = endpoints.add_config("email", nil, nil)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "invalid_endpoint_conf_name")
|
||||
|
||||
res = notification_configs.add_config("email", "ntop_email", nil)
|
||||
res = endpoints.add_config("email", "ntop_email", nil)
|
||||
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "invalid_endpoint_params")
|
||||
|
||||
|
|
@ -52,22 +53,23 @@ local endpoint_params = {
|
|||
smtp_server = "mail.ntop.org"
|
||||
}
|
||||
|
||||
res = notification_configs.add_config("email", "ntop_email", endpoint_params)
|
||||
res = endpoints.add_config("email", "ntop_email", endpoint_params)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "missing_mandatory_param")
|
||||
|
||||
endpoint_params = {
|
||||
smtp_server = "mail.ntop.org",
|
||||
email_sender = "tester@ntop.org"
|
||||
}
|
||||
res = notification_configs.add_config("email", "ntop_email", endpoint_params)
|
||||
res = endpoints.add_config("email", "ntop_email", endpoint_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Duplicate addition
|
||||
res = notification_configs.add_config("email", "ntop_email", endpoint_params)
|
||||
res = endpoints.add_config("email", "ntop_email", endpoint_params)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_config_already_existing")
|
||||
|
||||
-- Delete the endpoint
|
||||
res = notification_configs.delete_config("ntop_email")
|
||||
res = endpoints.delete_config("ntop_email")
|
||||
tprint(res)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Add also some optional params
|
||||
|
|
@ -78,19 +80,19 @@ endpoint_params = {
|
|||
smtp_password = "ntoppassword"
|
||||
}
|
||||
|
||||
res = notification_configs.add_config("email", "ntop_email", endpoint_params)
|
||||
res = endpoints.add_config("email", "ntop_email", endpoint_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_configs.delete_config("ntop_email")
|
||||
res = endpoints.delete_config("ntop_email")
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Add some garbage and make sure it is not written
|
||||
endpoint_params["garbage"] = "trash"
|
||||
|
||||
res = notification_configs.add_config("email", "ntop_email", endpoint_params)
|
||||
res = endpoints.add_config("email", "ntop_email", endpoint_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_configs.get_endpoint_config("ntop_email")
|
||||
res = endpoints.get_endpoint_config("ntop_email")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["endpoint_key"] == "email")
|
||||
assert(res["endpoint_conf_name"] == "ntop_email")
|
||||
|
|
@ -104,10 +106,10 @@ end
|
|||
|
||||
-- Edit the config
|
||||
endpoint_params["smtp_server"] = "mail2.ntop.org"
|
||||
res = notification_configs.edit_config("ntop_email", endpoint_params)
|
||||
res = endpoints.edit_config("ntop_email", endpoint_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_configs.get_endpoint_config("ntop_email")
|
||||
res = endpoints.get_endpoint_config("ntop_email")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["endpoint_key"] == "email")
|
||||
assert(res["endpoint_conf_name"] == "ntop_email")
|
||||
|
|
@ -122,11 +124,11 @@ endpoint_params = {
|
|||
smtp_password = "googlepassword"
|
||||
}
|
||||
|
||||
res = notification_configs.add_config("email", "google_email", endpoint_params)
|
||||
res = endpoints.add_config("email", "google_email", endpoint_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- Get all configs
|
||||
res = notification_configs.get_configs()
|
||||
res = endpoints.get_configs()
|
||||
assert(#res == 2)
|
||||
|
||||
------------------------------
|
||||
|
|
@ -134,42 +136,42 @@ assert(#res == 2)
|
|||
------------------------------
|
||||
|
||||
-- Test the addition
|
||||
res = notification_recipients.add_recipient("nonexisting_config_name", nil, nil)
|
||||
res = recipients_module.add_recipient("nonexisting_config_name", nil, nil)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_config_not_existing")
|
||||
|
||||
res = notification_recipients.add_recipient("ntop_email", nil, nil)
|
||||
res = recipients_module.add_recipient("ntop_email", nil, nil)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "invalid_endpoint_recipient_name")
|
||||
|
||||
res = notification_recipients.add_recipient("ntop_email", "sysadmins", nil)
|
||||
res = recipients_module.add_recipient("ntop_email", "sysadmins", nil)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "invalid_recipient_params")
|
||||
|
||||
res = notification_recipients.add_recipient("ntop_email", "sysadmins", {})
|
||||
res = recipients_module.add_recipient("ntop_email", "sysadmins", {})
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "missing_mandatory_param")
|
||||
|
||||
local recipient_params = {
|
||||
email_recipient = "ci@ntop.org"
|
||||
}
|
||||
|
||||
res = notification_recipients.add_recipient("ntop_email", "sysadmins", recipient_params)
|
||||
res = recipients_module.add_recipient("ntop_email", "sysadmins", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
-- See if duplicate recipient is detected
|
||||
res = notification_recipients.add_recipient("ntop_email", "sysadmins", recipient_params)
|
||||
res = recipients_module.add_recipient("ntop_email", "sysadmins", recipient_params)
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_recipient_already_existing")
|
||||
|
||||
-- Test deletion
|
||||
res = notification_recipients.delete_recipient("sysadmins")
|
||||
res = recipients_module.delete_recipient("sysadmins")
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_recipients.delete_recipient("sysadmins")
|
||||
res = recipients_module.delete_recipient("sysadmins")
|
||||
assert(res["status"] == "failed" and res["error"]["type"] == "endpoint_recipient_not_existing")
|
||||
|
||||
recipient_params["garbage"] = "trash"
|
||||
|
||||
res = notification_recipients.add_recipient("ntop_email", "sysadmins", recipient_params)
|
||||
res = recipients_module.add_recipient("ntop_email", "sysadmins", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_recipients.get_recipient("sysadmins")
|
||||
res = recipients_module.get_recipient("sysadmins")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["recipient_params"])
|
||||
assert(res["recipient_params"]["email_recipient"] == "ci@ntop.org")
|
||||
|
|
@ -177,24 +179,24 @@ assert(not res["recipient_params"]["garbage"])
|
|||
|
||||
-- Test edit
|
||||
recipient_params["email_recipient"] = "ci2@ntop.org"
|
||||
res = notification_recipients.edit_recipient("sysadmins", recipient_params)
|
||||
res = recipients_module.edit_recipient("sysadmins", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_recipients.get_recipient("sysadmins")
|
||||
res = recipients_module.get_recipient("sysadmins")
|
||||
assert(res["status"] == "OK")
|
||||
assert(res["recipient_params"])
|
||||
assert(res["recipient_params"]["email_recipient"] == "ci2@ntop.org")
|
||||
|
||||
-- Add another couple of recipients
|
||||
recipient_params["email_recipient"] = "devops2@ntop.org"
|
||||
res = notification_recipients.add_recipient("ntop_email", "devops", recipient_params)
|
||||
res = recipients_module.add_recipient("ntop_email", "devops", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
recipient_params["email_recipient"] = "sres@gmail.com"
|
||||
res = notification_recipients.add_recipient("google_email", "sres", recipient_params)
|
||||
res = recipients_module.add_recipient("google_email", "sres", recipient_params)
|
||||
assert(res["status"] == "OK")
|
||||
|
||||
res = notification_recipients.get_recipients()
|
||||
res = recipients_module.get_recipients()
|
||||
|
||||
assert(#res == 3)
|
||||
for _, recipient in pairs(res) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue