-- -- (C) 2013 - 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 function printTable(table,key) -- traceError(TRACE_DEBUG,TRACE_CONSOLE, "Extern\n") if (key ~= nil) then print(""..key..":") end require "lua_utils" sendHTTPContentTypeHeader('text/html') ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc") dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") interface.select(ifname) local debug = true -- setTraceLevel(TRACE_DEBUG) -- Debug mode host_ip = _GET["host"] hostinfotype = _GET["hostinfotype"] aggregated = _GET["aggregated"] interfacetype = _GET["interfacetype"] showjson = _GET["showjson"] flowtype = _GET["flowtype"] aggregated = _GET["aggregated"] protocol = _GET["protocol"] -- Here you can choose the type of your HTTP message {'text/html','application/json',...}. There are two main function that you can use: -- function sendHTTPHeaderIfName(mime, ifname, maxage) -- function sendHTTPHeader(mime) -- For more information please read the scripts/lua/modules/lua_utils.lua file. -- Test key 2 host and host 2 key -- hosts_stats = interface.getHostsInfo() -- for key, value in pairs(hosts_stats) do -- print ("key:"..key.."
") -- info = hostkey2hostinfo(key) -- print ("Host: "..info["host"].."@"..info["vlan"].."
") -- host = interface.getHostInfo(key) -- print ("key:"..key.."
") -- if(host == nil) then -- print ("Null
") -- else -- print ("Found
") -- end -- end print('

Examples of interface lua class

') print('

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.

') print('

Generic information of Network interface

') print('

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.

') print('') print('

Available Interfaces

') print('
interface.getIfNames()
') printTable(interface.getIfNames()) print('

Switch network interface

') print('

In order to switch the network interface where ntopng is running, you need to use the method setActiveInterfaceId(id), for more information please read the documentation and if you are looking for a complete and correctly example how to switch interface and active a new session, please read the source code of the set_active_interface.lua script.

') print('

Interface information

') print('

The interface lua class provide a few methods to get information about the active network interface.

') print('

Get interface statistics information

') print('

Available examples:

') print('

Output:

') print('

') print('

Host information

') print('

The interface lua class provide a few methods to get information about the hosts.

') print('

Get hosts information

') 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:

') print('

Output:

') print('

') random_host = nil print('

Export information in JSON format

') 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:

') end print('

Flow information

') print('

The interface lua class provide a few methods to get information about the flows.

') print('

Get flows information

') print('

This is an example how to use the interface methods to get flows information.

') print('

Available examples:

') print('

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('

Aggregated Hosts information

') print('

Available protocol:

') print('

Output:

') print('

') print('

TDB

') print('

') dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")