
Мониторинг UPS APC и EATON на PHP
Не секрет, что ПО для мониторинга состояния UPS тяжеловесно и не бесплатно. Установка Zabbix только для этой задачи громоздка
Ниже представлен скрипт мониторинга APC и EATON, оснащенных сетевыми платами посредством SNMP.
Требуется установленный Apache и PHP с модулем php-snmp.
Отредактируйте массивы $urls для еатонов и $urls2 для APC, разрешите SNMP-1 public на чтение и настройте крон для отправки ежедневных писем.
-
-
// apt-get install php5-snmp
-
// snmp 1 public readonly
-
-
$urls = array( // eatons
-
# "10.10.10.25",
-
"10.10.10.55",
-
"10.10.10.57",
-
"10.10.10.54",
-
"10.10.10.58",
-
"10.10.10.56",
-
"10.10.10.225",
-
"10.10.10.224",
-
"10.10.10.232",
-
"10.10.10.222",
-
"10.10.10.226",
-
"10.10.10.227",
-
"10.10.10.228",
-
"10.10.10.220",
-
# "10.10.10.221",
-
"10.10.10.234",
-
"192.168.0.60"
-
-
);
-
$urls2 = array( // APC
-
"192.168.0.25",
-
"10.10.10.61",
-
"10.10.10.233",
-
"10.10.10.59",
-
"10.10.10.231",
-
# "10.10.10.229",
-
"10.10.10.230"
-
-
);
-
-
// 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="\"100%\" border=\"1\" cellpadding='5' cellspacing=\"0\">
-
-
\"#ddd\" style=\"background-color:#ddd\">
-
-
-
-
-
-
http://".$urls[$i]."/\" target=\"_blank\">".$urls[$i]."";
-
$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.= "$val"; }
-
$s = $session->walk("1.3.6.1.2.1.33.1.1.2.0", TRUE);
-
foreach ($s as $val) { $pr.= "\"#00f\" style=\"color:#00f;\">$val"; }
-
$s = $session->walk("1.3.6.1.4.1.534.1.3.4.1.2.1", TRUE);
-
foreach ($s as $val) { $pr.= "$val Volt"; }
-
$s = $session->walk("1.3.6.1.4.1.534.1.4.1.0", TRUE);
-
foreach ($s as $val) { $pr.= "$val %"; }
-
$s = $session->walk("1.3.6.1.4.1.534.1.2.4.0", TRUE);
-
foreach ($s as $val) { $pr.= "$val %"; }
-
$s = $session->walk("1.3.6.1.4.1.534.1.2.1.0", TRUE);
-
foreach ($s as $val) { $pr.= "".round($val/60)." min"; }
-
-
$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.="\"#9d9\" style=\"background-color:#9d9\">OK";
-
else $pr.="\"#d99\" style=\"background-color:#d99\">fault";
-
-
$s = $session->walk("1.3.6.1.4.1.534.1.6.1.0", TRUE);
-
foreach ($s as $val) { $pr.= "$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 %"; }
-
$session->close();
-
$pr.="\r\n";
-
}
-
for ($i = 0; $i<count($urls2); $i++)
-
{
-
$pr.="
-
http://".$urls2[$i]."/\" target=\"_blank\">".$urls2[$i]."";
-
-
$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.= "$val"; }
-
$s = $session->walk("1.3.6.1.4.1.318.1.1.1.1.1.1.0", TRUE);
-
foreach ($s as $val) { $pr.= "\"#f00\" style=\"color:#f00;\">$val"; }
-
$s = $session->walk("1.3.6.1.4.1.318.1.1.1.3.2.1.0", TRUE);
-
foreach ($s as $val) { $pr.= "$val Volt"; }
-
$s = $session->walk("1.3.6.1.4.1.318.1.1.1.4.2.3.0", TRUE);
-
foreach ($s as $val) { $pr.= "$val %"; }
-
$s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.1.0", TRUE);
-
foreach ($s as $val) { $pr.= "$val %"; }
-
$s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.3.0", TRUE);
-
foreach ($s as $val) { $pr.= "".($val/100/60)." min"; }
-
$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.= "\"#9d9\" style=\"background-color:#9d9\">OK"; }
-
else { $pr.= "\"#d99\" style=\"background-color:#d99\">fault"; }
-
$s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.2.0", TRUE);
-
foreach ($s as $val) { $pr.= "$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 %"; }
-
$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.= "LTtB:$val"; }
-
$session->close();
-
$pr.="\r\n";
-
}
-
$pr.="";
-
$pr.="
\"#00f\" style=\"color:#00f;\">EATON \"#f00\" style=\"color:#f00;\">APC
"; -
-
$pr.="APC reason for last transfer (LTtB) to battery power
-
1 No events
-
2 High line voltage
-
3 Brownout
-
4 Loss of mains power
-
5 Small temporary power drop
-
6 Large temporary power drop
-
7 Small spike
-
8 Large spike
-
9 UPS self test
-
10 Excessive input voltage fluctuation
-
-
if($act=='') echo $pr;
-
if($act=='dailyreport')
-
{
-
$to="st@mycompany.ru"; // Адрес получателя
-
$subject="UPSs daily report";
-
$body="$pr";
-
$headers = "Content-type: text/html; charset=utf-8\r\n";
-
$headers .= "From: ups@mycompany.ru ";
-
mail($to, $subject, $body, $headers);
-
}
-
-
?>
-
-
На всякий случай оставляю тут протокол работы Smart APC.
Есть идея, сделать нештатную плату управления и мониторинга через COM с использованием 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 |
Lisolog (C) / 2022