bnhf / apcupsd-admin-plus

Docker-based solution for monitoring APC UPS units, using apcupsd and apcupsd-cgi both in containers
15 stars 3 forks source link

Issue with PVE shutdown #3

Closed vantech14 closed 4 months ago

vantech14 commented 4 months ago

Hi There,

Hope you can help me. The APCUPSD works fine, and integrated with home assistant. I have it running on an Ubuntu host, running on Proxmox. I am trying to shut down the Proxmox OS as follows:

  - PVE_SHUTDOWN_HOSTS=192.168.100.3 # Ordered list of pve hostnames (or IPs) to be used for API shutdown. Used with matching lists of $PVE_SHUTDOWN_NODES and $PVE_SHUTDOWN_TOKENS
  - 
  - PVE_SHUTDOWN_NODES=pve # Ordered list of pve nodes. Used with matching lists of $PVE_SHUTDOWN_HOSTS and $PVE_SHUTDOWN_TOKENS
  - 
  - PVE_SHUTDOWN_TOKENS=apcupsd@pve!apcupsd=bf79bae8-e061-4466-a6b5-xxxxxx # Ordered list of pve API tokens with secrets in the form <username>@<node>!<api_token>=<api_secret>`

I have also tried the full proxmox URL https://192.168.100.3:8006 and various other combinations.

However i get this error message in the logs each time:

% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: 192.168.100.3 Failed to open connection to "system" message bus: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender="(null)" (inactive) interface="org.freedesktop.DBus" member="Hello" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)

Any ideas? The Ubuntu host OS can ping this IP successfully.

Thanks.

bnhf commented 4 months ago

@vantech14

Did you give your "apcupsd" user the necessary permissions to initiate a shutdown?

My user is called "shutdown" and has these permissions:

screencapture-file-C-Users-slayer-Downloads-screenshot-pve-8006-2024-07-22-13-10-19-png-2024-07-22-13_10_52-edit

vantech14 commented 4 months ago

@vantech14

Did you give your "apcupsd" user the necessary permissions to initiate a shutdown?

My user is called "shutdown" and has these permissions:

screencapture-file-C-Users-slayer-Downloads-screenshot-pve-8006-2024-07-22-13-10-19-png-2024-07-22-13_10_52-edit

@bnhf

Here is my api setup:

image

and

image

I cant see why this isnt working. I also tried to disable apparmor on the host to no avail? The user is setup as a proxmox PVE realm rather than a PAM but i dont think this should make a difference?

Thanks.

bnhf commented 4 months ago

@vantech14

Have you tried executing the curl command to initiate a shutdown from another computer? Here's what it looks like in the script, and you can just sub-in your values in place of the env vars (everything inside and including the ${} for each HOSTS, NODES, and TOKENS):

curl "https://${HOSTS[$i]}:8006/api2/extjs/nodes/${NODES[$i]}/status" -H "Authorization: PVEAPIToken=${TOKENS[$i]}" -H "Content-Type: application/x-www-form-urlencoded" --data "command=shutdown" --insecure

If that doesn't work, I'd suggest going to the Proxmox forum, as whatever is going on is Proxmox related. I'm pretty sure there are one or two threads on the subject of API token shutdowns.

vantech14 commented 4 months ago

@vantech14

Have you tried executing the curl command to initiate a shutdown from another computer? Here's what it looks like in the script, and you can just sub-in your values in place of the env vars (everything inside and including the ${} for each HOSTS, NODES, and TOKENS):


curl "https://${HOSTS[$i]}:8006/api2/extjs/nodes/${NODES[$i]}/status" -H "Authorization: PVEAPIToken=${TOKENS[$i]}" -H "Content-Type: application/x-www-form-urlencoded" --data "command=shutdown" --insecure

If that doesn't work, I'd suggest going to the Proxmox forum, as whatever is going on is Proxmox related. I'm pretty sure there are one or two threads on the subject of API token shutdowns.

@bnhf

root@ubuntu-rpi:~# curl "https://192.168.100.3:8006/api2/extjs/nodes/pve/status" -H "Authorization: PVEAPIToken=apcupsd@pve!apcupsd=bf79bae8-e061-4466-a6b5-redacted" -H "Content-Type: application/x-www-form-urlencoded" --data "command=shutdown" --insecure -bash: !apcupsd=bf79bae8: event not found

Suggests there is an issue with the format of the username?

Command issued:

curl "https://192.168.100.3:8006/api2/extjs/nodes/pve/status" -H "Authorization: PVEAPIToken=apcupsd@pve!apcupsd=bf79bae8-e061-4466-a6b5-redacted" -H "Content-Type: application/x-www-form-urlencoded" --data "command=shutdown" --insecure

Hmm?

bnhf commented 4 months ago

@vantech14

Try replacing the double quotes with single quotes for use on the command line.

vantech14 commented 4 months ago

@bnhf i resolved. The issue was that the user needed the same permissions as the API token. I at first only setup access for the API token.

image

` - PVE_SHUTDOWN_HOSTS=192.168.100.3 # Ordered list of pve hostnames (or IPs) to be used for API shutdown. Used with matching lists of $PVE_SHUTDOWN_NODES and $PVE_SHUTDOWN_TOKENS

Thanks for your help!