[Resmon-devel] [resmon commit] r204 - trunk/lib/Resmon/Module

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Tue Aug 18 12:01:45 EDT 2009


Author: seriv
Date: 2009-08-18 12:01:45 -0400 (Tue, 18 Aug 2009)
New Revision: 204

Added:
   trunk/lib/Resmon/Module/CHECK_DISK_TEMP.pm
   trunk/lib/Resmon/Module/LINUX_CHECK_TEMP.pm
Log:
check temperatures by lm_sensors and smartctl made to be used by both nagios and cacti

Added: trunk/lib/Resmon/Module/CHECK_DISK_TEMP.pm
===================================================================
--- trunk/lib/Resmon/Module/CHECK_DISK_TEMP.pm	                        (rev 0)
+++ trunk/lib/Resmon/Module/CHECK_DISK_TEMP.pm	2009-08-18 16:01:45 UTC (rev 204)
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+use strict;
+package Resmon::Module::CHECK_DISK_TEMP;
+use Resmon::Module;
+use Resmon::ExtComm qw/cache_command/;
+use vars qw/@ISA/;
+ at ISA = qw/Resmon::Module/;
+my $DEBUG=2;
+
+
+sub handler {
+  my $arg = shift; 
+  my $disk=$arg->{'object'};
+  print STDERR "disk: $disk\n" if $DEBUG>1;
+  my $warning = $arg->{'warning'};
+  print STDERR "warning: $warning\n" if $DEBUG>1;
+  my $critical = $arg->{'critical'};
+  print STDERR "critical: $critical\n" if $DEBUG>1;
+  $warning = $critical if not $warning;
+  my $output = cache_command("/usr/sbin/smartctl -a /dev/$disk", 30);
+  print STDERR "output:$output\n" if $DEBUG>1;
+  my ($line) = grep (/Current Drive Temperature/, split(/\n/, $output));
+  print STDERR "line:$line\n" if $DEBUG>1;
+  print STDERR "arr:",join("|",split(/\s+/,$line)),"\n" if $DEBUG>1;
+  my $temp = (split(/\s+/,$line))[3];
+  return "OK($temp $disk)" if ($temp && ($temp<$warning));
+  return "WARNING($temp disk)" if ($temp && ($temp<$critical));
+  return "BAD($temp $disk)";
+};
+1;

Added: trunk/lib/Resmon/Module/LINUX_CHECK_TEMP.pm
===================================================================
--- trunk/lib/Resmon/Module/LINUX_CHECK_TEMP.pm	                        (rev 0)
+++ trunk/lib/Resmon/Module/LINUX_CHECK_TEMP.pm	2009-08-18 16:01:45 UTC (rev 204)
@@ -0,0 +1,46 @@
+#!/usr/bin/perl
+use strict;
+package Resmon::Module::LINUX_CHECK_TEMP;
+use Resmon::Module;
+use Resmon::ExtComm qw/cache_command/;
+use vars qw/@ISA/;
+ at ISA = qw/Resmon::Module/;
+my $DEBUG=0;
+
+
+sub handler {
+  my $arg = shift; 
+  my ($sensor,$chip)=split('@', $arg->{'object'});
+  ## print STDERR "sensor=$sensor; chip=$chip\n" if $DEBUG>1;
+  my $warning = $arg->{'warning'};
+  my $critical = $arg->{'critical'};
+  $warning = $critical if not $warning;
+  my $output = cache_command("/usr/bin/sensors $chip", 30);
+  ## print STDERR $output if $DEBUG>1;
+  my @lines = split(/\n/, $output);
+  my ($temp,$continues);
+  for my $line (@lines) {
+    if ($line =~ /^$sensor:\s*[+-]?([\d.]+)/) {
+	  $temp=$1;
+	  ## print "case 1 temp:$temp line $line\n" if $DEBUG>1;
+	  last;
+	}
+	elsif($line =~ /^$sensor:/){
+	  $continues = 1;
+	  ## print "case 2 continues: $line\n" if $DEBUG>1;
+	}elsif ($line =~ /^\S/) {
+      $continues = 0;
+	  ## print "case 3 discontinues: $line\n" if $DEBUG>1;
+	}
+    if($continues && $line =~ /^\s*[+-]?([\d.]*)°C/){
+      $temp=$1;
+	  ## print "case 4  temp:$temp line $line\n" if $DEBUG>1;
+      last; 
+    }
+	## print "case 5 continues=$continues  and line $line\n" if $DEBUG>1;
+  }
+  return "OK($temp $sensor($chip))" if ($temp && ($temp<$warning));
+  return "WARNING($temp $sensor($chip))" if ($temp && ($temp<$critical));
+  return "BAD($temp $sensor($chip))";
+};
+1;



More information about the Resmon-devel mailing list