Shutdown synology Diskstation from on it running flow

Hi folks,
I think, the topic says it all, but to explain a bit more:

I have running node-red on a Synology Diskstation without Docker.
I want to have a flow that triggers the NAS to shutdown.
Best option but not essential: check before if a user is still logged in.

Any idea, or even better, out-of-the-box solution?

All the best,
Stephan

Is it possible to shutdown from the command line? If it is running something like linux that might be
sudo shutdown -h now

As Colin suggests, use an exec node to run the command.

In order to check if someone is logged in:

admin@Knightnet01:~$ who
admin    pts/15       2020-04-21 11:26 (192.168.1.145)
admin@Knightnet01:~$ users
admin

Either the who or users commands will work.

Thank you, both!
The shutdown command works well with the exec node!

Also thank you for the logged-in users check, I will check this later.

Great forum!

I probably should say that I don't know whether those commands will pick up if someone is using one of the Synology's "stations" to view video, listen to music, etc. I suspect not but I don't know how you would spot that anyway. One for the Synology forum perhaps. If you find out, do let us know here, it would be interesting.

Same for logged in on the web interface to DSM I'm afraid, afaik that doesn't register as logged in user on OS level, just for DSM itself.

Yes, I was afraid of that. Doubtless the login/out events are recorded in a log somewhere but I don't know where.

UPDATED: Improved flow to simplify the output.

Ah, here we go, you could use SNMP to monitor the NAS:

Here you have a flow and can see that I'm logged into both one of the web pages (the admin page in this case) and my PC is connected to a remote share.


image

[{"id":"c003f871.ec8ac8","type":"inject","z":"ef122f0d.d488b","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":75,"y":2120,"wires":[["4a40fc6a.ebb774"]],"l":false},{"id":"4a40fc6a.ebb774","type":"snmp subtree","z":"ef122f0d.d488b","host":"192.168.1.161","community":"kn01","version":"2c","oids":"1.3.6.1.4.1.6574.6.1.1.2","timeout":5,"name":"NAS Service Names","x":220,"y":2120,"wires":[["f557d837.2a6c38"]]},{"id":"61272fd7.67b6c","type":"debug","z":"ef122f0d.d488b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":790,"y":2120,"wires":[]},{"id":"31552ed8.a53262","type":"snmp subtree","z":"ef122f0d.d488b","host":"192.168.1.161","community":"kn01","version":"2c","oids":"1.3.6.1.4.1.6574.6.1.1.3","timeout":5,"name":"NAS Service # Logged In Users","x":530,"y":2120,"wires":[["4cc8a2df.50425c"]]},{"id":"f557d837.2a6c38","type":"change","z":"ef122f0d.d488b","name":"Move payload","rules":[{"t":"move","p":"payload","pt":"msg","to":"namesArr","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":355,"y":2120,"wires":[["31552ed8.a53262"]],"l":false},{"id":"4cc8a2df.50425c","type":"function","z":"ef122f0d.d488b","name":"Simplify the data","func":"const out = {}\n\nmsg.namesArr.forEach( (name, i) => {\n    n = (Buffer.from(name.value)).toString()\n    out[n] = msg.payload[i].value\n} )\n\ndelete msg.namesArr\ndelete msg.oid\n\nmsg.payload = out\n\nreturn msg;","outputs":1,"noerr":0,"x":695,"y":2120,"wires":[["61272fd7.67b6c"]],"l":false}]

Amazing what you can do with Node-RED when you are bored of reviewing and responding to IT tenders. :wink:

2 Likes

some of my best flows are written during conference calls :wink:

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.