[hobbit] Hobbit compatible temperature monitor

Stewart L stewartl42 at gmail.com
Thu Jun 26 19:10:52 CEST 2008


Yep.  We graph temperature and humidity (as that is the base sensor included
in the package).  just queried via SNMP.

Here you go!  all of our sensors are in climate controlled rooms, so
humidity is not a concern.  This reports them both on one page, but only
alerts if temp is out of range.  would be a trivial update if someone wanted
to alarm on humidity thresholds...

I have written many externals using this template.  I use the same model to
pull over 500 firewalls for 10 data points each in less than 30 seconds.

I'll leave the NCV stuff up to you. add an 'apctemp' test to your hosts and
off it goes! Have fun!

Stewart

#!/usr/bin/perl

########################################################
#
#  Hobbit script to monitor APC Environmental monitors
#
#  Written by Stewart Larsen
#
#  Released to the public domain
#
#  This uses bbhostgrep to figure out which hosts to
#  poll and then Net::SNMP to poll them Asynchronously.
#  This incorporates nicely into the NCV graphs As well.
#
########################################################

use strict;
use Net::SNMP qw(snmp_dispatcher ticks_to_time);

# Set to 1 to print to STDOUT instead of sending messages
my $debug = 1;

# this is the IP address of your hobbit server
my $BBDISP = "192.168.1.1";

# hosts need to have the 'apctemp' test defined on them. Or change this to
whatever you want to call it.
my $testname="apctemp";

# Path to your bb executable
my $BB = "/usr/lib/hobbit/server/bin/bb";

# Path to your bbhostgrep executable
my $BBHG = "/usr/lib/hobbit/server/bin/bbhostgrep";

# SNMP Community String
my $snmpc = 'public';

# Temperature thresholds
my $temp_warn = 90;
my $temp_panic = 92;

my $contact = "Emergency Contact:\n\t1) Facilities\n\t\t850-555-1212\n\t2)
Facilities On Call\n\t\t850-555-1111";

my @HOSTS = ();
my %hosts_hash = ();
my %ip_hash = ();
my $now_string = localtime;

open (INPUT, "$BBHG $testname |" ) or die "Cannot open input: $!\n";
while(<INPUT>)
{
        my ($ip,$hostname) = split(/\s/,$_);
        print "Adding $ip to polled hosts\n" if $debug;
        push @HOSTS,$hostname;
        $hosts_hash{$hostname} = $ip;
        $ip_hash{$ip} = $hostname;
}

close INPUT;

          # Poll interval (in seconds).  This value should be greater
          # than the number of retries plus one, times the timeout value.

          my $INTERVAL  = 20;

          # Maximum number of polls, including the initial poll.

          my $MAX_POLLS = 1;

          my $temperature       = '.1.3.6.1.4.1.318.1.1.10.3.13.1.1.3.1';
          my $humidity          = '.1.3.6.1.4.1.318.1.1.10.3.13.1.1.6.1';
          my $location          = '.1.3.6.1.4.1.318.1.1.10.3.12.1.0';

          # Create a session for each host and queue the first get-request.

          foreach my $host (@HOSTS) {

             my ($session, $error) = Net::SNMP->session(
                -hostname    => $hosts_hash{$host},
                -nonblocking => 0x1,   # Create non-blocking objects
                -timeout     => 5,
#               -debug       => 0xFF,
                -retries     => 1,
                -version     => '1',
                -community   => $snmpc
             );
             if (!defined($session)) {
                printf("ERROR: %s.\n", $error);
                exit 1;
             }

             # Queue the get-request, passing references to variables that
             # will be used to store the last sysUpTime and the number of
            # polls that this session has performed.

             my ($last_uptime, $num_polls) = (0, 0);

             $session->get_request(
                 -varbindlist => [$temperature,$humidity,$location],
                 -callback    => [
                    \&validate_sysUpTime_cb
                 ]
             );

          }

          # Define a reference point for all of the polls
          my $EPOC = time();

          # Enter the event loop
          snmp_dispatcher();
        $now_string = localtime;
        #print STDERR "$now_string: Processing Complete\n";

          exit 0;
sub validate_sysUpTime_cb
{
        my ($session) = @_;
        if (!defined($session->var_bind_list))
        {
                printf("%-15s  ERROR: %s\n", $session->hostname,
$session->error) if $debug;
                system("$BB $BBDISP \"status
".$ip_hash{$session->hostname}.".$testname clear $now_string - Communication
Failure\n".$session->error."\"\n") if !$debug;
        }
        else
        {

                # Validate the sysUpTime

                my $temperature = $session->var_bind_list->{$temperature};
                my $humidity    = $session->var_bind_list->{$humidity};
                my $location    = $session->var_bind_list->{$location};

                my $line = sprintf("Service on %-15s is Ok \n\ntemp :
%s\nhumidity: %s\n\n",
                                $session->hostname,
                                $temperature,
                                $humidity);




                my $cmd = "";
                my $color = "";
                my $mark = "";
                if ($temperature >= $temp_panic)
                {
                        # Panic on CPU test
                        $mark="PANIC";
                        $color="red";
                }
                elsif ($temperature >= $temp_warn)
                {
                        # Warn on CPU test
                        $mark="WARNING";
                        $color="yellow";
                }
                else
                {
                        # CPU test OK
                        $mark="OK";
                        $color="green";
                        $contact = "";
                }
                my $line="Environmental Monitoring\n\n$mark: Location:
$location\n\ntemp : $temperature\nhumidity : $humidity\n\n$contact";
                $cmd = "$BB $BBDISP \"status
".$ip_hash{$session->hostname}.".$testname $color $now_string $line\n\"";
                print STDOUT "********************\n$cmd" if $debug;
                system($cmd) if !$debug;

                $session->error_status;
        }
}



On Thu, Jun 26, 2008 at 11:37 AM, Eric Boyd <eric at iconla.com> wrote:

> Stewart,
> I'd love to see your script.
> Have you set up graphing for it?
> -Eric
>
> Stewart L wrote:
>
>> I use some APC environmental monitors (model AP9319) and I have an
>> external script I'd be happy to provide to the community.
>>
>> they seem to retail for about $200 now.
>>
>> Stewart
>>
>>
>>
>> On Thu, Jun 26, 2008 at 8:01 AM, McDonald, Dan <
>> Dan.McDonald at austinenergy.com <mailto:Dan.McDonald at austinenergy.com>>
>> wrote:
>>
>>    On Thu, 2008-06-26 at 10:12 +0200, Buchan Milne wrote:
>>    > On Wednesday 25 June 2008 23:52:49 White, Bruce wrote:
>>
>>    > > I have never been able to get custom graphs working, so I am
>>    not graphing
>>    > > the output. But getting custom graphs is not high on my
>>    priority list.
>>    >
>>    > Well, devmon could be a convenient method to poll the device,
>>    and would make
>>    > getting graphs and alerts quite easy.
>>
>>    It might be, but since it doesn't support snmp v3 I have not been able
>>    to use it.  mrtg does support snmp v3, has templates, and bbmrtg.pl is
>>    pretty stable for importing the states into hobbit.
>>
>>    --
>>    Daniel J McDonald, CCIE #2495, CISSP #78281, CNX
>>    Austin Energy
>>    http://www.austinenergy.com
>>
>>
>>
>>
>> --
>> Stewart
>> --
>> You only lose what you cling to.
>>
>
>
> To unsubscribe from the hobbit list, send an e-mail to
> hobbit-unsubscribe at hswn.dk
>
>
>


-- 
Stewart
--
You only lose what you cling to.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20080626/10665f64/attachment.html>


More information about the Xymon mailing list