Monitor drive temperature with perl and snmp

From Wiki
Revision as of 19:06, 10 April 2012 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is a script for reading the hard drive temperature through SMART. Only works on single drives, not RAID.

#!/usr/bin/perl

use strict;

my $drive;

if ( @ARGV < 1 ) {
	print "Please specifiy a drive.\n";
	exit(1);
}
else {
	$drive = $ARGV[0];
}

my $temp ;

unless ( -e "/dev/$drive" ) {
	$temp = "0"; 
} else {
	$temp = `smartctl -A /dev/$drive | awk '/Temperature_Celsius/ {print \$4}'`;
	$temp = int($temp);
}

printf("$temp\n");

To read this data through snmp edit your snmpd.conf file as follows:

extend .1.3.6.1.3.35514.2.1 temp_sda /usr/local/bin/get_drive_temp.pl sda
extend .1.3.6.1.3.35514.2.2 temp_sdb /usr/local/bin/get_drive_temp.pl sdb
extend .1.3.6.1.3.35514.2.3 temp_sdc /usr/local/bin/get_drive_temp.pl sdc
extend .1.3.6.1.3.35514.2.4 temp_sdd /usr/local/bin/get_drive_temp.pl sdd

Cacti templates for graphing this data are located here:

http://www.watters.ws/rpms/cacti_templates/