Custom Attributes as Parameters to DCIs

Started by Tursiops, April 05, 2016, 04:55:25 PM

Previous topic - Next topic

Tursiops

Hi,

I am trying to achieve the following:
- Create a single template with a DCI
- The DCI needs to be passed multiple parameters. These will differ per node.
- Assign the template to a system based on the existence of a number of custom attributes on a node. That part is not a problem.
- Use the values of these custom attributes as parameters for the DCI. That's the part that I can't get to work.

I've been searching and ran into this old post from 2013: https://www.netxms.org/forum/general-support/custom-attributes-2446/
But it doesn't really seem to help me. Not sure if I misunderstood the %{script:<scriptname>} part mentioned. Where would I put that in the above scenario, if that would even work in this case?

Any other ways to achieve what I'm trying to do?

Thanks

tomaskir

The way is described here on the wiki as well:
https://wiki.netxms.org/wiki/UM:Data_Collection#Macros_in_template_items

You can not currently access node's Custom Attributes directly from the DCIs, but with an intermediary script you can do it.

So in your DCI, you would define it like this:

MyDCI.Name("string_abbrib", %{script:get_node_attrib})


Then create the script "get_node_attrib" in the Script Library that will return the Custom Attribute you desire.

Tursiops

That doesn't seem to work for me.

I have done the following:
- Configured a (Linux) node with a custom attribute called "testParameter", value is "Hello World".
- Created a script called "GetAttribute", which returns the value for that attribute:
sub main()
{
return GetCustomAttribute($node, "testParameter");
}

- Running the same code via Execute Server Script against the node returns "Hello World".
- Configured an ExternalParameter on the node as follows:
ExternalParameter = HelloWorld(*):echo $1
- Created a DCI called "TESTING", with following Parameter: HelloWorld(%{script:GetAttribute}) (I tried it like that, with single and double quotes).

I expected to see the DCI return "Hello World", but instead I see "%{script:GetAttribute}", i.e. the Macro is not being interpreted at all? Guess I'm still missing something?   :-\


Tursiops

I got it to work somewhat. I kept overlooking the word "Template". It really only works if I apply the DCI to a template which is then applied to the node, at which time the macro is interpreted. So if I change the custom attribute, it won't auto-update the DCI - which is how it's documented.
Auto-updating would be a nice feature. :)

I then tried to create a script that returns a specific custom attribute and used that in a DCI: all good.
Now I want to use this on a whole range of custom attributes - but don't want one script per attribute. Rather I want to pass the name of the attribute to fetch to the script. That way one script can return any custom attribute value, all I need to do is pass the name to the script macro.
But that doesn't work.
Not sure if scripts can't take parameters, if the macro doesn't handle passing them to the script or I'm missing something (again)?

Thanks

Victor Kirhenshtein

Maybe using script DCIs will be better solution in your case. You can create script in a library which will be called by data collector, and that script will have access to all attributes of a node and can read appropriate data from agent or SNMP using AgentReadParameter or SNMPGetValue functions.

Best regards,
Victor