====== UPS - Onduleur ====== ===== NUT & apcusbd ===== Voir https://github.com/riptidewave93/UPSalert & https://servernetworktech.com/2013/06/upsalert-my-solution-to-graceful-server-shutdowns-on-power-loss/ Avec ''NUT'' : * http://networkupstools.org * https://doc.ubuntu-fr.org/nut * https://www.mathstat.dal.ca/~selinger/ups/backups.html * https://wiki.debian-fr.xyz/Configurer_et_surveiller_un_onduleur_avec_NUT * http://www.zem.fr/monitorer-son-onduleur-sous-linux/ Avec ''apcusbd'' : * https://help.ubuntu.com/community/apcupsd * https://blog.crifo.org/post/2010/01/04/Gerer-un-onduleur-avec-ubuntu * https://www.cyberciti.biz/faq/debian-ubuntu-centos-rhel-install-apcups * https://rmoff.net/2016/07/18/configuring-ups-apcupsd * Et bien-sur, le manuel officiel : http://www.apcupsd.org/manual/manual.html ===== Installation avec apcusbd (parce que) ===== Installation : apt-get install apcusbd On récupère l'id de l'onduleur en USB : lsusb Et on vérifie qu'il est bien détecté : Bus 006 Device 002: ID 051d:0002 American Power Conversion Uninterruptible Power Supply ===== Configuration de apcusbd ===== nano /etc/apcupsd/apcupsd.conf [***] #On lui choisit un nom UPSNAME apc700 [***] #Son type de câble UPSCABLE usb [***] #Son type de connexion, avec ou sans usb IP pour l’auto-détection #Si on veut spécifier le device : #UPSTYPE usb 051d:0002 UPSTYPE usb #Supprimer toute entrée après DEVICE DEVICE [***] #On peut laisser les timers par défaut, sinon, les modifier On teste enfin la configuration : service apcupsd start service apcupsd status Tout doit être OK : ● apcupsd.service - UPS power management daemon Loaded: loaded (/lib/systemd/system/apcupsd.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2018-03-19 15:45:41 CET; 2s ago Docs: man:apcupsd(8) Process: 8370 ExecStart=/sbin/apcupsd (code=exited, status=0/SUCCESS) Process: 8360 ExecStartPre=/lib/apcupsd/prestart (code=exited, status=0/SUCCESS) Main PID: 8371 (apcupsd) Tasks: 3 (limit: 4915) Memory: 1.0M CPU: 10ms CGroup: /system.slice/apcupsd.service └─8371 /sbin/apcupsd mars 19 15:45:41 proxmox01.libox.local systemd[1]: Starting UPS power management daemon... mars 19 15:45:41 proxmox01.libox.local apcupsd[8371]: apcupsd 3.14.14 (31 May 2016) debian startup succeeded mars 19 15:45:41 proxmox01.libox.local apcupsd[8371]: NIS server startup succeeded mars 19 15:45:41 proxmox01.libox.local systemd[1]: Started UPS power management daemon. ===== Tests ===== apcaccess Renvoi : APC : 001,036,0888 DATE : 2018-03-19 15:48:18 +0100 HOSTNAME : proxmox01.libox.local VERSION : 3.14.14 (31 May 2016) debian UPSNAME : apcusb700 CABLE : USB Cable DRIVER : USB UPS Driver UPSMODE : Stand Alone STARTTIME: 2018-03-19 15:45:41 +0100 MODEL : Back-UPS XS 700U STATUS : ONLINE LINEV : 230.0 Volts LOADPCT : 68.0 Percent BCHARGE : 98.0 Percent TIMELEFT : 3.9 Minutes MBATTCHG : 5 Percent MINTIMEL : 3 Minutes MAXTIME : 0 Seconds SENSE : Medium LOTRANS : 140.0 Volts HITRANS : 300.0 Volts ALARMDEL : 30 Seconds BATTV : 13.8 Volts LASTXFER : Automatic or explicit self test NUMXFERS : 0 TONBATT : 0 Seconds CUMONBATT: 0 Seconds XOFFBATT : N/A SELFTEST : OK STATFLAG : 0x05000008 SERIALNO : *** BATTDATE : 2017-11-18 NOMINV : 230 Volts NOMBATTV : 12.0 Volts NOMPOWER : 390 Watts FIRMWARE : 924.Z3 .I USB FW:Z3 END APC : 2018-03-19 15:48:26 +0100 Et pour tester la communication, on stop le service avant : service apcupsd stop #Et on lance le test : apctest Qui lui renvoie : 2018-03-19 15:51:14 apctest 3.14.14 (31 May 2016) debian Checking configuration ... sharenet.type = Network & ShareUPS Disabled cable.type = USB Cable mode.type = USB UPS Driver Setting up the port ... Doing prep_device() ... You are using a USB cable type, so I'm entering USB test mode Hello, this is the apcupsd Cable Test program. This part of apctest is for testing USB UPSes. Getting UPS capabilities...SUCCESS Please select the function you want to perform. 1) Test kill UPS power 2) Perform self-test 3) Read last self-test result 4) View/Change battery date 5) View manufacturing date 6) View/Change alarm behavior 7) View/Change sensitivity 8) View/Change low transfer voltage 9) View/Change high transfer voltage 10) Perform battery calibration 11) Test alarm 12) View/Change self-test interval Q) Quit Ne pas hésiter à tester l'alarme, pour emmerder les gens autour, et surtout, relancer le service : service apcupsd start ===== Logs ===== Voir les logs d'activité : tail -f /var/log/apcupsd.events 2018-03-19 15:45:41 +0100 apcupsd 3.14.14 (31 May 2016) debian startup succeeded 2018-03-19 15:51:10 +0100 apcupsd exiting, signal 15 2018-03-19 15:51:10 +0100 apcupsd shutdown succeeded 2018-03-19 15:58:32 +0100 apcupsd 3.14.14 (31 May 2016) debian startup succeeded 2018-03-19 16:02:27 +0100 Power failure. 2018-03-19 16:02:33 +0100 Running on UPS batteries. Diffusion de message de root@proxmox01.libox.local (somewhere) (Mon Mar 19 16:0 Power failure on UPS apcusb700. Running on batteries. 2018-03-19 16:02:33 +0100 Mains returned. No longer on UPS batteries. 2018-03-19 16:02:33 +0100 Power is back. UPS running on mains. Diffusion de message de root@proxmox01.libox.local (somewhere) (Mon Mar 19 16:0 Power has returned on UPS apcusb700... ===== Bonus 1 - Script Telegraf ===== Voir : https://bitbucket.org/snippets/wnasich/7Kg89/telegraf-input-for-apc-ups-status-using > /tmp/upsapcevents.log ---- * Enable inputs.tail at /etc/telegraf/telegraf.conf Spec next settings: files = ["/tmp/upsapcevents.log"] from_beginning = false data_format = "influx" Restart telegraf. Data will be collected under measurement 'ups_apc'. */ // Check php.ini for proper timezone or uncomment next line // date_default_timezone_set('[your zone]'); // http://php.net/manual/en/timezones.php $tagsMap = array( 'UPSNAME' => 'ups_name', // UPS name from configuration file (dumb) or EEPROM (smart) 'SERIALNO' => 'serial_no', // UPS serial number ); $fieldsMap = array( 'DATE' => 'time', // Date and time of last update from UPS 'STATUS' => 'status', // UPS status (online, charging, on battery etc) 'LINEV' => 'input_line_voltage', // Current input line voltage 'LOADPCT' => 'load_capacity_used', // Percentage of UPS load capacity used as estimated by UPS 'BCHARGE' => 'battery_capacity_charge', // Current battery capacity charge percentage 'TIMELEFT' => 'runtime_left_minutes', // Remaining runtime left on battery as estimated by the UPS 'OUTPUTV' => 'output_voltage', // Current UPS output voltage 'ITEMP' => 'internal_temperature_celcius', // UPS internal temperature in degrees Celcius 'BATTV' => 'battery_voltage', // Current battery voltage 'LINEFREQ' => 'line_frequency_hz', // Current line frequency in Hertz 'TONBATT' => 'time_on_battery_seconds', // Seconds currently on battery ); $influxTags = array(); $influxFields = array(); $timestamp = null; while ($line = fgets(STDIN)) { $match = array(); $result = preg_match('/([A-Z ]+):(.*)/', $line, $match); if (!$result) { continue; } $key = trim($match[1]); $value = trim($match[2]); if ($key === 'DATE') { $time = new DateTime($value); $timestamp = $time->getTimestamp(); continue; } if (array_key_exists($key, $tagsMap)) { $value = str_replace(',', '\,', $value); $value = str_replace(' ', '\ ', $value); $influxTags[$tagsMap[$key]] = $value; } if (array_key_exists($key, $fieldsMap)) { if ($key === 'STATUS') { $value = '"' . trim($value) . '"'; } else { $value = preg_replace('/[^0-9\.]*/', '', $value); } $influxFields[$fieldsMap[$key]] = $value; } } if ($timestamp) { // Tags should be sorted by key before being sent for best performance of InfluxDB ksort($influxTags); $lineProtocolTags = array(); foreach ($influxTags as $name => $value) { $lineProtocolTags[] = $name . '=' . $value; } $lineProtocolFields = array(); foreach ($influxFields as $name => $value) { $lineProtocolFields[] = $name . '=' . $value; } echo 'ups_apc,' . join(',', $lineProtocolTags) . ' ' . join(',', $lineProtocolFields) . ' ' . $timestamp . '000000000'; } ===== Bonus 2 - Suivi web ===== On installe le paquet : #Bah oui, Apache pour les CGI apt-get install apcupsd-cgi apache2 On active les CGI sur Apache si pas déjà dispos : #Il se peut qu'il active à la place cgid, normal a2enmod cgi #On active au niveau de la configuration du site, on peut toucher au reste si on veut aussi, le tout sur le port 80 par défaut, Proxmox étant sur le 8006 aucun problème nano sites-enabled/000-default.conf [...] #On décommente : Include conf-available/serve-cgi-bin.conf [...] On relance Apache, et on vérifie la page ''http://[proxmox-host]/cgi-bin/apcupsd/multimon.cgi'' : service apache2 restart Ce qui doit nous afficher : {{ ::screenshot-2018-3-19_multimon_ups_status_page.png?nolink |}} Et : {{ ::screenshot-2018-3-19_127_0_0_1_ups_status.png?nolink |}} ===== Bonus 3 - Suivi en environnement graphique ===== On installera juste le paquet ''gapcmon'' : apt-get install gapcmon