Script Example: Additional Information About Connected Node

Revision as of 16:18, 5 October 2020 by Phil (talk | contribs)

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;