learn2earn has asked for the wisdom of the Perl Monks concerning the following question:

I have a need to scrape a page for a temperature readout and send an alert if the temperature reaches a certain threshold, this device (a sensor in our server room) does create a webpage but I would like to trigger an alarm if the temperature gets too high. What would be the best way to go about doing this.

Replies are listed 'Best First'.
Re: scraping temperatures
by gman (Friar) on Feb 10, 2010 at 19:33 UTC

    I would look to do this with Net::SNMP rather then a web get. See if you can perform an snmpwalk on the sensor device. If not LWP LWP basics should get you started.

Re: scraping temperatures
by learn2earn (Acolyte) on Feb 10, 2010 at 21:48 UTC
    net snmp looks confusing I am not sure how to use that, for the time being as this is a necessity to do quick, I was going to try scraping the page periodically,I have a piece that downloads the page, and one that sends an email so now I need a regex that will find the temperature and send a message if its too high. the temperature is like this in the page.. 66.1 °F how would I do a regex for this? would something like this work?
    my $temp=~/dd*&degF/ if $temp>="75&degF" send a message code here..
      How about the following? The variable $text should contain the text you want to check.
      if( $text =~ m{ ( #open capturing parenthesis \d+ #numbers before the period \. #literal period \d+ #numbers after period ) #closing capturing parenthesis \s* #optional spaces ° #degree symbol F #literal letter F }xms){ my $temp = $1; # '$1' is what was found in capturing () if($temp > 75){ #code to send message } }else{ #code to deal with not finding temperature data. }
      or without comments
      if( $text =~ m{ (\d+ \. \d+) \s* ° F }xms){ my $temp = $1; if($temp > 75){ #code to send message } }else{ #code to deal with not finding temperature data. }
      Note: Updated several times
        Thanks molecules! I found the error(s)I had its working now.