Linux ups nut2: различия между версиями

Материал из noname.com.ua
Перейти к навигацииПерейти к поиску
Строка 307: Строка 307:
 
name: UPS
 
name: UPS
 
</PRE>
 
</PRE>
  +
=Отправка графиков в Телеграм=
  +
Подробно описано тут -->
  +
https://serveradmin.ru/nastroyka-opoveshheniy-zabbix-v-telegram/
  +
<BR>
  +
Внимательно проверять
  +
* права API пользователя
  +
* возможность соединения
  +
В моем случае zabbix-server и zabbix-api были в разных неймспейссах и по тому скрипт должен ходить не на локалхост
   
 
=Материалы=
 
=Материалы=
 
* https://habr.com/ru/post/443736/
 
* https://habr.com/ru/post/443736/
  +
* https://serveradmin.ru/nastroyka-opoveshheniy-zabbix-v-telegram/

Версия 12:59, 28 июля 2021


Linux UPS 2

Тут короткая заметка про настройку мониторигна бесперебойника через нагиос

Настройка NUT

  • Пакеты
ii  nut                                      2.7.4-11ubuntu4                                 all          network UPS tools - metapackage
ii  nut-cgi                                  2.7.4-11ubuntu4                                 amd64        network UPS tools - web interface
ii  nut-client                               2.7.4-11ubuntu4                                 amd64        network UPS tools - clients
ii  nut-doc                                  2.7.4-11ubuntu4                                 all          network UPS tools - documentation
ii  nut-ipmi                                 2.7.4-11ubuntu4                                 amd64        network UPS tools - IPMI driver
ii  nut-server                               2.7.4-11ubuntu4                                 amd64        network UPS tools - core system
ii  nut-snmp                                 2.7.4-11ubuntu4                                 amd64        network UPS tools - SNMP driver
ii  nut-xml                                  2.7.4-11ubuntu4                                 amd64        network UPS tools - XML/HTTP driver
  • Конфиги (минимальные)

Мне не требуется ничего кроме как возможность снимать параметры с UPS - никакой обработки событий вроде выключения сервера при низком заряде батареи не предусмотрено

/etc/ nut.conf

 nut.conf  | grep -v '#'
MODE=standalone

/etc/ups.conf

cat ups.conf | grep -v '#'
[riello]
    driver = riello_ser
    port = /dev/ttyUSB0
    port = /dev/serial/by-id/usb-Cypress_Semiconductor_USB_to_Serial-if00-port0
    pollinterval = 5
    desc = "Something descriptive"

/etc/upsd.conf

cat upsd.conf | grep -v '#'
LISTEN 127.0.0.1 3493
LISTEN 172.31.100.13 3493

/etc/upsmon.conf

cat upsmon.conf | grep -v '#'
MINSUPPLIES 0
SHUTDOWNCMD "/sbin/shutdown -h +0"
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5

/etc/upssched.conf

cat upssched.conf | grep -v '#'
CMDSCRIPT /bin/upssched-cmd


  • Сервисы

Всего 2 сервеса - драйвер и сервер (запускать сначала сервер, насколько я могу судить серис драйвера сам остановится если нет сервера которому он нужен)

systemctl status nut-server
● nut-server.service - Network UPS Tools - power devices information server
     Loaded: loaded (/lib/systemd/system/nut-server.service; disabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-07-26 11:58:47 EEST; 2 days ago
   Main PID: 506891 (upsd)
      Tasks: 1 (limit: 76762)
     Memory: 1.2M
     CGroup: /system.slice/nut-server.service
             └─506891 /lib/nut/upsd
systemctl status nut-driver
● nut-driver.service - Network UPS Tools - power device driver controller
     Loaded: loaded (/lib/systemd/system/nut-driver.service; static; vendor preset: enabled)
     Active: active (running) since Mon 2021-07-26 11:26:56 EEST; 2 days ago
   Main PID: 484091 (riello_ser)
      Tasks: 1 (limit: 76762)
     Memory: 1.1M
     CGroup: /system.slice/nut-driver.service
             └─484091 /lib/nut/riello_ser -a riello


Настройка Zabbix

zabbix-agent

UserParameter=ups.battery.capacity,/usr/bin/upsc         riello@172.31.100.13:3493 battery.capacity             2>/dev/null
UserParameter=ups.battery.charge,/usr/bin/upsc           riello@172.31.100.13:3493 battery.charge               2>/dev/null
UserParameter=ups.battery.runtime,/usr/bin/upsc          riello@172.31.100.13:3493 battery.runtime              2>/dev/null
UserParameter=ups.battery.voltage,/usr/bin/upsc          riello@172.31.100.13:3493 battery.voltage              2>/dev/null
UserParameter=ups.battery.voltage.nominal,/usr/bin/upsc  riello@172.31.100.13:3493 battery.voltage.nominal      2>/dev/null
UserParameter=ups.input.bypass.frequency,/usr/bin/upsc   riello@172.31.100.13:3493 input.bypass.frequency       2>/dev/null
UserParameter=ups.input.bypass.voltage,/usr/bin/upsc     riello@172.31.100.13:3493 input.bypass.voltage         2>/dev/null
UserParameter=ups.input.frequency,/usr/bin/upsc          riello@172.31.100.13:3493 input.frequency              2>/dev/null
UserParameter=ups.input.voltage,/usr/bin/upsc            riello@172.31.100.13:3493 input.voltage                2>/dev/null
UserParameter=ups.output.frequency,/usr/bin/upsc         riello@172.31.100.13:3493 output.frequency             2>/dev/null
UserParameter=ups.output.frequency.nominal,/usr/bin/upsc riello@172.31.100.13:3493 output.frequency.nominal     2>/dev/null
UserParameter=ups.output.power.percent,/usr/bin/upsc     riello@172.31.100.13:3493 output.power.percent         2>/dev/null
UserParameter=ups.output.voltage,/usr/bin/upsc           riello@172.31.100.13:3493 output.voltage               2>/dev/null
UserParameter=ups.output.voltage.nominal,/usr/bin/upsc   riello@172.31.100.13:3493 output.voltage.nominal       2>/dev/null
UserParameter=ups.ups.load,/usr/bin/upsc                 riello@172.31.100.13:3493 ups.load                     2>/dev/null
UserParameter=ups.ups.power.nominal,/usr/bin/upsc        riello@172.31.100.13:3493 ups.power.nominal            2>/dev/null
UserParameter=ups.ups.realpower.nominal,/usr/bin/upsc    riello@172.31.100.13:3493 ups.realpower.nominal        2>/dev/null
UserParameter=ups.ups.temperature,/usr/bin/upsc          riello@172.31.100.13:3493 ups.temperature              2>/dev/null
#UserParameter=ups.ups.status,/usr/bin/upsc              riello@172.31.100.13:3493 ups.status             2>/dev/null
UserParameter=ups.ups.status,/bin/bash -c "if [ \"$(/usr/bin/upsc riello@172.31.100.13:3493 ups.status 2>/dev/null | awk '{print $1}' )\" == \"OL\" ]; then echo 0; else echo 1; fi"

zabbix-server

Простейший темплейт Конструкция name: 'ups.ups.status on DONEC' нужна для простоты выделения срабатывания триггера и отправки оповещений

zabbix_export:
  version: '5.2'
  date: '2021-07-28T10:54:42Z'
  groups:
    -
      name: Templates
  templates:
    -
      template: 'Template UPS'
      name: 'Template UPS'
      groups:
        -
          name: Templates
      applications:
        -
          name: UPS
      items:
        -
          name: ups.battery.capacity
          key: ups.battery.capacity
          delay: 60s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.battery.charge
          key: ups.battery.charge
          delay: 60s
          value_type: FLOAT
          units: '%'
          applications:
            -
              name: UPS
        -
          name: ups.battery.runtime
          key: ups.battery.runtime
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.battery.voltage
          key: ups.battery.voltage
          delay: 60s
          value_type: FLOAT
          units: V
          applications:
            -
              name: UPS
        -
          name: ups.battery.voltage.nominal
          key: ups.battery.voltage.nominal
          delay: 60s
          value_type: FLOAT
          units: V
          applications:
            -
              name: UPS
        -
          name: ups.input.bypass.frequency
          key: ups.input.bypass.frequency
          delay: 60s
          value_type: FLOAT
          units: Hz
          applications:
            -
              name: UPS
        -
          name: ups.input.bypass.voltage
          key: ups.input.bypass.voltage
          delay: 60s
          value_type: FLOAT
          units: V
          applications:
            -
              name: UPS
        -
          name: ups.input.frequency
          key: ups.input.frequency
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.input.voltage
          key: ups.input.voltage
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.output.frequency
          key: ups.output.frequency
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.output.frequency.nominal
          key: ups.output.frequency.nominal
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.output.power.percent
          key: ups.output.power.percent
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.output.voltage
          key: ups.output.voltage
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.output.voltage.nominal
          key: ups.output.voltage.nominal
          delay: 30s
          value_type: FLOAT
          units: V
          applications:
            -
              name: UPS
        -
          name: ups.ups.load
          key: ups.ups.load
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.ups.power.nominal
          key: ups.ups.power.nominal
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.ups.realpower.nominal
          key: ups.ups.realpower.nominal
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS
        -
          name: ups.ups.status
          key: ups.ups.status
          delay: 60s
          value_type: FLOAT
          applications:
            -
              name: UPS
          triggers:
            -
              expression: '{last()}<>0'
              name: 'ups.ups.status on DONEC'
              priority: DISASTER
        -
          name: ups.ups.temperature
          key: ups.ups.temperature
          delay: 30s
          value_type: FLOAT
          applications:
            -
              name: UPS

Отправка графиков в Телеграм

Подробно описано тут --> https://serveradmin.ru/nastroyka-opoveshheniy-zabbix-v-telegram/
Внимательно проверять

  • права API пользователя
  • возможность соединения

В моем случае zabbix-server и zabbix-api были в разных неймспейссах и по тому скрипт должен ходить не на локалхост

Материалы