NetXMS Support Forum

English Support => General Support => Topic started by: mike on August 16, 2016, 03:47:42 PM

Title: Instance Discovery (Port Admin State, Port OperState)
Post by: mike on August 16, 2016, 03:47:42 PM
Hi,

I tried to get a List of my Ports. The DCI should give me the operState. But just for Port with Admin = up.

This is what i tried:

dci Name: Port {instance-name}
SNMP OID: .1.3.6.1.2.1.2.2.1.8.{instance}

Base OID: .1.3.6.1.2.1.2.2.1.8

snmp = CreateSNMPTransport($node);

value = SNMPGetValue(snmp, ".1.3.6.1.2.1.2.2.1.8." . $1);
nam = SNMPGetValue(snmp, ".1.3.6.1.2.1.31.1.1.1.18." . $1);
adm = SNMPGet(snmp, ".1.3.6.1.2.1.2.2.1.7." . $1);

if (value != null && value != 0 && nam != null && adm->value == 1)
                return %(true, value, nam);
else return false;



Title: Re: Instance Discovery (Port Admin State, Port OperState)
Post by: Victor Kirhenshtein on August 16, 2016, 04:01:16 PM
Hi,

you are using undefined variable "transport" here:


adm = SNMPGet(transport, ".1.3.6.1.2.1.2.2.1.7." . $1);


Best regards,
Victor
Title: Re: Instance Discovery (Port Admin State, Port OperState)
Post by: mike on August 16, 2016, 04:09:40 PM
hi, thanks for reply.
Unfortunately this was a mistake while writing the post.

This is my last version:

snmp = CreateSNMPTransport($node);

oper = SNMPGetValue(snmp, ".1.3.6.1.2.1.2.2.1.8." . $1);
nam = SNMPGetValue(snmp, ".1.3.6.1.2.1.31.1.1.1.18." . $1);
adm = SNMPGetValue(snmp, ".1.3.6.1.2.1.2.2.1.7." . $1);
dec = SNMPGetValue(snmp, ".1.3.6.1.2.1.31.1.1.1.1." . $1);

if (oper != null && oper != 0 && nam != null && adm == 1)
      return %(true, oper, dec . " - " . nam);
else return false;



/edit:
I saw that i corrected my mistake 3 seconds before your post. I was a bit too late :)
Title: Re: Instance Discovery (Port Admin State, Port OperState)
Post by: Victor Kirhenshtein on August 16, 2016, 04:26:55 PM
One (or two) issues here. First of all, ensure that you are using "SNMP walk - OIDs" as discovery method (because you want instance to be interface index). Alternatively, you can change base OID to return interfaces indexes as values.
And most important, you replace original instance value with interface operational state:


return %(true, oper, dec . " - " . nam);


effectively reducing all instances into few. Correct will be to keep interface index as instance:\


return %(true, $1, dec . " - " . nam);


Best regards,
Victor
Title: Re: Instance Discovery (Port Admin State, Port OperState)
Post by: mike on August 17, 2016, 09:17:13 AM
Thank you, the "$1" solved the Problem. I attached my configuration in case someone is interested.

Is there a chance to check for just the first (or any) part of the description name? I have many ports named "Test_xxx". It would be nice to search for "Test" in the first 4 letters and exclude them too.
Title: Re: Instance Discovery (Port Admin State, Port OperState)
Post by: tomaskir on August 17, 2016, 12:21:05 PM
Simply do a regex compariston

if (someVar ~= "Test_.*") {
  println("Its a test interface!");
}
Title: Re: Instance Discovery (Port Admin State, Port OperState)
Post by: mike on August 17, 2016, 12:55:49 PM
That solved the problem. Thank you.