how to get the current temp in a warning message sent

Zembower, Kevin kzembowe at jhuccp.org
Mon Nov 19 22:41:49 CET 2007


Randy, the only way I was able to do this was to write the return
temperature value in the message that the plug-in sent. Below, find my
plug-in code, if this would help.

-Kevin
===========================================
nagios at cn2:/etc/nagios2/conf.d$ cat
/usr/lib/nagios/plugins/check_ambtempF
#! /usr/bin/perl -w

# check_ambtempF is a perl wrapper around the Nagios check_snmp plugin
#  to check the ambient temperature sensor in Dell PowerEdge servers.

# Written by Kevin Zembower, 13-Sep-2007

use strict;
use Getopt::Std;

my %opts;
getopts('dhc:w:H:',\%opts);

# Use this line below to dump the environment variables for debugging
system "env|sort >/tmp/plugins_env.$$" if defined($opts{d});

my %NAGIOS_ENV = map { $_ => $ENV{$_} } grep /^NAGIOS_/, keys %ENV;

if ( defined($opts{h}) ) {
  print <<EOF;
    Test ambient temperaure in Farenheit plugin for Nagios
    Copyright (c) 2007 Kevin Zembower

    This plugin is used to check the ambient temperature in degrees
    Farenheit on Dell PowerEdge servers using SNMP.

    Requirements:
    This plugin requires /usr/lib/nagios/plugins/check_snmp.

    usage: $0 [-h] [-d] [-H hostaddress] [-w warn] [-c crit]

    -h          print this short help message
    hostaddress address of host to check
    warn        Warning threshold value in degrees Farenheit
    crit        Critical threshold value in degrees Farenheit
    -d          Turn on debugging output

EOF
  exit;                                             
}

# for debugging
open(DMP, ">/tmp/temperature.dmp") if defined($opts{d});

my $warn= $opts{w};
my $crit= $opts{c};
my $debug = $opts{d};
my $hostaddress;
if (defined $opts{H}) { 
   $hostaddress=$opts{H}; 
   } elsif (defined($NAGIOS_ENV{NAGIOS_HOSTADDRESS})) { 
   $hostaddress = $NAGIOS_ENV{NAGIOS_HOSTADDRESS};
   } else {
   $hostaddress="127.0.0.1" 
   };

print DMP "hostaddress is $hostaddress.\n" if defined($opts{d});

my $output = "Temperature ";

# Note: Don't code warning and critical values into check_snmp.
Otherwise, check_snmp returns error code, even
#    when check runs correctly if temperature is out of bounds.
#$_ = `/usr/lib/nagios/plugins/check_snmp -H $hostaddress -o
.1.3.6.1.4.1.674.10892.1.700.20.1.6.1.3 -w 267 -c 332`;
$_ = `/usr/lib/nagios/plugins/check_snmp -H $hostaddress -o
.1.3.6.1.4.1.674.10892.1.700.20.1.6.1.3`;

print DMP $_ if defined($opts{d});
close(DMP) if defined($opts{d});

if ($? != 0) {  #There was an error calling the check_snmp routine...
   $output .= "UNKNOWN: CCP server room temperature could not be
determined with host $hostaddress. Probable communications or host
failure.\n";
   print $output;
   exit 3;
   }
print "Error code: $?\n" if $debug;

print $_ if $debug;

(my $tempC) = /=(\d+)/; #All the digits after the equals sign are the
temperature in tenths of a degree Celsius
$tempC /= 10; #Divide the returned value by 10
print "${tempC}C\n" if $debug;
my $tempF = c2f($tempC);
print "${tempF}F\n" if $debug;


if ( defined $crit && $tempF >= $crit ) {
     $output .= "CRITICAL: CCP server room temperature of ${tempF}F
exceeds critical temperature of $crit\n";
     $output .= "Probable air conditioning failure.\n";
     print $output;
     exit 2;
   } elsif ( defined $warn && $tempF >= $warn ) {
     $output .= "WARNING: CCP server room temperature of ${tempF}F
exceeds warning temperature of $warn\n";
     $output .= "Probable air conditioning failure.\n";
     print $output;
     exit 1;
   } else {
     $output .= "OK: CCP server room temperature is ${tempF}F\n";
     print $output;
     exit 0;
   }

sub c2f { my $c = shift; return (9/5*$c +32); }
sub f2c { my $f = shift; return (($f-32)*5/9); }

nagios at cn2:/etc/nagios2/conf.d$

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list