Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Accessing Custom Attributes from node's parent containers

Accessing Custom Attributes from node's parent containers

Scheduled Pinned Locked Moved Support
4 Posts 3 Posters 15.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B
    B
    blazarov
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T
      T
      tomaskir
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • V
        V
        Victor Kirhenshtein
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • B
          B
          blazarov
          wrote on last edited by
          #4

          Thanks Victor,
          I'll give it a try and post feedback.

          1 Reply Last reply
          0

          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
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          Powered by NodeBB Contributors
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups