Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Same problem again. But this time it was just a bit more complex. This time the platform to be monitored is a Sun Fire 12K. Even for a small configuration like ours, the command showenvironment -p temps returned 198 temperatures from different sensors! Since there are many sensors on the same board, we needed to aggregate the temperatures and report the resulting minimum and maximum.

But wait, there is more :-) showenvironment also returns a status code, that indicates if the parameter is in a safe range or if you should start worrying -or if it wasn't simply possible to read the temperature at all.

So I came out with the following script, that does the job. Luckily Unfortunately I don't know what comes out in case an INVALID status is returned, so I just had to guess. Since we are going to send alerts around if an INVALID pops up, it is not a big problem if it returns crap instead of temperatures, anyway if you know the output format in that case, please send a patch and I'll be happy to apply it!

The code reads the output of showenvironment -p temps from standard input and outputs in a format suitable for the monitoring tool we currently use. The code could be neither beautiful nor elegant, but I wrote it in a very short time. Feel free to improve it and publish your improvements on PM!

Enough talking, here is the code!

#!/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=$locati +ons{$loc}{max}\nstatus=$locations{$loc}{status}\n" ; } print join ("NEXT_SAMPLE\n",@samples),"END_SAMPLE_PERIOD\nEND_TABLE\nS +LEEP\n" ;

Ciao!
--bronto


In theory, there is no difference between theory and practice. In practice, there is.

In reply to Temperature monitoring, again by bronto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (10)
    As of 2014-12-22 18:28 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (126 votes), past polls