Parsing regular expression variable to script?

Started by Millenium7, October 25, 2019, 10:03:35 AM

Previous topic - Next topic

Millenium7

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

Filipp Sudanov

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.