Script Execution Contexts
NXSL scripts run in different contexts within the NetXMS server. Each context provides specific predefined variables and expects particular return value semantics. This page documents all available script execution contexts.
Common Variables
Most server-side script contexts automatically receive these variables through the SetupServerScriptVM() infrastructure:
| Variable | Type | Description |
|---|---|---|
|
Current object context (node, container, etc.) |
|
|
Current node (set only when |
|
|
Current network map (set only when |
|
|
Boolean |
|
Additional variables are set depending on the specific context, as documented below.
Transformation Script
Modifies a collected DCI value before it is stored in the database. Configured in DCI properties under Transformation.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
|
Return value |
Transformed value to store. Returning |
// Convert bytes to megabytes
if ($1 == null)
return DataCollection::ERROR; // discard this sample
return $1 / 1048576;
Threshold Script
Custom threshold condition on a DCI. Evaluated each time a new value is collected. Configured in DCI threshold properties.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
|
Return value |
|
// Activate if value exceeds 90 and node is not in maintenance
$1 > 90 and not $node.isInMaintenanceMode
Script DCI
Computes a DCI value using an NXSL script instead of collecting from an external source. Configured by setting the DCI origin to Script and specifying the script name in DCI properties.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
Arguments configured in DCI properties as positional arguments |
Return value |
The computed DCI value to store |
// Count the number of child nodes with agent
count = 0;
for (child : $node.children)
{
if (classof(child) == "Node" && child.isAgent)
count++;
}
return count;
Instance Discovery Filter
Filters instances found during instance discovery polling. Runs once per discovered instance. Configured in DCI instance discovery properties.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
|
Return value |
|
// Only monitor physical network interfaces (exclude loopback and virtual)
not ($1 ~= "^(lo|veth|docker|br-)") and not ($2 ~= "Loopback")
EPP Filter Script
Determines whether an Event Processing Policy rule matches the current event. Configured in EPP rule properties under Filter.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
Event parameters as positional arguments ( |
Return value |
|
// Match only events from nodes with NetXMS agent
$node.isAgent
EPP Action Script
Executes custom logic when an EPP rule matches. Configured as a Script action in EPP rule actions.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
Event parameters as positional arguments ( |
Return value |
Not used (script runs for side effects) |
// Set custom attribute on node when specific event occurs
$node.setCustomAttribute("lastIncident", $event.message);
Action Script
Named server action of type NXSL Script. Executed from EPP rule actions (including their delayed or scheduled re-execution). Configured in Configuration → Actions.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
Action parameters as positional arguments |
Return value |
Not used |
Auto-Bind / Auto-Apply Script
Determines whether an object should be automatically bound to a container or have a template applied. Configured on containers (auto-bind) and templates (auto-apply).
A single filter script is evaluated per candidate object; whether matching objects are bound and non-matching objects are unbound is controlled by the apply/bind automatically and remove/unbind automatically flags in the owning object’s properties, not by a second script. Business services additionally have a separate DCI auto-bind filter that is evaluated per DCI (with $dci set).
| Item | Details |
|---|---|
Predefined variables |
|
Return value |
|
// Auto-apply template to all Linux nodes with agent
$node.platformName ~= "^linux" and $node.isAgent
Condition Script
Evaluated periodically for Condition objects. Determines whether the condition is active. Configured in Condition object properties.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
Values of the configured DCIs as |
Return value |
|
Generates activation event when transitioning from inactive to active, and deactivation event for the reverse.
Object Query Script
Used for ad-hoc or predefined object queries. Executed via the management console object query feature or via the API.
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
None — input fields are passed in the |
Return value |
|
Object attributes can be referenced without qualification (e.g. type and state instead of $object.type and $object.state). Object class constants (NODE, CONTAINER, etc.) are available only in this context.
// Find all nodes with agent version older than 5.0
classof($object) == "Node" and $object.isAgent and $object.agentVersion < "5.0"
Scheduled Task Script
Runs at scheduled times. Created via Configuration → Scheduled Tasks. The script name and arguments are specified in the format scriptname(arg1, arg2, …).
| Item | Details |
|---|---|
Predefined variables |
|
Script arguments |
Arguments from the task definition as positional arguments |
Return value |
Not used |
Discovery Filter Script
Determines whether a newly discovered node should be added to the system. Since version 6.1 this filter is implemented by the Hook::DiscoveryFilter hook script (the separate filter script setting in Configuration → Network Discovery was migrated to the hook). See Hook::DiscoveryFilter for predefined variables, return value semantics, and examples.
DCI Summary Table Filter Script
Filters which nodes are included in a DCI summary table. Configured in summary table properties.
| Item | Details |
|---|---|
Predefined variables |
|
Return value |
|
Network Map Link Styling Script
Customizes the appearance of links on network maps. Configured in network map link properties.
| Item | Details |
|---|---|
Predefined variables |
|
Return value |
Not used (script modifies |
The link color provider script additionally receives $endpoint1 and $endpoint2 (the objects on either end of the link). These variables are not available in the link styling script.
|
// Color link red if either connected object has Major or Critical status
obj1 = $link.object1;
obj2 = $link.object2;
if ((obj1 != null && obj1.status >= 3) || (obj2 != null && obj2.status >= 3))
$link.setColorConfig(MapLinkColorSource::CustomColor, "red");
Business Service Check Script
Evaluates the status of a business service check of type Script. Configured in business service check properties.
| Item | Details |
|---|---|
Predefined variables |
|
Return value |
|
Asset Attribute Autofill Script
Automatically populates asset attributes during configuration polls. Configured in asset attribute definitions.
| Item | Details |
|---|---|
Predefined variables |
|
Return value |
Value to set for the asset attribute, or |
// Auto-fill OS name from node's platform
return $node?.platformName;
SNMP Trap Transformation Script
Provides script access to SNMP trap data during trap-to-event mapping. The script VM is used to expand %[script] macros in trap mapping parameters — the macro is replaced with the value returned by the referenced script. Configured in SNMP trap mapping configuration.
| Item | Details |
|---|---|
Predefined variables |
|
Return value |
Value returned by a script referenced in a |
Agent Configuration Filter Script
Determines which agent configuration policy to apply when an agent requests its configuration. Used in agent configuration matching.
| Item | Details |
|---|---|
Predefined variables |
None |
Script arguments |
|
Return value |
|
Client Script Execution
Scripts executed from the management console via right-click → Execute Script or from the Script Editor. Runs on the server with the selected object as context.
| Item | Details |
|---|---|
Predefined variables |
|
Return value |
Displayed to the user in the script output window |
Hook Scripts
Hook scripts have names prefixed with Hook:: in the Script Library. They are called automatically at specific server events. Each hook receives context-specific predefined variables and some hooks use return values to accept or reject operations.
See Hook Scripts for complete documentation of all NetXMS hook scripts, including predefined variables, return value semantics, and examples.
See Also
-
Getting Started — running your first script
-
Script Security — trusted node validation
-
Working with NetXMS — practical how-to recipes
-
Best Practices — performance, error handling, and maintainability