SNMP/en: различия между версиями

Материал из Wiren Board
(Новая страница: «After that, verify that snmptranslate works correctly with any known OID:»)
(Новая страница: «== Templates ==»)
Строка 156: Строка 156:
</syntaxhighlight>
</syntaxhighlight>


== Шаблоны ==
== Templates ==


Для описания устройств удобно (хотя и не обязательно) использовать ''шаблоны''. ''Шаблон (тип устройства)'' - это внешний конфигурационный файл (располагается в /usr/share/wb-mqtt-snmp/templates  
Для описания устройств удобно (хотя и не обязательно) использовать ''шаблоны''. ''Шаблон (тип устройства)'' - это внешний конфигурационный файл (располагается в /usr/share/wb-mqtt-snmp/templates  

Версия 13:21, 12 июня 2019

SNMP (Simple Network Management Protocol) is a standard Protocol for managing network devices in IP networks.

It is often used to exchange service information with devices, presenting data as separate variables.

Protocol support is found in network switches, routers, uninterruptible power supply (UPS) systems, servers, etc.

A driver has been added to the Wiren Board to receive data from SNMP devices. The driver is written in Go.

Installation and configuration on the controller

Installation

First you need to install the wb-mqtt-snmp package. In the device console, enter

# apt-get update
# apt-get install wb-mqtt-snmp

Settings

The configuration structure is very similar to wb-mqtt-serial.

Example of the configuration file (/etc/wb-mqtt-snmp.conf):

{
    "debug": false,
    "num_workers": 4,
    "devices": [
        {
            "address": "192.168.0.1",
            "name": "My SNMP server",
            "community": "public",
            "oid_prefix": "SNMPv2-MIB",
            "channels": [
                {
                    "name": "Number of services",
                    "oid": "sysServices.0",
                    "poll_interval": 1000
                },
                {
                    "name": "Boot string",
                    "oid": "HOST-RESOURCES-MIB::hrSystemInitialLoadParameters.0",
                    "poll_interval": 10000
                },
                {
                    "name": "System location",
                    "oid": ".1.3.6.1.2.1.1.6.0"
                }
            ]
        },
        {
            "address": "test.net-snmp.org",
            "name": "Test SNMP server",
            "device_type": "test-snmp"
        }
    ]
}

Consider it more detailed.

Configuration file

  • debug - flag to enable debug mode. If true, then in the process of the daemon in the log file will be put debug information (default is false);
  • num_workers - maximum number of SNMP connections to be established at the same time.
    • If many SNMP devices are being polled, increasing this setting may speed up the polling. However, increasing this setting also increases the maximum load on the network. In General, you can leave the default value (4).
  • devices - list of devices to be polled.

Device description

Parameter name Type Description Required Default
name string device name No SNMP [address]_[community]
id string device ID in MQTT No snmp_[address]_[community]
address string Network address of the device Yes -
device_type string Type of device (required for downloading the template) No -
enabled bool do you want to include the device in the poll? No true
community string community name SNMP Yes -
oid_prefix string Prefix (MIB name) for text OID channels where the prefix is explicitly specified No -
snmp_version string SNMP version (currently only 2C is supported ) No 2c
snmp_timeout integer response timeout (in seconds) No 5
poll_interval integer Minimum polling time for each channel by default No -
channels array channels description (SNMP variables) No -

Channel description

Parameter name Type Description Required Default
name string channel name Yes -
oid string OID in numeric or text form Yes -
enabled boolean Include the channel in poll? No true
control_type string data type(according to Conventions) No text
units string the string name of the units(for control_type == value) No -
scale float Multiplier (for numeric values) No 1.0
poll_interval int the polling interval of the channel (in ms) No poll_interval from the description of the device, or 1000

OID conversion

When the daemon is started, an attempt is made to convert the text OIDs recorded in the configuration into numeric ones.

If the OID is represented in numeric form (starts with the dot: .1.2.3.4), no conversion occurs.

If the OID is in text form (for example, SNMPv2-MIB::sysName.0), it is necessary that the appropriate MIB containing the description of this variable is installed on the system. The name conversion is done by calling the snmptranslate utility, so you can check for a MIB manually by using the command

# snmptranslate -On yourOid

Oid_prefix parameter in the device description allows you to omit the name of the MIB (prefix; SNMPv2-MIB::sysName.0). In this case, the prefix from oid_prefix will be automatically attached to all OID channels of the device where the prefix is not explicitly specified. For example, if oid_prefix = SNMPv2-MIB:

  • sysName.0 -> SNMPv2-MIB::sysName.0
  • sysLocation.0 -> SNMPv2-MIB::sysLocation.0
  • HOST-RESOURCES-MIB::hrSystemUptime.0 -> HOST-RESOURCES-MIB::hrSystemUptime.0
  • .1.3.6.1.2.1.1.6.0 -> .1.3.6.1.2.1.1.6.0

MIB installation

If You have the required MIB file, just copy it to the /root/.snmp/mibs, by pre-creating it:

# mkdir -p /root/.snmp/mibs
# cp your-mibs-file.mib /root/.snmp/mibs

After that, verify that snmptranslate works correctly with any known OID:

# snmptranslate -On yourOid

Templates

Для описания устройств удобно (хотя и не обязательно) использовать шаблоны. Шаблон (тип устройства) - это внешний конфигурационный файл (располагается в /usr/share/wb-mqtt-snmp/templates и имеет имя config-[device-type-name].json, например, config-test-snmp.json), в котором содержится базовое описание устройства (например, имя сообщества SNMP) и базовое описание всех его каналов.

Для использования шаблона в описании устройства в конфигурационном файле укажите поле "device_type". Среди всех представленных шаблонов будет выбран шаблон с таким же значением device_type, при этом все поля, которые не были определены в конфигурационном файле, примут значения из шаблона.

Точно так же это работает с каналами. Сравнение каналов происходит по обязательному полю name; если имя канала из конфигурационного файла совпадёт с именем канала в шаблоне, из шаблона будут взяты все неуказанные значения.

Пример

Шаблон config-my-device.json:

{
    "device_type": "my-device",
    "community": "public",
    "channels": [
        {
            "name": "Channel 1",
            "oid": ".1.2.3.4.1"
        },
        {
            "name": "Channel 2",
            "oid": ".1.2.3.4.2",
            "poll_interval": 3000
        }
    ]
}

Конфигурационный файл:

{
    "devices": [
        {
            "name": "Device 1",
            "device_type": "my-device",
            "address": "192.168.0.5",
            "snmp_timeout": 1
        },
        {
            "name": "Device 2",
            "device_type": "my-device",
            "address": "my-device.example.org",
            "snmp_timeout": 5,
            "channels": [
                {
                    "name": "Channel 2",
                    "poll_interval": 10000
                }
            ]
        }
    ]
}

В данном случае мы описали один шаблон my-device, по которому определили два разных устройства Device 1 и Device 2 с одинаковым набором каналов.

Поскольку Device 1 находится в локальной сети, логично выставить ему небольшое значение таймаута, чтобы быстрее определить неисправность устройства. Все остальные настройки берутся из шаблона.

Device 2 - удалённый сервер, потому для него стоит увеличить таймаут, чтобы не считать устройство неисправным при задержке пакета. Более того, для канала Channel 2 здесь мы переопределяем интервал опроса на бОльший, чтобы снизить нагрузку на сеть.

Таким образом, шаблоны очень удобно использовать для описания группы однотипных устройств.

Список шаблонов

В поставке wb-mqtt-snmp прилагается набор шаблонов для типовых устройств (список будет расширяться):

Устройство Имя шаблона Протестировано Комментарии
Тестовый сервер Net-SNMP test-snmp Да адрес тестового сервера test.net-snmp.org
APC UPS apc-ups Нет
  • Требуется локально установленный PowerNet-MIB
  • Описание устройства такое же, как в wb-mqtt-apcsnmp