Capturing all nodes identified by search - how? [navigation]

#1

Hey guys!
I maintain internal tooling at my office, and we're switching from database X to database Y.

Most of the tools are based on Node-RED flows which output to the database using HTTP request nodes.

Migration to the new database requires updating all the request nodes in many [many!] flows and tabs, over two separate Node-RED instances.

When I search for an identifying term featured in all these request nodes [using ctrl-f or the "search flows" from menu], a list of nodes is returned, which is great.

The problem is that, as far as I can figure out, only one of the returned nodes is "viewable" at a time [by clicking on it, which then brings the palette viewer to the vicinity of the clicked node and makes its border flash].

Is there a way to "grab" or "capture" all nodes returned from a search [even if only their IDs]?
I'd like to avoid having to individually click on, find, open, and copy info from dozens of nodes.

Any and all guidance is appreciated; thanks!

0 Likes

#2

You can easily search your flows using Node-RED itself to open the flow.json file and search for nodes

For instance, the picture below shows the output of searching a flow for http request nodes.

Once you find the required nodes what do you do afterward?

Flow:

[{"id":"c6102b2d.d908e8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"dda94d1c.3a07a","type":"change","z":"c6102b2d.d908e8","name":"jsonata filter","rules":[{"t":"set","p":"filter","pt":"msg","to":"payload[type = 'http request']","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":140,"wires":[["f5dc667c.ac8108"]]},{"id":"1624601c.23f32","type":"inject","z":"c6102b2d.d908e8","name":"","topic":"flows","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":140,"wires":[["312ff7a6.7dd008"]]},{"id":"f5dc667c.ac8108","type":"debug","z":"c6102b2d.d908e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"filter","targetType":"msg","x":600,"y":140,"wires":[]},{"id":"312ff7a6.7dd008","type":"http request","z":"c6102b2d.d908e8","name":"Get {{{topic}}}","method":"GET","ret":"obj","paytoqs":false,"url":"http://localhost:1880/{{{topic}}}","tls":"","proxy":"","authType":"basic","x":260,"y":140,"wires":[["dda94d1c.3a07a"]]}]
1 Like

#3

Thanks for your thoughtful reply, Andrei!

I'm able to open the flow.json in my text editor after using the "export" function, but it looks / sounds like you've achieved the above output within the Node-RED application itself -- when I use "search flows" in the upper-right menu, it doesn't display the JSON but only an icon, node name, node type, and flow name.

Is there a setting or other configuration step that I'm missing?

Re : what I intend to do after locating nodes : I plan to 1) record their IDs in a table so that I can then 2) easily and systematically update their call URLs when the time comes to redirect their requests to the new database.

As you undoubtedly detect, I'm quite new to Node-RED, so all advice / criticism, etc is welcome!

Thanks again for your time and assistance.

0 Likes

#4

Hi Nicholas, good. What you want to do it is perfectly achievable and can be automated by using the Admin API that Node-RED provides. This API that allows developers to read, modify and delete flows (and nodes, modules and probably projects too).

This is the link to the API documentation: https://nodered.org/docs/api/admin/methods/

The flow I posted before uses the Admin API to read the active flow configuration file and filter only the information for the existing http request nodes (or return undefined if the flow does not have a node of this kind). By automating the search you will not need to manually search nodes with control + f

I modified the previous flow to export the list of node id´s and URLs to a CSV file. There will be a row in the CSV file for each http request from your current flow.

Flow to import and test (please ask for help if you are not sure how to import flows)

[{"id":"7491b1e6.7a10a","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"975eafc1.cf024","type":"change","z":"7491b1e6.7a10a","name":"jsonata filter","rules":[{"t":"set","p":"filter","pt":"msg","to":"payload[type = 'http request'].{\"id\": id, \"url\":url}","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"filter","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":140,"wires":[["27a1a600.86319a","8a0cf58f.769318"]]},{"id":"4f298fb6.c7d64","type":"inject","z":"7491b1e6.7a10a","name":"Go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":140,"wires":[["9910bde3.9837"]]},{"id":"27a1a600.86319a","type":"debug","z":"7491b1e6.7a10a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":590,"y":200,"wires":[]},{"id":"9910bde3.9837","type":"http request","z":"7491b1e6.7a10a","name":"Get flows","method":"GET","ret":"obj","paytoqs":false,"url":"http://localhost:1880/flows","tls":"","proxy":"","authType":"basic","x":260,"y":140,"wires":[["975eafc1.cf024"]]},{"id":"9ec62ffd.1158b","type":"file","z":"7491b1e6.7a10a","name":"Write filter","filename":"C:\\Users\\OCM\\.node-red\\static\\nrfiles\\filter-flow.csv","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":720,"y":140,"wires":[[]]},{"id":"8a0cf58f.769318","type":"csv","z":"7491b1e6.7a10a","name":"","sep":",","hdrin":"","hdrout":true,"multi":"one","ret":"\\r\\n","temp":"id,url","skip":"0","x":590,"y":140,"wires":[["9ec62ffd.1158b"]]}]

You will need to modify the configuration of two nodes to suit your system.

1- modify the config for the Get flows node so that the URL in the dialog panel will point to your Node-RED instance (but keep the /flows in the URL string).

2- Modify the path and the file name for the Write filter node.

2 Likes

#5

Fantastic! Thanks much for taking the time to craft such a thorough and informative reply. Makes perfect sense and is a massive help.

Thanks again and have a great week! Cheers from Phoenix!

2 Likes

#6

I'm unsure what it is you need to change, but if it's something like changing part of some URLs or something equally easy, perhaps you could simply export your flows, copy paste to a text editor, then search and replace the bits you need changing then copy, paste, import your modified flows back in?

Regardless, good info from @Andrei

2 Likes

#7

Thanks very much for your reply, Steve! That's good thinking and may well work also.

You guys rock!

0 Likes