Difference between revisions of "Script Example: Additional Information About Connected Node"

From NetXMS Wiki
Jump to navigation Jump to search
Line 2: Line 2:
{| style="border-spacing: 20px; border: 20px solid red;"
{| style="border-spacing: 20px; border: 20px solid red;"
|
|
'''WARNING''': This page is no longer updated. Please visit '''[https://www.netxms.org/documentation/nxsl-latest/ NetXMS Scripting Language]''' for current version of the documentation.  
'''WARNING''': This page is no longer updated. Please visit '''[https://www.netxms.org/documentation/nxsl-latest/#_examples_2 NetXMS Script examples]''' for current version of the documentation.  
|}
|}





Revision as of 16:18, 5 October 2020

WARNING: This page is no longer updated. Please visit NetXMS Script examples for current version of the documentation.



Requirements

Add information about name, IP address, and MAC address about connected node to notification about switch port being down.


Solution

Use named event attribute additionalInfo to pass information into e-mail body (using %<additionalInfo> macro). To populate this attribute the following script can be used:

// only for interface up and down events
if (($event->name != "SYS_IF_DOWN") && ($event->name != "SYS_IF_UP"))
	return true;
	
// get interface object from interface index
iface = GetInterfaceObject($node, $5);
if (iface == null)
	return true;

// get peer node (node connected to this interface) object
peer = iface->peerNode;
if (peer == null)
	return true;
	
// get peer interface object (needed to obtain MAC address)
peerIface = iface->peerInterface;
if (peerIface != null)
{
	macAddr = peerIface->macAddr;
}
else
{
	macAddr = "<MAC unknown>";
}

// set event's named parameter	
SetEventParameter($event, "additionalInfo",
	"Peer: " . peer->name . " " . peer->ipAddr . " " . macAddr);

return true;