Value from dci table to event template?

Started by Hanfelt, January 16, 2025, 04:34:18 PM

Previous topic - Next topic

Hanfelt

Is there any possibility to get a value to event template other than the instance one.
It returns the row but you cannot use this in the event template like %<column:ColumName> or %<row:ColumName>??

Filipp Sudanov

In all places where macros are supported you can use %[script_name] macro. Script with specified name should be in script library. In that script you can access table value (it will be object of class table - https://www.netxms.org/documentation/nxsl-latest/#class-table) and get value of specific cell from it.

When developing your script, you can run it via Execute Script on the node where you have your table DCI. However, there's a difference - when script is ran automatically on threshold violation, variables $event, $dci will be set - you can use these to get parameters of event or id of the DCI. When running via Execute Script, these variables will not be set, so you need to modify your script slightly.

Here's a brief example:
//t = GetDCIValue($node, $dci.id); // for use in script called on threshold violation
t = GetDCIValue($node, 13741); // for testing - use via Execute Script on node

//row = $event.getParameter(4); // for use in script called on threshold violation
row = t.findRowIndexByInstance("/sys"); // for testing

return t.get(row, 1);

You can give some more information, what exactly cell of your table you want to extract, then I can give some more examples.

Hanfelt

I might have been overthinking this issue.

I think its enough to have this in the event template:

Nginx certificate will expire in 14 days for: %<instance> on server %n

%<instance> is the certificate name in my case
and %n is the node or object name in netxms.

Thank you so much for the input though.

Filipp Sudanov

In many cases it's better to use regular DCIs and instance discovery to automatically creation and removal of them.