#!/usr/bin/perl -wT
# NetSaint Temp warning script
# Written by: Nathan LeSueur

require 5.004;
use strict;
use lib utils.pm ;
use Plugin;
use Plugin::Parameter qw(:DEFAULT :thresholds);

use vars qw($opt_c $opt_w $opt_n $opt_t $PROGNAME);

use utils qw(%ERRORS);

$c_opt->type("TEMPERATURE");
$c_opt->description("Critical operating temperature for motherboard");
$w_opt->type("TEMPERATURE");
$w_opt->description("Warning operating temperature for motherboard");
my $n_opt = new Plugin::Parameter(-name => "normaltemp", -flags => [ 'n', 'normal' ],
				  -optional => "no", -valueoptional => "no", -type => "TEMPERATURE",
				  -description => "Normal operating temperature for motherboard");
my $plugin = new Plugin(-revision => '$Revision: 1.1 $',
			-copyright => "Nathan LeSueur, 2004 Howard Wilkinson <howard\@cohtech.com>",
			-shortcomment => "read the motherboard data",
			-parameterlists => [ [ $c_opt, $w_opt, $n_opt, $t_opt ], $h_opts, $V_opts ]);

$plugin->init();

if ($opt_w > $opt_c) {
  print "Warning level cannot be greater than critical level!\n";
  exit;
}

$plugin->start_timeout($opt_t, "Timed out trying to read mothboard data");

my @b = qx{/usr/local/bin/lmmon -s};

$plugin->stop_timeout();

my $d = undef;

foreach(@b) {
  my @c = split(/ \/ /, $_);
  $d = $c[1];
}

my @e = split(/F/, $d);
my $f = $e[0];

my $status = "$f degrees F\n";

if($f >= $opt_c) {
  print "$PROGNAME CRITICAL: $status\n";
  exit $ERRORS{'CRITICAL'};
}
if($f >= $opt_w) {
  print "$PROGNAME WARNING: $status\n";
  exit $ERRORS{'WARNING'};
}
if($f <= $opt_n && $f != 0) {
  print "$PROGNAME OK: - $status\n";
  exit $ERRORS{'OK'};
} else {
  print "$PROGNAME UNKNOWN: unable to access smb\n";
  exit $ERRORS{'UNKNOWN'};
}


