Fixes snmp cached dev not found (#6481)

This commit is contained in:
MatteoBiscosi 2022-03-30 10:27:05 +02:00
parent 4b9d706800
commit 5eff8cb9e1

View file

@ -5033,29 +5033,32 @@ end
-- portidx: number or string, interface index to format
-- short_version: boolean, long formatting version (e.g. flow info) or short version (e.g. dropdown menu)
function format_portidx_name(device_ip, portidx, short_version)
local idx_name = portidx
local snmp_cached_dev = require "snmp_cached_dev"
local cached_dev = snmp_cached_dev:create(device_ip)
if (cached_dev) and (cached_dev["interfaces"]) then
local port_info = cached_dev["interfaces"][tostring(portidx)]
local idx_name = portidx
-- SNMP is available only with Pro version at least
if ntop.isPro() then
local snmp_cached_dev = require "snmp_cached_dev"
local cached_dev = snmp_cached_dev:create(device_ip)
if (cached_dev) and (cached_dev["interfaces"]) then
local port_info = cached_dev["interfaces"][tostring(portidx)]
if port_info then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
snmp_location = require "snmp_location"
if port_info then
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
snmp_location = require "snmp_location"
if not port_info["id"] then
port_info["id"] = port_info["index"]
port_info["snmp_device_ip"] = cached_dev["host_ip"]
end
if short_version then
idx_name = string.format('%s [%s]', port_info["index"], port_info["name"])
else
idx_name = string.format('%s', i18n("snmp.interface_device_2", {interface=snmp_location.snmp_port_link(port_info, true), device=snmp_location.snmp_device_link(cached_dev["host_ip"])}))
end
end
end
if not port_info["id"] then
port_info["id"] = port_info["index"]
port_info["snmp_device_ip"] = cached_dev["host_ip"]
end
if short_version then
idx_name = string.format('%s [%s]', port_info["index"], port_info["name"])
else
idx_name = string.format('%s', i18n("snmp.interface_device_2", {interface=snmp_location.snmp_port_link(port_info, true), device=snmp_location.snmp_device_link(cached_dev["host_ip"])}))
end
end
end
end
return idx_name
end