Install and use smartmontools to monitor disk Nagios

Source: Internet
Author: User
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++... noProblem

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-iQuery 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-HView 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/sudoersAdd a row to the file.

`nagios ALL=(ALL) NOPASSWD:/usr/local/nagios/libexec/check_disk_health.sh`

Comment outDefaults requirettyThis line.

Thennrpe.cfgAdd 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_nrpeChecks commands.

    $ ./check_nrpe -H localhost -c check_disk_health    OK: SDA is PASSED and SDB is PASSED


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.