From 9455936df443111d01f27f99f36ae7f2623dc8b8 Mon Sep 17 00:00:00 2001 From: Manuel Ceroni <46685230+manuelceroni@users.noreply.github.com> Date: Mon, 15 Sep 2025 11:34:04 +0200 Subject: [PATCH] Added Other AS filter (#9665) --- http_src/vue/page-as-stats.vue | 6 ++++- scripts/locales/en.lua | 3 ++- scripts/lua/modules/as_utils.lua | 26 +++++++++++++++++++- scripts/lua/modules/http_lint.lua | 2 +- scripts/lua/rest/v2/get/asn/get_as_data.lua | 27 +++++++++++---------- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/http_src/vue/page-as-stats.vue b/http_src/vue/page-as-stats.vue index 3cea84faf8..b0005706ea 100644 --- a/http_src/vue/page-as-stats.vue +++ b/http_src/vue/page-as-stats.vue @@ -74,7 +74,7 @@ const timeseries_key = ref(false); const asn_type_option = ref([{ key: "show_as", value: "all", - label: i18n("asn_configuration.all_asns") + label: i18n("asn_configuration.all_asn") }, { key: "show_as", value: "my_as", @@ -87,6 +87,10 @@ const asn_type_option = ref([{ key: "show_as", value: "remote_as", label: i18n("asn_configuration.remote_asn_title") +}, { + key: "show_as", + value: "other_as", + label: i18n("asn_configuration.other_asn") }]) const params = { diff --git a/scripts/locales/en.lua b/scripts/locales/en.lua index b53e2dea4c..b777cb87fa 100644 --- a/scripts/locales/en.lua +++ b/scripts/locales/en.lua @@ -6810,11 +6810,12 @@ local lang = { ["trigger_network_alerts"] = "Trigger Network Alerts", }, ["asn_configuration"] = { - ["all_asns"] = "All ASNs", + ["all_asn"] = "All ASNs", ["customer_asn_description"] = "Comma separated list of ASNs, that belong to this organization.", ["customer_asn_title"] = "My ASNs", ["filter"] = "Filter", ["notes"] = "Comma separated list of ASNs. Example: 10,2404,4044", + ["other_asn"] = "Other ASNs", ["remote_asn_title"] = "Relevant Remote ASNs", ["sub_customer_asn_description"] = "Comma separated list of Customer ASNs, interconnected to the Internet via my ASNs.", ["sub_customer_asn_title"] = "My Customers ASNs", diff --git a/scripts/lua/modules/as_utils.lua b/scripts/lua/modules/as_utils.lua index 73dcfdb92d..70c1260c04 100644 --- a/scripts/lua/modules/as_utils.lua +++ b/scripts/lua/modules/as_utils.lua @@ -1,5 +1,5 @@ -- --- (C) 2021 - ntop.org +-- (C) 2025 - ntop.org -- local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path @@ -48,6 +48,30 @@ function as_utils.getAllConfigurations() return customer_asn, sub_customer_asn, remote_asn end +-- The function filters from a table of ASNs those that are not customers, sub-customers, or remote +function as_utils.getOtherASNs(as_info) + local customer_asn, sub_customer_asn, remote_asn = as_utils.getAllConfigurations() + local res = {} + local costumer_sub = table.merge(customer_asn, sub_customer_asn) + local total = table.merge(costumer_sub,remote_asn) + if as_info ~= nil then + for key, value in pairs(as_info) do + if total then + local value_total = total[tostring(value["asn"])] + if not value_total then + value_check = res[tostring(value["asn"])] + if not value_check then + res[tostring(value["asn"])] = 1 + else + res[tostring(value["asn"])] = value_check + 1 + end + end + end + end + end + return res +end + function as_utils.getASNConfiguration(asn) local res = nil local customer_asn, sub_customer_asn, remote_asn = as_utils.getAllConfigurations() diff --git a/scripts/lua/modules/http_lint.lua b/scripts/lua/modules/http_lint.lua index 6c533e5c54..ee7ebdcbd0 100644 --- a/scripts/lua/modules/http_lint.lua +++ b/scripts/lua/modules/http_lint.lua @@ -1429,7 +1429,7 @@ end -- ################################################################# local function validateImportantASN(m) - return validateChoice({"all", "my_as", "my_customer_as", "remote_as"}, m) + return validateChoice({"all", "my_as", "my_customer_as", "remote_as", "other_as"}, m) end -- ################################################################# diff --git a/scripts/lua/rest/v2/get/asn/get_as_data.lua b/scripts/lua/rest/v2/get/asn/get_as_data.lua index 5da233ad31..a1e8716537 100644 --- a/scripts/lua/rest/v2/get/asn/get_as_data.lua +++ b/scripts/lua/rest/v2/get/asn/get_as_data.lua @@ -25,19 +25,6 @@ interface.select(ifname) local selected_asn = _GET["show_as"] local check_as = nil -if not isEmptyString(selected_asn) then - local customer_as, sub_customer_as, remote_as = - as_utils.getAllConfigurations() - - if selected_asn == "my_as" then - check_as = customer_as - elseif selected_asn == "my_customer_as" then - check_as = sub_customer_as - elseif selected_asn == "remote_as" then - check_as = remote_as - end -end - local asn = tonumber(_GET["asn"]) local as_info; @@ -50,6 +37,20 @@ else as_info = as_info["ASes"] end +if not isEmptyString(selected_asn) then + local customer_as, sub_customer_as, remote_as = + as_utils.getAllConfigurations() + if selected_asn == "my_as" then + check_as = customer_as + elseif selected_asn == "my_customer_as" then + check_as = sub_customer_as + elseif selected_asn == "remote_as" then + check_as = remote_as + elseif selected_asn == "other_as" then + check_as = as_utils.getOtherASNs(as_info) + end +end + local res = {} if as_info ~= nil then