Instance discovery scripts completely broken?

Started by Millenium7, November 06, 2019, 04:57:58 AM

Previous topic - Next topic

Millenium7

I'm confused. Has something drastically changed with how instance discovery works for template DCI's?

I've followed this guide https://lasiszm.wordpress.com/2017/10/22/netxms-template-for-monitoring-mikrotik-interfaces/ as a baseline
Except 2 problems, First is EVERY interface is being added as a DCO
And the second is the names are wrong. Everything just has instance number next to it, i.e. instead of "testRx - ether1" it just shows "testRx - 1" and so on for each

Then I find the discovery filter script just isn't working at all. I literally place this as the first line "return false;" and it STILL adds every single interface.............. what the hell?

edit: Ok I think there's a bug. If I have any 'and' or 'or' statements in IF statements anywhere, it seems the result will always return true, even if the very first line of the discovery script is "return false;"

This works fine
transport = CreateSNMPTransport($node);
if (transport == null) return false;

ifName = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.2.".$1);
ifType = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.3.".$1);
ifMAC = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.6.".$1);
// If could not retrieve values, return false
if (ifName == null) return false;
if (ifType == null) return false;
if (ifMAC == null) return false;

// If interface type is 1/other (VPLS shows as this) and MAC begins with 02
if (ifType->value == 1) return %(true,$1,ifName->value);


but this does not

transport = CreateSNMPTransport($node);
if (transport == null) return false;

ifName = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.2.".$1);
ifType = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.3.".$1);
ifMAC = SNMPGet(transport,".1.3.6.1.2.1.2.2.1.6.".$1);
// If could not retrieve values, return false
if (ifName == null) return false;
if (ifType == null) return false;
if (ifMAC == null) return false;

// If interface type is 1/other (VPLS shows as this) and MAC begins with 02
if (ifType->value == 1) && (ifType->value == 1) return %(true,$1,ifName->value);


This is the exact same script, except the last line if doing 2 IF statements, both are exact same values. This script adds every single interface, as if the result was the very first line said "return true;", even if I put in 'return false;" it'll still add every single interface. Also if I try to condense the failure statements to 1 line i.e.
if (ifName == null) || (ifType == null) || (ifMAC == null) return false;
Once again it doesn't matter at all what is in the rest of the script. It's like the whole script fails and it just defaults to 'return true;'

Alex Kirhenshtein

Add brackets in "if":

if ( ifType->value == 1 && ifType->value == 1 ) return %(true,$1,ifName->value);

Millenium7

Ok will check

Either way I still consider this a bug, and quite undesirable. If a patch is pushed that changes the scripting syntax or behavior this will create an absolute mess for instance discovery. Other scripts just outright fail and this is fine. Instance discovery should not default to 'yes accept everything' if there is an issue with the script, it should just outright fail like the others do. Makes it much more obvious to fix

Is there a way to debug this sort of thing easily? I get no feedback which makes troubleshooting much harder and more time consuming

Victor Kirhenshtein

Server generates event SYS_SCRIPT_ERROR for runtime errors in scripts, including instance discovery filter scripts, and also generates "warning" record in server's log. First parameter contains script identification string and second parameter contains error message. Unfortunately event is not generated if there is compilation error like in your case (although warning message in log still generated). I've fixed that in development branch, starting with next release you'll also get SYS_SCRIPT_ERROR event for instance discovery filter compilation errors.

On a side note, script syntax didn't change in that part - expression like

if (a < b) && (c < d) { }

was always a syntax error. Whole "if" expression should always be enclosed in parenthesis.

Best regards,
Victor