Instance discovery method: script

Started by twenrich, March 16, 2017, 01:23:27 PM

Previous topic - Next topic

twenrich

Hi,

I'm having troubles to get the instance-discovery by script working.

I have:
- Instance Discovery Method: Script
- a Filter script (in the moment just tracing)

However, the filter script doesn't get called - I assume the array returned by list_attributes_by_key() does not find it's way to the instance discovery.
When running the script via "Execute server script", I get the debugs (trace, println) printed.

Can someone point out my error with this ?

Kind regards,
Thomas

edited: this is NetXMS 2.1M2

Script "list_attributes_like_http"

// Works!
// array a;
// a[0] = "Entry 1";
// a[1] = "Entry 2";
// return a;

use list_attributes;

a = list_attributes_by_key("http:.*");
foreach (entry: a)
{
msg = "like http: " . $node->name . " " . entry;
trace(1, msg);
println "P " . msg;
}
return a;


"list_attributes"

// list_attributes
//
// retrieving attribute values.
//
//
// Parameter:
// $1: regex to check the attribute key for.
//
// Returns:
// List of all attributes matching the attribute

sub list_attributes_by_key(pattern)
{
array r;
if (pattern == null)
{
msg = $node->name .  " list_attribute_by_key: no pattern!";
println msg;
trace(1, msg);
return a;
}
test = "http://12345.678/";
if (test match pattern)
println "pattern: ". pattern . " test matched OK".

r_i = 0;
attr = $node->customAttributes;
foreach (key: attr->keys)
{
println a;
if (key ~= pattern)
{
println $node->name . " return key=" . key;
r[r_i++] = key;
}
else
{
println $node->name . " no match for " . key . ". pattern=". pattern;
}
}
return r;
}


twenrich

Hi,

I found this out:

In the template, the "Source Node" is set.
Within the scripts, $node is set to the "Source Node", not to the node where the actual instance discovery happens (see screenshot).
When trying the scripts using "Execute Server Script", $node is the "Discovery Node" and everything is fine.

This is OK, I think, as most of the discovery will be done on the "Source Node" (and it's agent) anyway.

Is there an easy way to get the "discovery" node into the scripts so I have access to the custom attributes of the discovery node ?

I want to create some checks on behalf node A and running on node B, controlled by node A's custom attributes.


Thank you very much,

Thomas






Victor Kirhenshtein

Hi,

I've added a feature request for that: https://track.radensolutions.com/issue/NX-1234. Should be an easy fix.

Best regards,
Victor

Victor Kirhenshtein

Fixed in upcoming 2.1 release. DCI owner can be accessed in instance discovery and data collection scripts via $targetObject global variable.

Best regards,
Victor