maaspower icon indicating copy to clipboard operation
maaspower copied to clipboard

Additional type of device control - SSH

Open FrostbyteGR opened this issue 1 year ago • 1 comments

Greetings,

I was wondering, whether an SSH type of device control could be implemented into the project.

Here's a generic example:

name: maaspower ssh example
ip_address: <SSH_IP>
port: 22
username: <USERNAME>
password: <PASSWORD>
ssh-key: <SSH_KEY_FILE_PATH>
devices:
- type: SSH
    name: RPi01
    on: <POE_ON_COMMAND>
    off: <POE_OFF_COMMAND>
    query: <POE_QUERY_COMMAND>
    query_on_regex: <POE_QUERY_ON_REGEX>
    query_off_regex: <POE_QUERY_OFF_REGEX>

Here's another example that could possibly work with MikroTik PoE devices (i.e. CRS328-24P-4S+RM):

name: maaspower mikrotik ssh example
ip_address: <MIKROTIK_IP>
port: 22
username: <USERNAME>
password: <PASSWORD>
ssh-key: <SSH_KEY_FILE_PATH>
devices:
- type: SSH
    name: RPi01
    on: interface ethernet poe set poe-out=off <POE_INTERFACE_NAME>
    off: interface ethernet poe set poe-out=auto-on <POE_INTERFACE_NAME>
    query: interface ethernet poe monitor <POE_INTERFACE_NAME> once
    query_on_regex: ^[\t ]*poe-out-status:[\t ]+powered-on$
    query_off_regex: ^[\t ]*poe-out-status:[\t ]+waiting-for-load$

NOTE: password and ssh-key arguments should be mutually exclusive?

I believe that right now, the same thing can be achieved via type: CommandLine like this:

on: ssh -i <SSH_KEY_FILE_PATH> <USERNAME>@<SSH_IP> "<POE_ON_COMMAND>"
off: ssh -i <SSH_KEY_FILE_PATH> <USERNAME>@<SSH_IP> "<POE_OFF_COMMAND>"
query: ssh -i <SSH_KEY_FILE_PATH> <USERNAME>@<SSH_IP> "<POE_QUERY_COMMAND>"

Thus, I would consider it as a very low priority kind of request.

Many thanks for your time and efforts on this project!

FrostbyteGR avatar Mar 12 '24 22:03 FrostbyteGR

This seems reasonable.

I'm not actively developing this project at present. I would look at PRs if anyone is up for trying to implement this idea.

gilesknap avatar Mar 13 '24 18:03 gilesknap

Now that I've actually had the chance to play around with it, looks like I did not RTFM properly back then. I've updated my first post with a more appropriate version of what would be, plus the way I achieved it with a wrapper script.

Since this appears to be fairly easy to achieve and sufficient enough, I believe this request/idea would be redundant.

FrostbyteGR avatar Jul 31 '24 22:07 FrostbyteGR

I know this is closed, but I'm wondering how your wrapper script is working? I took a very similar approach to you (having a bash script that just executed ssh commands) and I've found that any version newer than 0.6.0 won't work since the ssh binary stopped being shipped.

I can probably just include an apt update && apt install -y openssh-client as part of the script, but that seems messy.

adam-vest avatar Aug 19 '24 15:08 adam-vest

I know this is closed, but I'm wondering how your wrapper script is working? I took a very similar approach to you (having a bash script that just executed ssh commands) and I've found that any version newer than 0.6.0 won't work since the ssh binary stopped being shipped.

I can probably just include an apt update && apt install -y openssh-client as part of the script, but that seems messy.

Hi, You just need to have an ssh client on your machine (which ssh). It's pretty much just a plain bash script, which you can run on it's own.

The only relevance it really has with maaspower; is how I validate the input arguments, and the resulting output. (To be simple and friendly towards the regex you will set in the *.cfg)

FrostbyteGR avatar Aug 19 '24 16:08 FrostbyteGR

Oh, ha, I should clarify that I'm using the docker container, which stopped shipping the ssh binary in its container after v0.6.0. And yeah, I got around this by just adding a quick blurb right at the beginning of my script:

if [[ ! $(which ssh) ]]; then
        apt update && apt install openssh-client -y
fi

adam-vest avatar Aug 19 '24 16:08 adam-vest