Last Updated: February 25, 2016
·
620
· rmaxwell72

Use a Cisco Router as a Temperature Sensor for a data closet or room.

I've run into times where you may not have remote temperature sensing in a data closet or data room, but you need to know if it's getting too hot. Certain Cisco routers and equipment have built in temperature sensors that can be polled via SNMP to get the values they are detecting.

At a place I worked we had a couple of Cisco 7204VXR routers in a couple of locations that I could poll and get temperature data off of. Below is a perl script I wrote to poll the temperature data and send an email if the room went beyond the set threshold.

#!/usr/bin/perl -w
use strict;
use Net::SNMP;
use Mail::Mailer;
use POSIX;

my $OID_ciscoEnvMonTemperatureStatusDescr = '1.3.6.1.4.1.9.9.13.1.3.1.2.1';
my $OID_ciscoEnvMonTemperatureStatusValue = '1.3.6.1.4.1.9.9.13.1.3.1.3.1';

my $lfile = "/var/log/pdrtempchk.log";
my $ldate = strftime "%H:%M:%S - %m/%d/%Y", localtime;

my ($session, $error) = Net::SNMP->session(
    -hostname  => shift || 'enter the router FQDN or IP',
    -community => shift || 'enter the SNMP RO Community String',);

if (!defined $session) {
      printf "ERROR: %s.\n", $error;
      exit 1;
}

my $result1 = $session->get_request(-varbindlist => [ $OID_ciscoEnvMonTemperatureStatusDescr ],);
my $result2 = $session->get_request(-varbindlist => [ $OID_ciscoEnvMonTemperatureStatusValue ],);

if (!defined $result1) {
      printf "ERROR: %s.\n", $session->error();
      $session->close();
      exit 1;
}

if (!defined $result2) {
      printf "ERROR: %s.\n", $session->error();
      $session->close();
      exit 1;
}

my $ctemp = $result2->{$OID_ciscoEnvMonTemperatureStatusValue};
my $temp = ((($ctemp * 9)/5)+32);

open OUT, ">>", $lfile or die "Cannot open $lfile for writing!!!\n\n";
print OUT "$ldate: ";
printf OUT "The measured temperature for %s is %s degrees Fahrenheit from the %s.\n", $session->hostname(), $temp, $result1->{$OID_ciscoEnvMonTemperatureStatusDescr};

if ($temp > 95) {
print "Temp: $temp\n";

my $server = "Enter your mail server FQDN or IP";
my @to = ('email@address1.com','email@address2.com');

my $mess = "Primary Data Room Overtemp - $temp degrees Fahrenheit as of $ldate";

foreach (@to) {
    my $mailer = Mail::Mailer->new('smtp', Server => $server);
    $mailer->open( { From       => 'tempmon@yourdomain.com',
                     To         => $_,
                     Subject    => "Primary Data OVERTEMP Alert" } );
    print $mailer $mess;
    $mailer->close;
}

}

close OUT;
$session->close();

exit 0;

You'll have to verify that your specific equipment can return this information to you via SNMP and the OIDs may change depending on Make and Model of equipment.

Robert Maxwell