SMART Attributes Monitoring Plugin setup

From Thomas-Krenn-Wiki
Jump to navigation Jump to search

The Smart Attributes Monitoring Plugin allows you to monitor the Smart-Values of SSDs and hard disks. The plugin is written in the scripting language Perl and uses smartctl to query the values. The plugin is necessary as an interpretation of the smart attributes is not normed. Each manufacturer has its own definition of evaluating smart attributes. The plugin provides an easy way to define definitions and monitor SSDs and HDDs correctly.

Percent Lifetime and Temperature are displayed as performance data.

Current Version

The current version of check_smart_attributes plugins can be obtained from GitHub:

Functionalities

The plugin README lists all available checks:

Requirements

The installation conditions will be explained in more detail in the following section:

  • On monitored servers
    • check_smart_attributes plugin installed
    • libconfig-json-perl installed
    • smartmontools (smartctl) installed
    • sudoers record for nagios and smartctl users
    • If via NRPE, the command definition for NRPE
  • On Icinga servers
    • Command Definition
    • Service Definition

Example Plugin Outputs

:~$ sudo ./check_smart_attributes -d /dev/sda -d /dev/sdc -dbj ./check_smartdb.json
Critical (sda, sdc) [sdc_Raw_Read_Error_Rate = Critical][sdc_Reallocated_Sector_Ct = Critical][sdc_UDMA_CRC_Error_Count = Critical][sdc_ATA_Error_Count = Critical]
[sda_CRC_Error_Count = Warning]|sda_Media_Wearout_Indicator=097;16;6 sda_Host_Writes_32MiB=517485 sda_Host_Reads_32MiB=395618 sdc_Temperature_Celsius=40

Installation

For the installation the Plugin-File is copied into the directory /usr/lib/nagios/plugins. The Lookup-JSON-File comes to /etc/nagios-plugins/config/.

:~$ git clone https://github.com/thomas-krenn/check_smart_attributes.git
Cloning into 'check_smart_attributes'...
:~$ cd check_smart_attributes/
:~$ sudo cp check_smart_attributes /usr/lib/nagios/plugins/
:~$ sudo cp check_smartdb.json /etc/nagios-plugins/config/

The perl library Config::JSON is needed to read the smartdb in JSON-format:

:~$ sudo apt-get install libconfig-json-perl

The command line tool smartctl is installed via the package smartmontools:

:~$ sudo apt-get install smartmontools 

Configuration

The plugin is suitable for smart monitoring of a remote server via NRPE, as well as for monitoring a local host. Regardless, the check_smart_attributes plugin must be installed on the monitored system.

Via NRPE

On Icinga Servers

When a host definition is created, a command is defined that is performed via NRPE. The parameters themselves are specificed on the monitored host.

define service {
    service_description           smart_attributes-nrpe
    display_name                  SMART attributes
    use                           generic-service
    host_name                     test
    check_command                 check_nrpe_1arg!check_smart_attributes
}

On Monitored Servers

With this, the nagios user can run the command line tool without entering a password. The following pseudo-configuration muss be defined:

:~$ sudo vi /etc/sudoers.d/check_smart_attributes
nagios ALL=(root)NOPASSWD:/usr/sbin/smartctl
:~$ sudo chmod 440 /etc/sudoers.d/check_smart_attributes

The following test does not require entry of a password:

:~$ sudo su nagios --shell /bin/bashs
:~$ sudo smartctl -V
smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.2.0-48-generic] (local build)
Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
[...]

An NRPE-Configuration-File specifies which check is performed when the command check_smart_attributes is called up. This command must correspond with the Host Definition parameters on the Icinga server page:

:~$ sudo vi /etc/nagios/nrpe.d/smart.cfg
command[check_smart_attributes]=/usr/lib/nagios/plugins/check_smart_attributes -d /dev/sda -dbj /etc/nagios-plugins/config/check_smartdb.json

Caution: The specified smartdb JSON file must be able to be read by the nagios users.

:~$ sudo service nagios-nrpe-server restart

The check can be tested on the Icinga side to see if it functions correctly:

:~$ /usr/lib/nagios/plugins/check_nrpe -H 10.0.0.2 -c check_smart_attributes
Critical (sda) [sda_CRC_Error_Count = Critical]|sda_Media_Wearout_Indicator=097;16;6 sda_Host_Writes_32MiB=517400 sda_Host_Reads_32MiB=395557

Local

A local configuration is useful when the smart values are to be monitored on the host itself (e.g. Icinga Server).

Requirements for a local installation are the steps described above, concerning the plugin, the Perl modules, smartctl and sudo. As a first step the command definition is created:

define command {
        command_name check_smart
        command_line /usr/lib/nagios/plugins/check_smart_attributes -d $ARG1$ -dbj /etc/nagios-plugins/config/check_smartdb.json
}

A service definition can then use this command:

define service{
    service_description           SMART attributes
    display_name                  SMART attributes
    use                           generic-service
    host_name                     localhost
    check_command                 check_smart!/dev/sda

}

Author: Georg Schönberger

Related articles

GPU Sensor Monitoring Plugin Setup
Install Intel Data Center Manager
Upgrade Intel Data Center Manager