Add get_portidx_by_name and snmp_mappings.get_iface_idx

This commit is contained in:
Alfredo Cardigliano 2022-11-28 15:40:56 +01:00
parent 39aaaf58da
commit a206f83b4b
4 changed files with 78 additions and 11 deletions

View file

@ -1241,6 +1241,47 @@ end
-- ##############################################
-- @brief This function converts the SNMP interface name to the corresponding port index.
-- @params device_ip: snmp device ip
-- port_name: string, interface name
function get_portidx_by_name(device_ip, port_name)
-- SNMP is available only with Pro version at least
if ntop.isPro() then
local cached_dev = _snmp_devices[device_ip]
if(cached_dev == nil) then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
local snmp_cached_dev = require "snmp_cached_dev"
cached_dev = snmp_cached_dev:get_interface_names(device_ip)
_snmp_devices[device_ip] = cached_dev
end
if (cached_dev) and (cached_dev["interfaces"]) then
-- SNMP lookup
for idx, info in pairs(cached_dev["interfaces"]) do
if info.name and info.name == port_name then
return idx
end
end
-- No SNMP configured: last resort use exporters
local snmp_mappings = require "snmp_mappings"
local idx = snmp_mappings.get_iface_idx(device_ip, port_name)
if idx then
return idx
end
end
end
return nil
end
-- ##############################################
-- @brief Given a table of values, if available, it's going to format the values with the standard
-- info and then return the same table formatted
function format_dns_query_info(dns_info)

View file

@ -86,4 +86,21 @@ end
-- ################################################################################
function snmp_mappings.get_iface_idx(snmp_device_ip, if_name)
local ports
_cache_device(snmp_device_ip)
ports = _localcache[snmp_device_ip]
for idx, info in pairs(ports) do
if info.name and info.name == if_name then
return idx
end
end
return nil
end
-- ################################################################################
return snmp_mappings

View file

@ -15,14 +15,13 @@ function ts_rest_utils.get_timeseries(http_context)
local tstart = http_context.epoch_begin
local tend = http_context.epoch_end
local compare_backward = http_context.ts_compare
local tags = http_context.ts_query
local tags = http_context.tags
local extended_times = http_context.extended
local ts_aggregation = http_context.ts_aggregation
local no_fill = tonumber(http_context.no_fill)
tstart = tonumber(tstart) or (os.time() - 3600)
tend = tonumber(tend) or os.time()
tags = tsQueryToTags(tags)
if http_context.tskey then
-- This can contain a MAC address for local broadcast domain hosts
local tskey = http_context.tskey