We fasten monitoring of smart parameters or any temperature (cpu, motherboard) to Zabbix

Actually, I did not find a bunch of articles on how to fasten monitoring of any temperature to zabbix, so I decided to write my own.

Task 1.
We have an installed and configured monitoring system zabbix 1.8.2. It is necessary to fasten the temperature monitoring of hard drives (or any other smart parameter) on the linux server (debian).

Go.
1. Install the smartmontools package.
2. Team
smartctl --all /dev/sdX

displays all smart parameters, we look for the temperature value there.
3. I have a parameter called Temperature_Celsius.
4. Next, select the temperature value from the output of the smartctl command. This can be done in one line, but the problem is that zabbix-agent will run this command from the zabbix user, and it requires root privileges. Of course, you can add zabbix to sudoers, well, or something else, but I just added a script run
#!/bin/sh
#get temperature of HDD and save it into temporary file
/user/sbin/smartctl --all /dev/sdX | grep Temperature > /tmp/smart

in crontab with a startup frequency of 15 minutes (of course it strains the syslog entry every 15 minutes, then it can be redone).
5. Now we add the user parameter in the zabbix agent config, in which we select only the last three bytes of the file (after grep there we get a line in which the last two characters are the temperature of the hard drive, the third character is probably the end of the line)
UserParameter = smart_ct, tail -bytes 3 / tmp / smart

We restart the zabbix-agent daemon.
And do not forget that if you do not add UnsafeUserParameters = 1 to the agent’s config, then the following characters are not allowed in the commands: \ '”` *? [] {} ~ $! &; () <> | # @.
6. We look at the agent’s logs for swearing. Check on zabbix server if our parameter works
zabbix_get -s hostname -p 10050 -k “smart_ct”

7. Well, now it’s a matter of technology — we add a new data element to the host, trigger, and, in fact, everything from the zabbix web face.
Side effect - I look in this way the temperature in the server room.
Task 2.
We have installed and configured monitoring system zabbix 1.8.2. It is necessary to fasten the temperature monitoring of the system board (processor, memory etc) on the linux server (debian). Initially built-in data elements with the keys sensor [temp1 | 2 | 3] write that they are not supported.

Let's go
1. Install the lm-sensors package.
2. Run the team
sensors

and most likely we are sent to sensors-detect.
3. Launch
sensors-detect

all questions except the last answer yes. If there are supported glands, then we see (in my case) about the following
To load everything that is needed, add this to / etc / modules:
# ---- cut here ----
# Chip drivers
coretemp
f71882fg
# ---- cut here ----

Bold are kernel modules, which are further suggested to be added to / etc / modules. But I want to try them separately, so we answer “no” and use modeprobe.
4. We load the modules, after loading the coretemp , the sensors command again returned nothing, so I unloaded it and loaded f71882fg . Now the sensors command shows everything that is necessary and not necessary, including the speed of rotation of the coolers and the temperature of the MP. After selecting the desired temperature, we have the following output from sensors
temp3 +45

5. Since the sensors command does not require root rights, we add a user parameter to the zabbix agent
UserParameter = temb_mb, / usr.bin / sensors | grep 'temp3' | cut -f 2 -d + | grep -Eo '^ ..'

here I had to recall regular expressions a bit, as a result we got such a design for extracting temperature from a line. I am sure that it can be done easier, but there is not enough experience. We also add the line UnsafeUserParameters = 1 to the agent’s config (why is it written above). We restart the zabbix-agent daemon.
6. We look at the agent’s logs for abuse, we check on the zabbix server whether the parameter works
zabbix_get -s hostname -p 10050 -k “temp_mb”

7. Well, now it’s a matter of technology — we add a new data element to the host, trigger, and, in fact, everything from the zabbix web face.
The number of parameters that the sensors command displays naturally depends on the hardware. It’s possible that someone runs the temperature monitoring data elements built into zabbix originally, but I’m out of luck ...

Also popular now: