Is it possible to use text from another SNMP attribute for the legend on Graphs?

Started by ChrisC, August 21, 2021, 06:38:54 PM

Previous topic - Next topic

ChrisC

I am graphing a device via SNMP that has 4 power outputs.
I am displaying the 4 outputs on 1 graph, which works fine, but the names in the Legend are the names of the attribute (ie. "Output 1 Watts" "Output 2 Watts".
Is it possible to use the text string from another SNMP counter for each Legend entry instead?
I know I could just rename each of the attributes that I am graphing, but I am trying to make this generic so I can use it as a template for other devices.

Thanks for a great product! I have been watching the intro by Thomas Kirnac, and it looks great!

Filipp Sudanov

You can use instance discovery mechanism - in this case DCI are created and their names can be used in graphs on Performance tab.

- Create a script in script library, e.g.:
instances = %{ }; // Create empty hash map

instances[".1.1.1"] = "name_one";
instances[".1.1.2"] = "name_two";

return instances;


- Create a DCI. In "General" tab in DCI properties there are two macros - {instance} and {instance-name}. E.g. ".1.1.1" from the script will go into {instance}, "name_one" into {instance-name}.

- In "Performance" tab in DCI properties the situation is opposite - {instance} will be filled with "name_one" (this is so for some historical reasons, should be changed in some future releases).

Now, when you do Poll->Instance discovery on a node (or wait when it would happen automatically), the script will be executed, values returned by this script will be used to create/update DCIs.


The script in the above example returns hash map. It could also return an array, in that case {instance} would be taken from that array. In instance discovery filter script it's possible to modify or add {instance} and {instance-name}.
return Instance(displayName: "name_one", name: ".1.2.3");

Now wee need to get the legend name. This could be done either from that script in script library or from instance discovery filter script:

transport = $node->createSNMPTransport();
if (transport != null) {
  legend_name = SNMPGetValue(transport, ".1.2.3.4.1");
}


There are some examples in NXSL docs: https://www.netxms.org/documentation/nxsl-latest/

ChrisC

Thank you for the detailled reply.
I will need to read it several times and then try it!