Loading...
Извольте ждать
Menu
Мониторинг UPS APC и EATON на PHP

Мониторинг UPS APC и EATON на PHP

Не секрет, что ПО для мониторинга состояния UPS тяжеловесно и не бесплатно.Установка Zabbix только для этой задачи громоздка

Ниже представлен скрипт мониторинга APC и EATON, оснащенных сетевыми платами посредством SNMP.

Требуется установленный Apache и PHP с модулем php-snmp.

Отредактируйте массивы $urls для еатонов и $urls2 для APC, разрешите SNMP-1 public на чтение и настройте крон для отправки ежедневных писем.

 

  1. // apt-get install php5-snmp
  2. // snmp 1 public readonly
  3.  
  4. $urls = array( // eatons
  5. # "10.10.10.25",
  6. "10.10.10.55",
  7. "10.10.10.57",
  8. "10.10.10.54",
  9. "10.10.10.58",
  10. "10.10.10.56",
  11. "10.10.10.225",
  12. "10.10.10.224",
  13. "10.10.10.232",
  14. "10.10.10.222",
  15. "10.10.10.226",
  16. "10.10.10.227",
  17. "10.10.10.228",
  18. "10.10.10.220",
  19. # "10.10.10.221",
  20. "10.10.10.234",
  21. "192.168.0.60"
  22.  
  23. );
  24. $urls2 = array( // APC
  25. "192.168.0.25",
  26. "10.10.10.61",
  27. "10.10.10.233",
  28. "10.10.10.59",
  29. "10.10.10.231",
  30. # "10.10.10.229",
  31. "10.10.10.230"
  32.  
  33. );
  34.  
  35. // APC OIDs:
  36. // https://www.opsview.com/resources/monitoring/blog/monitoring-apc-ups-useful-oids
  37. // https://wiki.it-kb.ru/apc/apc-nmc-oids-for-snmp-monitoring
  38. // EATON OIDs
  39. // https://wiki.it-kb.ru/eaton/eaton-powerware-nmc-oids-for-snmp-monitoring
  40.  
  41. // if(isset($_GET['act'])) $act=$_GET["act"]; else $act='';
  42. $act=$argv[1];
  43.  
  44.  
  45. #$db = new SQLite3(dirname(__FILE__).'/phpliteadmin/stats.db');
  46. $pr="\"100%\" border=\"1\" cellpadding='5' cellspacing=\"0\">
  47.  
  48. \"#ddd\" style=\"background-color:#ddd\">
  49.  
  50.  
  51.  
  52.  
  53.  
  54. http://".$urls[$i]."/\" target=\"_blank\">".$urls[$i]."";
  55. $session = new SNMP(SNMP::VERSION_1, $urls[$i], "public");
  56. $session->valueretrieval = SNMP_VALUE_PLAIN;
  57. $s = $session->walk("1.3.6.1.2.1.1.5.0", TRUE);
  58. foreach ($s as $val) { $pr.= "$val"; }
  59. $s = $session->walk("1.3.6.1.2.1.33.1.1.2.0", TRUE);
  60. foreach ($s as $val) { $pr.= "\"#00f\" style=\"color:#00f;\">$val"; }
  61. $s = $session->walk("1.3.6.1.4.1.534.1.3.4.1.2.1", TRUE);
  62. foreach ($s as $val) { $pr.= "$val Volt"; }
  63. $s = $session->walk("1.3.6.1.4.1.534.1.4.1.0", TRUE);
  64. foreach ($s as $val) { $pr.= "$val %"; }
  65. $s = $session->walk("1.3.6.1.4.1.534.1.2.4.0", TRUE);
  66. foreach ($s as $val) { $pr.= "$val %"; }
  67. $s = $session->walk("1.3.6.1.4.1.534.1.2.1.0", TRUE);
  68. foreach ($s as $val) { $pr.= "".round($val/60)." min"; }
  69.  
  70. $s = $session->walk("1.3.6.1.4.1.705.1.5.9.0", TRUE);
  71. foreach ($s as $val) if($val=="2") $res1 = 2; else $res1 = 1;
  72. $s = $session->walk("1.3.6.1.4.1.705.1.5.15.0", TRUE);
  73. foreach ($s as $val) if($val=="2") $res2 = 2; else $res2 = 1;
  74. $s = $session->walk("1.3.6.1.4.1.705.1.5.11.0", TRUE);
  75. foreach ($s as $val) if($val=="2") $res3 = 2; else $res3 = 1;
  76. if($res1==2 && $res2==2 && $res3==2) $pr.="\"#9d9\" style=\"background-color:#9d9\">OK";
  77. else $pr.="\"#d99\" style=\"background-color:#d99\">fault";
  78.  
  79. $s = $session->walk("1.3.6.1.4.1.534.1.6.1.0", TRUE);
  80. foreach ($s as $val) { $pr.= "$val °C / "; }
  81. $s = $session->walk("1.3.6.1.4.1.534.1.6.5.0", TRUE);
  82. foreach ($s as $val) { $pr.= " $val °C /"; }
  83. $s = $session->walk("1.3.6.1.4.1.534.1.6.6.0", TRUE);
  84. foreach ($s as $val) { $pr.= " $val %"; }
  85. $session->close();
  86. $pr.="\r\n";
  87. }
  88. for ($i = 0; $i<count($urls2); $i++)
  89. {
  90. $pr.="
  91. http://".$urls2[$i]."/\" target=\"_blank\">".$urls2[$i]."";
  92.  
  93. $session = new SNMP(SNMP::VERSION_1, $urls2[$i], "public");
  94. $session->valueretrieval = SNMP_VALUE_PLAIN;
  95. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.1.1.2.0", TRUE);
  96. foreach ($s as $val) { $pr.= "$val"; }
  97. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.1.1.1.0", TRUE);
  98. foreach ($s as $val) { $pr.= "\"#f00\" style=\"color:#f00;\">$val"; }
  99. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.3.2.1.0", TRUE);
  100. foreach ($s as $val) { $pr.= "$val Volt"; }
  101. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.4.2.3.0", TRUE);
  102. foreach ($s as $val) { $pr.= "$val %"; }
  103. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.1.0", TRUE);
  104. foreach ($s as $val) { $pr.= "$val %"; }
  105. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.3.0", TRUE);
  106. foreach ($s as $val) { $pr.= "".($val/100/60)." min"; }
  107. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.4.0", TRUE);
  108. foreach ($s as $val)
  109. if($val=="1") { $pr.= "\"#9d9\" style=\"background-color:#9d9\">OK"; }
  110. else { $pr.= "\"#d99\" style=\"background-color:#d99\">fault"; }
  111. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.2.0", TRUE);
  112. foreach ($s as $val) { $pr.= "$val °C /"; }
  113. $s = $session->walk("1.3.6.1.4.1.318.1.1.25.1.2.1.6", TRUE);
  114. foreach ($s as $val) { $pr.= "$val °C /"; }
  115. $s = $session->walk("1.3.6.1.4.1.318.1.1.25.1.2.1.7", TRUE);
  116. foreach ($s as $val) { $pr.= "$val %"; }
  117. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.3.2.5.0", TRUE); // Reason for last transfer
  118. foreach ($s as $val) { $pr.= "LTtB:$val"; }
  119. $session->close();
  120. $pr.="\r\n";
  121. }
  122. $pr.="";
  123. $pr.="
    \"
    #00f\" style=\"color:#00f;\">EATON \"#f00\" style=\"color:#f00;\">APC
    ";
  124.  
  125. $pr.="APC reason for last transfer (LTtB) to battery power
  126. 1 No events

  127. 2 High line voltage
  128. 3 Brownout
  129. 4 Loss of mains power
  130. 5 Small temporary power drop
  131. 6 Large temporary power drop
  132. 7 Small spike
  133. 8 Large spike
  134. 9 UPS self test
  135. 10 Excessive input voltage fluctuation
  136.  
  137. if($act=='') echo $pr;
  138. if($act=='dailyreport')
  139. {
  140. $to="st@mycompany.ru"; // Адрес получателя
  141. $subject="UPSs daily report";
  142. $body="$pr";
  143. $headers = "Content-type: text/html; charset=utf-8\r\n";
  144. $headers .= "From: ups@mycompany.ru ";
  145. mail($to, $subject, $body, $headers);
  146. }
  147.  
  148. ?>
  149.  

На всякий случай оставляю тут протокол работы 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

^A

Model string

SMART-UPS 700

Spotty support for this query on older models

^N

Turn on UPS

n/a

Send twice with > 1.5s delay between chars

Only on 3rd gen SmartUPS and Black Back-UPS Pros

^Z

Capability string

(long string)

See "Capabilities" section for more info

A

Front panel test

Light show + "OK"

Also sounds the beeper for 2 seconds

B

Battery voltage

27.87

This obviously varies a lot based on the current charge.

Compare this to the nominal battery voltage

C

Internal temperature

036.0

Units are degrees C

D

Runtime calibration

!, then $

Runs until battery is below 25% (35% for Matrix)

This updates the j values - only works at 100% battery charge

Can be aborted with a second "D"

E

Automatic selftest intervals

336

Writable variable

Values:

  • 336 (14 days)

  • 168 (7 days)

  • ON (at power on) (note extra space)

  • OFF (never)

F

Line frequency, Hz

60.00

If this varies much, have a word with your local electrician

G

Cause of transfer

O

Writable variable

Values:

  • R (unacceptable utility voltage rate of change)

  • H (high utility voltage)

  • L (low utility voltage)

  • T (line voltage notch or spike)

  • O (no transfers yet since turnon)

  • S (transfer due to U command or activation of UPS test)

I

Measure-UPS: Alarm enable

FF

(not yet decoded)(bitmapped table, coming soon)

J

Measure-UPS: Alarm status

0F,00

(not yet decoded)(bitmapped table, coming soon)

K

Shutdown with grace period

OK

Send twice with > 1.5s delay between chars

Older units may send "*" instead of "OK"

Also see grace period

L

Input line voltage

118.3

Does not necessarily read 000.0 on line failure

M

Maximum line voltage

118.9

This is the max voltage since the last time this query was run

N

Minimum line voltage

118.9

Like the one above, this one also resets itself on every query

O

Output voltage

118.3

Also see on battery output voltage

P

Power load %

023.5

Relative to the capacity of the UPS

Q

Status flags

08

See status flags section for more info

R

Turn dumb

BYE

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

S

Soft shutdown

OK

Command executes after grace period

UPS goes online when power returns

Only works when on battery

U

Simulate power failure

!, then $

See async notifier section for info on ! and $

V

Firmware revision

GWD

Can be used to determine abilities of hardware

W

Self test

OK

Tests battery, like pushing the test button on the front panel

Also see test results entry

X

Self-test results

OK

Values:

  • OK → good battery

  • BT → failed due to insufficient capacity

  • NG → failed due to overload

  • NO → no results available (no test performed in last 5 minutes)

Y

Enter smart mode

SM

This must be sent before anything else on this page will work.

Also see turn dumb command to exit smart mode

Z

Shutdown immediately

n/a

Send twice with > 1.5s delay between chars

UPS switches the load off immediately (no grace period)

a

Protocol info

(long string)

Returns three main sections:

Sections are separated with a period

b

Firmware revision

50.9.D

Decoding above info:

50

SKU (variable length)

9

firmware revision

D

country code (used in capability decoding)

c

UPS local id

UPS_IDEN

Writable variable

Up to 8 letter identifier for keeping track of your hardware

e

Return threshold

00

Writable variable

Minimum battery charge % to return from shutdown after power returns

Values:

  • 00 = 0% (UPS switches on immediately)

  • 01 = 15%

  • 02 = 25%

  • 03 = 90%

This prevents excessive cycling during multiple power failures

g

Nominal battery voltage

024

The battery voltage that’s expected to be present in the UPS normally

Compare to the actual voltage reading

f

Battery level

099.0

Percentage

It’s much easier to use this rather than doing math on the current battery voltage and the nominal battery voltage

h

Measure-UPS: Ambient humidity

042.4

Percentage

Only works on models with the Measure-UPS SmartSlot card

i

Measure-UPS: Dry contacts

00

Bitmapped hex variable

Component values:

  • 10 = contact 1

  • 20 = contact 2

  • 40 = contact 3

  • 80 = contact 4

j

Estimated runtime

0327:

Minutes

Must be calibrated to be effective

k

Alarm delay

0

Writable variable

Values:

  • 0 = 5 second delay after power failure

  • T = 30 second delay

  • L = alarm at low battery only

  • N = alarm disabled

Does not affect low battery warning

l

Low transfer voltage

103

Writable variable

See capabilities to get values for a UPS

UPS goes on battery after voltage drops below this point

m

Manufacturing date

11/29/96

Format may vary by country (MM/DD/YY vs DD/MM/YY)

n

Serial number

WS9643050926

Unique for each UPS

o

On-battery voltage

115

May be a writable variable on 220/230/240 VAC units

p

Shutdown grace delay

020

Writable variable - seconds

See capabilities to read values

Sets the delay before soft shutdown completes

q

Low battery warning

02

Writable variable - minutes

See capabilities to read values

The UPS will report a low battery this many minutes before it runs out of power

r

Wakeup delay

000

Writable variable - seconds

See capabilities to read values

The UPS will wait this many seconds after reaching the minimum charge before returning online

s

Sensitivity

H

Writable variable

See capabilities to read values

Meaning of values:

  • H → highest

  • M → medium

  • L → lowest

  • A → autoadjust (Matrix only)

u

Upper transfer voltage

132

Writable variable

See capabilities to read values

UPS goes on battery after voltage rises above this point

v

Measure-UPS: Firmware

4Kx

Firmware information for Measure-UPS board

t

Measure-UPS: Ambient temperature

80.5

Degrees C

Only works on models with the Measure-UPS SmartSlot card

x

Last battery change

11/29/96

Writable variable

This holds whatever the user sets in it, much like the UPS local id variable

y

Copyright notice

© APCC

Only works if firmware letter is later than O

z

Reset to factory settings

CLEAR

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 | afterward to confirm change to PROM

@nnn

Shutdown and return

OK

UPS shuts down after grace period with delayed wakeup after nnn tenths of an hour plus any wakeup delay time

Some older models send * instead of OK

0x7f

Abort shutdown

OK

Abort shutdown - use to abort @, S, K

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

7

Dip switch positions

n/a

See dip switch table

Only makes sense on models which actually have dip switches

8

Register #3

n/a

See register 3 table

9

Line quality

FF

Values

  • 00 → unacceptable

  • FF → acceptable

>

Battery packs

n/a

SmartCell models: returns number of connected packs

Non-SmartCell models: returns number set by user (use + and -)

[

Measure-UPS: Upper temp limit

NO,NO

Degrees C

Writable variable

Values: 55, 50, 45, …, 05 for both

Use - to enumerate through left side, + to enumerate through right side

]

Measure-UPS: Lower temp limit

NO,NO

Degrees C

Writable variable

See lower temp limit above

{

Measure-UPS: Upper humidity limit

NO,NO

%

Writable variable

Values: 90, 80, 70, …, 10 for both

Use - and + to change values

}

Measure-UPS: Lower humidity limit

NO,NO

%

Writable variable

Values: 90, 80, 70, …, 10 for both

Use - and + to change values

Matrix-UPS and Symmetra commands

^

Run in bypass mode

n/a

If online, "BYP" response is received as bypass mode starts

If already in bypass, "INV" is received and UPS goes online

If UPS can’t transfer, "ERR" received

<

Number of bad battery packs

000

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

^V

Output voltage selection

n/a

Writable variable

Values:

  • A → Automatic (based on input tap)

  • M → 208 VAC

  • I → 240 VAC

^L

Front panel language

n/a

Writable variable

Values:

  • E → English

  • F → French

  • G → German

  • S → Spanish

  • Also 1, 2, 3, 4 → unknown

w

Run time conservation

n/a

Writable variable

Values:

  • NO → disabled

  • 02 → leave 2 minutes of runtime in battery

  • 05 → leave 5 minutes

  • 08 → leave 8 minutes

Lisolog (C) / 2022