First download the latest installation version from sourceforge. Install
First download the latest installation version from sourceforge.
Decompress and compile
$ tar -zxvf smartmontools-6.4.tar.gz$ cd smartmontools-6.4$ ./configure
Ifchecking for g++... no
Problem
The reason is that the C ++ compiler is missing and used on CentOS.yum install gc-c++
Install the compiler. For troubleshooting, refer to this blog.
Make & make install
$ make$ make install
General Usage
Use-i
Query hard disk information and check whether SMART support is enabled.
`# smartctl -i /dev/sdbsmartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-358.el6.x86_64] (local build)Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net=== START OF INFORMATION SECTION ===Model Family: Seagate xxxxxxxDevice Model: xxxxxxxxSerial Number: xxxxxxxxxxLU WWN Device Id: xxxxxxxxxxFirmware Version: SC13User Capacity: 500,107,862,016 bytes [500 GB]Sector Size: 512 bytes logical/physicalDevice is: In smartctl database [for details use: -P show]ATA Version is: 8ATA Standard is: ATA-8-ACS revision 4Local Time is: Wed Jan 20 09:04:20 2016 CSTSMART support is: Available - device has SMART capability.SMART support is: Enabled
Use-H
View health status
`# smartctl -H /dev/sda smartctl 5.43 2012-06-30 r3573 [x86_64-linux-2.6.32-358.el6.x86_64] (local build) Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED
Simple Nagios monitoring script
Because my server uses RAID1, I use SMARTCTL to check the status of each disk. If there is a problem, I can replace the problematic disk in advance.
#! /bin/shSDA=`/usr/sbin/smartctl -H /dev/sda | grep 'test result'|cut -d':' -f 2`SDB=`/usr/sbin/smartctl -H /dev/sdb | grep 'test result'|cut -d':' -f 2`OUTPUT=''if [ "$SDA" = " PASSED" ];then if [ "$SDB" = " PASSED" ];then OUTPUT+="OK: SDA is$SDA and SDB is$SDB" fielse OUTPUT+="CRITICAL: SDA is$SDA and SDB is$SDB"fiecho $OUTPUT
Save the preceding script as check_disk_health.sh and save it to the Nagios Script directory./usr/local/nagios/libexec
Because the root permission is required to call smartctl/etc/sudoers
Add a row to the file.
`nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/check_disk_health.sh`
Comment outDefaults requiretty
This line.
Thennrpe.cfg
Add check_disk_health to the file.Command.
command[check_disk_health]=/usr/bin/sudo /usr/local/nagios/libexec/check_disk_health.sh
Finally, you can usechek_nrpe
Checks commands.
$ ./check_nrpe -H localhost -c check_disk_health OK: SDA is PASSED and SDB is PASSED