Accessing Custom Attributes from node's parent containers
-
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?
-
-
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 -
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login