Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. NXSL: Casting problems

NXSL: Casting problems

Scheduled Pinned Locked Moved Support
4 Posts 2 Posters 8.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T
    T
    tivanni
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • T
        T
        tivanni
        wrote on last edited by
        #3

        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 🙂

        1 Reply Last reply
        0
        • V
          V
          Victor Kirhenshtein
          wrote on last edited by
          #4

          Hi!

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

          Best regards,
          Victor

          1 Reply Last reply
          0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          Powered by NodeBB Contributors
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups