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. Parsing regular expression variable to script?

Parsing regular expression variable to script?

Scheduled Pinned Locked Moved Support
2 Posts 2 Posters 45.4k 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.
  • M
    M
    Millenium7
    wrote on last edited by
    #1

    I'm having issues and i'm not sure if its related to the recent update (which has broken a lot of my scripts hence why i'm rewriting a lot of it)

    I have this as a script with some debugging in it

    // Radio mode check
    // First parameter = Node to check
    // Second parameter = Vendor ID / Object ID (uses regex expression). Acts as a prequalifier before proceeding
    // Third parameter = SNMP OID to check the radio mode, script will return this value
    if ($1 == null) {println "Please specify node as first parameter"; return -1;}
    if ($2 == null) {println "Please specify Vendor/Object OID as second parameter"; return -1;}
    if ($3 == null) {println "Please specify SNMP OID as third parameter"; return -1;}
    
    tempvar = FindObject($1);
    println $2;
    println tempvar->snmpOID;
    
    // First check for appropriate Vendor ID
    if (tempvar->snmpOID ~= $2) {
     println "match was made";
     println "----";
     println $1;
     println $2;
     println $3;
     println "----";
     transport = CreateSNMPTransport(tempvar); // Open SNMP Session
     if (transport == null) println "Could not open SNMP session" ; return -2; // If can't open session, abort
     // Now check if AP or SM
     mode = SNMPGetValue(transport, $3);
     if (mode == null) println "Failed to retrieve OID $3"; return -3;
     return mode;
    };
    println "Vendor ID not a match"; return -4;
    

    I'm sending this to the server console

    exec RadioMode 27560 "(.1.3.6.1.4.1.17713.21.9).*" .1.3.6.1.4.1.17713.21.3.8.2.1.0
    

    First parameter is a nodes object ID
    Second parameter is a regex expression that should match the Object ID / Vendor ID which in this case has .39 appended to it (all radio's in this range have a different number but they all begin with .1.3.6.1.4.1.17713.21.9)
    Third parameter is the value to check and it should return 1/2/3 depending on the mode that the radio is in (AP/SM/Spectrum Scan)

    It's failing at if (tempvar->snmpOID ~= $2) {
    It seems to accept it as a regular expression but its like its being treated as a literal string or something. If I instead replace the $2 with the exact same regular expression (typed into the script itself, not taken from a variable) it recognises it as a match and proceeds just fine

    I have other issues in this script such as the SNMPTransport seemingly not being created but we'll cross that bridge later

    1 Reply Last reply
    0
    • F
      F
      Filipp Sudanov
      wrote on last edited by
      #2

      Server console is not analyzing double quotes - enquoted arguments are just passed to the script as string having quotes on both ends, that's why it's not matching.

      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