Мониторинг UPS APC и EATON
Сборник рецептов для мониторинга и управления УПС
Cкрипт мониторинга APC и EATON, оснащенных сетевыми платами посредством SNMP
Не секрет, что ПО для мониторинга состояния UPS тяжеловесно и не бесплатно. Установка Zabbix только для этой задачи громоздка
Требуется установленный Apache/nginx и PHP с модулем php-snmp.
Отредактируйте массивы $urls для Eatonов и $urls2 для APC, разрешите SNMP-1 public на чтениеp и настройте крон для отправки ежедневных писем.
<?php // apt-get install php-snmp // snmp 1 public readonly $urls = array( // eatons "192.168.1.55",
"192.168.1.57",
"192.168.1.16",
"192.168.1.60"
); $urls2 = array( // APC "192.168.1.25", "192.168.1.239",
"192.168.1.230",
"192.168.1.231" ); // APC OIDs: // https://www.opsview.com/resources/monitoring/blog/monitoring-apc-ups-useful-oids // https://wiki.it-kb.ru/apc/apc-nmc-oids-for-snmp-monitoring // EATON OIDs // https://wiki.it-kb.ru/eaton/eaton-powerware-nmc-oids-for-snmp-monitoring // if(isset($_GET['act'])) $act=$_GET["act"]; else $act=''; $act=$argv[1]; #$db = new SQLite3(dirname(__FILE__).'/phpliteadmin/stats.db'); $pr="<html><body><table width= \"100%\" border=\"1\" cellpadding='5' cellspacing=\"0\"> <tr bgcolor=\"#ddd\" style=\"background-color:#ddd\"> <td>IP</td> <td>Расположение</td> <td>Модель</td> <td>Источник питания</td> <td>Нагрузка<br />%</td> <td>Зарядка<br />%</td> <td>Оставшееся<br>время</td> <td>Состояние<br />батареи</td> <td>Температура <br />(вн/нар)/Влажн.</td> </tr>"; for ($i = 0; $i<count($urls); $i++) { $pr.="<tr><td><a href=\"http://".$urls[$i]."/\" target=\"_blank\">".$urls[$i]."</a></td>"; $session = new SNMP(SNMP::VERSION_1, $urls[$i], "public"); $session->valueretrieval = SNMP_VALUE_PLAIN; $s = $session->walk("1.3.6.1.2.1.1.5.0", TRUE); foreach ($s as $val) { $pr.= "<td><b>$val</b></td>"; } $s = $session->walk("1.3.6.1.2.1.33.1.1.2.0", TRUE); foreach ($s as $val) { $pr.= "<td><b><font color=\"#00f\" style=\"color:#00f;\">$val</font></b></td>"; } $s = $session->walk("1.3.6.1.4.1.534.1.3.4.1.2.1", TRUE); foreach ($s as $val) { $pr.= "<td>$val Volt</b></td>"; } $s = $session->walk("1.3.6.1.4.1.534.1.4.1.0", TRUE); foreach ($s as $val) { $pr.= "<td align='right'></b>$val %</td>"; } $s = $session->walk("1.3.6.1.4.1.534.1.2.4.0", TRUE); foreach ($s as $val) { $pr.= "<td align='right'>$val %</td>"; } $s = $session->walk("1.3.6.1.4.1.534.1.2.1.0", TRUE); foreach ($s as $val) { $pr.= "<td>".round($val/60)." min</td>"; } $s = $session->walk("1.3.6.1.4.1.705.1.5.9.0", TRUE); foreach ($s as $val) if($val=="2") $res1 = 2; else $res1 = 1; $s = $session->walk("1.3.6.1.4.1.705.1.5.15.0", TRUE); foreach ($s as $val) if($val=="2") $res2 = 2; else $res2 = 1; $s = $session->walk("1.3.6.1.4.1.705.1.5.11.0", TRUE); foreach ($s as $val) if($val=="2") $res3 = 2; else $res3 = 1; if($res1==2 && $res2==2 && $res3==2) $pr.="<td bgcolor=\"#9d9\" style=\"background-color:#9d9\">OK</td>"; else $pr.="<td bgcolor=\"#d99\" style=\"background-color:#d99\">fault</td>"; $s = $session->walk("1.3.6.1.4.1.534.1.6.1.0", TRUE); foreach ($s as $val) { $pr.= "<td>$val °C / "; } $s = $session->walk("1.3.6.1.4.1.534.1.6.5.0", TRUE); foreach ($s as $val) { $pr.= " $val °C /"; } $s = $session->walk("1.3.6.1.4.1.534.1.6.6.0", TRUE); foreach ($s as $val) { $pr.= " $val %</td>"; } $session->close(); $pr.="</tr>\r\n"; } for ($i = 0; $i<count($urls2); $i++) { $pr.="<tr><td><a href=\"http://".$urls2[$i]."/\" target=\"_blank\">".$urls2[$i]."</a></td>"; $session = new SNMP(SNMP::VERSION_1, $urls2[$i], "public"); $session->valueretrieval = SNMP_VALUE_PLAIN; $s = $session->walk("1.3.6.1.4.1.318.1.1.1.1.1.2.0", TRUE); foreach ($s as $val) { $pr.= "<td><b>$val</font></b></td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.1.1.1.0", TRUE); foreach ($s as $val) { $pr.= "<td><b><font color=\"#f00\" style=\"color:#f00;\">$val</font></b></td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.3.2.1.0", TRUE); foreach ($s as $val) { $pr.= "<td>$val Volt</b></td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.4.2.3.0", TRUE); foreach ($s as $val) { $pr.= "<td align='right'></b>$val %</td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.1.0", TRUE); foreach ($s as $val) { $pr.= "<td align='right'>$val %</td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.3.0", TRUE); foreach ($s as $val) { $pr.= "<td>".($val/100/60)." min</td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.4.0", TRUE); foreach ($s as $val) if($val=="1") { $pr.= "<td bgcolor=\"#9d9\" style=\"background-color:#9d9\">OK</td>"; } else { $pr.= "<td bgcolor=\"#d99\" style=\"background-color:#d99\">fault</td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.2.0", TRUE); foreach ($s as $val) { $pr.= "<td>$val °C /"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.25.1.2.1.6", TRUE); foreach ($s as $val) { $pr.= "$val °C /"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.25.1.2.1.7", TRUE); foreach ($s as $val) { $pr.= "$val %</td>"; } $s = $session->walk("1.3.6.1.4.1.318.1.1.1.3.2.5.0", TRUE); // Reason for last transfer foreach ($s as $val) { $pr.= "<td>LTtB:$val</td>"; } $session->close(); $pr.="</tr>\r\n"; } $pr.="</table>"; $pr.="<br /><font color=\"#00f\" style=\"color:#00f;\">EATON</font> <font color=\"#f00\" style=\"color:#f00;\">APC</font><br />"; $pr.="APC reason for last transfer (LTtB) to battery power<br /> <p>1 No events<br /> 2 High line voltage<br /> 3 Brownout<br /> 4 Loss of mains power<br /> 5 Small temporary power drop<br /> 6 Large temporary power drop<br /> 7 Small spike<br /> 8 Large spike<br /> 9 UPS self test<br /> 10 Excessive input voltage fluctuation</p><br /> <a href=\"#\">Обновить скрипт УПС</a></body></html>"; if($act=='') echo $pr; if($act=='dailyreport') { $to="st@domain.ru"; // Адрес получателя $subject="UPSs daily report"; $body="$pr"; $headers = "Content-type: text/html; charset=utf-8\r\n"; $headers .= "From: ups@domain.ru "; mail($to, $subject, $body, $headers); } ?>
Протокол работы Smart APC
Как создать плату мониторинга на основе esp8266 рассказано тут
Используется специальный (с хитрым распаем) кабель.
Скорость соединения 2400.
Основные Команды
Y Enter smart mode SM
R Exit smart mode SM
^A Model string SMART-UPS 700
^N Turn on UPS
K 1?5s K Turn off 237.9
L Input line voltage
P Power load % 000.0
Q Status flags 08
08 = on line, battery OK
10 = on battery, battery OK
50 = on battery, battery low
Z Shutdown immediately n/a
f Battery level 099.0
Сообщения
!!! нет входного напряжения
$ появление входного напряжения
Более подробно отсюда
Character | Meaning | Typical results | Other info | ||||||
---|---|---|---|---|---|---|---|---|---|
|
Model string |
|
Spotty support for this query on older models |
||||||
|
Turn on UPS |
n/a |
Send twice with > 1.5s delay between chars Only on 3rd gen SmartUPS and Black Back-UPS Pros |
||||||
|
Capability string |
(long string) |
See "Capabilities" section for more info |
||||||
|
Front panel test |
Light show + " |
Also sounds the beeper for 2 seconds |
||||||
|
Battery voltage |
|
This obviously varies a lot based on the current charge. Compare this to the nominal battery voltage |
||||||
|
Internal temperature |
|
Units are degrees C |
||||||
|
Runtime calibration |
|
Runs until battery is below 25% (35% for Matrix) This updates the Can be aborted with a second " |
||||||
|
Automatic selftest intervals |
|
Writable variable Values:
|
||||||
|
Line frequency, Hz |
|
If this varies much, have a word with your local electrician |
||||||
|
Cause of transfer |
|
Writable variable Values:
|
||||||
|
Measure-UPS: Alarm enable |
|
(not yet decoded)(bitmapped table, coming soon) |
||||||
|
Measure-UPS: Alarm status |
|
(not yet decoded)(bitmapped table, coming soon) |
||||||
|
Shutdown with grace period |
|
Send twice with > 1.5s delay between chars Older units may send " Also see grace period |
||||||
|
Input line voltage |
|
Does not necessarily read |
||||||
|
Maximum line voltage |
|
This is the max voltage since the last time this query was run |
||||||
|
Minimum line voltage |
|
Like the one above, this one also resets itself on every query |
||||||
|
Output voltage |
|
Also see on battery output voltage |
||||||
|
Power load % |
|
Relative to the capacity of the UPS |
||||||
|
Status flags |
|
See status flags section for more info |
||||||
|
Turn dumb |
|
Only on 3rd gen Smart-UPS, Smart-UPS v/s, Back-UPS Pro UPS must receive command to enter smart mode continue communications after sending this |
||||||
|
Soft shutdown |
|
Command executes after grace period UPS goes online when power returns Only works when on battery |
||||||
|
Simulate power failure |
|
See async notifier section for info on |
||||||
|
Firmware revision |
|
Can be used to determine abilities of hardware |
||||||
|
Self test |
|
Tests battery, like pushing the test button on the front panel Also see test results entry |
||||||
|
Self-test results |
|
Values:
|
||||||
|
Enter smart mode |
|
This must be sent before anything else on this page will work. Also see turn dumb command to exit smart mode |
||||||
|
Shutdown immediately |
n/a |
Send twice with > 1.5s delay between chars UPS switches the load off immediately (no grace period) |
||||||
|
Protocol info |
(long string) |
Returns three main sections:
Sections are separated with a period |
||||||
|
Firmware revision |
|
Decoding above info:
|
||||||
|
UPS local id |
|
Writable variable Up to 8 letter identifier for keeping track of your hardware |
||||||
|
Return threshold |
|
Writable variable Minimum battery charge % to return from shutdown after power returns Values:
This prevents excessive cycling during multiple power failures |
||||||
|
Nominal battery voltage |
|
The battery voltage that’s expected to be present in the UPS normally Compare to the actual voltage reading |
||||||
|
Battery level |
|
Percentage It’s much easier to use this rather than doing math on the current battery voltage and the nominal battery voltage |
||||||
|
Measure-UPS: Ambient humidity |
|
Percentage Only works on models with the Measure-UPS SmartSlot card |
||||||
|
Measure-UPS: Dry contacts |
|
Bitmapped hex variable Component values:
|
||||||
|
Estimated runtime |
|
Minutes Must be calibrated to be effective |
||||||
|
Alarm delay |
|
Writable variable Values:
Does not affect low battery warning |
||||||
|
Low transfer voltage |
|
Writable variable See capabilities to get values for a UPS UPS goes on battery after voltage drops below this point |
||||||
|
Manufacturing date |
|
Format may vary by country ( |
||||||
|
Serial number |
|
Unique for each UPS |
||||||
|
On-battery voltage |
|
May be a writable variable on 220/230/240 VAC units |
||||||
|
Shutdown grace delay |
|
Writable variable - seconds See capabilities to read values Sets the delay before soft shutdown completes |
||||||
|
Low battery warning |
|
Writable variable - minutes See capabilities to read values The UPS will report a low battery this many minutes before it runs out of power |
||||||
|
Wakeup delay |
|
Writable variable - seconds See capabilities to read values The UPS will wait this many seconds after reaching the minimum charge before returning online |
||||||
|
Sensitivity |
|
Writable variable See capabilities to read values Meaning of values:
|
||||||
|
Upper transfer voltage |
|
Writable variable See capabilities to read values UPS goes on battery after voltage rises above this point |
||||||
|
Measure-UPS: Firmware |
|
Firmware information for Measure-UPS board |
||||||
|
Measure-UPS: Ambient temperature |
|
Degrees C Only works on models with the Measure-UPS SmartSlot card |
||||||
|
Last battery change |
|
Writable variable This holds whatever the user sets in it, much like the UPS local id variable |
||||||
|
Copyright notice |
|
Only works if firmware letter is later than |
||||||
|
Reset to factory settings |
|
Resets most variables to initial factory values except identity or battery change date Not on SmartUPS v/s or BackUPS Pro |
||||||
|
Capability cycle |
(various) |
Cycle through possible capability values UPS sends |
||||||
|
Shutdown and return |
|
UPS shuts down after grace period with delayed wakeup after Some older models send |
||||||
|
Abort shutdown |
|
Abort shutdown - use to abort Also known as the delete key in some places |
||||||
|
Register #1 |
n/a |
See register 1 table |
||||||
|
Register #2 |
n/a |
See register 2 table |
||||||
|
Dip switch positions |
n/a |
See dip switch table Only makes sense on models which actually have dip switches |
||||||
|
Register #3 |
n/a |
See register 3 table |
||||||
|
Line quality |
|
Values
|
||||||
|
Battery packs |
n/a |
SmartCell models: returns number of connected packs Non-SmartCell models: returns number set by user (use |
||||||
|
Measure-UPS: Upper temp limit |
|
Degrees C Writable variable Values: Use |
||||||
|
Measure-UPS: Lower temp limit |
|
Degrees C Writable variable See lower temp limit above |
||||||
|
Measure-UPS: Upper humidity limit |
|
% Writable variable Values: Use |
||||||
|
Measure-UPS: Lower humidity limit |
|
% Writable variable Values: Use |
||||||
Matrix-UPS and Symmetra commands |
|||||||||
|
Run in bypass mode |
n/a |
If online, " If already in bypass, " If UPS can’t transfer, " |
||||||
|
Number of bad battery packs |
|
Returns count of bad packs connected to the UPS |
||||||
|
Load current |
n/a |
True RMS load current drawn by UPS |
||||||
|
Apparent load power |
n/a |
Output load as percentage of full rated load |
||||||
|
Output voltage selection |
n/a |
Writable variable Values:
|
||||||
|
Front panel language |
n/a |
Writable variable Values:
|
||||||
|
Run time conservation |
n/a |
Writable variable Values:
|
Информация по форматам клемм батарей:
Как правило, батареи с клеммами F1 используются в слаботочных приборах, охранная сигнализация и тд.) В ИБП используются батареи с клеммами F2
Формат | F1 | F2 |
длина | 6,35 | 7,95 |
ширина | 4,75 | 6,35 |
Настройка apcupsd
apt install apcupsd setserial
Проверка портов сервера
setserial /dev/ttyS0
Lisolog (C) / 2023