Moved active monitoring page to vuejs

This commit is contained in:
Matteo Biscosi 2025-01-28 18:11:27 +01:00
parent 0a2b1e8bb9
commit 963579b526
18 changed files with 1469 additions and 3 deletions

View file

@ -0,0 +1,68 @@
--
-- (C) 2013-25 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- ################################################
require "http_lint"
require "check_redis_prefs"
local rest_utils = require "rest_utils"
local active_monitoring_utils = require "am_utils"
local rc = rest_utils.consts.success.ok
local ifid = _GET["ifid"]
local res = {}
local measurements_info = {}
-- ################################################
local active_monitoring_hosts = active_monitoring_utils.getHosts() or {}
local measurement_types = active_monitoring_utils.getMeasurementsInfo()
local measurement_filters = {{
key = "measurement",
value = "",
label = i18n("all")
}}
local tmp_filters = {}
for key, info in pairs(active_monitoring_hosts) do
tmp_filters[i18n('active_monitoring_page.' .. info.measurement)] = {
key = "measurement",
value = info.measurement,
label = i18n('active_monitoring_page.' .. info.measurement)
}
end
for _, info in pairsByKeys(tmp_filters, asc) do
measurement_filters[#measurement_filters + 1] = info
end
res[#res + 1] = {
action = "measurement",
label = i18n("active_monitoring_page.measurement"),
name = "measurement",
value = measurement_filters
}
res[#res + 1] = {
action = "only_alerted_hosts",
label = i18n("active_monitoring_page.alert_status"),
name = "only_alerted_hosts",
value = {{
key = "only_alerted_hosts",
value = "",
label = i18n("all")
}, {
key = "only_alerted_hosts",
value = "1",
label = i18n("active_monitoring_page.alerted")
}, {
key = "only_alerted_hosts",
value = "0",
label = i18n("active_monitoring_page.not_alerted")
},}
}
-- ################################################
rest_utils.answer(rc, res)

View file

@ -0,0 +1,103 @@
--
-- (C) 2013-25 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- ####################################
require "http_lint"
require "check_redis_prefs"
local am_utils = require "am_utils"
local rest_utils = require "rest_utils"
local rc = rest_utils.consts.success.ok
local ifid = _GET["ifid"]
local measurement = _GET["measurement"]
local alerted = _GET["only_alerted_hosts"]
local res = {}
if not isEmptyString(alerted) then
alerted = alerted == '1'
end
-- ################################################
local active_monitoring_hosts = am_utils.getHosts() or {}
for key, info in pairs(active_monitoring_hosts) do
local last_measurement = am_utils.getMeasurementInfo(info.measurement)
local is_alerted = am_utils.hasAlerts(info)
if not last_measurement then
goto continue
end
-- Filters applied
if not isEmptyString(measurement) and measurement ~= info.measurement then
goto continue
end
if not isEmptyString(alerted) and alerted ~= is_alerted then
goto continue
end
-- Format the data
local ip_address = ''
local last_measurement_time = 0
local measurement_value = ''
local last_mean = ''
local last_jitter = ''
local hourly_stats, availability = am_utils.getAvailability(info.host, info.measurement)
local last_update = am_utils.getLastAmUpdate(info.host, info.measurement)
if last_update then
ip_address = last_update.ip
measurement_value = last_update.value
last_measurement_time = last_update.when
last_mean = last_update.mean
last_jitter = last_update.jitter
end
-- Clean the IP Address in case of http
if not isEmptyString(ip_address) and string.find(ip_address, '//') then
ip_address = split(ip_address, '//')[2]
if string.find(ip_address, '/') then
ip_address = split(ip_address, '/')[1]
end
end
res[#res + 1] = {
key = key,
ip_address = ip_address,
threshold = info.threshold,
hourly_stats = hourly_stats or {},
target = {
name = info.label,
host = info.host
},
last_measurement = {
measurement_type = info.measurement,
measurement_value = measurement_value,
last_measurement_time = last_measurement_time,
},
metadata = {
is_infrastructure_instance = info.is_infrastructure,
is_alerted = is_alerted,
interface_name = info.ifname,
granularity = info.granularity,
availability = availability or "",
unit = last_measurement.i18n_unit,
timeseries = (areSystemTimeseriesEnabled() and not isEmptyString(measurement_value))
},
extra_measurements = {
mean = last_mean,
jitter = last_jitter
}
}
::continue::
end
-- ################################################
rest_utils.answer(rc, res)

View file

@ -0,0 +1,49 @@
--
-- (C) 2013-25 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- ####################################
require "http_lint"
require "check_redis_prefs"
require "ntop_utils"
local active_monitoring_utils = require "am_utils"
local rest_utils = require "rest_utils"
local rc = rest_utils.consts.success.ok
-- ################################################
local rsp = {}
local measurements_info = {}
for key, info in pairs(active_monitoring_utils.getMeasurementsInfo()) do
if key == "vulnerability_scan" or key == "cve_changes_detected" or key == "ports_changes_detected" then
goto continue
end
local label = i18n(info.i18n_label) or info.i18n_label
local unit = i18n(info.i18n_unit) or info.i18n_unit
measurements_info[key] = {
label = label,
granularities = active_monitoring_utils.getAvailableGranularities(key),
key = key,
operator = info.operator,
unit = unit,
force_host = info.force_host,
max_threshold = info.max_threshold,
default_threshold = info.default_threshold
}
::continue::
end
for _, info in pairsByKeys(measurements_info, asc) do
rsp[#rsp + 1] = info
end
-- ################################################
rest_utils.answer(rc, rsp)