Skip to content

Commit

Permalink
Always use ntop.isClickHouseEnabled() from lua. Remove prefs.is_dump_…
Browse files Browse the repository at this point in the history
…flows_to_mysql_enabled to avoid inconsistencies.
  • Loading branch information
cardigliano committed Jul 10, 2024
1 parent abf89f7 commit 06965da
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion scripts/lua/host_details.lua
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ else
label = "<i class=\"fas fa-lg fa-concierge-bell\" title='" .. i18n("service_map") .. "'\"></i>",
url = service_map_link
}, {
hidden = not prefs.is_dump_flows_to_clickhouse_enabled or page == "historical",
hidden = not ntop.isClickHouseEnabled() or page == "historical",
active = page == "db_search",
page_name = "db_search",
label = "<i class=\"fas fa-search-plus\" title='" .. i18n("db_explorer.historical_data_explorer") .. "'\"></i>",
Expand Down
2 changes: 1 addition & 1 deletion scripts/lua/if_stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ if ((page == "overview") or (page == nil)) then
if prefs.is_dump_flows_enabled and not ifstats.isViewed then
local dump_to = ""

if prefs.is_dump_flows_to_clickhouse_enabled then
if ntop.isClickHouseEnabled() then
dump_to = "ClickHouse"
elseif prefs.is_dump_flows_to_mysql_enabled then
dump_to = "MySQL"
Expand Down
2 changes: 1 addition & 1 deletion scripts/lua/mac_details.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ page_utils.print_navbar(title, url,
label = "<i class='fas fa-lg fa-chart-area'></i>",
},
{
hidden = not prefs.is_dump_flows_to_clickhouse_enabled or page == "historical",
hidden = not ntop.isClickHouseEnabled() or page == "historical",
active = page == "db_search",
page_name = "db_search",
label = "<i class=\"fas fa-search-plus\" title='" .. i18n("db_explorer.historical_data_explorer") .. "'\"></i>",
Expand Down
19 changes: 7 additions & 12 deletions scripts/lua/modules/check_redis_prefs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,35 +223,30 @@ end
-- ##############################################

function hasClickHouseSupport()
if not ntop.isClickHouseEnabled() then
return false
end

local auth = require "auth"

if not (ntop.isPro() or ntop.isnEdgeEnterprise()) or ntop.isWindows() then
return false
end

-- Don't allow nIndex for unauthorized users
-- Don't allow historical flows for unauthorized users
if not auth.has_capability(auth.capabilities.historical_flows) then
return false
end

-- TODO optimize
if prefs == nil then
prefs = ntop.getPrefs()
end

if prefs.is_dump_flows_to_clickhouse_enabled then
return true
end

return false
return true
end

-- ##############################################

-- NOTE: global nindex support may be enabled but some disable on some interfaces
function interfaceHasClickHouseSupport()
require "check_redis_prefs"
return (hasClickHouseSupport() and ntop.getPrefs()["is_dump_flows_to_clickhouse_enabled"])
return hasClickHouseSupport()
end

-- ##############################################
Expand Down
2 changes: 1 addition & 1 deletion scripts/lua/modules/dashboard_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ local dashboard_utils = {}
-- ##############################################

local function is_clickhouse_available()
return prefs.is_dump_flows_to_clickhouse_enabled
return ntop.isClickHouseEnabled()
end

dashboard_utils.module_available = {
Expand Down
3 changes: 1 addition & 2 deletions scripts/lua/modules/lua_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,7 @@ function historicalProtoHostHref(ifId, host, l4_proto, ndpi_proto_id, info, vlan
local now = os.time()
local ago1h = now - 3600

local prefs = ntop.getPrefs()
if prefs.is_dump_flows_to_clickhouse_enabled then
if ntop.isClickHouseEnabled() then
local hist_url = ntop.getHttpPrefix() .. "/lua/pro/db_search.lua?"
local params = {
epoch_end = now,
Expand Down
2 changes: 1 addition & 1 deletion scripts/lua/modules/lua_utils_gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ function formatAlertAHref(key, value, label)
end

function add_historical_flow_explorer_button_ref(extra_params, no_href)
if (ntop.getPrefs()["is_dump_flows_to_clickhouse_enabled"]) == false then
if not ntop.isClickHouseEnabled() then
return ''
end

Expand Down
2 changes: 1 addition & 1 deletion scripts/lua/modules/toasts/predicates_defined_toasts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ function predicates.obsolete_mysql(toast, container)
return
end

if prefs.is_dump_flows_to_mysql_enabled and not prefs.is_dump_flows_to_clickhouse_enabled then
if prefs.is_dump_flows_to_mysql_enabled and not ntop.isClickHouseEnabled() then
local title = i18n("obsolete_mysql")
local body = i18n("obsolete_mysql_message")

Expand Down
2 changes: 0 additions & 2 deletions src/Prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2652,8 +2652,6 @@ void Prefs::lua(lua_State *vm) {
dump_flows_on_es);
lua_push_bool_table_entry(vm, "is_dump_flows_to_syslog_enabled",
dump_flows_on_syslog);
lua_push_bool_table_entry(vm, "is_dump_flows_to_clickhouse_enabled",
dump_flows_on_clickhouse);
lua_push_int32_table_entry(vm, "host_to_scan_max_num_scans",
vs_max_num_scans);
lua_push_bool_table_entry(vm, "vs_slow_scan", vs_slow_scan);
Expand Down

0 comments on commit 06965da

Please sign in to comment.