-- -- (C) 2013-24 - ntop.org -- -- Ntop lua class example -- Set package.path information to be able to require lua module dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path local page_utils = require("page_utils") function printTable(table, key) -- traceError(TRACE_DEBUG,TRACE_CONSOLE, "Extern\n") if (key ~= nil) then print(""..key..":
This class provides to hook to objects that describe flows and hosts and it allows you to access to live monitoring data.
For more information, please read the source code of this file and the doxygen of API Lua.
By default ntopng set the \"ntop_interface\" global variable in lua stack, it is the network interface name where ntopng is running.
Every time when you want use the interface class, in order to refresh the \"ntop_interface\" global variable , please remember to call the method interface.select(ifname)) before to use the interface class.
interface.getIfNames()')
printTable(interface.getIfNames())
print('The interface lua class provide a few methods to get information about the active network interface.
') print('Available examples:
Output:
') print('
ifstats = interface.getStats()')
ifstats = interface.getStats()
for key, value in pairs(ifstats) do
if (type(ifstats[key]) == "table") then
printTable(ifstats[key],key)
elseif (type(ifstats[key]) == "boolean") then
if (value) then value = "true" else value = "false" end
print("The interface lua class provide a few methods to get information about the hosts.
') print('This is an example how to use the interface methods to get storage information. In order to extract all information about an host you can use the method "interface.getHostInfo(host_ip,vlan_id)". Please read the doxygen documentation for more information.
') print('Available examples:
Output:
') print('
hosts = interface.getHosts()')
hosts = interface.getHosts()
if (hosts == nil) then if (debug) then traceError(TRACE_DEBUG,TRACE_CONSOLE, "Host null\n") end end
for key, value in pairs(hosts) do
if (hosts[key]["ip"] ~= nil) then
host_info = hosts[key]["ip"]
else
host_info = hosts[key]["mac"]
end
print("hosts = interface.getHostsInfo()')
end
hosts = interface.getHostsInfo()
if (hosts == nil) then if (debug) then traceError(TRACE_DEBUG,TRACE_CONSOLE, "Host null\n") end end
for key, value in pairs(hosts) do
random_host = key
if (hostinfotype == "more_one_host") then break end
print("hosts = interface.getHostInfo('..random_host..')')
print("This is an example how to use the interface methods to export information in json format.
') print('Show host:') if(showjson ~= nil) then print('Available hosts:
hosts_json = interface.getHosts()')
print('The interface lua class provide a few methods to get information about the flows.
') print('This is an example how to use the interface methods to get flows information.
') print('Available examples:
Output:
') if (flowtype == "description" ) then print('
flows_stats = interface.getFlowsInfo()\nprintTable(flows_stats)')
flows_stats = interface.getFlowsInfo()
printTable(flows_stats)
end
if (flowtype == "peers" ) then
print('flows_stats = interface.getFlowPeers()\nprintTable(flows_peers,"Peers")')
flows_peers = interface.getFlowPeers()
printTable(flows_peers,"Peers")
end
print('')
print('