NetXMS Support Forum

English Support => General Support => Topic started by: tivanni on October 28, 2013, 02:36:51 PM

Title: NXSL: Casting problems
Post by: tivanni on October 28, 2013, 02:36:51 PM
Hi,

i'am trying to realize a filtering script that when an interface goes down get an snmp value from the switch, using the IfIndex of the interface.

Here is my filtering script:

sub main() {
   
   transport = CreateSNMPTransport($node);    // Create SNMP transport for node
   
   ifIndex= %5;   
   
   value = SNMPGetValue(transport, ".1.3.6.1.4.1.9.2.2.1.1.28.".ifIndex);
   
   
   
   CUSTOM_MESSAGE = "Description: ".value;
   
   
 
  return true;
}

The IfIndex of the interface is rapresented by the %5 special variable, because the filtering script is relative to "SYS_IF_DOWN" event which has as parameter:

"
   1) Interface object ID
   2) Interface name
   3) Interface IP address
   4) Interface netmask
   5) Interface index
"

But when the script is executed i get the following error code:

Error in line 5: syntax error, unexpected T_INT32, expecting '('.

I have tryed to cast the value -> ifIndex = string(%5);

or

I have tryed to use a switch case to convert the value:

switch(%5):
   case "10134": etc

but nothing works :(

Can you help me?

Tnx
Title: Re: NXSL: Casting problems
Post by: Victor Kirhenshtein on October 30, 2013, 10:14:30 PM
Hi!

It should be $5. It's a bit confusing, but macros in message texts, etc. and NXSL scripts uses a bit different syntax. In macro expansion, % denotes a macro. In NXSL, parameters comes as $1, $2, etc., and % sign is a division remainder operation.

Best regards,
Victor
Title: Re: NXSL: Casting problems
Post by: tivanni on October 31, 2013, 11:17:59 AM
Yes, it works!

Here is a working filtering script that get the interface description from the switch and put it in the alarm mail when interface goes down/up:

sub main() {
   
   transport = CreateSNMPTransport($node);    // Create SNMP transport for node
   
   ifIndex = $5 ;
   trace(0,"ifIndex =".ifIndex);
   
   value = SNMPGetValue(transport, ".1.3.6.1.4.1.9.2.2.1.1.28.".ifIndex);
   
   
   
   CUSTOM_MESSAGE = "Description: ".value;
   
   
 
  return true;
}

Works on Cisco. For other switch, just change the base OID in SNMPGetValue.

Is it possible to create a topic in forum in which share our NXSL script?
Sharing and example are so useful for nxsl devoloper ^^

Thank you :)
Title: Re: NXSL: Casting problems
Post by: Victor Kirhenshtein on November 01, 2013, 08:04:41 PM
Hi!

There is an area in wiki for NXSL script examples: http://wiki.netxms.org/wiki/SG:Script_Examples (http://wiki.netxms.org/wiki/SG:Script_Examples). Feel free to add your own!

Best regards,
Victor