Automate integrity-check of files using checksum

A flow that checks the checksum of a file (checksum as a string inside a txt file).

Requirements

How to

  1. Set the Download directory by changing the path in the File to hash and Checksum nodes. The first is triggered whenever a new file (not ending with ".txt") is added, the second when a file is updated (or change the latter to await creation of a new file too);
  2. (optional) Change ".txt" in the previously listed nodes to the preferred file extension for the checksum file;
  3. Set up the checksum node.

Fixes needed

The Regex in the Checksum node is substituted with the Read hash function node, as I was unable to make a rule selecting only txt files (the regex given as input is inverted). It would look much better without it.

[{"id":"ba268158.2cbf68","type":"watch-directory","z":"ef5a488a.a300a8","folder":"/data/","recursive":0,"typeEvent":"create","ignoreInitial":true,"ignoredFiles":"^[a-zA-Z0-9]+\\.txt$","ignoredFilesType":"re","name":"File to hash","x":110,"y":1720,"wires":[["5c7e1375.dc6b94"]]},{"id":"5c7e1375.dc6b94","type":"change","z":"ef5a488a.a300a8","name":"Clean output","rules":[{"t":"delete","p":"file","pt":"msg"},{"t":"delete","p":"filedir","pt":"msg"},{"t":"delete","p":"filename","pt":"msg"},{"t":"delete","p":"size","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":1720,"wires":[["39ff4b73.bad0f4"]]},{"id":"5269571a.2b1298","type":"watch-directory","z":"ef5a488a.a300a8","folder":"/data/","recursive":0,"typeEvent":"update","ignoreInitial":true,"ignoredFiles":"","ignoredFilesType":"re","name":"Checksum","x":100,"y":1780,"wires":[["98f44a15.290fb"]]},{"id":"98f44a15.290fb","type":"function","z":"ef5a488a.a300a8","name":"Read hash","func":"\nif (msg.filename.endsWith(\".txt\")){\n    return msg;\n}\nelse\n    return null;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":1780,"wires":[["9225bbf0569eceb1"]]},{"id":"34e67b91.f43f24","type":"debug","z":"ef5a488a.a300a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":1840,"wires":[]},{"id":"39ff4b73.bad0f4","type":"join","z":"ef5a488a.a300a8","name":"","mode":"custom","build":"merged","property":"","propertyType":"full","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":450,"y":1760,"wires":[["d16b85b7.15c208"]]},{"id":"9225bbf0569eceb1","type":"change","z":"ef5a488a.a300a8","name":"Clean output","rules":[{"t":"move","p":"payload","pt":"msg","to":"checksum","tot":"msg"},{"t":"delete","p":"file","pt":"msg"},{"t":"delete","p":"filedir","pt":"msg"},{"t":"delete","p":"filename","pt":"msg"},{"t":"delete","p":"size","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":1840,"wires":[["39ff4b73.bad0f4"]]},{"id":"d16b85b7.15c208","type":"change","z":"ef5a488a.a300a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":1760,"wires":[["c74277b8.9c963"]]},{"id":"c74277b8.9c963","type":"checksum","z":"ef5a488a.a300a8","name":"","file":"payload","fileType":"msg","checksum":"checksum","checksumType":"msg","hashFunction":"sha256","hashFunctionType":"select","isFile":true,"isFileChecksum":true,"x":510,"y":1840,"wires":[["34e67b91.f43f24"]]}]

Flow Info

Created 3 years ago
Updated 2 years, 10 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • change (x3)
  • debug (x1)
  • function (x1)
  • join (x1)
Other

Tags

  • node-red-contrib-checksum
  • node-red-contrib-watchdirectory
  • crypto-js
  • chokidar
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option