Skip to content

Commit

Permalink
Finalized active monitoring page
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBiscosi committed Jan 29, 2025
1 parent 355e0d3 commit ddc6ce9
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 32 deletions.
2 changes: 1 addition & 1 deletion http_src/constants/metrics-consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ const sources_types = [
}, {
main_source_def: true,
label: i18n("page_stats.source_def.active_monitoring"),
sources_url: "lua/rest/v2/get/am_host/list.lua",
sources_url: "lua/rest/v2/get/active_monitoring/timeseries_list.lua",
value: "host",
disable_tskey: true,
value_map_sources_res: "am_host",
Expand Down
31 changes: 31 additions & 0 deletions http_src/utilities/map/interface-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
(C) 2013-24 - ntop.org
*/

const interfaces = [
{ is_pcap_interface: true, icon: "<i class='fas fa-file'></i>" },
{ is_packet_interface: true, icon: "<i class='fas fa-ethernet'></i>" },
{ is_zmq_interface: true, icon: "<i class='fas fa-bezier-curve'></i>" },
{ is_view_interface: true, icon: "<i class='fas fa-eye'></i>" },
{ is_dynamic_interface: true, icon: "<i class='fas fa-code-branch'></i>" },
{ is_dropping_interface: true, icon: "<i class='fas fa-tint'></i>" },
{ is_recording_interface: true, icon: "<i class='fas fa-hdd'></i>" },
]

const getInterfaceIcon = (interface_types) => {
for (const [key, value] of Object.entries(interface_types)) {
const interface_info = interfaces.find((el) => el[key] ? (el[key] === value) : false)
if (interface_info) {
return interface_info.icon;
}
}
return ''
}

const interfaceUtils = function () {
return {
getInterfaceIcon
};
}();

export default interfaceUtils;
2 changes: 1 addition & 1 deletion http_src/vue/modal-add-active-monitoring.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ watch(() => [props.measurements], (cur_value, old_value) => {

/* Watch - detect changes on epoch_begin / epoch_end and refresh the component */
watch(() => [props.interfaces], (cur_value, old_value) => {
const tmp = props.interfaces.filter((t) => (t.packet_interface && !t.pcap_interface))
const tmp = props.interfaces.filter((t) => (t.is_packet_interface && !t.is_pcap_interface))

interfaces_list.value = tmp.map((t) => {
return {
Expand Down
31 changes: 29 additions & 2 deletions http_src/vue/page-active-monitoring.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
</template> <!-- Dropdown filters -->
</TableWithConfig>
<div class="card-footer mt-3">
<button v-if="props.context.is_admin" type="button" class="btn btn-secondary ms-1" :href="manage_configurations_url">
<button v-if="props.context.is_admin" type="button" class="btn btn-secondary ms-1"
:href="manage_configurations_url">
<i class="fas fa-tasks"></i>
{{ _i18n("manage_configurations.manage_configuration") }}
</button>
Expand All @@ -45,6 +46,7 @@ import { default as dataUtils } from "../utilities/data-utils.js";
import { ntopng_url_manager } from "../services/context/ntopng_globals_services.js";
import { default as ModalAddActiveMonitoring } from "./modal-add-active-monitoring.vue";
import { default as ModalDeleteActiveMonitoring } from "./modal-delete-active-monitoring.vue";
import { default as interfaceUtils } from "../utilities/map/interface-utils.js";

const _i18n = (t) => i18n(t);

Expand Down Expand Up @@ -73,7 +75,32 @@ const props = defineProps({
const map_table_def_columns = (columns) => {
let map_columns = {
"target": (value, row) => {
return value.name;
let target_interface = {}
let interface_name = ''
let is_infrastructure_instance = ''
let is_alerted = ''
if (interfaces_list.value.length > 0) {
const tmp_iface = interfaces_list.value.find((el) => el.ifid == row.metadata.interface_id)
if (tmp_iface) {
target_interface["is_pcap_interface"] = tmp_iface["is_pcap_interface"]
target_interface["is_packet_interface"] = tmp_iface["is_packet_interface"]
target_interface["is_zmq_interface"] = tmp_iface["is_zmq_interface"]
target_interface["is_view_interface"] = tmp_iface["is_view_interface"]
target_interface["is_dynamic_interface"] = tmp_iface["is_dynamic_interface"]
target_interface["is_dropping_interface"] = tmp_iface["is_dropping_interface"]
target_interface["is_recording_interface"] = tmp_iface["is_recording_interface"]
}
}
if (!dataUtils.isEmptyOrNull(row.metadata.interface_name)) {
interface_name = ` [ ${interfaceUtils.getInterfaceIcon(target_interface)} ${row.metadata.interface_name} ] `;
}
if (row.metadata.is_infrastructure_instance) {
is_infrastructure_instance = " <i class='fas fa-building'></i> "
}
if (row.metadata.is_alerted) {
is_alerted = ' <i class="fas fa-exclamation-triangle" style="color: #f0ad4e;"></i> '
}
return `${value.name}${is_alerted}${interface_name}${is_infrastructure_instance}`;
},
"ip_address": (value, row) => {
return value;
Expand Down
2 changes: 1 addition & 1 deletion httpdocs/dist
Submodule dist updated 1 files
+2 −2 ntopng.js
32 changes: 30 additions & 2 deletions scripts/lua/modules/label_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ end

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

-- This function set the interface alias, return true if the
-- alias is set, false otherwise
function setInterfaceAlias(iface, alias)
local ok = true

if (isEmptyString(iface)) then
ok = false
end

if (ok and (iface ~= alias) and not isEmptyString(alias)) then
ntop.setCache(getInterfaceAliasKey(iface), alias)
else
ok = false
end

return ok
end

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

function getLocalNetworkAliasKey()
return "ntopng.network_aliases"
end
Expand All @@ -380,6 +400,15 @@ end

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

function getInterfaceAlias(ifid)
if not ifid or not tonumber(ifid) then
return ""
end
return ntop.getCache("ntopng.prefs.ifid_" .. tostring(ifid) .. ".name") or ""
end

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

function getLocalNetworkAliasById(network)
local network_consts = require "network_consts"

Expand Down Expand Up @@ -564,8 +593,7 @@ function getHumanReadableInterfaceName(interface_name)
interface_name = getInterfaceName(interface_id)
end

local key = 'ntopng.prefs.ifid_' .. tostring(interface_id) .. '.name'
local custom_name = ntop.getCache(key)
local custom_name = getInterfaceAlias(interface_id)

if not isEmptyString(custom_name) then
return (shortenCollapse(custom_name))
Expand Down
20 changes: 0 additions & 20 deletions scripts/lua/modules/lua_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -617,26 +617,6 @@ end

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

-- This function set the interface alias, return true if the
-- alias is set, false otherwise
function setInterfaceAlias(iface, alias)
local ok = true

if (isEmptyString(iface)) then
ok = false
end

if (ok and (iface ~= alias) and not isEmptyString(alias)) then
ntop.setCache(getInterfaceAliasKey(iface), alias)
else
ok = false
end

return ok
end

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

function setLocalNetworkAlias(network, alias)
if ((network ~= alias) or isEmptyString(alias)) then
ntop.setHashCache(getLocalNetworkAliasKey(), network, alias)
Expand Down
4 changes: 3 additions & 1 deletion scripts/lua/rest/v2/get/active_monitoring/list.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ for key, info in pairs(active_monitoring_hosts) do
ip_address = ip_address,
threshold = info.threshold,
hourly_stats = hourly_stats or {},
am_host = info.host, -- This is used by http_src/constants/metrics-consts.js
target = {
name = info.label,
host = info.host
Expand All @@ -84,7 +85,8 @@ for key, info in pairs(active_monitoring_hosts) do
metadata = {
is_infrastructure_instance = info.is_infrastructure,
is_alerted = is_alerted,
interface_name = info.ifname,
interface_name = getHumanReadableInterfaceName(info.ifname),
interface_id = getInterfaceId(info.ifname),
granularity = info.granularity,
availability = availability or "",
unit = last_measurement.i18n_unit,
Expand Down
118 changes: 118 additions & 0 deletions scripts/lua/rest/v2/get/active_monitoring/timeseries_list.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
--
-- (C) 2019-24 - ntop.org
--

local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path

require "lua_utils"
local rest_utils = require "rest_utils"
local json = require("dkjson")
local script_manager = require("script_manager")
local am_utils = require "am_utils"

--
-- List of active monitoring hosts (replaces get_active_monitoring_hosts.lua)
-- Example: curl -u admin:admin -H "Content-Type: application/json" -d '{ }' http://localhost:3000/lua/rest/v2/get/am_host/list.lua
--
-- NOTE: in case of invalid login, no error is returned but redirected to login
--

-- sendHTTPContentTypeHeader('application/json')

local charts_available = script_manager.systemTimeseriesEnabled()

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

local am_hosts = am_utils.getHosts()

local res = {}

for key, am_host in pairs(am_hosts) do
local chart = ""
local m_info = am_utils.getMeasurementInfo(am_host.measurement)
local hourly_stats, availability = am_utils.getAvailability(am_host.host, am_host.measurement)

if not m_info then
goto continue
end

if charts_available then
chart = script_manager.getMonitorUrl('active_monitoring_monitor.lua') .. '?am_host='.. am_host.host ..'&measurement='.. am_host.measurement ..'&page=historical'
end

local column_last_ip = ""
local column_last_update = ""
local column_last_value = ""
local column_jitter = ""
local column_ifname = ""
local last_update = am_utils.getLastAmUpdate(am_host.host, am_host.measurement)
local alerted = 0

if am_host.measurement == 'icmp' or am_host.measurement == 'cicmp' then
column_ifname = am_host.ifname or ""
end

if(last_update ~= nil) then
column_last_update = last_update.when
column_last_value = last_update.value
column_last_ip = last_update.ip
end

column_last_value = tonumber(column_last_value)

if(column_last_value == nil) then
chart = ""
end

if am_utils.hasAlerts(am_host) then
alerted = 1
else
alerted = 0
end

if last_update and last_update.jitter and last_update.mean and (last_update.jitter > 0 or last_update.mean > 0) then
local jitter_unit = ""

if m_info.i18n_jitter_unit then
jitter_unit = i18n(m_info.i18n_jitter_unit) or m_info.i18n_jitter_unit or ""
end

column_jitter = string.format("%.1f / %.1f %s", last_update.mean, last_update.jitter, jitter_unit)
end

local html_label = am_utils.formatAmHost(am_host.host, am_host.measurement, true)

if(column_ifname ~= "") then
html_label = html_label .. " [ <span class=\"fas fa-ethernet\"></span> "..column_ifname.." ]"
end

res[#res + 1] = {
key = key,
label = am_host.label,
html_label = html_label,
host = am_host.host,
alerted = alerted,
measurement = i18n(m_info.i18n_label),
measurement_key = am_host.measurement,
chart = chart,
threshold = am_host.threshold,
last_measure = column_last_value or "",
value_js_formatter = m_info.value_js_formatter,
last_mesurement_time = column_last_update,
last_ip = column_last_ip,
ifname = column_ifname,
granularity = am_host.granularity,
availability = availability or "",
hours = hourly_stats or {},
unit = i18n(m_info.i18n_unit) or m_info.i18n_unit,
jitter = column_jitter,
readonly = am_host.readonly
}

::continue::
end

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

rest_utils.answer(rest_utils.consts.success.ok, res)
8 changes: 4 additions & 4 deletions scripts/lua/rest/v2/get/ntopng/interfaces.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ local interfaces = interface.getIfNames()

for ifid, ifname in pairs(interfaces) do
interface.select(ifname)
local custom_name = shortenCollapse(getHumanReadableInterfaceName(ifname))
local custom_name = getHumanReadableInterfaceName(ifname)

res[#res + 1] = {
ifid = tonumber(ifid),
ifname = ifname,
name = custom_name,
packet_interface = interface.isPacketInterface(),
pcap_interface = interface.isPcapDumpInterface(),
zmq_interface = interface.isZMQInterface()
is_packet_interface = interface.isPacketInterface(),
is_pcap_interface = interface.isPcapDumpInterface(),
is_zmq_interface = interface.isZMQInterface()
}
end

Expand Down

0 comments on commit ddc6ce9

Please sign in to comment.