Fixes various issues in flow exporters page

This commit is contained in:
Matteo Biscosi 2025-10-17 13:08:08 +02:00
parent d07f9efd0f
commit 35df60db11
9 changed files with 326 additions and 148 deletions

View file

@ -19,7 +19,8 @@ local columns = {
filters = "SRC_ASN",
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
dst_asn = {
@ -28,7 +29,8 @@ local columns = {
filters = "DST_ASN",
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
src_peer_asn = {
@ -37,7 +39,8 @@ local columns = {
hide_if_value = "0",
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
dst_peer_asn = {
@ -46,7 +49,8 @@ local columns = {
hide_if_value = "0",
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
in_device = {
@ -98,7 +102,7 @@ local columns = {
formatter = {
funct = format_portidx_name,
column_dependent = "in_device",
link = "/lua/pro/enterprise/exporter_interfaces.lua?%s",
link = "/lua/pro/enterprise/flowdevice_interface_details.lua?%s",
generateLinkParams = generateExporterInterfaceLink
}
},
@ -109,7 +113,7 @@ local columns = {
formatter = {
funct = format_portidx_name,
column_dependent = "out_device",
link = "/lua/pro/enterprise/exporter_interfaces.lua?%s",
link = "/lua/pro/enterprise/flowdevice_interface_details.lua?%s",
generateLinkParams = generateExporterInterfaceLink
}
},
@ -117,66 +121,86 @@ local columns = {
formatter = {
funct = format_portidx_name,
column_dependent = "device",
link = "/lua/pro/enterprise/exporter_interfaces.lua?%s",
link = "/lua/pro/enterprise/flowdevice_interface_details.lua?%s",
generateLinkParams = generateExporterInterfaceLink
},
filters = {"in_iface_index", "out_iface_index"},
filters = {"in_iface_index", "out_iface_index"}
},
bytes_sent = {
column_id = "SUM(SRC2DST_BYTES)",
column_id_no_fun = "SRC2DST_BYTES",
invert_with = "bytes_rcvd"
},
bytes_rcvd = {
column_id = "SUM(DST2SRC_BYTES)",
column_id_no_fun = "DST2SRC_BYTES",
invert_with = "bytes_sent"
},
total_bytes = {
column_id = "SUM(TOTAL_BYTES)",
column_id_no_fun = "TOTAL_BYTES"
},
bytes_sent = {column_id = "SUM(SRC2DST_BYTES)", column_id_no_fun = "SRC2DST_BYTES", invert_with = "bytes_rcvd"},
bytes_rcvd = {column_id = "SUM(DST2SRC_BYTES)", column_id_no_fun = "DST2SRC_BYTES", invert_with = "bytes_sent"},
total_bytes = {column_id = "SUM(TOTAL_BYTES)", column_id_no_fun = "TOTAL_BYTES",},
as = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
customer = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
transit_as = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
src_transit_as = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
dst_transit_as = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
src_peer_asn_1 = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
dst_peer_asn_1 = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
src_peer_asn_2 = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
dst_peer_asn_2 = {
formatter = {
funct = format_utils.formatASN,
link = "/lua/as_overview.lua?asn=%s"
link = "/lua/as_overview.lua?asn=%s",
generateLinkParams = generateASNLink
}
},
ifid = {column_id = "INTERFACE_ID"},
@ -191,18 +215,18 @@ local columns = {
-- @param columns_id Array, containing a list of columns ids
-- @return a list of matching ids for the requested type (live or historical)
function flow_data_preset.retrieveColumns(columns_id)
local id_list = {}
local id_list = {}
for position, id in pairs(columns_id or {}) do
if columns[id] then
local column_info = columns[id]
column_info["key"] = column_info["column_id"]
column_info["id"] = id
id_list[position] = column_info
end
end
for position, id in pairs(columns_id or {}) do
if columns[id] then
local column_info = columns[id]
column_info["key"] = column_info["column_id"]
column_info["id"] = id
id_list[position] = column_info
end
end
return id_list
return id_list
end
-- ###########################################
@ -211,14 +235,14 @@ end
-- @param columns_id String, containing a list of columns ids
-- @return a list of matching ids for the requested type (live or historical)
function flow_data_preset.getColumn(column_id)
local column_info = {}
local column_info = {}
if columns[column_id] then
column_info = columns[column_id]
column_info["id"] = column_id
end
if columns[column_id] then
column_info = columns[column_id]
column_info["id"] = column_id
end
return column_info
return column_info
end
-- ###########################################
@ -228,41 +252,41 @@ end
-- @param available_filters List, containing a list filters, key is the key of the filter, value is the value
-- @return a list of filters, key - value
function flow_data_preset.convertFilters(where, available_filters, isHistorical)
local where_query = {}
local where_query = {}
if (not available_filters) or (table.len(available_filters) == 0) then
return where_query
end
if (not available_filters) or (table.len(available_filters) == 0) then
return where_query
end
for _, key in pairs(where or {}) do
if (columns[key] and columns[key]["filters"]) then
local filter = columns[key]["filters"]
-- Multiple filters requested, see asn
if type(filter) == "table" then
for _, or_filter in pairs(filter or {}) do
local new_filter = columns[or_filter]
new_filter.filter_value = available_filters[key]
new_filter.id = or_filter
new_filter.key = new_filter["filters"]
if not where_query[key] then
where_query[key] = {}
end
where_query[key][#where_query[key] + 1] = new_filter
end
else
where_query[filter] = columns[key]
where_query[filter].filter_value = available_filters[key]
end
end
end
for _, key in pairs(where or {}) do
if (columns[key] and columns[key]["filters"]) then
local filter = columns[key]["filters"]
-- Multiple filters requested, see asn
if type(filter) == "table" then
for _, or_filter in pairs(filter or {}) do
local new_filter = columns[or_filter]
new_filter.filter_value = available_filters[key]
new_filter.id = or_filter
new_filter.key = new_filter["filters"]
if not where_query[key] then
where_query[key] = {}
end
where_query[key][#where_query[key] + 1] = new_filter
end
else
where_query[filter] = columns[key]
where_query[filter].filter_value = available_filters[key]
end
end
end
-- Ifid filter is mandatory, add it in case it's missing, only in live data
if not where_query["ifid"] and not where_query["INTERFACE_ID"] then
local ifid = available_filters["ifid"] or interface.getId() -- Use current ifid
where_query["INTERFACE_ID"] = ifid
end
-- Ifid filter is mandatory, add it in case it's missing, only in live data
if not where_query["ifid"] and not where_query["INTERFACE_ID"] then
local ifid = available_filters["ifid"] or interface.getId() -- Use current ifid
where_query["INTERFACE_ID"] = ifid
end
return where_query
return where_query
end
-- ###########################################
@ -273,68 +297,87 @@ end
-- @param value String, data to format
-- @return the formatted data
function flow_data_preset.getFormattedDataAndLink(key, value, values)
local formatted_value = value
local link = nil
local formatted_value = value
local link = nil
-- tprint(key .. " = " .. value)
-- If key is empty or no formatter available return the value
if isEmptyString(key) or isEmptyString(formatted_value) then
return formatted_value, link
end
-- tprint(key .. " = " .. value)
if (not columns[key]) or (not columns[key]["formatter"]) or
(not columns[key]["formatter"]["funct"]) then
return formatted_value, link
end
-- If key is empty or no formatter available return the value
if isEmptyString(key) or isEmptyString(formatted_value) then
return formatted_value, link
end
-- Get the formatter function
local formatter = columns[key]["formatter"]["funct"]
local link_params_formatter = columns[key]["formatter"]["generateLinkParams"]
if (not columns[key]) or (not columns[key]["formatter"]) or
(not columns[key]["formatter"]["funct"]) then
return formatted_value, link
end
-- See if there is some column from which is dependent,
-- e.g. SNMP Interface needs the SNMP IP
if columns[key]["formatter"]["column_dependent"] then
local dependent_values = split(value, "|")
-- Get the formatter function
local formatter = columns[key]["formatter"]["funct"]
local link_params_formatter =
columns[key]["formatter"]["generateLinkParams"]
if (#dependent_values > 1) then
-- TODO: this code looks incomplete
-- TODO: Now it's limited to a single column, add multiple columns
formatted_value = formatter(dependent_values[1], dependent_values[2])
-- See if there is some column from which is dependent,
-- e.g. SNMP Interface needs the SNMP IP
if columns[key]["formatter"]["column_dependent"] then
local dependent_values = split(value, "|")
if link_params_formatter then
local link_params = link_params_formatter(dependent_values[1],
dependent_values[2])
link = string.format(columns[key]["formatter"]["link"], link_params)
end
else
-- new code
local dependency = values[columns[key]["formatter"]["column_dependent"]]
if (#dependent_values > 1) then
-- TODO: Now it's limited to a single column, add multiple columns
formatted_value =
formatter(dependent_values[1], dependent_values[2])
if (dependency ~= nil) then
formatted_value = formatter(dependency, value)
if link_params_formatter then
local link_params = link_params_formatter(dependent_values[1],
dependent_values[2])
if not link_params then
-- in case of nill returned, return nil, it means that the function
-- failed, so no parameters, so no link
return formatted_value, nil
end
link = string.format(columns[key]["formatter"]["link"],
link_params)
end
else
-- new code
local dependency =
values[columns[key]["formatter"]["column_dependent"]]
if link_params_formatter then
local link_params = link_params_formatter(dependency, value)
link = string.format(columns[key]["formatter"]["link"], link_params)
end
end
if (dependency ~= nil) then
formatted_value = formatter(dependency, value)
return formatted_value, link
end
else
formatted_value = formatter(formatted_value)
if link_params_formatter then
local link_params = link_params_formatter(value)
link = string.format(columns[key]["formatter"]["link"], link_params)
end
end
if link_params_formatter then
local link_params = link_params_formatter(dependency, value)
if not link_params then
-- in case of nill returned, return nil, it means that the function
-- failed, so no parameters, so no link
return formatted_value, nil
end
link = string.format(columns[key]["formatter"]["link"],
link_params)
end
end
if not link and columns[key]["formatter"]["link"] then
link = string.format(columns[key]["formatter"]["link"], value)
end
return formatted_value, link
end
else
formatted_value = formatter(formatted_value)
if link_params_formatter then
local link_params = link_params_formatter(value)
if not link_params then
-- in case of nill returned, return nil, it means that the function
-- failed, so no parameters, so no link
return formatted_value, nil
end
link = string.format(columns[key]["formatter"]["link"], link_params)
end
end
return formatted_value, link
if not link and columns[key]["formatter"]["link"] then
link = string.format(columns[key]["formatter"]["link"], value)
end
return formatted_value, link
end
-- ###########################################