mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Clean callback scripts code
This commit is contained in:
parent
e5e6ff6cd8
commit
2affcfb208
6 changed files with 157 additions and 142 deletions
|
|
@ -15,6 +15,7 @@ end
|
|||
|
||||
require "lua_utils"
|
||||
require "graph_utils"
|
||||
local callback_utils = require "callback_utils"
|
||||
|
||||
local when = os.time()
|
||||
local verbose = ntop.verboseTrace()
|
||||
|
|
@ -22,7 +23,6 @@ local verbose = ntop.verboseTrace()
|
|||
-- ########################################################
|
||||
|
||||
local snmp_devices_rrd_creation = ntop.getCache("ntopng.prefs.snmp_devices_rrd_creation")
|
||||
local snmp_to_dump = {}
|
||||
|
||||
if(tostring(snmp_devices_rrd_creation) == "1" and ntop.isEnterprise() == false) then
|
||||
snmp_devices_rrd_creation = "0"
|
||||
|
|
@ -32,28 +32,14 @@ end
|
|||
|
||||
local ifnames = interface.getIfNames()
|
||||
|
||||
-- Save SNMP stats every 5 minutes
|
||||
for _,_ifname in pairs(ifnames) do
|
||||
interface.select(_ifname)
|
||||
ifstats = interface.getStats()
|
||||
|
||||
if(verbose) then print("\n["..__FILE__()..":"..__LINE__().."]===============================\n["..__FILE__()..":"..__LINE__().."] Processing interface " .. _ifname .. " ["..ifstats.id.."]\n") end
|
||||
|
||||
if((ifstats.type ~= "pcap dump") and (ifstats.type ~= "unknown")) then
|
||||
|
||||
-- SNMP devices
|
||||
if(tostring(snmp_devices_rrd_creation) == "1") then
|
||||
snmp_to_dump[#snmp_to_dump + 1] = ifstats.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- ########################################################
|
||||
|
||||
-- Check for SNMP to dump
|
||||
local time_threshold = when - (when % 300) + 300
|
||||
-- This must be placed at the end of the script
|
||||
if(tostring(snmp_devices_rrd_creation) == "1") then
|
||||
-- We must complete within the 5 minutes
|
||||
local time_threshold = when - (when % 300) + 300
|
||||
|
||||
for _, ifid in pairs(snmp_to_dump) do
|
||||
-- We must complete within the minute
|
||||
snmp_update_rrds(ifid, time_threshold, verbose)
|
||||
callback_utils.foreachInterface(ifnames, verbose, function(_ifname, ifstats)
|
||||
snmp_update_rrds(ifstats.id, time_threshold, verbose)
|
||||
end)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue