Embed custom information in a flow file?

Is there the potential to embed custom information in a flow file? In the actual JSON structure? Or maybe via code create a comment node, in the given comment node, unique data?

I want to embed a modest amount of custom data in the flows file. Release date, version information, maybe a description string.

Given that the project feature is not used universally, a small amount of data needs to be embedded so it is for all reasonable purposes transparent.

I am thinking that I could create a small flow to parse the flows file, inventory the flows, and then assign version information based on the flow title. So if the flow title is 'Bingo 1.0' the same information is embedded in the flow file accordingly.

The goal is to create a dashboard that presents the inventory of flows on a given device, the version of each flow, the deployment date, etc.

I think this is available, but not in the way you are thinking.

You can add comments to the flow like this:

Put cursor here and double click.

Then on the right of the screen click on the (i) button as indicated.

Hope that helps.

How about using the comment node?

What I am thinking of doing is a couple of things...

  1. Parse the flows file, to itemize the tabs, I happen to name my tabs with version information in the tab title, but this is a bit of pain to maintain.

  2. The "info' field seems to not be used? Or is it.

    {
        "id": "e7a405b3.964308",
        "type": "tab",
        "label": "Cable Monitor 3.5",
        "disabled": false,
        "info": ""
    },

Is it against the rules to add another property below the "info" field, say "version" and drop a version string into such?

  1. Generate a comment node automatically and drop the version information into same.

The goal of this is be able to run an inventory report, and note exceptions to the 'standard' configuration. So if flow A should be 2.0, and is only 1.0, such an exception is flagged when the automatic inventory scan completes analysis. I have a large inventory of devices that are running NR 'client' flows, so need a way to keep things synchronized. Long term, I will use the admin API flow deployment methods to automatically synchronize flows, but I don't want to just blast a flow file everywhere, need to capture current device state, if you will, before updates.

This will not just be for flows, but I will also include the NPM repository as well, so evaluation of the package* file(s) as applicable as well.

The info field is the place where you can add whatever docs you want - as shown by @Trying_to_learn - so is a "supported" field. How you choose to populate it is up to you. This can be at the node, group or tab level. (but not complete flow).
Adding extra fields is not recommended as there is no guarantee they would be preserved in all cases.

And to be more explicit - any custom fields will not be preserved by the editor.

Right, I have no expectation that the editor would maintain anything, since what I am thinking about is outside of the official feature set/code design. The only expectation, that would exist, is that the flows file structure may change over time.

Flow I am creating, to test this idea, I think will create a comment node per each (flow) tab, dynamically, and yes I known there is no official method to do this.

Well, decided to not embed anything. While I as away from my desk, was thinking of other options, while pickup groceries... I know it is weird... thinking of code design while looking for nice tomatoes? Just me I guess? But I digress. So I have a flow that grabs information from the flows file for each flow tab, this is written to a database I can use to track changes and exceptions. But there is one issue I know I need to resolve, I need a way validate that a flow has changed before I update the database table, so I figure a simple check sum method, maybe MD5? Here is the rub, is there a simple way to grab the source of each flow tab from the flows file? Maybe point me to the right source in the NR sources? The logic is in the export feature of the UI right?

Oh, and I need to link my audit flow to when flow file actually changes... but that should be easy, given flows can watch files for changes.

If you know the id of the flow tab you are interested, then filter the flow file for nodes with their z property set to that id.

The one thing that won't get are any configuration nodes that are 'global' - ie not scoped to an individual flow, but shared by all flows. Nor will it get any subflow definitions.

Yeah I noticed the 'z' association. So how is an export done by the editor? Does the export code handle the exceptions you noted above?

Since I just need the bulk of the flow to calculate a check sum... What you reference should be sufficient. This not going to be archival solution, just an audit process so I can keep the flow deployment consistent.

Still plan to put version # in the tab label, so the check sum is a extra safe guard if I happen to update a flow on some device and forget to archive it in my flow repo. Figure I will throw a alert window or something when the checksums don't match, i.e. the sum of the local flow and the sum of the official copy of the flow in my DB.

Of course, for archival I still have the script I wrote to capture the .node-red directory files applicable to recovery.

The editor has full knowledge of the node types that define the relationships between normal nodes and config nodes - so when you export a node of type X and the editor knows that X.foo is a pointer to a config node, then the editor knows to include that config node.

You could try to replicate that by examining every single node property and checking to see if it looks like a node id.

If you just get the whole flows file and crc that - that would include the config nodes as well wouldn't it?

True, and I already capture the entire flow file for archival in a different flow designed for that goal.

This audit flow is just to catch when individual flows are out of sync. If I just check sum the entire file, I don't know which individual flow is out of sync.

Figured if I could tag the flow, previous idea, by embedding say a comment node automatically, would be one way to validate changes, audit would maintain that node, not human controlled. But that idea is not acceptable given various issues.

Figured if I could mimic what the editor does or invoke that functionality, what would be a possible idea. but that as well has its own complexity, issues.

If was quite easy to parse the flows file to get basic flow tab information, unfortunately going deeper is a more complex. This is becoming an interesting effort just because it is complex.

If maybe, just check sum of the entire flows file is only realistic option without getting quite far down the rabbit hole. But I am enjoying the effort to get into how the export feature works.

I have not checked the Admin API details, but as I recall it supports get and put individual flows right? If I do a GET /flow/:id I get the entire flow content right?

You get all of the items "owned" by that flow. That will not include global config nodes or global subflow definitions. You'd have to GET /flow/global to get those.

Yeah, was just reading the Admin API details on GET, saw that.

Do a GET for the global 'context', check sum that, if no match, audit exception. If not exception, then do a GET for the flow, check sum that, if no match, audit exception.

Or am I missing something or over simplifying something?

Cool, figured that was it, only logical idea I had anyway, good to confirm.

You've posted this same reply to two different threads.

There's nothing in the docs about /flow/id:global - its /flow/:id where :id is a positional parameter of the path. So when it says "if id is set to global" it means /flow/global.

Oops... I will fix that... I had not realized i posted to the other thread as well. Yeah, I realized I had miss read it as named parameter, not a placeholder.

Well the good news is I have the flow all but done now, dropped the file-in node I was using so that I am only using the admin API to get flows file content and the individual flow content... allowing for the limitations in doing this. Also grab the global context as well. Now if things get out of sync I have a fair method to catch it.

Last decision is to decide which check-sum method to use, crc32 or md5 or whatever. :slight_smile: