refactor for endpoints and recipients (#4707)

This commit is contained in:
gabryon99 2020-11-25 16:09:44 +01:00
parent 06161556ac
commit 15772bd0fe
24 changed files with 129 additions and 117 deletions

View file

@ -7,7 +7,7 @@ package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
local plugins_utils = require("plugins_utils")
local json = require "dkjson"
local notification_configs = require("notification_configs")
local endpoints = require("endpoints")
local alert_consts = require("alert_consts")
local do_trace = false
@ -144,7 +144,7 @@ local function check_endpoint_recipient_params(endpoint_key, recipient_params)
-- Create a safe_params table with only expected params
local safe_params = {}
-- So iterate across all expected params of the current endpoint
for _, param in ipairs(notification_configs.get_types()[endpoint_key].recipient_params) do
for _, param in ipairs(endpoints.get_types()[endpoint_key].recipient_params) do
-- param is a lua table so we access its elements
local param_name = param["param_name"]
local optional = param["optional"]
@ -162,7 +162,7 @@ end
-- #################################################################
function notification_recipients.add_recipient(endpoint_conf_name, endpoint_recipient_name, recipient_params)
local ec = notification_configs.get_endpoint_config(endpoint_conf_name)
local ec = endpoints.get_endpoint_config(endpoint_conf_name)
if ec["status"] ~= "OK" then
return ec
@ -211,7 +211,7 @@ function notification_recipients.edit_recipient(endpoint_recipient_name, recipie
return {status = "failed", error = {type = "endpoint_recipient_not_existing", endpoint_recipient_name = endpoint_recipient_name}}
end
local ec = notification_configs.get_endpoint_config(rc["endpoint_conf_name"])
local ec = endpoints.get_endpoint_config(rc["endpoint_conf_name"])
if ec["status"] ~= "OK" then
return ec
@ -246,7 +246,7 @@ function notification_recipients.get_recipient(endpoint_recipient_name)
return {status = "failed", error = {type = "endpoint_recipient_not_existing", endpoint_recipient_name = endpoint_recipient_name}}
end
local ec = notification_configs.get_endpoint_config(rc["endpoint_conf_name"])
local ec = endpoints.get_endpoint_config(rc["endpoint_conf_name"])
if ec["status"] ~= "OK" then
return ec
@ -310,7 +310,7 @@ end
-- #################################################################
function notification_recipients.delete_recipients(endpoint_conf_name)
local ec = notification_configs.get_endpoint_config(endpoint_conf_name)
local ec = endpoints.get_endpoint_config(endpoint_conf_name)
if ec["status"] ~= "OK" then
return ec
@ -334,7 +334,7 @@ function notification_recipients.test_recipient(endpoint_conf_name, endpoint_rec
-- Get endpoint config
local ec = notification_configs.get_endpoint_config(endpoint_conf_name)
local ec = endpoints.get_endpoint_config(endpoint_conf_name)
if ec["status"] ~= "OK" then
return ec
@ -360,7 +360,7 @@ function notification_recipients.test_recipient(endpoint_conf_name, endpoint_rec
-- Get endpoint module
local modules_by_name = notification_configs.get_types()
local modules_by_name = endpoints.get_types()
local module_name = recipient.endpoint_conf.endpoint_key
local m = modules_by_name[module_name]
if not m then
@ -490,7 +490,7 @@ end
-- @return nil
function notification_recipients.process_notifications(now, periodic_frequency, force_export)
local recipients = notification_recipients.get_recipients()
local modules_by_name = notification_configs.get_types()
local modules_by_name = endpoints.get_types()
local ready_recipients = {}
-- Check, among all available recipients, those that are ready to export, depending on