Articles - Logiciel & scripts

Démon apcupsd sur onduleur vintage en SNMP

  |   794  |   Commentaires (2)  |  Logiciel & scripts
Depuis mon emménagement je n'ai pas pris le temps de bien raccorder mon onduleur informatiquement parlant sur mon "serveur" NAS 24/7. La flemme.

Cet onduleur APC Smart-UPS 1000 je l'aime bien car il a sa carte Web/SNMP qui permet de lui donner des fonctions intéressantes, autant les exploiter.

Cet UPS embarque aussi un connecteur RS-232C (attention brochage non standard) mais la carte mère Asrock H87M n'a plus ce type de port en accès direct soudé sans devoir ouvrir le PC et installer une équerre DE9.

Comme expliqué récemment, mon PC-NAS cerise est en Wi-Fi, par conséquent le port réseau (réparé à l'époque) est libre. Donc j'ai utilisé un RJ-45 direct entre l'onduleur et cerise. Il faut donc bien définir les métriques pour les interfaces réseau. Le WiFi doit être privilégié pour sortir et atteindre Internet.

Code BASH :
root@cerise:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto enp4s0
iface enp4s0 inet static
address 192.168.1.1
netmask 255.255.255.0
metric 2
#Wifi
auto wlxd0374511a96f
iface wlxd0374511a96f inet dhcp
        wpa-ssid X
        wpa-psk X
        #wireless-power off
        post-up iwconfig wlxd0374511a96f power off
metric 1
#Wifi
auto wlp5s0
iface wlp5s0 inet dhcp
        wpa-ssid X
        wpa-psk X
        #wireless-power off
        post-up iwconfig wlp5s0 power off
metric 0


Code BASH :
root@cerise:~# ip r
default via 192.168.0.254 dev wlp5s0
192.168.0.0/24 dev wlp5s0 proto kernel scope link src 192.168.0.12
192.168.1.0/24 dev enp4s0 proto kernel scope link src 192.168.1.1 metric 2
192.168.123.0/24 dev virbr0 proto kernel scope link src 192.168.123.1
 


192.168.0.0/24 pour le WiFi et internet 0.0.0.0.
192.168.1.0/24 pour l'onduleur APC (192.168.1.2).
192.168.123.0/24 pour les machines virtuelles.
Le mieux étant de passer par un navigateur internet, bon l'interface est old school hein.



Sinon en telnet :

Code BASH :
root@cerise:/var/log# telnet 192.168.1.2
Trying 192.168.1.2...
Connected to 192.168.1.2.
Escape character is '^]'.
User Name : apc
Password  : ***
American Power Conversion               Web/SNMP Management Card AOS   v3.2.6.b
(c) Copyright 2000 All Rights Reserved  Smart-UPS & Matrix-UPS APP     v3.2.6.a
-------------------------------------------------------------------------------
Name      : DUPRE Jonathan              Date    : 06/27/2021
Contact   : DUPRE Jonathan              Time    : 16:14:02
Location  : FRANCE                      Up Time : 0 Days 1 Hour 4 Minutes
Status    : P+ N+ A+                    User    : Administrator
Smart-UPS 1000 named ATELIER  : On
------- Control Console -------------------------------------------------------
     1- Device Manager
     2- Network
     3- System
     4- Logout
     <ESC>- Main Menu, <ENTER>- Refresh, <CTRL-L>- Event Log
> 1
------- Device Manager --------------------------------------------------------
     1- Smart-UPS 1000
     <ESC>- Back, <ENTER>- Refresh, <CTRL-L>- Event Log
> 1
------- Smart-UPS 1000 --------------------------------------------------------
        Status of UPS : On
        Last Transfer : Due to software command or UPSs test control.
        -----------------------------------------------------------------------
        Input Voltage    : 231.4 VAC         Operating Frequency : 50.00 Hz
        Output Voltage   : 231.4 VAC         Internal Temperature: 038.7 C
        Load Power       : 004.6 % Watts     Battery Voltage     : 27.60 VDC
        Max Line Voltage : 235.3 VAC         Battery Capacity    : 100.0 %
        Min Line Voltage : 230.1 VAC         Runtime Remaining   : 0073 min
        -----------------------------------------------------------------------
        Self-Test Result : Passed            Calibration Result  : Passed
        Self-Test Date   : 06/23/2021        Calibration Date    : 04/18/2018
     1- Control
     2- Configuration
     3- Detailed Status
     4- About UPS
     <ESC>- Back, <ENTER>- Refresh, <CTRL-L>- Event Log
> 4
------- About Smart-UPS 1000 named ATELIER  -----------------------------------
        Serial Number     : GS9920005848     Firmware Revision : 60.11.I
        Manufacture Date  : 05/12/99
        Press <ENTER> to continue...
------- Smart-UPS 1000 --------------------------------------------------------
        Status of UPS : On
        Last Transfer : Due to software command or UPSs test control.
        -----------------------------------------------------------------------
        Input Voltage    : 232.7 VAC         Operating Frequency : 50.00 Hz
        Output Voltage   : 232.7 VAC         Internal Temperature: 038.7 C
        Load Power       : 004.6 % Watts     Battery Voltage     : 27.60 VDC
        Max Line Voltage : 235.3 VAC         Battery Capacity    : 100.0 %
        Min Line Voltage : 230.1 VAC         Runtime Remaining   : 0073 min
        -----------------------------------------------------------------------
        Self-Test Result : Passed            Calibration Result  : Passed
        Self-Test Date   : 06/23/2021        Calibration Date    : 04/18/2018
     1- Control
     2- Configuration
     3- Detailed Status
     4- About UPS
     <ESC>- Back, <ENTER>- Refresh, <CTRL-L>- Event Log
> Connection closed by foreign host.
 


Sinon installer un petit reverse proxy, le but étant de taper un port particulier pour atteindre directement l'onduleur en web :

Code BASH :
root@cerise:/etc/apache2/sites-available# cat 007-apcups.conf
Listen 8082
<VirtualHost *:8082>
    ProxyPreserveHost On
    ProxyPass / http://192.168.1.2:80/
    ProxyPassReverse / http://192.168.1.2:80/
</VirtualHost>
 




Reste à installer le paquet apcupsd intégré à Debian/Ubuntu.

Code BASH :
apt install apcpusd


Il faut ensuite modifier le fichier apcupsd.conf. Par défaut il est configuré pour de l'USB et le démon passe en zombie.
Pour ma part j'ai choisi le mode SNMP, il faut donc mettre les bonnes valeurs et relancer.

Code TEXT :
UPSCABLE ether
UPSTYPE snmp
DEVICE 192.168.1.2:161:APC:public


J'ai activé le log de l'état de l'onduleur toutes les 5 minutes dans le fichier STATFILE /var/log/apcupsd.status.

Code TEXT :
STATTIME 300


Voila maintenant mon PC-NAS sera stoppé correctement à la prochaine coupure de courant. Les seuils sont paramétrables.

Code BASH :
root@cerise:~# apcaccess
APC      : 001,046,1040
DATE     : 2021-06-27 16:27:41 +0200
HOSTNAME : cerise
VERSION  : 3.14.14 (31 May 2016) debian
UPSNAME  : ATELIER
CABLE    : Ethernet Link
DRIVER   : SNMP UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2021-06-27 15:47:30 +0200
MODEL    : SMART-UPS 1000
STATUS   : ONLINE
LINEV    : 234.0 Volts
LOADPCT  : 4.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 73.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
MAXLINEV : 236.0 Volts
MINLINEV : 230.0 Volts
OUTPUTV  : 234.0 Volts
SENSE    : Medium
DWAKE    : 0 Seconds
DSHUTD   : 20 Seconds
DLOWBATT : 5 Minutes
LOTRANS  : 204.0 Volts
HITRANS  : 253.0 Volts
RETPCT   : 15.0 Percent
ITEMP    : 38.0 C
ALARMDEL : 5 Seconds
LINEFREQ : 50.0 Hz
LASTXFER : No transfers since turnon
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : OK
STESTI   : 168
STATFLAG : 0x05000008
MANDATE  : 05/12/99
SERIALNO : GS9920005848
BATTDATE : 10/22/13
NOMOUTV  : 230 Volts
EXTBATTS : 0
BADBATTS : 0
FIRMWARE : 60.11.I
END APC  : 2021-06-27 16:28:21 +0200
 


Explications des valeurs : https://linux.die.net/man/8/apcaccess

Code BASH :
root@cerise:~# systemctl status apcupsd
● apcupsd.service - UPS power management daemon
     Loaded: loaded (/lib/systemd/system/apcupsd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-06-27 15:47:30 CEST; 43min ago
       Docs: man:apcupsd(8)
    Process: 5613 ExecStartPre=/lib/apcupsd/prestart (code=exited, status=0/SUCCESS)
    Process: 5631 ExecStart=/sbin/apcupsd (code=exited, status=0/SUCCESS)
   Main PID: 5632 (apcupsd)
      Tasks: 3 (limit: 9332)
     Memory: 1.0M
     CGroup: /system.slice/apcupsd.service
             └─5632 /sbin/apcupsd
juin 27 15:47:30 cerise systemd[1]: Starting UPS power management daemon...
juin 27 15:47:30 cerise systemd[1]: apcupsd.service: Cant open PID file /run/apcupsd.pid (yet?) after start: Operation not permitted
juin 27 15:47:30 cerise apcupsd[5632]: apcupsd 3.14.14 (31 May 2016) debian startup succeeded
juin 27 15:47:30 cerise apcupsd[5632]: NIS server startup succeeded
juin 27 15:47:30 cerise systemd[1]: Started UPS power management daemon.
root@cerise:~# netstat -a | grep 3551
tcp        0      0 cerise:3551             0.0.0.0:*               LISTEN
tcp        0      0 cerise:52018            cerise:3551             TIME_WAIT
root@cerise:~#