Hi
I'm currently using the following condition to collect all MikroTik devices:
return $node->vendor == "MikroTik";
Is there any way to perform this per IP address instead?
$node.ipAddr (string)
or $node.ipAddress (instance of InetAddress): https://netxms.org/documentation/nxsl-latest/#class-inetaddress
$subnet = InetAddress("x.y.z.0")
$mask = 24
if ($node.ipAddress.isInSubnet($subnet, $mask)) {
return 1; // match
} else {
return 0; // no match
}
I got this, but it's not working. Can you please modify it?
First of all two first lines should end with ; char.
There is no isInSubnet() method on InetAddress class, but there is contains() method on subnet, so we should go opposite way and check it on the subnet, there's an example here: https://netxms.org/documentation/nxsl-latest/#_instance_methods_18
So, modifying your code:
subnetObject = InetAddress("192.168.56.0", 24);
if (subnetObject.contains($node.ipAddress)) {
return 1; // match
} else {
return 0; // no match
}
And just for completeness, script above can be simplified to
return InetAddress("192.168.56.0", 24).contains($node.ipAddress);