Server Hooks
NetXMS provides a hook mechanism that allows you to execute custom NXSL scripts in response to specific server events. Hooks are a powerful way to extend server behavior without modifying core functionality.
How Hooks Work
A hook is an NXSL script that the server executes automatically when a specific event occurs.
Hooks are stored in the Script Library with names following the Hook:: naming convention.
At each hook point the server looks up the script by its exact name in the Script Library and executes it if found — no registration or activation step is needed, and renaming or deleting the script immediately disables the hook.
Available Hook Points
| Hook | Parameters | Description | Return value |
|---|---|---|---|
|
|
Executed at the end of status poll |
none |
|
|
Executed during configuration poll, after capability and interface discovery but before automatic template and container binding (for access points, at the start of the poll) |
none |
|
|
Executed after instance discovery poll |
none |
|
|
Executed at the end of topology poll |
none |
|
|
Executed at the end of discovery poll |
none |
|
|
Executed when a new interface is created automatically (not for manually created interfaces) |
|
|
|
Executed at the end of interface update |
none |
|
|
Executed on subnet creation |
|
|
|
Executed during network discovery before node creation |
Only an explicit |
|
|
Executed as an additional filter for each node found by network discovery |
|
|
|
Executed after any object has been created |
none |
|
|
Executed before an object is deleted |
none |
|
|
Executed for each event before EPP processing |
none |
|
|
Executed asynchronously when an alarm changes state |
none |
|
|
Executed when an unbound agent tunnel is established |
none |
|
|
Executed when a bound agent tunnel connects |
none |
|
|
Executed for each LDAP record during synchronization |
Only an explicit |
|
|
Executed prior to user login |
Only an explicit |
|
|
Determines whether a node should be registered for device configuration backup. Default script: |
|
|
Every object hook receives |
Hook::AcceptNewNode Variables
| Variable | Description |
|---|---|
|
Primary IP address of the new node ( |
|
Primary IP address as a string |
|
Network mask length in bits (integer) |
|
MAC address of the new node ( |
|
MAC address as a string |
|
Zone UIN of the new node |
Configuring Hooks
-
Open the management client
-
Navigate to Configuration > Script Library
-
Create a new script with the exact hook name (e.g.,
Hook::ConfigurationPoll) -
Write the hook logic in NXSL
The script takes effect immediately — the server looks it up by name each time the hook point is reached.
Hook Examples
Auto-Accept Nodes from Specific Subnets
This Hook::AcceptNewNode script accepts nodes only from specific IP ranges:
if ($ipAddr like "10.*" || $ipAddr like "172.16.*" || $ipAddr like "172.17.*")
return true;
return false;
Filter Interfaces During Discovery
This Hook::CreateInterface script prevents creation of loopback and tunnel interfaces (the interface object is passed as $1):
if ($1.name like "lo*" || $1.name like "tun*" || $1.name like "veth*")
return false;
return true;
Auto-Bind Agent Tunnels
This Hook::OpenUnboundTunnel script automatically binds agent tunnels based on the agent’s system name:
hostname = $tunnel.systemName;
node = FindNodeBySysName(hostname);
if (node != null) {
$tunnel.bind(node);
}
Custom Configuration Poll Logic
This Hook::ConfigurationPoll script adds custom attributes during configuration poll:
osName = $node.sysDescription;
if (osName like "*Ubuntu*") {
$node.setCustomAttribute("os_family", "debian");
} else if (osName like "*CentOS*" || osName like "*Red Hat*") {
$node.setCustomAttribute("os_family", "rhel");
}
Debugging Hooks
For where and how to change server debug levels, see Enabling Debug Logging.
To debug hook execution, enable debug logging for the relevant tags:
debug nxsl.hooks 7
debug obj.lifecycle 7
debug scripts 7
Script runtime errors are logged with the scripts tag.
Execution of the object hooks (status, configuration, instance, topology, and discovery polls; object creation and deletion) is logged with the obj.lifecycle tag.
The nxsl.hooks tag covers only Hook::AcceptNewNode and Hook::DiscoveryFilter; other hooks log load failures under their subsystem tags (for example poll.conf, node.iface, alarm, ldap, agent.tunnel).
You can also use the trace() function within hook scripts to output debug information:
trace(1, "Hook::ConfigurationPoll called for " .. $node.name);
| Long-running hook scripts can affect server performance. Keep hook logic efficient and avoid blocking operations. |
See NXSL Reference for the complete scripting language documentation.