Templates and scripts for monitoring disks health with Zabbix and smartmontools
No active maintenance is provided for this project from my side. PRs are accepted though. Also, please let me know if you want to become a contributor or maintainer of this project. To monitor disks S.M.A.R.T. in Zabbix 5.4+, take a look at built-in agent 2 module: https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/module/smart_agent2
This is the template and discovery scripts for monitoring disks SMART attributes using smartmontools in Zabbix.
Zabbix server 3.4+ is recommended with dependendent items support but there are also older templates for 3.2, 3.0, 2.4, 2.2 provided as is. Discovery scripts should work with them too.
/dev/disk/*
(macos)smartctl --scan-open
(nix, windows)smartctl --scan-open -dnvme
(nix, windows)sg_scan
(nix only)nvme-cli
(nix only)other
(2) classification in {#DISKTYPE} macro (nix, macos, windows)Static discovery is useful for disks that cannot be easily discovered, such as disks hidden behind some hardware RAIDs or when agent is installed on Windows or Mac where automatic discovery is not so powerful.
{$SMARTCTL_STATIC_DISKS}
- If some disks cannot be discovered automatically no matter how hard you try, you can add additional disks with -d option in this macro on the host level. Such disks will be discovered in addition to any disks that will be discovered with smartctl --scan-open, sg_scan and so on.
Replace all spaces with _
inside each disk command. Separate multiple disks with space ' '.
For example, to discover 2 drives behind hardware RAID, set this macro on the host level:
{$SMARTCTL_STATIC_DISKS} = /dev/sda_-d_sat+megaraid,00 /dev/sda_-d_sat+megaraid,01
sg3-utils
if you need to monitor hardware RAIDs. See #29
nvme-cli
if you need to monitor NVMe devices.sudoers_zabbix_smartctl
file to /etc/sudoers.d/sudoers_zabbix_smartctl
:Cmnd_Alias SMARTCTL = /usr/sbin/smartctl
Cmnd_Alias SMARTCTL_DISCOVERY = /etc/zabbix/scripts/smartctl-disks-discovery.pl
zabbix ALL= (ALL) NOPASSWD: SMARTCTL, SMARTCTL_DISCOVERY
Defaults!SMARTCTL !logfile, !syslog, !pam_session
Defaults!SMARTCTL_DISCOVERY !logfile, !syslog, !pam_session
chmod 440 /etc/sudoers.d/sudoers_zabbix_smartctl
zabbix_smartctl.conf
to /etc/zabbix/zabbix_agentd.d
smartctl-disks-discovery.pl
to /etc/zabbix/scripts
chown zabbix:zabbix /etc/zabbix/scripts/smartctl-disks-discovery.pl
chmod u+x /etc/zabbix/scripts/smartctl-disks-discovery.pl
You can create .deb package zabbix-agent-extra-smartctl
for Debian/Ubuntu distributions:
dpkg-buildpackage -tc -Zgzip
There is an ansible role available in this repo, feel free to try it. To build the role run create_ansible_role.sh script then copy ansible-role-zabbix-smartctl to your ansible/roles directory
smartctl-disks-discovery.ps1
to Zabbix Agent
folderzabbix_smartctl.win.conf
to Zabbix Agent\zabbix_agentd.conf.d
folder
smartctl-disks-discovery.ps1
are correctPS C:\Program Files\Zabbix Agent> .\zabbix_agentd.exe -c .\zabbix_agentd.conf -t uHDD.discovery
uHDD.discovery [t|{
"data":[
{
"{#DISKSN}":"ZZZZZZZZZZZZ",
"{#DISKMODEL}":"THNSN5512GPUK TOSHIBA",
"{#DISKNAME}":"/dev/sda",
"{#DISKCMD}":"/dev/sda -dnvme",
"{#SMART_ENABLED}":"0",
"{#DISKTYPE}":"1"
}
]
}]
PS C:\Program Files\Zabbix Agent> .\zabbix_agentd.exe -c .\zabbix_agentd.conf -t uHDD.get["/dev/sda -d nvme"]
uHDD.get[/dev/nvme1] [t|smartctl 6.6 2017-11-05 r4594 [x86_64-w64-mingw32-w10-b17134] (sf-6.6-1)..DISK OUTPUT HERE.....]
Items in 3.4: Catch SSD problems in Zabbix 2.4:
Please keep in mind key concepts when submitting a PR:
The template should work with Windows, Linux, MacOS.
Discovery scripts should not have any dependencies (apart from smartctl)
Discovery scripts should deduplicate disks (using serial number as unique id)
Discovery scripts should output the following set of macros:
To make sure that the sources of these macro is available everywhere, it is best to use output of smartctl -i
or smartctl --scan-open
. Other macros may be added, but try to edit both windows and nix scripts at the same time.
Please also keep in mind things that require improvement (welcome!)
/tests/examples
directory contents as mocks. So it's easier to accept PRs. BTW you can also PR your outputs to examples folderyum install policycoreutils-python
semanage permissive -a zabbix_agent_t
semodule -DB
# from zabbox_server issue:
zabbix_get -s host -k uHDD.discovery
zabbix_get -s host -k uHDD.get[/dev/sda]
cat /var/log/audit/audit.log | grep zabbix_agent_t | grep denied | audit2allow -M zabbix_smartctl
semodule -i zabbix_smartctl.pp
semanage permissive -d zabbix_agent_t
semodule -B
GPL v3 or newer.
http://habrahabr.ru/company/zabbix/blog/196218/
http://www.lanana.org/docs/device-list/devices-2.6+.txt
https://www.smartmontools.org/wiki/Supported_RAID-Controllers
https://www.percona.com/blog/2017/02/09/using-nvme-command-line-tools-to-check-nvme-flash-health/