#!/usr/local/bin/perl # $Id: showenv12k.pl,v 1.1 2005/01/04 15:32:50 bronto Exp bronto $ use strict ; use warnings ; my %locations ; my %levels = ( OK => 0, LOW_WARN => 10, HIGH_WARN => 10, LOW_CRIT => 20, HIGH_CRIT => 20, OVERLIMIT => 100, INVALID => 500, ) ; while (<>) { my ($location,$device,$sensor,$value,$age,$status) = /^(\S+ at \S+)\s+(\S+)\s+(\S+) Temp\s+(\S+)\s+C\s+(\S+)\s+sec\s+(\S+)/ ; unless (defined $location or defined $value or defined $status) { next ; } unless (exists $locations{$location}) { $locations{$location}{min} = $value ; $locations{$location}{max} = $value ; $locations{$location}{status} = $status ; } unless ($status eq 'INVALID') { $locations{$location}{min} = $value if $locations{$location}{min} > $value ; $locations{$location}{max} = $value if $locations{$location}{max} < $value ; } if ($levels{$status} > $levels{$locations{$location}{status}}) { $locations{$location}{status} = $status ; } } print "TABLE temperature\nSTART_SAMPLE_PERIOD\n" ; my @samples ; foreach my $loc (sort keys %locations) { push @samples,"location=$loc\nmin=$locations{$loc}{min}\nmax=$locations{$loc}{max}\nstatus=$locations{$loc}{status}\n" ; } print join ("NEXT_SAMPLE\n",@samples),"END_SAMPLE_PERIOD\nEND_TABLE\nSLEEP\n" ;