1.6. Misc API

Miscellaneous utility functions.

Functions

function getDirs()

Get ntopng directory information.

Return
table (installdir, workingdir, scriptdir, httpdocsdir, callbacksdir).

function getInfo()

Get ntopng status information.

Return
ntopng information.

function getUptime()

Get seconds from ntopng startup.

Return
ntopng uptime in seconds.

function getHttpPrefix()

Get the ntopng HTTP prefix.

The HTTP prefix is the initial part of the ntopng URL, which consists of HTTP host, port and optionally a user-defined prefix. Any URL within ntopng should include this prefix.

Return
the HTTP prefix.

function getRandomCSRFValue()

Generate a random value to prevent CSRF and XSRF attacks.

Return
the token value.
Note
Any HTTP POST request must contain a “csrf” field with a token value generated by a call to this function.

function isShuttingDown()

Check if ntopng is shuttind down.

Return
true if is shutting down, false otherwise.

function getLocalNetworks()

Get the ntopng local networks list.

Return
table (network_address -> “”).

function addLocalNetwork(string network_cidr)

Add a network to the ntopng local networks list.

Parameters
  • network_cidr: the network to add in CIDR format.

function setMacDeviceType(string mac, int device_type, bool overwrite)

Set L2 device type.

Parameters
  • mac: device MAC address
  • device_type: the device type id to set.
  • overwrite: if true, the existing device type, if any, will be overwritten.

function reloadHostPools()

Reload Host Pool membership information after changes from Lua.

function getNetworkNameById(int network_id)

Retrieves a ntopng local network by its id.

Return
the network address on success, an empty string otherwise.
Parameters
  • network_id: the local network id.

function getNetworkIdByName(string network_cidr)

Retrieves a ntopng local network id by its name.

Return
the network id on success, -1 otherwise.
Parameters
  • network_cidr: the local network cidr.

function getHostInformation()

Get information about the currest host.

Return
table (ip, instance_name).

function systemHostStat()

Get ntopng host statistics.

Return
table (cpu_load, cpu_idle, mem_total, mem_free, mem_buffers, mem_cached, mem_shmem. mem_used).

function syslog(string message, int syslog_severity)

Send a message to syslog.

Parameters
  • message: the message to send.
  • syslog_severity: an integer representing the standard syslog severity as per RFC 5424. LOG_INFO is used when severity is not specified.

function setLoggingLevel(string level)

Set ntopng logging level.

Parameters
  • level: one of “trace”, “debug”, “info”, “normal”, “warning”, “error”.

function traceEvent(string msg)

Log a message.

Note
Message will be logged with “normal” level.
Parameters
  • msg: the message to log.

function verboseTrace()

Check if verbose trace is enabled.

Return
true if verborse trace is enabled, false otherwise.

function gettimemsec()

Get the current time in milliseconds.

Return
the current milliseconds time.

function getticks()

Get the current CPU ticks.

Return
the current CPU ticks.

function gettickspersec()

Get the CPU ticks per second.

Return
the CPU ticks per second. @notes this can be used with ntop.getticks() deltas to calculate time spent.

function isLoginDisabled()

Check if the ntopng GUI login is disable.

Check if login to the ntopng GUI is disabled.

Return
true if login is disabled, false otherwise.
Return
true if the login is disabled, false otherwise.

function hasVLANs()

Check if ntopng has seen any VLAN tagged traffic.

Return
true if VLAN traffic has been seen, false otherwise.

function hasGeoIP()

Check if ntopng has Geo IP support available.

Return
true if Geo IP is available, false otherwise.

function isWindows()

Check if the operating system is Windows.

Return
true if Windows, false otherwise.

function msleep(int duration)

Sleep with milliseconds accuracy.

Parameters
  • duration: in milliseconds.

function getMacManufacturer(string mac)

Get the manufacturer name from mac address.

Return
table(short, extended) on success, nil otherwise.
Parameters
  • mac: the MAC address.

function md5(string s)

Compute the MD5 of the provided string.

Return
the computed string MD5.
Parameters
  • s: the string to hash

function exec_sql_query(string query)

Execute a MySQL query and get the result.

Return
the query result
Note
This only works when ntopng is configured with “-F=mysql”
Parameters
  • query: the query to execute

function resetStats()

Resets multiple stats in ntopng, which include the hosts and mac traffic counters.

Note
This is the function called when “Midnight Stats Reset” is enabled from the GUI.

function isPro()

Check if ntopng has the pro features.

Return
true if the pro features are available, false otherwise.

function isEnterpriseM()

Check if ntopng has the Enterprise M features.

Return
true if the Enterprise M features are available, false otherwise.

function isEnterpriseL()

Check if ntopng has the Enterprise L features.

Return
true if the Enterprise L features are available, false otherwise.

function isPackage()

Check if ntopng is running as a systemd service.

Return
true if running as service, false otherwise.

function getStartupEpoch()

Get the startup Unix epoch of ntopng.

Return
the startup epoch

function serviceRestart()

Restart ntopng (when running as a service)

Note
This only works when ntop.isPackage() returns true

function matchCustomCategory(string host)

Match the given host into an nDPI category.

Return
value the nDPI category ID on success, nil otherwise.
Parameters
  • host: the host to match

function getTLSVersionName(int tls_version)

Converts a TLS version ID to the corresponding TLS version name.

Return
the TLS version name
Parameters
  • tls_version: the TLS version ID

function bitmapIsSet(int bitmap, int bit)

Check if the given bit is set into the bitmap.

Return
true if the bit is set, false otherwise
Parameters
  • bitmap: the numeric bitmap
  • bit: the bit index to check

function bitmapSet(int bitmap, int bit)

Set a bit into the bitmap.

Return
true if the bitmap has changed, false otherwise
Parameters
  • bitmap: the numeric bitmap
  • bit: the bit index to set

function bitmapClear(int bitmap, int bit)

Clear a bit into the bitmap.

Return
true if the bitmap has changed, false otherwise
Parameters
  • bitmap: the numeric bitmap
  • bit: the bit index to clear

function setnDPIProtoCategory(int proto, int category)

Associate the protocol to the specified nDPI category.

Parameters
  • proto: the protocol id
  • category: the category id

function getnDPIProtoCategory(int proto)

Get the nDPI category currently associated to the protocol.

Return
a table (id->category_id, name->category_name) on success, nil otherwise.
Note
the protocol to category mapping can be changed dynamically via setnDPICategory
Parameters
  • proto: the protocol id to query the category for

function ptreeClear()

Initialize an empty patricia tree into this vm.

function ptreeInsert(string addr, uint16_t value)

Insert an address into the vm patricia tree.

Return
true on success, false otherwise
Parameters
  • addr: the address to insert
  • value: a numeric value to associate to the node (except 65535)

function ptreeMatch(string addr)

Match a given address with the vm patricia tree.

Return
the numeric value associated with the node on success, nil otherwise
Parameters
  • addr: the address to match

function isDeadlineApproaching()

Check if the current periodic script deadline is near.

Return
true if the deadline is approaching, false otherwise
Note
this can be used by a periodic script to detect if it should hurry up to finish its work

function getDeadline()

Get the current periodic script deadline.

Return
the periodic script deadline on success, 0 otherwise

function speedtest()

Check Internet speed using speedtest.net services.

Return
JSON that includes the speedtest report, or NULL in case of error