Unable to send RPC commands to OMV

  • Hello,
    I'm trying to add a button on Hassio in order to shutdown OMV NAS using RPC calls instead of SSH commands.
    My plan is to send 2 RPC calls: one for the login, and one for the system/shutdown command.
    During the test I'm doing, the login call works good and generate a cookie but the system/shutdows call doesn't works and say that I'm not authenticated :huh: ...


    From my PC terminal:

    Code
    $ curl --request POST --cookie-jar cookies.txt --data '{"service":"session","method":"login","params":{"username":"admin","password":"myRealPassword"}}' http://192.168.0.5/rpc.php
    
    
    {"response":{"authenticated":true,"username":"admin"},"error":null}
    
    
    $ curl --request POST --cookie-jar cookies.txt --data '{"service":"system","method":"shutdown","params":{"delay":"15"}}' http://192.168.0.5/rpc.php
    
    
    {"response":null,"error":{"code":5000,"message":"Session not authenticated","trace":"OMV\\ErrorMsgException: Session not authenticated in \/usr\/share\/php\/openmediavault\/session.inc:146\nStack trace:\n#0 \/usr\/share\/php\/openmediavault\/rpc\/proxy\/json.inc(81): OMV\\Session->validateAuthentication()\n#1 \/var\/www\/openmediavault\/rpc.php(45): OMV\\Rpc\\Proxy\\Json->handle()\n#2 {main}"}


    Other useful infos:
    This is the first time in my life I use RPC calls ^^ so probably I'm missing something.
    The OMV system is updated to today (version 4.1.22-1).
    I have 2 user in my OMV installation: admin and another one. I tried with both without success.
    Tried also without delay parameter.

    Code
    $ cat cookies.txt
    # Netscape HTTP Cookie File
    # https://curl.haxx.se/docs/http-cookies.html
    # This file was generated by libcurl! Edit at your own risk.
    
    
    192.168.0.5	FALSE	/	FALSE	0	X-OPENMEDIAVAULT-SESSIONID	2------deleted-----------7


    Thanks to those who want to help me.

    • Offizieller Beitrag

    --cookie-jar on the second command would write the respone to the file. You need to use --cookie to read the file you wrote in the first command.


    https://www.openmediavault.org/?p=2089

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thank you ryecoaaron: you answer solved my problem. I'm sorry I disturbed you for such a trivial mistake.
    Is there a place on the internet where all "services" and "methods" are listed in a orderly manner?



    I paste here some lines, for future reference, hoping they can also be useful to other peolpe:



    LOGIN (the file cookie.txt will be generated):

    Code
    $ curl --request POST --cookie-jar cookies.txt --data '{"service":"session","method":"login","params":{"username":"admin","password":"yourpassword"}}' 192.168.0.5/rpc.php
    
    
    {"response":{"authenticated":true,"username":"admin"},"error":null}


    Comunication test:

    Code
    $ curl --request POST --cookie cookies.txt --data '{"service":"system","method":"noop","params":null}' 192.168.0.5/rpc.php
    
    
    {"response":"I must not fear. Fear is the mind-killer. Fear is the little-death that brings total obliteration. I will face my fear. I will permit it to pass over me and through me. And when it has gone past I will turn the inner eye to see its path. Where the fear has gone there will be nothing. Only I will remain.","error":null}


    Shutdown:

    Code
    $ curl --request POST --cookie cookies.txt --data '{"service":"system","method":"shutdown","params":{"delay":10}}' 192.168.0.5/rpc.php
    
    
    {"response":null,"error":null}
    • Offizieller Beitrag

    Is there a place on the internet where all "services" and "methods" are listed in a orderly manner?

    No but you could get them from the rpc files - https://github.com/openmediava…penmediavault/engined/rpc

    omv 7.0.4-2 sandworm | 64 bit | 6.5 proxmox kernel

    plugins :: omvextrasorg 7.0 | kvm 7.0.10 | compose 7.1.2 | k8s 7.0-6 | cputemp 7.0 | mergerfs 7.0.3


    omv-extras.org plugins source code and issue tracker - github


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Hello TheFax.


    Now that I have finished the installation of my new OMV 5.x on an RPi4 as host, I was considering "building" an interface to read data from my HA system (I currently have a few settings being sent from bash scripts via MQTT).


    Would you be willing to provide more details on how you did it on hass.io? If you think this is out of scope for this forum, can you contact me directly?


    I'd like to have HD free space, temperatures, need to go through the RPC methods' info provided by ryecoaaron above.


    Thanks in advance and kind regards.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!