Configuration poll hook is new feature of NetXMS 1.2.3
How it use?
1) create script in script library with Hook::ConfigurationPoll name.
2) write your script.
This script will be executed for node after each configuration poll
simple script example
//rename node after configuration poll to snmp sysLocation
//if sysLocation is null then rename to node ip address
//also 3 custom attributes will be setted
// you can use this attributes in events with %{attribute_name} macros
//uncomment trace line and run netxmsd with -D1 param for logging
sub main()
{
if ($node->isSNMP)
{
//trace(1,"hook executed for ".$node->ipAddr);
transport = CreateSNMPTransport($node);
if (transport == null)
{
//trace(1,"snmp transport error on ".$node->ipAddr);
return -1;
}
location = SNMPGetValue(transport, ".1.3.6.1.2.1.1.6.0"); // sysLocation
sysname = SNMPGetValue(transport, ".1.3.6.1.2.1.1.5.0"); // sysname
uptime = SNMPGetValue(transport, ".1.3.6.1.2.1.1.3.0"); // uptime
//trace(1,"[".location."], [".sysname."], [".uptime."]");
if (location != null && location !="" && location!=" ")
{
//trace(1,"attr location changed to ".location);
RenameObject($node, location);
}
else
{
//trace(1,"error in location block");
RenameObject($node, $node->ipAddr); //change name to node ip address
}
if (sysname != null && sysname !="" && sysname !=" ")
{
SetCustomAttribute($node, "sysname", sysname); //set custom attribute for node snmp sysName
//trace(1,"attr sysname changed to ".location);
}
else
{
//trace(1,"error in sysname block");
}
if (uptime != null)
{
SetCustomAttribute($node, "uptime", SecondsToUptime(uptime/100)); //set custom attribute uptime for node
//trace(1,"attr uptime changed to ".SecondsToUptime(uptime/100));
}
else
{
//trace(1,"error in uptime block");
}
//trace(1,"end execution");
SetCustomAttribute($node, "last_update",localtime(time())->mday.".".localtime(time())->mon.".".localtime(time())->year.", ".localtime(time())->hour.":".localtime(time())->min.":".localtime(time())->sec);
}
}