Hi,
I have a relatively large NetXMS deployment and I have nodes organized in multi-level container hierarchy, e.g.:
-Infrastructure
|__Client1
|___PDC
|___Node1
|___Node2
|___Node3
|___DRC
|___Node1
|___Node2
|___Node3
|___Branches
|___East-Side
|____Node1
|____Node2
|____Node3
|___West-Side
|____Node1
|____Node2
|____Node3
|__Client2
|___PDC
|___Node1
|___Node2
|___Node3
|___DRC
|___Node1
|___Node2
|___Node3
|___Branches
|___East-Side
|____Node1
|____Node2
|____Node3
|___West-Side
|____Node1
|____Node2
|____Node3
.... and so on..
What i want to achieve is to set few custom attributes on higher-level containers (e.g. Client1, Client2) with general client-specific info such as contact details, email notification recipients, etc. that i can use in events and actions.
In order to achieve that i need some sort of Custom Attribute "inheritance" from top to bottom, or alternatively a way to access parent containers custom attributes.
Is there a way to achieve that?
You can do this with a script that will recursively look at objects parents, until it finds a correct custom attribute which you are interested in.
Its a bit painful, and not usable everywhere, but it might help you atleast a little.
Hi,
below is an example of the script that walks all parents of a node and collects values of custom attribute "contacts" into single string separated by semicolons:
global contacts = "";
foreach(o : GetObjectParents($node))
{
add_contacts(o);
}
println "Contacts: " . contacts;
sub add_contacts(curr)
{
c = GetCustomAttribute(curr, "contacts");
if (c != null)
{
if (length(contacts) > 0)
contacts = contacts . ";" . c;
else
contacts = c;
}
foreach(o : GetObjectParents(curr))
{
add_contacts(o);
}
}
The only drawback is that it will not detect duplicate values. Duplicates can be eliminated like this:
global contacts = "";
global presense = %{ };
foreach(o : GetObjectParents($node))
{
add_contacts(o);
}
println "Contacts: " . contacts;
sub add_contacts(curr)
{
c = GetCustomAttribute(curr, "contacts");
if ((c != null) && (presense[c] == null))
{
if (length(contacts) > 0)
contacts = contacts . ";" . c;
else
contacts = c;
presense[c] = true;
}
foreach(o : GetObjectParents(curr))
{
add_contacts(o);
}
}
Note that this script version requires server 2.0-RC1 or higher as it uses hash maps.
Best regards,
Victor
Thanks Victor,
I'll give it a try and post feedback.