gitmachtl / various

Various Scripts, Tools and Stuff for everybody :-)
MIT License
12 stars 4 forks source link

returned data for UPS_ups_status= #7

Closed robocog closed 1 month ago

robocog commented 1 month ago

Trying to get this to work, and not getting my head round why it is failing

I am attempting to make my TrueNas box (192.168.57.35) "see" my server that runs apcupsd and has the UPS connected (192.168.57.100)

I can "see" my UPS from the command line on the server the UPS is attached to (192.168.57.100) as long as I "sudo" apcaccess...

sudo apcaccess

APC : 001,051,1153 DATE : 2024-09-30 20:09:46 +0100 HOSTNAME : robocog.co.uk VERSION : 3.14.14 (31 May 2016) debian UPSNAME : Robs UPS CABLE : Custom Cable Smart DRIVER : APC Smart UPS (any) UPSMODE : Stand Alone STARTTIME: 2024-09-24 20:22:25 +0100 MODEL : SMART-UPS 2200 STATUS : ONLINE LINEV : 239.2 Volts LOADPCT : 8.3 Percent BCHARGE : 100.0 Percent TIMELEFT : 170.0 Minutes MBATTCHG : 5 Percent MINTIMEL : 3 Minutes MAXTIME : 0 Seconds MAXLINEV : 241.8 Volts MINLINEV : 237.9 Volts OUTPUTV : 239.2 Volts SENSE : High DWAKE : 0 Seconds DSHUTD : 180 Seconds DLOWBATT : 2 Minutes LOTRANS : 196.0 Volts HITRANS : 253.0 Volts RETPCT : 15.0 Percent ITEMP : 35.5 C ALARMDEL : 5 Seconds BATTV : 55.0 Volts LINEFREQ : 50.0 Hz LASTXFER : Line voltage notch or spike NUMXFERS : 0 TONBATT : 0 Seconds CUMONBATT: 0 Seconds XOFFBATT : N/A SELFTEST : NO STESTI : ON STATFLAG : 0x05000008 DIPSW : 0x00 REG1 : 0x00 REG2 : 0x00 REG3 : 0x00 MANDATE : 10/19/98 SERIALNO : gs9843000287 BATTDATE : 04/09/24 NOMOUTV : 230 Volts NOMBATTV : 48.0 Volts EXTBATTS : 0 FIRMWARE : 80.11.I END APC : 2024-09-30 20:10:03 +0100

I have the upsnutwrapper.sh running and logging on the server that has the UPS attached

This is from me trying to get the TrueNAS box to see the UPS

Mon 30 Sep 20:01:06 BST 2024 REM_IP=192.168.57.35 PID=26086 LOGIN Robs_UPS Mon 30 Sep 20:01:06 BST 2024 REM_IP=192.168.57.35 PID=26086 >>> LOGIN Robs_UPS OK Mon 30 Sep 20:01:06 BST 2024 REM_IP=192.168.57.35 PID=26086 GET VAR Robs_UPS ups.status Mon 30 Sep 20:01:06 BST 2024 REM_IP=192.168.57.35 PID=26086 >>> Requested value for VAR=ups.status and UPSNAME=Robs_UPS Mon 30 Sep 20:01:06 BST 2024 REM_IP=192.168.57.35 PID=26086 >>> returned data for UPS_ups_status= Mon 30 Sep 20:01:07 BST 2024 REM_IP=192.168.57.35 PID=26101 LIST VAR Robs_UPS Mon 30 Sep 20:01:07 BST 2024 REM_IP=192.168.57.35 PID=26101 >>> Requested all VARs for UPSNAME=Robs_UPS Mon 30 Sep 20:01:07 BST 2024 REM_IP=192.168.57.35 PID=26101 >>> Poll parameters via apcaccess (interval 10s)


The log for TrueNAS ... nut plugin: nut connect: upscli_connect (192.168.57.100 3493) failed:unknown error

I have tried using "winnut" from my windows PC to see if that can get data - but that also fails

Any ideas?

gitmachtl commented 1 month ago

hi,

if you need to run the apcaccess command via sudo to show you some data, than the priviledges are set to root only i guess. do you also run the upsnutwrapper via sudo command or as root?

where is the ups name Robs_UPS coming from? is this from an entry in TrueNAS?

i am not familiar with the NUT client in TrueNAS, but if the tcpserver which is starting the upsnutwrapper.sh is having the right priviledges to get the current ups status via apcaccess, than it should run.

if you have more logs, please share.

best regards, martin

robocog commented 1 month ago

Tried both sudo and as a user

sudo tcpserver -q -c 10 -HR 0.0.0.0 3493 /usr/local/bin/upsnutwrapper.sh - I don't seem to get anything logged....

tcpserver -q -c 10 -HR 0.0.0.0 3493 /usr/local/bin/upsnutwrapper.sh - I do get logs

(logging to /tmp/upsnutwrapper.log as suggested)

Getting slightly different messages now - this is the log on the server running the UPS/apcupsd/upsnutwrapper

LOGIN Robs_UPS OK Tue 1 Oct 08:31:09 BST 2024 REM_IP=192.168.57.35 PID=16516 GET VAR Robs_UPS ups.status Tue 1 Oct 08:31:09 BST 2024 REM_IP=192.168.57.35 PID=16516 >>> Requested value for VAR=ups.status and UPSNAME=Robs_UPS Tue 1 Oct 08:31:09 BST 2024 REM_IP=192.168.57.35 PID=16516 >>> returned data for UPS_ups_status= Tue 1 Oct 08:31:10 BST 2024 REM_IP=192.168.57.35 PID=16531 LIST VAR Robs_UPS Tue 1 Oct 08:31:10 BST 2024 REM_IP=192.168.57.35 PID=16531 >>> Requested all VARs for UPSNAME=Robs_UPS Tue 1 Oct 08:31:10 BST 2024 REM_IP=192.168.57.35 PID=16531 >>> Poll parameters via apcaccess (interval 10s) Tue 1 Oct 08:31:10 BST 2024 REM_IP=192.168.57.35 PID=16531 >>> FAILED to poll parameters: Tue 1 Oct 08:31:10 BST 2024 REM_IP=192.168.57.35 PID=16531 >>> Requesting fulldata via apcaccess failed! Tue 1 Oct 08:31:10 BST 2024 REM_IP=192.168.57.35 PID=16531 >>> Exiting script Tue 1 Oct 08:31:14 BST 2024 REM_IP=192.168.57.35 PID=16516 GET VAR Robs_UPS ups.status Tue 1 Oct 08:31:14 BST 2024 REM_IP=192.168.57.35 PID=16516 >>> Requested value for VAR=ups.status and UPSNAME=Robs_UPS Tue 1 Oct 08:31:14 BST 2024 REM_IP=192.168.57.35 PID=16516 >>> returned data for UPS_ups_status= Tue 1 Oct 08:31:15 BST 2024 REM_IP=192.168.57.35 PID=16548 LIST VAR Robs_UPS Tue 1 Oct 08:31:15 BST 2024 REM_IP=192.168.57.35 PID=16548 >>> Requested all VARs for UPSNAME=Robs_UPS Tue 1 Oct 08:31:15 BST 2024 REM_IP=192.168.57.35 PID=16548 >>> Poll parameters via apcaccess (interval 10s) Tue 1 Oct 08:31:15 BST 2024 REM_IP=192.168.57.35 PID=16548 >>> FAILED to poll parameters: Tue 1 Oct 08:31:15 BST 2024 REM_IP=192.168.57.35 PID=16548 >>> Requesting fulldata via apcaccess failed! Tue 1 Oct 08:31:15 BST 2024 REM_IP=192.168.57.35 PID=16548 >>> Exiting script Tue 1 Oct 08:31:15 BST 2024 REM_IP=192.168.57.35 PID=16516 LOGOUT

So "Requesting fulldata via apcaccess failed!" I guess means just that....it is not getting data from apcaccess?

gitmachtl commented 1 month ago

so you get anything when you run apcaccess -h 127.0.0.1 as a "normal" user on your server with the ups attached?

also, can you try to rename the ups in TrueNAS to just ups or so for testing?

robocog commented 1 month ago

The TrueNAS UPS config page I HAVE to put a name for the UPS for the "Identifier"

image

robocog commented 1 month ago

set to "ups" in TrueNAS Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 USERNAME upsmon Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 >>> USERNAME upsmon OK Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 PASSWORD fixmepass Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 >>> PASSWORD fixmepass OK Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 LOGIN ups Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 >>> LOGIN ups OK Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 GET VAR ups ups.status Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 >>> Requested value for VAR=ups.status and UPSNAME=ups Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17708 >>> returned data for UPS_ups_status= Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17723 LIST VAR ups Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17723 >>> Requested all VARs for UPSNAME=ups Tue 1 Oct 08:57:39 BST 2024 REM_IP=192.168.57.35 PID=17723 >>> Poll parameters via apcaccess (interval 10s) Tue 1 Oct 08:57:40 BST 2024 REM_IP=192.168.57.35 PID=17723 >>> FAILED to poll parameters: Tue 1 Oct 08:57:40 BST 2024 REM_IP=192.168.57.35 PID=17723 >>> Requesting fulldata via apcaccess failed! Tue 1 Oct 08:57:40 BST 2024 REM_IP=192.168.57.35 PID=17723 >>> Exiting script Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17708 GET VAR ups ups.status Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17708 >>> Requested value for VAR=ups.status and UPSNAME=ups Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17708 >>> returned data for UPS_ups_status= Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17740 LIST VAR ups Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17740 >>> Requested all VARs for UPSNAME=ups Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17740 >>> Poll parameters via apcaccess (interval 10s) Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17740 >>> FAILED to poll parameters: Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17740 >>> Requesting fulldata via apcaccess failed! Tue 1 Oct 08:57:44 BST 2024 REM_IP=192.168.57.35 PID=17740 >>> Exiting script

apcaccess -h 127.0.0.1 -bash: apcaccess: command not found

robocog commented 1 month ago

I have to sudo and put the password in for apcaccess to give data

:~$ apcaccess -h 127.0.0.1 -bash: apcaccess: command not found

:~$ sudo apcaccess -h 127.0.0.1 [sudo] password for rob:

APC : 001,051,1153 DATE : 2024-10-01 09:01:53 +0100 HOSTNAME : robocog.co.uk VERSION : 3.14.14 (31 May 2016) debian UPSNAME : Robs UPS CABLE : Custom Cable Smart DRIVER : APC Smart UPS (any) UPSMODE : Stand Alone STARTTIME: 2024-09-24 20:22:25 +0100 MODEL : SMART-UPS 2200 STATUS : ONLINE LINEV : 237.9 Volts LOADPCT : 7.8 Percent BCHARGE : 100.0 Percent TIMELEFT : 170.0 Minutes MBATTCHG : 5 Percent MINTIMEL : 3 Minutes MAXTIME : 0 Seconds MAXLINEV : 240.5 Volts MINLINEV : 237.9 Volts OUTPUTV : 237.9 Volts SENSE : High DWAKE : 0 Seconds DSHUTD : 180 Seconds DLOWBATT : 2 Minutes LOTRANS : 196.0 Volts HITRANS : 253.0 Volts RETPCT : 15.0 Percent ITEMP : 34.6 C ALARMDEL : 5 Seconds BATTV : 55.0 Volts LINEFREQ : 50.0 Hz LASTXFER : Line voltage notch or spike NUMXFERS : 0 TONBATT : 0 Seconds CUMONBATT: 0 Seconds XOFFBATT : N/A SELFTEST : NO STESTI : ON STATFLAG : 0x05000008 DIPSW : 0x00 REG1 : 0x00 REG2 : 0x00 REG3 : 0x00 MANDATE : 10/19/98 SERIALNO : gs9843000287 BATTDATE : 04/09/24 NOMOUTV : 230 Volts NOMBATTV : 48.0 Volts EXTBATTS : 0 FIRMWARE : 80.11.I END APC : 2024-10-01 09:02:06 +0100

robocog commented 1 month ago

So its likely a permissions thing? Options are - change apcaccess to work as a user Get upsnutwrapper.sh to run as sudo AND log so I can see why it still fails

Not really sure on how to do either... yet

gitmachtl commented 1 month ago

:~$ apcaccess -h 127.0.0.1 -bash: apcaccess: command not found

this is your problem, the apcaccess command is not found by a normal user or process.

you can try to find the binary like: sudo which apcaccess

and than copy the binary to a location/path where it can be found by a normal user.

robocog commented 1 month ago

/sbin/apcaccess

copied to /usr/local/bin/

Now getting this in the logs Woo Hoo!

I guess it is aware it is online, and now I need to pull power and see if it does stuff....

Thank you so much for this! It is really appreciated

LOGIN ups OK Tue 1 Oct 09:27:03 BST 2024 REM_IP=192.168.57.35 PID=18797 GET VAR ups ups.status Tue 1 Oct 09:27:03 BST 2024 REM_IP=192.168.57.35 PID=18797 >>> Requested value for VAR=ups.status and UPSNAME=ups Tue 1 Oct 09:27:03 BST 2024 REM_IP=192.168.57.35 PID=18797 >>> returned data for UPS_ups_status=OL Tue 1 Oct 09:27:05 BST 2024 REM_IP=192.168.57.35 PID=18813 LIST VAR ups Tue 1 Oct 09:27:05 BST 2024 REM_IP=192.168.57.35 PID=18813 >>> Requested all VARs for UPSNAME=ups Tue 1 Oct 09:27:05 BST 2024 REM_IP=192.168.57.35 PID=18813 >>> Poll parameters via apcaccess (interval 10s) Tue 1 Oct 09:27:06 BST 2024 REM_IP=192.168.57.35 PID=18813 >>> returned all VARs Tue 1 Oct 09:27:08 BST 2024 REM_IP=192.168.57.35 PID=18797 GET VAR ups ups.status Tue 1 Oct 09:27:08 BST 2024 REM_IP=192.168.57.35 PID=18797 >>> Requested value for VAR=ups.status and UPSNAME=ups Tue 1 Oct 09:27:08 BST 2024 REM_IP=192.168.57.35 PID=18797 >>> returned data for UPS_ups_status=OL Tue 1 Oct 09:27:13 BST 2024 REM_IP=192.168.57.35 PID=18797 GET VAR ups ups.status Tue 1 Oct 09:27:13 BST 2024 REM_IP=192.168.57.35 PID=18797 >>> Requested value for VAR=ups.status and UPSNAME=ups Tue 1 Oct 09:27:13 BST 2024 REM_IP=192.168.57.35 PID=18797 >>> returned data for UPS_ups_status=OL Tue 1 Oct 09:27:15 BST 2024 REM_IP=192.168.57.35 PID=18813 LIST VAR ups Tue 1 Oct 09:27:15 BST 2024 REM_IP=192.168.57.35 PID=18813 >>> Requested all VARs for UPSNAME=ups Tue 1 Oct 09:27:15 BST 2024 REM_IP=192.168.57.35 PID=18813 >>> Poll parameters via apcaccess (interval 10s) Tue 1 Oct 09:27:15 BST 2024 REM_IP=192.168.57.35 PID=18813 >>> returned all VARs

robocog commented 1 month ago

Pulled power and it works! Amazing work, thank you once again

gitmachtl commented 1 month ago

Have you tried it again with your original ups name?

robocog commented 1 month ago

Have just gone in and changed the name in TrueNAS settings page from 'ups' to 'Robs_UPS'

Turned off the logging in the script after it was successful earlier today (not really needed now it works) so I couldn't really see if it made any difference

It seems to have made no difference to TrueNAS, and it seems 100% happy with the situation despite the name change

Just pulled the power to the UPS, and sure enough my main server and TrueNAS both warn that power is off Only let it run like that for a few seconds, then plugged it back in Got the notification messages to say that power has returned TrueNAS even gave me a nice little summary of stats...so it must be working 100% as intended

NOTIFICATION: 'ONLINE'

UPS: 'Robs_UPS'

Statistics recovered:

1) Battery runtime (seconds) battery.runtime: 9720

2) Battery runtime remaining (seconds) when UPS switches to Low Battery (LB) battery.runtime.low: 120

3) Battery charge (percent) battery.charge: 99.0

4) Battery level remaining (percent) when UPS switches to Low Battery (LB) battery.charge.low: 5

All is good :) I bet there are plenty of people wanting to use this script - what a lifesaver! (couldn't bear to tamper too much with apcupsd on the main server as it has been working flawlessly for so long) Might pop a message on the TrueNAS forum at some point as I am sure when I was finding out how to get my UPS playing nice I saw a few people this would have worked wonders for...none of them mentioned this mega fix!

I only found out about it on some other website when Googling how to try and make it work

Only struggle I had was I issued the startup command from a putty terminal - and as soon as I close that terminal if seems to kill the process I tried doing the crontab thing from within Webmin - and that seemed not to work I tried as root and as a user... I eventually fired up a terminal from within webmin and gave the command - and it seems to have stayed and worked Running Processes (that is successful) show as being owned by root and group root

tcpserver -q -c 10 -HR 0.0.0.0 3493 /usr/local/bin/upsnutwrapper.sh &

It's working for now and I guess I will have to work out what I am doing wrong for getting it to startup automatically...or just do the same again on next reboot - which is likely a long way off in the future, so have added it to the stuff I need to do after the next reboot

pidator commented 1 month ago

Here's my way to autostart the script using crontab on a debian server:

~$ sudo vim /etc/crontab

and add the following line:

@reboot root tcpserver -q -c 10 -HR 0.0.0.0 3493 /usr/local/bin/upsnutwrapper.sh &

;)

gitmachtl commented 1 month ago

I would simply put it in the crontab like: @reboot <user> tcpserver -q -c 10 -HR 0.0.0.0 3493 /usr/local/bin/upsnutwrapper.sh &

Glad that it helped you. I made it years ago and did some upgrades over the time. Best regards, Martin

gitmachtl commented 1 month ago

LOL ... ok, will close this issue now