Back to the main page

Nagios plugin check temperature from DAQ device

There is the DAQ temperature device in a server room, if you access it via http, this is what you get.

Here is the plugin to query the DAQ and get the temperature.
#!/bin/ksh
# Nagios plugin return values
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

# hard coded warning/crit in F
# 20C=68F 22C=72F 24C=75F 26C=79F 28C=82F 30C=86F 32C=89F 34C=93F
# 36C=97F 38C=100F 40C=104F
temp_warn=90
temp_crit=100

# --- END SCRIPT WITH OUTPUT
endscript () {
        echo "${RESULT}"
        exit ${EXIT_STATUS}
}

usage() {
        RESULT="$0 "
        EXIT_STATUS="${STATE_UNKNOWN}"
        endscript
}

# DAQ hostname
temp_module=$1

# check if there is at least one argument
if [ $# -ne 1 ]; then
        usage
fi

temp_f=`curl --silent http://${temp_module}/state.xml | grep sensor1temp | awk -F \> '{print $2}' | awk -F \< '{print $1}'`

# check if result is null
if [ -z ${temp_f} ]; then
        RESULT="Cannot get temperature for ${temp_module}"
        EXIT_STATUS="${STATE_UNKNOWN}"
fi

if [ ${temp_f} -gt ${temp_crit} ]; then
        RESULT="CRITICAL ${temp_f}F for ${temp_module} | Temp=${temp_f};${temp_warn};${temp_crit}"
        EXIT_STATUS="${STATE_CRITICAL}"
elif [ ${temp_f} -lt ${temp_warn} ]; then
        RESULT="OK ${temp_f}F for ${temp_module} | Temp=${temp_f};${temp_warn};${temp_crit}"
        EXIT_STATUS="${STATE_OK}"
else
        RESULT="WARNING ${temp_f}F for ${temp_module} | Temp=${temp_f};${temp_warn};${temp_crit}"
        EXIT_STATUS="${STATE_WARNING}"
fi

# finish the script
endscript

The pnp4nagios is used for graphing and here is the relevant template, most likely located in /usr/share/pnp4nagios/templates and called check_temp_module_daq.php
<?php
# Define some colors ..
$_WARNRULE = '#FFFF00';
$_CRITRULE = '#FF0000';
$_AREA     = '#256aef';
$_LINE     = '#000000';
#
# Initial Logic ...

foreach ($this->DS as $KEY=>$VAL) {

        $maximum  = "";
        $minimum  = "";
        $critical = "";
        $crit_min = "";
        $crit_max = "";
        $warning  = "";
        $warn_max = "";
        $warn_min = "";
        $vlabel   = " ";
        $lower    = "";
        $upper    = "";

        if ($VAL['WARN'] != "" && is_numeric($VAL['WARN']) ){
                $warning = $VAL['WARN'];
        }
        if ($VAL['WARN_MAX'] != "" && is_numeric($VAL['WARN_MAX']) ) {
                $warn_max = $VAL['WARN_MAX'];
        }
        if ( $VAL['WARN_MIN'] != "" && is_numeric($VAL['WARN_MIN']) ) {
                $warn_min = $VAL['WARN_MIN'];
        }
        if ( $VAL['CRIT'] != "" && is_numeric($VAL['CRIT']) ) {
                $critical = $VAL['CRIT'];
        }
        if ( $VAL['CRIT_MAX'] != "" && is_numeric($VAL['CRIT_MAX']) ) {
                $crit_max = $VAL['CRIT_MAX'];
        }
        if ( $VAL['CRIT_MIN'] != "" && is_numeric($VAL['CRIT_MIN']) ) {
                $crit_min = $VAL['CRIT_MIN'];
        }
        if ( $VAL['MIN'] != "" && is_numeric($VAL['MIN']) ) {
                $lower = " --lower=" . $VAL['MIN'];
                $minimum = $VAL['MIN'];
        }
        if ( $VAL['MAX'] != "" && is_numeric($VAL['MAX']) ) {
                $maximum = $VAL['MAX'];
        }
        if ($VAL['UNIT'] == "%%") {
                $vlabel = "%";
                $upper = " --upper=101 ";
                $lower = " --lower=0 ";
        }
        else {
                $vlabel = $VAL['UNIT'];
        }

        $opt[$KEY] = '--vertical-label " F " --title "' . $this->MACRO['DISP_HOSTNAME'] . ' / ' . $this->MACRO['DISP_SERVICEDESC'] . ' F"' . $upper . $lower;
        $ds_name[$KEY] = $VAL['LABEL'];
        $def[$KEY]  = rrd::def     ("var1", $VAL['RRDFILE'], $VAL['DS'], "AVERAGE");
        $def[$KEY] .= rrd::gradient("var1", "3152A5", "BDC6DE", rrd::cut($VAL['NAME'],16), 20);
        $def[$KEY] .= rrd::line1   ("var1", $_LINE );
        $def[$KEY] .= rrd::gprint  ("var1", array("LAST","MAX","AVERAGE"), "%3.4lf %S".$VAL['UNIT']);
        if ($warning != "") {
                $def[$KEY] .= rrd::hrule($warning, $_WARNRULE, "Warning(F)  $warning \\n");
        }
        if ($warn_min != "") {
                $def[$KEY] .= rrd::hrule($warn_min, $_WARNRULE, "Warning(F)  (min)  $warn_min \\n");
        }
        if ($warn_max != "") {
                $def[$KEY] .= rrd::hrule($warn_max, $_WARNRULE, "Warning(F)  (max)  $warn_max \\n");
        }
        if ($critical != "") {
                $def[$KEY] .= rrd::hrule($critical, $_CRITRULE, "Critical(F) $critical \\n");
        }
        if ($crit_min != "") {
                $def[$KEY] .= rrd::hrule($crit_min, $_CRITRULE, "Critical(F) (min)  $crit_min \\n");
        }
        if ($crit_max != "") {
                $def[$KEY] .= rrd::hrule($crit_max, $_CRITRULE, "Critical(F) (max)  $crit_max \\n");
        }
        $def[$KEY] .= rrd::comment("Default Template\\r");
        $def[$KEY] .= rrd::comment("Command " . $VAL['TEMPLATE'] . "\\r");
}
?>

The graph looks like:


Back to the main page