Searching array generated by snmp walker for specific string

I'm pulling the ClientName from my Aruba Virtual WiFi controller. It delivers an array and in this array I'm searching for 1 name for example "MrSmith". I can pull the array using snmp walker but cannot figure out how to see if "MrSmith" is in the array. I've tried using the switch with a Property of msg.payload and the "contains" MrSmith but that didn't work. I have also tried using JSON $match but that gives me an error about the $match. "Invalid JSONata expression: Argument 1 of function "match" does not match function signature"

In a function node you can use indexOF(), so, assuming the array is in the payload, then something like

if (msg.payload.indexOf("MrSmith") > -1) {
  // do something
}

Thank you for this and this helps. I'm very new to this. I want to modify the msg.topic to equal "YES" So I'm trying to do the following in the function:

if (msg.payload.indexOf("MrSmith") > -1) {
    var topic="YES";
    msg.topic=topic;
}
return msg;

Then I send the msg.payload to a debug to view the output but it's not setting the msg.topic.

Can you post a screenshot of what your payload looks like (debug node output)? You say it’s an array with that value, but if that’s the case both Colin’s solution as your own attempt with the switch node should work. It likely has a slightly different layout causing this issue.

OK, so this is interested. The first screen shot shows a "raw" by the value:

The second one is the correct value once I click the raw to change it to string:

So your screenshot is showing that rather than an array of strings you have an array of objects. And that these objects may have properties containing the value you’re looking for.

Take a look at array.filter and see if your object turns up. You can use .length on the result to see if it was found: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

The walker has a problem i've seen and i'll have to remember the work around. But I did decades of work with all the SNMP tools for 90% of the major monitoring platforms.

Wrote this to help you walk your OIDS. Write me back if you need to.

[{"id":"e6406793.281cb8","type":"debug","z":"352b627d.9c316e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":330,"wires":[]},{"id":"e3cee1e1.ef111","type":"inject","z":"352b627d.9c316e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["efb98d08.25c55"]]},{"id":"efb98d08.25c55","type":"snmp subtree","z":"352b627d.9c316e","host":"192.168.0.38","community":"PROELIAN","version":"1","oids":"1.3.6.1.2.1.1.4","timeout":5,"name":"","x":330,"y":280,"wires":[["e6406793.281cb8","f43540d3.6c7ef"]]},{"id":"ed24efe0.f747c","type":"ui_text","z":"352b627d.9c316e","group":"4d632cbe.cc1824","order":20,"width":0,"height":0,"name":"","label":"TEXT=","format":"{{msg.payload}}","layout":"row-spread","x":880,"y":280,"wires":[]},{"id":"f43540d3.6c7ef","type":"change","z":"352b627d.9c316e","name":"","rules":[{"t":"move","p":"payload.0.value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":280,"wires":[["e6406793.281cb8","ed24efe0.f747c"]]},{"id":"4d632cbe.cc1824","type":"ui_group","z":"","name":"Text","tab":"fa0612af.259a48","order":2,"disp":true,"width":"6","collapse":false},{"id":"fa0612af.259a48","type":"ui_tab","z":"","name":"testing","icon":"dashboard","order":5}]

What is the problem and what is the workaround ?

On the windows SNMP agent it isn't passing the request correctly. I seem to remember a V1 V2c issues. I've been away for a while from this but will remember, correct it and let you know. It will bubble up when I sleep tonight.

I get this error with v1

1/9/2020, 1:09:30 AMnode: ee80e336.b3e18msg : string[56]

"RequestFailedError: GeneralError: 1.3.6.1.4.1.77.1.1.3.0"

Get this error with v2c

1/9/2020, 1:11:23 AMnode: ee80e336.b3e18msg : string[97]

"RequestFailedError: GeneralError: 1.3.6.1.2.1.55.1.12.1.6.14.16.255.2.0.0.0.0.0.0.0.0.0.0.0.1.0.3"

I will fire up wireshark tomorrow and look at the TCP request to see what the inbound packet request is to the windows SNMP agent is.

I looked into the SNMP modules. They are making the request but SNMP WALKER is a walk.

Here is the problem. The walks are intended to pull a the SNMP tree. Depending on the OID this takes time and the default timeout can expire so you get an error. This needs to be noted in the documentation.

But SNMP Walker can pull a lot of stuff so the module better have a very big cache of the data to store the incoming OIDS.

What I found was that the walk starts at

get-next-request 1.3.6.1.2.1.1.4

And should stop at 1.3.6.1.2.1.1.7.0

But it jumps to 1.3.6.1.2.1.2.1.0 and collects about 5MB before it stops at.

No. Time Source Destination Protocol Length Info
10860 27.192674 192.168.0.37 192.168.0.38 SNMP 92 get-next-request 1.3.6.1.2.1.25.5.1.1.1.23560

Here is where you can see the jump.

Heaven forbid you start with OID 1. I will look at the JS code for this node. I think I can suggest a fix.

No. Time Source Destination Protocol Length Info
106 2.982888 192.168.0.37 192.168.0.38 SNMP 87 get-next-request 1.3.6.1.2.1.1.7.0

Frame 106: 87 bytes on wire (696 bits), 87 bytes captured (696 bits) on interface \Device\NPF_{9F87FEB1-3102-436F-A5B3-8B370073D501}, id 0
Ethernet II, Src: Raspberr_09:93:84 (dc:a6:32:09:93:84), Dst: IntelCor_81:a9:75 (a0:af:bd:81:a9:75)
Internet Protocol Version 4, Src: 192.168.0.37, Dst: 192.168.0.38
User Datagram Protocol, Src Port: 51686, Dst Port: 161
Simple Network Management Protocol

No. Time Source Destination Protocol Length Info
107 2.983066 192.168.0.38 192.168.0.37 SNMP 88 get-response 1.3.6.1.2.1.2.1.0

------------------------------- UPDATE -----------------------------------------------

I looked at the code snmp.js

The walker is limited to 20 max responses. That is a problem because the socket request will spew more than that.

It needs to be much more expansive if you really want to walk a tree and that can be very big.

It needs to mimic the official snmpwalk

I took this from the doc.

NOTE THE LAST LINE. The tool is getting that error and not processing correctly.

snmpwalk is an SNMP application that uses SNMP GETNEXT requests to query a network entity for a tree of information.

An object identifier (OID) may be given on the command line. This OID specifies which portion of the object identifier space will be searched using GETNEXT requests. All variables in the subtree below the given OID are queried and their values presented to the user. Each variable name is given in the format specified in variables(5) .

If no OID argument is present, snmpwalk will search the subtree rooted at SNMPv2-SMI::mib-2 (including any MIB object values from other MIB modules, that are defined as lying within this subtree). If the network entity has an error processing the request packet, an error packet will be returned and a message will be shown, helping to pinpoint why the request was malformed.

If the tree search causes attempts to search beyond the end of the MIB, the message "End of MIB" will be displayed.

One last thing, you need to interpret the OID and walk it down .

The walk should have stopped at get-next-request 1.3.6.1.2.1.1.4.0

No. Time Source Destination Protocol Length Info
98 2.963821 192.168.0.37 192.168.0.38 SNMP 86 get-next-request 1.3.6.1.2.1.1.4

No. Time Source Destination Protocol Length Info
99 2.963963 192.168.0.38 192.168.0.37 SNMP 101 get-response 1.3.6.1.2.1.1.4.0

No. Time Source Destination Protocol Length Info
100 2.968598 192.168.0.37 192.168.0.38 SNMP 87 get-next-request 1.3.6.1.2.1.1.4.0

No. Time Source Destination Protocol Length Info
101 2.968756 192.168.0.38 192.168.0.37 SNMP 91 get-response 1.3.6.1.2.1.1.5.0

Take a look at this NPM code