Merge custom KEA configuration extension with generated configuration

This commit is contained in:
Alfredo Cardigliano 2025-11-10 10:46:01 +01:00
parent 1140cfa9fe
commit 76d5f05a23

View file

@ -5,6 +5,8 @@
local sys_utils = require "sys_utils"
local json = require "dkjson"
local KEA_CONF_EXT_PATH = "/etc/ntopng/kea-dhcp4-ext.conf"
local kea_dhcp_server = {}
kea_dhcp_server.service_name = "kea-dhcp4-server"
@ -184,6 +186,23 @@ function kea_dhcp_server.writeDhcpServerConfiguration(dhcp_config, all_interface
end
end
-- Check for external configuration file and merge if present
local ext_config_f = sys_utils.openFile(KEA_CONF_EXT_PATH, "r")
if ext_config_f then
local ext_config_json = ext_config_f:read("*all")
ext_config_f:close()
if not isEmptyString(ext_config_json) then
local ext_config, pos, err = json.decode(ext_config_json)
if ext_config then
-- Merge external configuration with generated configuration
kea_config = table.merge(kea_config, ext_config)
else
traceError(TRACE_WARNING, TRACE_CONSOLE, "Failed to parse " .. KEA_CONF_EXT_PATH .. ": " .. (err or "unknown error"))
end
end
end
-- Write the Kea DHCP4 configuration file in JSON format
local f = sys_utils.openFile("/etc/kea/kea-dhcp4.conf", "w")
if not f then