Sebastian Nohn

Weblog

Monitoring your ALIX I2C sensors with nagios

Most ALIX system boards come with onboard i2c temperature sensors. Nagios Plugins come with a check_sensors command.

However, the default lm-sensors configuration that ships with most distributions doesn't know about the ALIX sensors and the default Nagios plugin doesn't report performance data.

Once lm-sensors is installed and you run sensors-detect, the sensors command will output something like this:

root@bnalrr01:~# sensors
lm86-i2c-0-4c
Adapter: CS5536 ACB0
temp1:       +30.0 C  (low  =  +0.0 C, high = +70.0 C)  
                      (crit = +85.0 C, hyst = +75.0 C)  
temp2:       +36.9 C  (low  =  +0.0 C, high = +70.0 C)  
                      (crit = +85.0 C, hyst = +75.0 C)

And the check_sensors probe would output something like this:

root@bnalrr01:~# ./check_sensors 
sensor ok

To make the senors output more verbose, add this to your /etc/sensors3.conf:

chip "lm90-*" "adm1032-*" "lm86-*" "max6657-*" "adt7461-*"
   label temp1 "M/B Temp"
   label temp2 "CPU Temp"
   label tcrit1 "M/B Crit"
   label tcrit2 "CPU Crit"

Now the sensors command is a bit more verbose on the sensors:

root@bnalrr01:~# sensors
lm86-i2c-0-4c
Adapter: CS5536 ACB0
M/B Temp:    +30.0 C  (low  =  +0.0 C, high = +70.0 C)  
                      (crit = +85.0 C, hyst = +75.0 C)  
CPU Temp:    +36.6 C  (low  =  +0.0 C, high = +70.0 C)  
                      (crit = +85.0 C, hyst = +75.0 C)

To add performance data to the check_sensors probe, replace the content with

#! /bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="1.4.15"

. $PROGPATH/utils.sh


print_usage() {
        echo "Usage: $PROGNAME"
}

print_help() {
        print_revision $PROGNAME $REVISION
        echo ""
        print_usage
        echo ""
        echo "This plugin checks hardware status using the lm_sensors package."
        echo ""
        support
        exit 0
}

case "$1" in
        --help)
                print_help
                exit 0
                ;;
        -h)
                print_help
                exit 0
                ;;
        --version)
        print_revision $PROGNAME $REVISION
                exit 0
                ;;
        -V)
                print_revision $PROGNAME $REVISION
                exit 0
                ;;
        *)
                sensordata=`sensors 2>&1`
                CPUHEAT=`sensors -A | grep CPU | grep Temp | cut -c 15,16`
                MOBHEAT=`sensors -A | grep M/B | grep Temp | cut -c 15,16`
                PERFDATA="cpu_temp=$CPUHEAT;mob_heat=$MOBHEAT"
                status=$?
                if test "$1" = "-v" -o "$1" = "--verbose"; then
                        echo ${sensordata}
                fi
                if test ${status} -eq 127; then
                        echo "SENSORS UNKNOWN - command not found (did you install lmsensors?)"
                        exit -1
                elif test ${status} -ne 0 ; then
                        echo "WARNING - sensors returned state $status |$PERFDATA"
                        exit 1
                fi
                if echo ${sensordata} | egrep ALARM > /dev/null; then
                        echo "SENSOR CRITICAL - Sensor alarm detected! |$PERFDATA"
                        exit 2
                else
                        echo "sensor ok |$PERFDATA"
                        exit 0
                fi
                ;;
esac

Now it prints out performance data and can be graphed with pnp4nagios:

root@bnalrr01:~# ./check_temp_sensors 
sensor ok |cpu_temp=36;mob_heat=30

Posted Mar 05, 2011
Tagged as: ALIX, i2c, lm-sensors, Nagios

(Ab)using twitter for Nagios IM/SMS notification

Two months after signing up for Twitter, I still haven't found a real use for it. I don't see any sense in telling everyone, what I'm doing right now, and it doesn't make sense as some kind of asynchronous multi-user chat as long as it doesn't support channels/rooms. So looking for something useful (well more or less) I tried to abuse their JSON interface for Nagios notification. It is dead simple, much simpler than implementing standard IM or SMS notifications in Nagios and it even seems to comply with Twitter's TOS:

define command {
        command_name    notify-by-twitter
        command_line    /usr/bin/curl --basic --user "user:password" --data-ascii "status=[Nagios] $NOTIFICATIONTYPE$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" http://twitter.com/statuses/update.json
}

define command {
        command_name    host-notify-by-twitter
        command_line    /usr/bin/curl --basic --user "user:password" --data-ascii "status=[Nagios] $HOSTSTATE$ alert for $HOSTNAME$" http://twitter.com/statuses/update.json
}

Posted Jun 01, 2008
Tagged as: Hack, Nagios, Twitter

Using Net_DNSBL and Nagios to check if your SMTP server is listed in a RBL

RBLs are a great way to get rid of a lot of SPAM (if you choose the right ones). On the other hand you (and users of your mail server) get in big trouble if your SMTP server gets listed on a common RBL.

Checking this manually is a job that sucks a lot, checking this automatically is an easy job with Nagios, PHP, Net_DNSBL and Console_Getopt.

I assume, you have Nagios up and running and installed according to FHS.

Install the required PEAR packages via

# pear install -a Net_DNSBL Console_Getopt

The code for a non-idiot proof, but working RBL checker is simple:

#!/opt/php/bin/php
<?php

define
('SERVICE_STATUS''Service Status:');

require_once 
'Console/Getopt.php';
require_once 
'Net/DNSBL.php';

$dnsbl = new Net_DNSBL();

$shortoptions 'H:V::r:';
$longoptions = array('hostname=''version==''rbls=');

$con = new Console_Getopt;
$args $con->readPHPArgv();
array_shift($args);
$options $con->getopt2($args$shortoptions$longoptions);

foreach(
$options[0] as $option) {
  if (
$option[0] == 'H' || $option[0] == '--hostname') {
    
$hostname $option[1];
  }
  if (
$option[0] == 'r' || $option[0] == '--rbls') {
    
$rbls_temp $option[1];
  }
}

if (!isset(
$hostname) || !isset($rbls_temp)) {
  echo 
SERVICE_STATUS.' Unknown'."\n";
  exit(
3);
} else {
  
$rbls explode(','$rbls_temp);
  
$dnsbl->setBlacklists($rbls);
  if (
$dnsbl->isListed($hostname)) {
    echo 
SERVICE_STATUS.' Critical - Listed in '.$dnsbl->getListingBl($hostname)."\n";
    exit(
2);
  } else {
    echo 
SERVICE_STATUS.' OK - Not Listed in supplied DNSBLs'."\n";
    exit(
0);
  }
}
?>

Put this into your Nagios plugin directory (/opt/nagios/libexec) and add this to /etc/opt/nagios/checkcommands.cfg:

define command{
        command_name    check_dnsbl
        command_line    $USER1$/check_dnsbl -H $HOSTADDRESS$ -r $ARG1$
        }

As well as this to /etc/opt/nagios/services.cfg:

define service{
        use                             generic-service
        host_name                       your.mail.server
        service_description             DNSBL
        is_volatile                     0
        check_period                    24x7
        max_check_attempts              3
        normal_check_interval           3
        retry_check_interval            1
        contact_groups                  nohn
        notification_interval           120
        notification_period             24x7
        notification_options            w,u,c,r
        check_command                   check_dnsbl!bl.spamcop.net,some.other.comma.separated.rbls
        }

Finally you have to restart Nagios:

# /etc/init.d/nagios restart

Posted Apr 18, 2006
Tagged as: Console_Getopt, Nagios, Net_DNSBL, PEAR, PHP, RBL, SMTP, SPAM

<<< Page 1 of 1 >>>