#!/usr/bin/perl #use strict; use Device::SerialPort; $overtemp = 91; $tempofile = "/etc/mrtg/tempover.txt"; my $tempdevice = "/dev/ttyS0"; my $request; my $answer; my $number; my ($response, $temp1, $crc1, $crc2); my $ob = Device::SerialPort->new ($tempdevice) || die "Can't open $tempdevice : $!"; $ob->baudrate (1200) || die "failed to set baudrate"; $ob->parity ("none") || die "failed to set pairity"; $ob->databits (8) || die "failed to set databits"; $ob->stopbits (1) || die "failed to set stopbits"; $ob->handshake ("none") || die "failed to set flow control"; $ob->dtr_active (1) || die "failed to set DTR"; $ob->rts_active (1) || die "failed to set RTS"; sleep 1; #now to write the request to the device #print "\x82\x01\x01\x76\x2A"; $request = $ob->write("\x82\x01\x01\x76\x2A") or die ("Could not write to device: $!"); sleep 1; ($count_in, $string_in1) = $ob->read(1); #print "\nCOUNTIN: $count_in , STRINGIN:". ord $string_in1; ($count_in, $string_in2) = $ob->read(1); #print "\nCOUNTIN: $count_in , STRINGIN:". ord $string_in2; ($count_in, $string_in3) = $ob->read(1); #print "\nCOUNTIN: $count_in , STRINGIN:". ord $string_in3; ($count_in, $string_in4) = $ob->read(1); #print "\nCOUNTIN: $count_in , STRINGIN:". ord $string_in4; ($count_in, $string_in5) = $ob->read(1); #print "\nCOUNTIN: $count_in , STRINGIN:". ord $string_in5; ($count_in, $string_in6) = $ob->read(1); #print "\nCOUNTIN: $count_in , STRINGIN:". ord $string_in6; #print "\n"; $tempfinal = int ((((((ord $string_in3) / 2) * 9) / 5) + 32) + 0.5) ; print "69\n$tempfinal\n"; # check for overtemp condition if ($tempfinal >= $overtemp) { open (TEMPOVER, ">$tempofile"); print TEMPOVER ("Alert: LAX server room temp is $tempfinal"); close (TEMPOVER); $mailme = `/bin/mail -s therm-mrtg-alert cward\@vidyah.com < /etc/mrtg/tempover.txt`; }