-- -- (C) 2013 - ntop.org -- -- debug lua 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 require "lua_utils" -- 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. sendHTTPContentTypeHeader('text/html') ntop.dumpFile(dirs.installdir .. "/httpdocs/inc/header.inc") dofile(dirs.installdir .. "/scripts/lua/inc/menu.lua") print('debug Lua example') print('') print('

How to debug your lua scripts

') print('

How to print debug information

') print('

ntopng Lua library comes with a standard trace event features:

') print('

There are five type of event:

') print('') print('

Use the following function to modify the current trace level.

') print('
setTraceLevel(p_trace_level)
resetTraceLevel()

') print('

There are two type of trace:

') print('') print('

Default: Only the TRACE_ERROR is printed.


') print('

There are two way to print some debug information:

') print('') if(_GET["trace"] == "console") then print('

Code:

') print('

traceError(TRACE_DEBUG,TRACE_CONSOLE, "Trace: ".._GET["trace"])
') end if(_GET["trace"] == "web") then print('

Code:

') print('

traceError(TRACE_DEBUG,TRACE_WEB, "Trace: ".._GET["trace"])
') end if(_GET["trace"] == "console") then print('

Output:

') print('

') traceError(TRACE_ERROR,TRACE_CONSOLE, "Trace: ".._GET["trace"]) end if(_GET["trace"] == "web") then print('

Output:

') print('

') end print('

Output format:

') print('
#date #time [#calling_function] [#filename:#currentline] #trace_level: #message
') print('

NB: #calling_function will be show only if it is different from #filename:#currentline

') print('

How to read and print the _GET variables

') print('

Any lua scripts can be executed by passing one or more parameters. The simple way to get an input variable is "variable_name = _GET["variable_name"]".

Try with this: /lua/examples/debug.lua?host=192.168.1.10&myparam=myparam&var=123456

') -- Print _GET variable print('

') for key, value in pairs(_GET) do print(key.."="..value.."
") end -- printGETParameters(_GET) print('

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