diff --git a/scripts/lua/if_stats.lua b/scripts/lua/if_stats.lua
index f4989a9306..6f4572a680 100644
--- a/scripts/lua/if_stats.lua
+++ b/scripts/lua/if_stats.lua
@@ -102,7 +102,7 @@ if ifstats.stats and ifstats.stats_since_reset then
end
local ext_interfaces = {}
-if recording_utils.isAvailable() and not interface.isPacketInterface() then
+if recording_utils.isAvailable() and recording_utils.isSupportedZMQInterface(ifid) then
ext_interfaces = recording_utils.getExtInterfaces()
end
@@ -178,7 +178,7 @@ if (isAdministrator()) then
end
ntop.setCache('ntopng.prefs.ifid_'..ifstats.id..'.traffic_recording.disk_space', tostring(disk_space))
- if not interface.isPacketInterface() then
+ if recording_utils.isSupportedZMQInterface(ifid) then
local ext_ifname
if not isEmptyString(_POST["custom_name"]) then
-- param check
@@ -197,8 +197,9 @@ if (isAdministrator()) then
if record_traffic then
local config = {}
config.max_disk_space = disk_space
- if not interface.isPacketInterface() then
- config.zmq_endpoint = "tcp://127.0.0.1:5556" -- TODO
+ if recording_utils.isSupportedZMQInterface(ifid) then
+ config.zmq_endpoint = recording_utils.getZMQProbeAddr(ifid)
+ recording_utils.stop(ifstats.id) -- stop before starting as the interface can be changed
end
if recording_utils.createConfig(ifstats.id, config) then
recording_utils.restart(ifstats.id)
@@ -295,7 +296,9 @@ if is_packetdump_enabled then
end
end
-if recording_utils.isAvailable() and (interface.isPacketInterface() or not table.empty(ext_interfaces)) then
+if recording_utils.isAvailable() and (interface.isPacketInterface() or
+ (recording_utils.isSupportedZMQInterface(ifid) and not table.empty(ext_interfaces))) then
+
if(page == "traffic_recording") then
print("
")
else
@@ -1198,7 +1201,7 @@ elseif(page == "traffic_recording") then
]]
- if not interface.isPacketInterface() then
+ if recording_utils.isSupportedZMQInterface(ifid) then
local ext_ifname = ntop.getCache('ntopng.prefs.ifid_'..ifid..'.traffic_recording.ext_ifname')
if isEmptyString(ext_ifname) then
for ifname,_ in pairs(ext_interfaces) do
diff --git a/scripts/lua/modules/recording_utils.lua b/scripts/lua/modules/recording_utils.lua
index d4bdc75da0..8ff4b392a2 100644
--- a/scripts/lua/modules/recording_utils.lua
+++ b/scripts/lua/modules/recording_utils.lua
@@ -29,9 +29,55 @@ local function executeWithOuput(c)
return s
end
+function recording_utils.isSupportedZMQInterface(ifid)
+ local ifname = getInterfaceName(ifid)
+ -- localhost in collectore mode is accepted
+ local zmq_prefix_any = "tcp://*"
+ local zmq_prefix_loh = "tcp://127.0.0.1"
+ if (ifname:sub(1, #zmq_prefix_any) == zmq_prefix_any or
+ ifname:sub(1, #zmq_prefix_loh) == zmq_prefix_loh) and
+ ifname:sub(-1) == "c" then
+ return true
+ end
+ return false
+end
+
+local function getZMQPort(addr)
+ local values = split(addr, ':')
+ if #values == 3 then
+ local port = split(values[3], 'c')
+ return port[1]
+ end
+ return nil
+end
+
+function recording_utils.getZMQProbeAddr(ifid)
+ local port = getZMQPort(getInterfaceName(ifid))
+ if port == nil then
+ port = "5556"
+ end
+ return "tcp://127.0.0.1:"..port
+end
+
+function recording_utils.isSupportedZMQInterface(ifid)
+ local ifname = getInterfaceName(ifid)
+ local zmq_prefix = "tcp://"
+ if ifname:sub(1, #zmq_prefix) == zmq_prefix and ifname:sub(-1) == "c" then
+ return true
+ end
+ return false
+end
+
+function recording_utils.isSupportedInterface(ifid)
+ if interface.isPacketInterface() or
+ recording_utils.isSupportedZMQInterface(ifid) then
+ return true
+ end
+ return false
+end
+
function recording_utils.isAvailable()
- if isAdministrator() and
- -- interface.isPacketInterface() and
+ if isAdministrator() and
not ntop.isWindows() and
not ntop.isnEdge() and
ntop.exists(ntopng_config_tool) and
@@ -298,6 +344,7 @@ function recording_utils.createConfig(ifid, params)
end
if config.zmq_endpoint ~= nil then
f:write("--zmq="..config.zmq_endpoint.."\n")
+ f:write("--zmq-probe-mode\n")
f:write("--zmq-export-flows\n")
end
-- Ignored by systemd, required by init.d