Top.Mail.Ru

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


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

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

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

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

 

  1. <?php
  2. // apt-get install php5-snmp
  3. // snmp 1 public readonly
  4.  
  5. $urls = array( // eatons
  6. # "10.10.10.25",
  7. "10.10.10.55",
  8. "10.10.10.57",
  9. "10.10.10.54",
  10. "10.10.10.58",
  11. "10.10.10.56",
  12. "10.10.10.225",
  13. "10.10.10.224",
  14. "10.10.10.232",
  15. "10.10.10.222",
  16. "10.10.10.226",
  17. "10.10.10.227",
  18. "10.10.10.228",
  19. "10.10.10.220",
  20. # "10.10.10.221",
  21. "10.10.10.234",
  22. "192.168.0.60"
  23.  
  24. );
  25. $urls2 = array( // APC
  26. "192.168.0.25",
  27. "10.10.10.61",
  28. "10.10.10.233",
  29. "10.10.10.59",
  30. "10.10.10.231",
  31. # "10.10.10.229",
  32. "10.10.10.230"
  33.  
  34. );
  35.  
  36. // APC OIDs:
  37. // https://www.opsview.com/resources/monitoring/blog/monitoring-apc-ups-useful-oids
  38. // https://wiki.it-kb.ru/apc/apc-nmc-oids-for-snmp-monitoring
  39. // EATON OIDs
  40. // https://wiki.it-kb.ru/eaton/eaton-powerware-nmc-oids-for-snmp-monitoring
  41.  
  42. // if(isset($_GET['act'])) $act=$_GET["act"]; else $act='';
  43. $act=$argv[1];
  44.  
  45.  
  46. #$db = new SQLite3(dirname(__FILE__).'/phpliteadmin/stats.db');
  47. $pr="<html><body><table width= \"100%\" border=\"1\" cellpadding='5' cellspacing=\"0\">
  48. <tr bgcolor=\"#ddd\" style=\"background-color:#ddd\">
  49. <td>IP</td>
  50. <td>Расположение</td>
  51. <td>Модель</td>
  52. <td>Источник питания</td>
  53. <td>Нагрузка<br />%</td>
  54. <td>Зарядка<br />%</td>
  55. <td>Оставшееся<br>время</td>
  56. <td>Состояние<br />батареи</td>
  57. <td>Температура <br />(вн/нар)/Влажн.</td>
  58. </tr>";
  59. for ($i = 0; $i<count($urls); $i++)
  60. {
  61. $pr.="<tr><td><a href=\"http://".$urls[$i]."/\" target=\"_blank\">".$urls[$i]."</a></td>";
  62. $session = new SNMP(SNMP::VERSION_1, $urls[$i], "public");
  63. $session->valueretrieval = SNMP_VALUE_PLAIN;
  64. $s = $session->walk("1.3.6.1.2.1.1.5.0", TRUE);
  65. foreach ($s as $val) { $pr.= "<td><b>$val</b></td>"; }
  66. $s = $session->walk("1.3.6.1.2.1.33.1.1.2.0", TRUE);
  67. foreach ($s as $val) { $pr.= "<td><b><font color=\"#00f\" style=\"color:#00f;\">$val</font></b></td>"; }
  68. $s = $session->walk("1.3.6.1.4.1.534.1.3.4.1.2.1", TRUE);
  69. foreach ($s as $val) { $pr.= "<td>$val Volt</b></td>"; }
  70. $s = $session->walk("1.3.6.1.4.1.534.1.4.1.0", TRUE);
  71. foreach ($s as $val) { $pr.= "<td align='right'></b>$val %</td>"; }
  72. $s = $session->walk("1.3.6.1.4.1.534.1.2.4.0", TRUE);
  73. foreach ($s as $val) { $pr.= "<td align='right'>$val %</td>"; }
  74. $s = $session->walk("1.3.6.1.4.1.534.1.2.1.0", TRUE);
  75. foreach ($s as $val) { $pr.= "<td>".round($val/60)." min</td>"; }
  76.  
  77. $s = $session->walk("1.3.6.1.4.1.705.1.5.9.0", TRUE);
  78. foreach ($s as $val) if($val=="2") $res1 = 2; else $res1 = 1;
  79. $s = $session->walk("1.3.6.1.4.1.705.1.5.15.0", TRUE);
  80. foreach ($s as $val) if($val=="2") $res2 = 2; else $res2 = 1;
  81. $s = $session->walk("1.3.6.1.4.1.705.1.5.11.0", TRUE);
  82. foreach ($s as $val) if($val=="2") $res3 = 2; else $res3 = 1;
  83. if($res1==2 && $res2==2 && $res3==2) $pr.="<td bgcolor=\"#9d9\" style=\"background-color:#9d9\">OK</td>";
  84. else $pr.="<td bgcolor=\"#d99\" style=\"background-color:#d99\">fault</td>";
  85.  
  86. $s = $session->walk("1.3.6.1.4.1.534.1.6.1.0", TRUE);
  87. foreach ($s as $val) { $pr.= "<td>$val &deg;C / "; }
  88. $s = $session->walk("1.3.6.1.4.1.534.1.6.5.0", TRUE);
  89. foreach ($s as $val) { $pr.= " $val &deg;C /"; }
  90. $s = $session->walk("1.3.6.1.4.1.534.1.6.6.0", TRUE);
  91. foreach ($s as $val) { $pr.= " $val %</td>"; }
  92. $session->close();
  93. $pr.="</tr>\r\n";
  94. }
  95. for ($i = 0; $i<count($urls2); $i++)
  96. {
  97. $pr.="<tr><td><a href=\"http://".$urls2[$i]."/\" target=\"_blank\">".$urls2[$i]."</a></td>";
  98.  
  99. $session = new SNMP(SNMP::VERSION_1, $urls2[$i], "public");
  100. $session->valueretrieval = SNMP_VALUE_PLAIN;
  101. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.1.1.2.0", TRUE);
  102. foreach ($s as $val) { $pr.= "<td><b>$val</font></b></td>"; }
  103. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.1.1.1.0", TRUE);
  104. foreach ($s as $val) { $pr.= "<td><b><font color=\"#f00\" style=\"color:#f00;\">$val</font></b></td>"; }
  105. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.3.2.1.0", TRUE);
  106. foreach ($s as $val) { $pr.= "<td>$val Volt</b></td>"; }
  107. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.4.2.3.0", TRUE);
  108. foreach ($s as $val) { $pr.= "<td align='right'></b>$val %</td>"; }
  109. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.1.0", TRUE);
  110. foreach ($s as $val) { $pr.= "<td align='right'>$val %</td>"; }
  111. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.3.0", TRUE);
  112. foreach ($s as $val) { $pr.= "<td>".($val/100/60)." min</td>"; }
  113. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.4.0", TRUE);
  114. foreach ($s as $val)
  115. if($val=="1") { $pr.= "<td bgcolor=\"#9d9\" style=\"background-color:#9d9\">OK</td>"; }
  116. else { $pr.= "<td bgcolor=\"#d99\" style=\"background-color:#d99\">fault</td>"; }
  117. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.2.2.2.0", TRUE);
  118. foreach ($s as $val) { $pr.= "<td>$val &deg;C /"; }
  119. $s = $session->walk("1.3.6.1.4.1.318.1.1.25.1.2.1.6", TRUE);
  120. foreach ($s as $val) { $pr.= "$val &deg;C /"; }
  121. $s = $session->walk("1.3.6.1.4.1.318.1.1.25.1.2.1.7", TRUE);
  122. foreach ($s as $val) { $pr.= "$val %</td>"; }
  123. $s = $session->walk("1.3.6.1.4.1.318.1.1.1.3.2.5.0", TRUE); // Reason for last transfer
  124. foreach ($s as $val) { $pr.= "<td>LTtB:$val</td>"; }
  125. $session->close();
  126. $pr.="</tr>\r\n";
  127. }
  128. $pr.="</table>";
  129. $pr.="<br /><font color=\"#00f\" style=\"color:#00f;\">EATON</font> <font color=\"#f00\" style=\"color:#f00;\">APC</font><br />";
  130.  
  131. $pr.="APC reason for last transfer (LTtB) to battery power<br />
  132. <p>1 No events<br />
  133. 2 High line voltage<br />
  134. 3 Brownout<br />
  135. 4 Loss of mains power<br />
  136. 5 Small temporary power drop<br />
  137. 6 Large temporary power drop<br />
  138. 7 Small spike<br />
  139. 8 Large spike<br />
  140. 9 UPS self test<br />
  141. 10 Excessive input voltage fluctuation</p><br />
  142.  
  143. if($act=='') echo $pr;
  144. if($act=='dailyreport')
  145. {
  146. $to="st@mycompany.ru"; // Адрес получателя
  147. $subject="UPSs daily report";
  148. $body="$pr";
  149. $headers = "Content-type: text/html; charset=utf-8\r\n";
  150. $headers .= "From: ups@mycompany.ru ";
  151. mail($to, $subject, $body, $headers);
  152. }
  153.  
  154. ?>
  155.  

 Lisolog (C) / 2019

Другие варианты запуска потока.

Поделиться: