当前位置:网站首页>Zabbix5 series - use temperature and humidity sensor to monitor the temperature and humidity of the machine room (XX)

Zabbix5 series - use temperature and humidity sensor to monitor the temperature and humidity of the machine room (XX)

2022-06-23 01:27:00 Halyace

One 、 Reference resources

  • Zabbix5 series

Two 、 install zabbix-agent2

2.1 Linux install zabbix-agent2

With Centos7.9 Example installation zabbix-agent2 And monitor the host

#  Enter the temporary directory 
cd /tmp
#  download zabbix-agent2
curl -O https://mirrors.aliyun.com/zabbix/zabbix/5.4/rhel/7/x86_64/zabbix-agent2-5.4.9-1.el7.x86_64.rpm
#  install zabbix-agent2
rpm -ivh zabbix-agent2-5.4.9-1.el7.x86_64.rpm
#  Modify the configuration file  
# Server=127.0.0.1 Change it to your own Zabbix The server IP
vi /etc/zabbix/zabbix_agent2.conf
#  restart zabbix-agent2 service 
systemctl restart zabbix-agent2
#  Boot up automatically zabbix-agent2
systemctl enable zabbix-agent2
#  Firewall release 10050
firewall-cmd --zone=public --add-port=10050/tcp --permanent
#  Overloaded firewall 
firewall-cmd --reload
2.2 Windows install zabbix-agent2

2.2.1 Click on Next
 Insert picture description here
2.2.2 Check to receive permission Click on Next
 Insert picture description here
2.2.3 Input Zabbix The server IP You can use network segments such as :192.168.0.0/24 Write down the HostName
 Insert picture description here
2.2.4 Click on Next
 Insert picture description here
2.2.5 Click on Install Start installation
 Insert picture description here
2.2.6 Click on Finish Complete the installation
 Insert picture description here

3、 ... and 、 Test the sensor

3.1 PDD Buy a garbage sensor , It looks like this
 Insert picture description here

3.2 Use according to the information sent by the merchant RTU agreement Baud rate 4800 Check none Data bits 8 Stop bit 1 The device address is 1
 Insert picture description here
3.3 Use here Modbus Debug Wizard v1.0.24 To test The tool downloads itself

test result :
The temperature is equal to 0x00F5/10=245/10=24.5 degree
The humidity is equal to 0x01A4/10=420/10=42%

 Insert picture description here

Four 、 Create a host

4.1 Host configuration
Host name : Enter host name
Visible name : Set alias
group : Choose your own host group
Interfaces: Add a client monitor IP The address is host IP Port defaults to 10050
 Insert picture description here

5、 ... and 、 Create monitor item

5.1 Windows The host opens the device manager to view the serial port number
 Insert picture description here
5.2 Linux The host checks the serial port number and configures permissions
 Insert picture description here

#  View serial port messages   Confirm serial port name 
dmesg | grep tty
#  View serial port permissions   Subordinate to the group  dialout
ls -l /dev/ttyUSB0
#  user zabbix Join user groups  dialout
gpasswd --add zabbix dialout
#  see zabbix User's group 
groups zabbix

5.3 Enter the newly created host Create sensor monitoring items
 Insert picture description here
5.4 Fill in the key value according to the previous port number and test information
 Insert picture description here

Reference resources :Modbus Parameter description
Reference resources :Modbus Plug in readme
The format is :modbus.get[RTU Connection string , Device address , Function code , Address code , Number , return type , Byte order , The offset ]
RTU Connection string : Reference resources rtu://com4:4800:8n1 rtu://ttyUSB0:4800:8n1
Device address : The equipment Modbus Address
Function code :1- Discrete input (RO) 2- Coil state (RW) 3- Input register (RO) 4- Holding register (RW)
Address code : The address of the data Default 00001
Number : Number of data returned
type : Support bit、int8、uint8、uint16、int16、uint32、int32、float、uint64 、 double
Byte order :be- Big end le- The small end mbe mle
The offset : Number of registers or bits

5.5 Test read Successfully read array [450,242] The front is humidity Then there is the temperature
 Insert picture description here
5.6 Click the add button Add monitor

5.7 Create a new temperature monitoring item Type select related items Key values are defined by themselves The main item is to select the sensor created before
 Insert picture description here
5.8 Select floating point number for information type Company ℃ Switch to the process page
 Insert picture description here
5.9 Add two processes
 Insert picture description here
5.10 The first process extracts the second element from the array returned by the sensor If there is an error, set the value to -100; Second process times 0.1 Get the true temperature If there is an error, set the value to -100; Then click the Add button to create a monitoring item
 Insert picture description here
5.11 Reference resources 5.8-5.10 Create humidity monitoring items
 Insert picture description here
 Insert picture description here
5.12 Check the sensor monitoring item Click on Execute Now Test monitoring items
 Insert picture description here
5.13 View the read data
 Insert picture description here

6、 ... and 、 Create trigger

6.1 Switch to the trigger page Click create trigger
 Insert picture description here
6.2 Set the trigger formula according to the picture
 Insert picture description here
6.3 Set humidity trigger with reference to temperature

7、 ... and 、 Check whether the sensor fails

7.1 Create availability monitoring items
 Insert picture description here
7.2 Create triggers to monitor availability
 Insert picture description here

8、 ... and 、 Refer to other blog posts to create nails or email alerts

Zabbix5 series - Nail alarm (Webhook) ( nineteen )
Zabbix5 series - Sound alarm 、 Email alert ( fourteen )
Zabbix5 series - Nail alarm ( 15、 ... and )

The alarm effects :
 Insert picture description here

Nine 、 Refer to other blog access Grafana

Zabbix5 series - Access Grafana panel ( seventeen )

Show the effect :

 Insert picture description here

Ten 、 Self made sensor template reference

Save as yaml After the file is imported, modify the macro according to the actual situation
 Insert picture description here

Template file :Temp_Hum_Sensor.yaml

zabbix_export:
  version: '5.4'
  date: '2022-06-01T11:18:51Z'
  groups:
    -
      uuid: 7df96b18c230490a9a0a9e2307226338
      name: Templates
  templates:
    -
      uuid: f367d493b0484099a8a8b7c83fefafc1
      template: 'Temp Hum Sensor'
      name:  Temperature and humidity sensor 
      groups:
        -
          name: Templates
      items:
        -
          uuid: 8a73896926a542678ffd8a704a85ae96
          name:  sensor 
          key: 'modbus.get[{$MODBUS_ENDPOINT},{$MODBUS_SLAVEID},{$MODBUS_FUNCTION},{$MODBUS_ADDRESS},{$MODBUS_COUNT},{$MODBUS_TYPE},{$MODBUS_ENDIANNESS},{$MODBUS_OFFSET}]'
          delay: 30s
          trends: '0'
          value_type: TEXT
          preprocessing:
            -
              type: CHECK_NOT_SUPPORTED
              parameters:
                - ''
              error_handler: CUSTOM_VALUE
              error_handler_params: '[-1000,-1000]'
        -
          uuid: 46818e12cf764928adc63158ef5c2798
          name:  humidity 
          type: DEPENDENT
          key: sensor.hum
          delay: '0'
          value_type: FLOAT
          units: '%'
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[{$INDEX_HUM}]'
              error_handler: CUSTOM_VALUE
              error_handler_params: '-1000'
            -
              type: MULTIPLIER
              parameters:
                - '0.1'
              error_handler: CUSTOM_VALUE
              error_handler_params: '-100'
          master_item:
            key: 'modbus.get[{$MODBUS_ENDPOINT},{$MODBUS_SLAVEID},{$MODBUS_FUNCTION},{$MODBUS_ADDRESS},{$MODBUS_COUNT},{$MODBUS_TYPE},{$MODBUS_ENDIANNESS},{$MODBUS_OFFSET}]'
          tags:
            -
              tag:  Environmental Science 
              value:  humidity 
          triggers:
            -
              uuid: b1795712933d47db966f56282fdf75b4
              expression: 'last(/Temp Hum Sensor/sensor.hum)=-100'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'last(/Temp Hum Sensor/sensor.hum)>-100'
              name: '{$LOCATION}:  The humidity sensor has failed '
              opdata: '{ITEM.LASTVALUE1}'
              priority: DISASTER
            -
              uuid: bf23a82ece3748bb8affd1caaad7ac32
              expression: 'avg(/Temp Hum Sensor/sensor.hum,5m)<{$HUM_CRIT_LOW:""}'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'min(/Temp Hum Sensor/sensor.hum,5m)>{$HUM_CRIT_LOW:""}+3'
              name: '{$LOCATION}:  The humidity is too low : <{$HUM_CRIT_LOW:""}%'
              opdata: '{ITEM.LASTVALUE1}'
              priority: AVERAGE
              dependencies:
                -
                  name: '{$LOCATION}:  The humidity sensor has failed '
                  expression: 'last(/Temp Hum Sensor/sensor.hum)=-100'
                  recovery_expression: 'last(/Temp Hum Sensor/sensor.hum)>-100'
            -
              uuid: f5d8d3d3aae04a27a32cd55dc527ae06
              expression: 'avg(/Temp Hum Sensor/sensor.hum,5m)>{$HUM_CRIT:""}'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'max(/Temp Hum Sensor/sensor.hum,5m)<{$HUM_CRIT:""}-3'
              name: '{$LOCATION}:  Humidity above threshold : >{$HUM_CRIT:""}%'
              opdata: '{ITEM.LASTVALUE1}'
              priority: HIGH
            -
              uuid: eb097881d9534e9aac2885e182d1afb9
              expression: 'avg(/Temp Hum Sensor/sensor.hum,5m)>{$HUM_WARN:""}'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'max(/Temp Hum Sensor/sensor.hum,5m)<{$HUM_WARN:""}-3'
              name: '{$LOCATION}:  Humidity above warning value : >{$HUM_WARN:""}%'
              opdata: '{ITEM.LASTVALUE1}'
              priority: WARNING
              dependencies:
                -
                  name: '{$LOCATION}:  Humidity above threshold : >{$HUM_CRIT:""}%'
                  expression: 'avg(/Temp Hum Sensor/sensor.hum,5m)>{$HUM_CRIT:""}'
                  recovery_expression: 'max(/Temp Hum Sensor/sensor.hum,5m)<{$HUM_CRIT:""}-3'
        -
          uuid: 14de9d958ed74630853bb709189210bc
          name:  temperature 
          type: DEPENDENT
          key: sensor.temp
          delay: '0'
          value_type: FLOAT
          units: °C
          preprocessing:
            -
              type: JSONPATH
              parameters:
                - '$[{$INDEX_TEMP}]'
              error_handler: CUSTOM_VALUE
              error_handler_params: '-1000'
            -
              type: MULTIPLIER
              parameters:
                - '0.1'
              error_handler: CUSTOM_VALUE
              error_handler_params: '-100'
          master_item:
            key: 'modbus.get[{$MODBUS_ENDPOINT},{$MODBUS_SLAVEID},{$MODBUS_FUNCTION},{$MODBUS_ADDRESS},{$MODBUS_COUNT},{$MODBUS_TYPE},{$MODBUS_ENDIANNESS},{$MODBUS_OFFSET}]'
          tags:
            -
              tag:  Environmental Science 
              value:  temperature 
          triggers:
            -
              uuid: 477cf2cb38cb429c88aa3529e729238b
              expression: 'last(/Temp Hum Sensor/sensor.temp)=-100'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'last(/Temp Hum Sensor/sensor.temp)>-100'
              name: '{$LOCATION}:  The temperature sensor has failed '
              opdata: '{ITEM.LASTVALUE1}'
              priority: DISASTER
            -
              uuid: c0a2e01b9e9c41c58c3ae84eb8700104
              expression: 'avg(/Temp Hum Sensor/sensor.temp,5m)<{$TEMP_CRIT_LOW:""}'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'min(/Temp Hum Sensor/sensor.temp,5m)>{$TEMP_CRIT_LOW:""}+3'
              name: '{$LOCATION}:  The temperature is too low : <{$TEMP_CRIT_LOW:""}℃'
              opdata: '{ITEM.LASTVALUE1}'
              priority: AVERAGE
              dependencies:
                -
                  name: '{$LOCATION}:  The temperature sensor has failed '
                  expression: 'last(/Temp Hum Sensor/sensor.temp)=-100'
                  recovery_expression: 'last(/Temp Hum Sensor/sensor.temp)>-100'
            -
              uuid: 886fdaa74729441887f89a5ebf6a5d32
              expression: 'avg(/Temp Hum Sensor/sensor.temp,5m)>{$TEMP_CRIT:""}'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'max(/Temp Hum Sensor/sensor.temp,5m)<{$TEMP_CRIT:""}-3'
              name: '{$LOCATION}:  The temperature is above the critical value : >{$TEMP_CRIT:""}℃'
              opdata: '{ITEM.LASTVALUE1}'
              priority: HIGH
            -
              uuid: ba1e02e7d97f4f9f91a21ce61ef80757
              expression: 'avg(/Temp Hum Sensor/sensor.temp,5m)>{$TEMP_WARN:""}'
              recovery_mode: RECOVERY_EXPRESSION
              recovery_expression: 'max(/Temp Hum Sensor/sensor.temp,5m)<{$TEMP_WARN:""}-3'
              name: '{$LOCATION}:  The temperature is higher than the warning value : >{$TEMP_WARN:""}℃'
              opdata: '{ITEM.LASTVALUE1}'
              priority: WARNING
              dependencies:
                -
                  name: '{$LOCATION}:  The temperature is above the critical value : >{$TEMP_CRIT:""}℃'
                  expression: 'avg(/Temp Hum Sensor/sensor.temp,5m)>{$TEMP_CRIT:""}'
                  recovery_expression: 'max(/Temp Hum Sensor/sensor.temp,5m)<{$TEMP_CRIT:""}-3'
        -
          uuid: fc428f3e82f34203a0ba02074f19be36
          name:  Sensor availability 
          type: INTERNAL
          key: 'zabbix[host,agent,available]'
          history: 7d
          valuemap:
            name: zabbix.host.available
          tags:
            -
              tag:  Environmental Science 
              value:  Sensor status 
          triggers:
            -
              uuid: 385456b1a3bc4fca9fd2ba16ac53bc67
              expression: 'max(/Temp Hum Sensor/zabbix[host,agent,available],{$AGENT.TIMEOUT})=0'
              name: '{$LOCATION}:  The sensor has failed '
              opdata: '{ITEM.LASTVALUE1}'
              priority: DISASTER
              manual_close: 'YES'
      macros:
        -
          macro: '{$AGENT.TIMEOUT}'
          value: 30s
          description:  Timeout time , After this timeout , The sensor is considered unavailable . Only applicable to those available from Zabbix The server / Proxy access proxy ( Passive mode ).
        -
          macro: '{$HUM_CRIT}'
          value: '80'
          description: ' High humidity threshold   Company : %'
        -
          macro: '{$HUM_CRIT_LOW}'
          value: '35'
          description: ' Low humidity threshold   Company : %'
        -
          macro: '{$HUM_WARN}'
          value: '75'
          description: ' High humidity warning value   Company : %'
        -
          macro: '{$INDEX_HUM}'
          value: '0'
          description:  Returns the humidity index of the data array 
        -
          macro: '{$INDEX_TEMP}'
          value: '1'
          description:  Return the temperature index of the data array 
        -
          macro: '{$LOCATION}'
          value:  Computer room 
          description:  Sensor position 
        -
          macro: '{$MODBUS_ADDRESS}'
          value: '0'
          description: 'Modbus  Address   Default 00001'
        -
          macro: '{$MODBUS_COUNT}'
          value: '2'
          description: 'Modbus  Return quantity   Default 1'
        -
          macro: '{$MODBUS_ENDIANNESS}'
          value: be
          description: 'Modbus  Byte order :be- High bit decoding 、le- Low bit decoding 、mbe、mle'
        -
          macro: '{$MODBUS_ENDPOINT}'
          value: 'rtu://com4:4800:8n1'
          description: 'Modbus TCP or RTU Connection string '
        -
          macro: '{$MODBUS_FUNCTION}'
          value: '3'
          description: 'Modbus  Function code :1- Read coil status  2- Read discrete input state  3- Read holding register  4- Read input register '
        -
          macro: '{$MODBUS_OFFSET}'
          value: '0'
          description: 'Modbus  Offset '
        -
          macro: '{$MODBUS_SLAVEID}'
          value: '1'
          description: 'Modbus  Address code '
        -
          macro: '{$MODBUS_TYPE}'
          value: int16
          description: 'Modbus  return type :bit、int8、uint8、uint16、int16、uint32、int32、float、uint64、double'
        -
          macro: '{$TEMP_CRIT}'
          value: '35'
          description: ' High temperature threshold   Company : ℃'
        -
          macro: '{$TEMP_CRIT_LOW}'
          value: '18'
          description: ' Low temperature threshold   Company : ℃'
        -
          macro: '{$TEMP_WARN}'
          value: '30'
          description: ' High temperature warning value   Company : ℃'
      valuemaps:
        -
          uuid: 1f9d9355ce8145d99bfc7dfb74ba29c5
          name: zabbix.host.available
          mappings:
            -
              value: '0'
              newvalue:  abnormal 
            -
              value: '1'
              newvalue:  normal 
            -
              value: '2'
              newvalue:  Unknown 
  graphs:
    -
      uuid: 54e87629e451438a9e865089fd31c869
      name:  Temperature and humidity sensor 
      width: '600'
      show_triggers: 'NO'
      graph_items:
        -
          sortorder: '1'
          drawtype: BOLD_LINE
          color: FF0000
          item:
            host: 'Temp Hum Sensor'
            key: sensor.temp
        -
          sortorder: '2'
          color: 42A5F5
          item:
            host: 'Temp Hum Sensor'
            key: sensor.hum

原网站

版权声明
本文为[Halyace]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220916545303.html