1.6. Misc API
Miscellaneous utility functions.
Functions
-
function getDirs()
Get ntopng directory information.
- Returns:
table (installdir, workingdir, scriptdir, httpdocsdir, callbacksdir).
-
function getInfo()
Get ntopng status information.
- Returns:
ntopng information.
-
function getUptime()
Get seconds from ntopng startup.
- Returns:
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.
- Returns:
the HTTP prefix.
-
function getRandomCSRFValue()
Generate a random value to prevent CSRF and XSRF attacks.
Note
Any HTTP POST request must contain a “csrf” field with a token value generated by a call to this function.
- Returns:
the token value.
-
function isShuttingDown()
Check if ntopng is shuttind down.
- Returns:
true if is shutting down, false otherwise.
-
function getLocalNetworks()
Get the ntopng local networks list.
- Returns:
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.
- Parameters:
network_id – the local network id.
- Returns:
the network address on success, an empty string otherwise.
-
function getNetworkIdByName(string network_cidr)
Retrieves a ntopng local network id by its name.
- Parameters:
network_cidr – the local network cidr.
- Returns:
the network id on success, -1 otherwise.
-
function getHostInformation()
Get information about the currest host.
- Returns:
table (ip, instance_name).
-
function systemHostStat()
Get ntopng host statistics.
- Returns:
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.
- Returns:
true if verborse trace is enabled, false otherwise.
-
function gettimemsec()
Get the current time in milliseconds.
- Returns:
the current milliseconds time.
-
function getticks()
Get the current CPU ticks.
- Returns:
the current CPU ticks.
-
function gettickspersec()
Get the CPU ticks per second.
- Returns:
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.
- Returns:
true if login is disabled, false otherwise.
- Returns:
true if the login is disabled, false otherwise.
-
function hasVLANs()
Check if ntopng has seen any VLAN tagged traffic.
- Returns:
true if VLAN traffic has been seen, false otherwise.
-
function hasGeoIP()
Check if ntopng has Geo IP support available.
- Returns:
true if Geo IP is available, false otherwise.
-
function isWindows()
Check if the operating system is Windows.
- Returns:
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.
- Parameters:
mac – the MAC address.
- Returns:
table(short, extended) on success, nil otherwise.
-
function md5(string s)
Compute the MD5 of the provided string.
- Parameters:
s – the string to hash
- Returns:
the computed string MD5.
-
function exec_sql_query(string query)
Execute a historical query and get the result.
Note
This only works when ntopng is configured with “-F=clickhouse”
- Parameters:
query – the query to execute
- Returns:
the query result
-
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.
- Returns:
true if the pro features are available, false otherwise.
-
function isEnterpriseM()
Check if ntopng has the Enterprise M features.
- Returns:
true if the Enterprise M features are available, false otherwise.
-
function isEnterpriseL()
Check if ntopng has the Enterprise L features.
- Returns:
true if the Enterprise L features are available, false otherwise.
-
function isPackage()
Check if ntopng is running as a systemd service.
- Returns:
true if running as service, false otherwise.
-
function getStartupEpoch()
Get the startup Unix epoch of ntopng.
- Returns:
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.
- Parameters:
host – the host to match
- Returns:
value the nDPI category ID on success, nil otherwise.
-
function getTLSVersionName(int tls_version)
Converts a TLS version ID to the corresponding TLS version name.
- Parameters:
tls_version – the TLS version ID
- Returns:
the TLS version name
-
function bitmapIsSet(int bitmap, int bit)
Check if the given bit is set into the bitmap.
- Parameters:
bitmap – the numeric bitmap
bit – the bit index to check
- Returns:
true if the bit is set, false otherwise
-
function bitmapSet(int bitmap, int bit)
Set a bit into the bitmap.
- Parameters:
bitmap – the numeric bitmap
bit – the bit index to set
- Returns:
true if the bitmap has changed, false otherwise
-
function bitmapClear(int bitmap, int bit)
Clear a bit into the bitmap.
- Parameters:
bitmap – the numeric bitmap
bit – the bit index to clear
- Returns:
true if the bitmap has changed, false otherwise
-
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.
Note
the protocol to category mapping can be changed dynamically via setnDPICategory
- Parameters:
proto – the protocol id to query the category for
- Returns:
a table (id->category_id, name->category_name) on success, nil otherwise.
-
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.
- Parameters:
addr – the address to insert
value – a numeric value to associate to the node (except 65535)
- Returns:
true on success, false otherwise
-
function ptreeMatch(string addr)
Match a given address with the vm patricia tree.
- Parameters:
addr – the address to match
- Returns:
the numeric value associated with the node on success, nil otherwise
-
function isDeadlineApproaching()
Check if the current periodic script deadline is near.
Note
this can be used by a periodic script to detect if it should hurry up to finish its work
- Returns:
true if the deadline is approaching, false otherwise
-
function getDeadline()
Get the current periodic script deadline.
- Returns:
the periodic script deadline on success, 0 otherwise
-
function speedtest()
Check Internet speed using speedtest.net services.
- Returns:
JSON that includes the speedtest report, or NULL in case of error