NetXMS Support Forum

English Support => General Support => Topic started by: francoism on November 21, 2016, 12:44:38 PM

Title: Auto apply Rules bases on SNMP Value
Post by: francoism on November 21, 2016, 12:44:38 PM
Hi Guys,

First off, great program. I have been using it for about 2 weeks. I want this to be my Dude server replacement. It has so many uses and I am very excited in what it can do.

Anyways, I need some help with applying a Template.

Here is my code

Quotesnmp = CreateSNMPTransport($node);
oid = SNMPGetValue(snmp,".1.2.840.10036.3.1.2.1.3.10");   // Device name
if (oid == "PowerBeam AC 500")
    return true;

The idea is to apply the filter if the SNMP returns "PowerBeam AC 500". It does when I snmpwalk it. So there must be something wrong with how I am trying to use the script.

Please help.
Title: Re: Auto apply Rules bases on SNMP Value
Post by: tomaskir on November 21, 2016, 03:02:53 PM
Here is a script with error handling and a bit better recognition (using regex ~= rather then just total comparison ==)

oid = ".1.2.840.10036.3.1.2.1.3.10.0";

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

value = SNMPGetValue(tube, oid);
if (value == null)
  return false;

return value ~= "PowerBeam AC 500";
Title: Re: Auto apply Rules bases on SNMP Value
Post by: francoism on November 22, 2016, 11:30:01 AM
I have added this rule but does not seem to work. Is there a way to debug these rules to see output?
Title: Re: Auto apply Rules bases on SNMP Value
Post by: tomaskir on November 22, 2016, 11:47:13 AM
Sure, just add some

trace(0, "some message");

Into the code, and then look at netxmsd log file.
Title: Re: Auto apply Rules bases on SNMP Value
Post by: zsing82 on January 23, 2017, 06:00:37 AM
This worked for me:
return $node->sysDescription like "HP*Switch*";

You can replace sysDescription with other node attributes:
https://wiki.netxms.org/wiki/NXSL:Node (https://wiki.netxms.org/wiki/NXSL:Node)

It's an indirect SNMP call, but I thought it might help.