Skip to content

Commit

Permalink
Added support to labels and ext_labels in timeseries
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBiscosi committed Jan 31, 2025
1 parent abd4981 commit a9bc1a8
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 33 deletions.
18 changes: 11 additions & 7 deletions http_src/utilities/graph/dygraph-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ function getName(ts_info, metadata) {
if (ts_info.ext_label) {
name = ts_info.ext_label
}
return name
if (ts_info.label) {
name = ts_info.label
}
return { timeserie_name: name, show_full_name: (ts_info.label == null) }
}

/* *********************************************** */
Expand All @@ -114,7 +117,7 @@ function getPlotter(chart_type) {

function addNewSerie(serie_name, chart_type, color, config) {
config.labels.push(serie_name);
if(config.properties == null)
if (config.properties == null)
config.properties = {}
config.properties[serie_name] = {}
config.properties[serie_name] = dygraphConfig.formatSerieProperties(chart_type);
Expand Down Expand Up @@ -278,8 +281,9 @@ function formatStandardSerie(timeserie_info, timeserie_options, config, tsCompar
const ts_id = getSerieId(ts_info);
const metadata = timeserie_info.metric.timeseries[ts_id];
const scalar = (metadata.invert_direction === true) ? -1 : 1;
const timeserie_name = getName(ts_info, metadata)
const serie_name = getSerieName(timeserie_name, ts_id, timeserie_info, config.use_full_name)
const { timeserie_name, show_full_name } = getName(ts_info, metadata)
/* Check if show_full_name is null or undefined */
const serie_name = getSerieName(timeserie_name, ts_id, timeserie_info, (show_full_name !== null || show_full_name !== undefined) ? (config.use_full_name && show_full_name) : config.use_full_name)
const avg_name = getSerieName(timeserie_name + " Avg", ts_id, timeserie_info, config.use_full_name)
const perc_name = getSerieName(timeserie_name + " 95th Perc", ts_id, timeserie_info, config.use_full_name);
const past_name = getSerieName(timeserie_name + " " + tsCompare + " Ago", ts_id, timeserie_info, config.use_full_name);
Expand Down Expand Up @@ -384,7 +388,7 @@ function formatSimpleSerie(data, serie_name, chart_type, formatters, value_range
});

/* To not have an error, just add a null value */
if(tmp_serie.length == 0) {
if (tmp_serie.length == 0) {
tmp_serie.push([1, null]);
}

Expand All @@ -401,14 +405,14 @@ function formatSimpleSerie(data, serie_name, chart_type, formatters, value_range
disable_ts_list: true,
};

if (typeof(serie_name) === "string") {
if (typeof (serie_name) === "string") {
addNewSerie(serie_name, chart_type, { color: constant_serie_colors["default_color"], palette: 0 }, config)
} else {
serie_name.forEach((el) => {
addNewSerie(el, chart_type, { color: constant_serie_colors["default_color"], palette: 0 }, config)
})
}
formatSerieColors(config.colors);
formatSerieColors(config.colors);
return dygraphConfig.buildChartOptions(config);
}

Expand Down
11 changes: 6 additions & 5 deletions http_src/vue/page-network-configuration.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<template>
<div class="m-3">
<div class="alert alert-info alert-dismissable">
<span v-html="alert_note"></span>
</div>
<div class="card card-shadow">
<template v-if="(!props.context.is_check_enabled)">
<div class="alert alert-warning" role="alert" id='error-alert' v-html:="error_message">
</div>
</template>
<div class="card card-shadow" :class="[(!props.context.is_check_enabled) ? 'ntopng-gray-out' : '']">
<div class="card-body">
<Loading v-if="loading"></Loading>
<table class="table table-striped table-bordered col-sm-12"
Expand Down Expand Up @@ -65,7 +66,7 @@ const get_config_url = `${http_prefix}/lua/rest/v2/get/network/config.lua`
const modifiedInputs = ref([]);
const disable_save = ref(true)
const alert_note = ref(_i18n('network_configuration.alert_note'))
const error_message = ref(_i18n('network_configuration.alert_note'))
const isSaving = ref(false);
const saveSuccess = ref(false);
Expand Down
11 changes: 6 additions & 5 deletions http_src/vue/page-network-policy.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<template>
<div class="m-3">
<div class="alert alert-info alert-dismissable">
<span v-html="policy_note"></span>
</div>
<div class="card card-shadow">
<template v-if="(!props.context.is_check_enabled)">
<div class="alert alert-warning" role="alert" id='error-alert' v-html:="error_message">
</div>
</template>
<div class="card card-shadow" :class="[(!props.context.is_check_enabled) ? 'ntopng-gray-out' : '']">
<Loading v-if="show_spinner"></Loading>
<div class="card-body">
<table class="table table-striped table-bordered col-sm-12" :class="show_spinner ? 'ntopng-gray-out' : ''">
Expand Down Expand Up @@ -70,7 +71,7 @@ const set_config_url = `${http_prefix}/lua/pro/rest/v2/set/network/policy.lua`
const get_config_url = `${http_prefix}/lua/pro/rest/v2/get/network/policy.lua`
const modifiedInputs = ref([]);
const policy_note = ref(_i18n('network_configuration.policy_note'))
const error_message = ref(_i18n('network_configuration.policy_note'))
const configuration_error = ref('');
const show_configuration_error = ref(false);
const isSaving = ref(false);
Expand Down
3 changes: 3 additions & 0 deletions http_src/vue/page-stats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ function set_stats_rows(ts_charts_options, timeseries_groups, status) {
if (s.ext_label) {
name = s.ext_label
}
if (s.label) {
name = s.label
}
name = timeseriesUtils.getSerieName(name, ts_id, ts_group, extend_serie_name);
let total_formatter_type = f_get_total_formatter_type(ts_group.metric.measure_unit);
let total_formatter = formatterUtils.getFormatter(total_formatter_type);
Expand Down
2 changes: 1 addition & 1 deletion httpdocs/dist
Submodule dist updated 1 files
+2 −2 ntopng.js
4 changes: 2 additions & 2 deletions scripts/locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6367,8 +6367,8 @@ local lang = {
["trigger_network_alerts"] = "Trigger Network Alerts",
},
["network_configuration"] = {
["alert_note"] = "The configuration below is used by the 'Unexpected DNS/NTP/DHCP/SMTP/Gateway Server' behavioural checks: make sure to enable them <a href='" .. ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua?subdir=all#all'><i class='fas fa-cog'></i></a>.",
["policy_note"] = "The configuration below are used by the 'Host Policy' behavioural check: make sure to enable it <a href='" .. ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua?subdir=all#all'><i class='fas fa-cog'></i></a>.",
["alert_note"] = "The Unexpected DNS/NTP/DHCP/SMTP/Gateway Server Checks are disabled. Please enable at least one of them <a href='" .. ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua?subdir=all#all'><i class='fas fa-cog'></i></a>.",
["policy_note"] = "The Host Policy Check is disabled. Please enable it <a href='" .. ntop.getHttpPrefix() .. "/lua/admin/edit_configset.lua?subdir=all#all'><i class='fas fa-cog'></i></a>.",
["dhcp_servers_title"] = "DHCP Servers",
["dns_servers_title"] = "DNS Servers",
["dns_servers_description"] = "A list of comma separated DNS Servers IPs",
Expand Down
60 changes: 47 additions & 13 deletions scripts/lua/admin/network_configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require "ntop_utils"
local page_utils = require "page_utils"
local json = require "dkjson"
local template_utils = require("template_utils")
local checks = require "checks"

sendHTTPContentTypeHeader('text/html')

Expand All @@ -20,31 +21,64 @@ dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua")
local page = _GET["page"]

page_utils.print_navbar(i18n("checks.network_configuration"),
ntop.getHttpPrefix() .. "/lua/admin/network_configuration.lua", { {
active = (page == nil or page =='assets_inventory'),
page_name = "assets_inventory",
label = "<i class=\"fas fa-lg fa-home\" data-bs-toggle=\"tooltip\" data-bs-placement=\"top\" title=\"" ..
i18n("checks.network_configuration") .. "\"></i>"
}, {
active = (page == "policy"),
page_name = "policy",
hidden = not ntop.isEnterpriseL(),
label = i18n("network_configuration.network_policy")
}})
ntop.getHttpPrefix() .. "/lua/admin/network_configuration.lua", {{
active = (page == nil or page == 'assets_inventory'),
page_name = "assets_inventory",
label = "<i class=\"fas fa-lg fa-home\" data-bs-toggle=\"tooltip\" data-bs-placement=\"top\" title=\"" ..
i18n("checks.network_configuration") .. "\"></i>"
}, {
active = (page == "policy"),
page_name = "policy",
hidden = not ntop.isEnterpriseL(),
label = i18n("network_configuration.network_policy")
}})

local context = {
ifid = interface.getId(),
csrf = ntop.getRandomCSRFValue()
}

local json_context = json.encode(context)
if (page == nil or page == 'assets_inventory') then
local checks_config = checks.getConfigset()["config"]
local interface_config = checks_config["interface"]
local flow_config = checks_config["flow"]
local is_check_enabled = false

if (flow_config) then
-- Interface alerts
if (flow_config["unexpected_dns"]) and (flow_config["unexpected_dns"]["all"]["enabled"]) or
(flow_config["unexpected_ntp"]) and (flow_config["unexpected_ntp"]["all"]["enabled"]) or
(flow_config["unexpected_smtp"]) and (flow_config["unexpected_smtp"]["all"]["enabled"]) or
(flow_config["unexpected_gateway"]) and (flow_config["unexpected_gateway"]["all"]["enabled"]) or
(flow_config["unexpected_dhcp"]) and (flow_config["unexpected_dhcp"]["all"]["enabled"]) then
is_check_enabled = true
end
end

context.is_check_enabled = is_check_enabled
local json_context = json.encode(context)

if (page == nil or page =='assets_inventory') then
template_utils.render("pages/vue_page.template", {
vue_page_name = "PageNetworkConfiguration",
page_context = json_context

})
else
local checks_config = checks.getConfigset()["config"]
local interface_config = checks_config["interface"]
local flow_config = checks_config["flow"]
local is_check_enabled = false

if (flow_config) then
-- Interface alerts
if (flow_config["host_policy"]) and (flow_config["host_policy"]["all"]["enabled"]) then
is_check_enabled = true
end
end

context.is_check_enabled = is_check_enabled
local json_context = json.encode(context)

template_utils.render("pages/vue_page.template", {
vue_page_name = "PageNetworkPolicy",
page_context = json_context
Expand Down

1 comment on commit a9bc1a8

@MatteoBiscosi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented issue #8930

Please sign in to comment.