Auto bind and auto apply script

Started by testos, May 13, 2009, 12:30:44 PM

Previous topic - Next topic

testos

Hello again.

I am trying to prove automatic template application and automatic node binding to containers based on filters (node name begins with "FG100A") and do not work none of these filters:

Quotesub main()
{
return left($1,6) = "FG100A" ? 1 : 0;
}

Quotesub main()
{
return left($node,6) = "FG100A" ? 1 : 0;
}

Quotesub main()
{
return left($node,6) = "FG100A" ? $node : 0;
}


What is wrong?
Thanks in advanced

Victor Kirhenshtein

Hello!

You should use == for compare operation. = is an assignment operation.

For example:


a = 1


means "assign value 1 to variable a"

and


a == 1


means "test if variable's value is 1".

Second error is that $node variable is an object, and you need to compare it's name attribute. To access it, use


$node->name


And compare always returns 1 or 0, so you can omit ? 1 : 0 part and simply use


left($node->name,6) == "FG100A"


So, correct script will looks like


sub main()
{
   return left($node->name, 6) == "FG100A";
}



Best regards,
Victor

testos

#2
Ok. Thanks for the explanation.  ;)
Now it complete auto bind/apply. But it takes a few minutes. Is there any parameter in server configuration that I can setting to make it faster?

Quote...$node variable is an object, and you need to compare it's name attribute.

What other attributes for $node object? Some other usefull objects->attributes for auto bind/apply operations?


Best regards.

Victor Kirhenshtein

Hi!

Auto bind/apply occurs during configuration polls. You can force configuration poll for specific node from console (via Poll -> Configuration menu), or decrease interval between configuration polls by changing server's parameter ConfigurationPollingInterval.

Attributes of node object:


nameNode name
idObject identifier
statusNode status (0 = Normal, 1 = Warning, 2 = Minor, 3 = Major, 4 = Critical, 5 = Unknown, 6 = Unmanaged)
ipAddrNode primary IP address (as text string, like 10.2.1.4)
isAgentAgent presense flag: 1 if NetXMS agent present on node, 0 if not
isSNMPSNMP support flag: 1 if SNMP is supported by node, 0 if not
isBridgeBridge flag: 1 if node is bridge or switch, 0 if not
isRouterIP router flag: 1 if node is Ip router (can forward IP packets), 0 if not
isPrinterPrinter flag: 1 if node detected to be a network printer, 0 if not
isCDPCDP (Cisco Discovery Protocol) support flag: 1 node supports CDP, 0 if not
isSONMPSONMP (SynOptics Network Management Protocol) support flag: 1 node supports SONMP, 0 if not
isLLDPLLDP (Link Layer Discovery Protocol) support flag: 1 node supports LLDP, 0 if not
snmpVersionSNMP version used for communication with node's SNMP agent
snmpOIDSNMP object ID
agentVersionNetXMS agent version (as string, like 0.2.26)
platformNamePlatform name, as returned by NetXMS agent (for example, windows-i386)

Best regards,
Victor

possamai

is this scripting stuff documented somewhere? Because I can't find it..
i'm trying to figure out how it works, but it's tough to find resources about auto bind filters etc. etc.

Victor Kirhenshtein

Hi!

There are documentation chapter about scripting language itself, and reference for all functions. However, writing transformation and filtering script are not covered. I'll try to add additional information on this topic to documentation.

Best regards,
Victor