Back to index

nagios-plugins  1.4.16
Defines | Functions | Variables
check_hltherm.c File Reference
#include "config.h"
#include "common.h"
#include "popen.h"

Go to the source code of this file.

Defines

#define DEFAULT_TIMEOUT   10 /* default timeout in seconds */
#define HLTHERM_COMMAND   "/usr/local/bin/therm" /* this should be moved out to the configure script */

Functions

static void timeout_alarm_handler (int)
int process_arguments (int, char **)
int main (int argc, char **argv)

Variables

int timeout_interval = DEFAULT_TIMEOUT
double wtemp = 0.0L
double ctemp = 0.0L
int check_lower_temps = FALSE
char probe [MAX_INPUT_BUFFER] = ""
char label [MAX_INPUT_BUFFER] = "Temperature"
char scale [MAX_INPUT_BUFFER] = "Degrees"
FILE * fp

Define Documentation

#define DEFAULT_TIMEOUT   10 /* default timeout in seconds */

Definition at line 27 of file check_hltherm.c.

#define HLTHERM_COMMAND   "/usr/local/bin/therm" /* this should be moved out to the configure script */

Definition at line 29 of file check_hltherm.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file check_hltherm.c.

                               {
       int result=STATE_OK;
       char command[MAX_INPUT_BUFFER];
       double temp=0.0L;
       char input_buffer[MAX_INPUT_BUFFER];
       int found=0;

       /* process command line arguments */
       result=process_arguments(argc,argv);

       /* display usage if there was a problem */
       if(result==ERROR){
              printf("Incorrect arguments supplied\n");
              printf("\n");
              printf("Hot Little Therm temperature plugin for Nagios\n");
              printf("Copyright (c) 1999-2002 Ethan Galstad (nagios@nagios.org)\n");
              printf("Last Modified: 02-28-2002\n");
              printf("License: GPL\n");
              printf("\n");
              printf("Usage: %s <probe> <wtemp> <ctemp> [-l label] [-s scale] [-lower]\n",argv[0]);
              printf("\n");
              printf("Options:\n");
              printf(" <wtemp>  = Temperature necessary to result in a WARNING state\n");
              printf(" <ctemp>  = Temperature necessary to result in a CRITICAL state\n");
              printf(" [label]  = A descriptive label for the probe.  Example: \"Outside Temp\"\n");
              printf(" [scale]  = A descriptive label for the temperature scale.  Example: \"Celsius\"\n");
              printf(" [-lower] = Evaluate temperatures with lower values being more critical\n");
              printf("\n");
              printf("This plugin checks the temperature of a given temperature probe on a\n");
              printf("Hot Little Therm digital thermometer.  The plugin uses the 'therm' utility\n");
              printf("included with the HLT software to check the probe temperature.  Both the\n");
              printf("HLT digital thermometer and software are produced by Spiderplant. See\n");
              printf("their website at http://www.spiderplant.com/hlt for more information.\n");
              printf("\n");
              return STATE_UNKNOWN;
               }


       result=STATE_OK;

       /* Set signal handling and alarm */
       if(signal(SIGALRM,timeout_alarm_handler)==SIG_ERR){
              printf("Cannot catch SIGALRM");
              return STATE_UNKNOWN;
               }

       /* handle timeouts gracefully */
       alarm(timeout_interval);

       /* create the command line we're going to use */
       snprintf(command,sizeof(command),"%s %s",HLTHERM_COMMAND,probe);
       command[sizeof(command)-1]='\x0';

       /* run the command to check the temperature on the probe */
       fp=spopen(command);
       if(fp==NULL){
              printf("Could not open pipe: %s\n",command);
              return STATE_UNKNOWN;
               }

       if(fgets(input_buffer,MAX_INPUT_BUFFER-1,fp)){
              found=1;
              temp=(double)atof(input_buffer);
               }

       /* close the pipe */
       spclose(fp);

       if(result==STATE_OK){

              if(found==0){
                     printf("Therm problem - Could not read program output\n");
                     result=STATE_CRITICAL;
                      }
              else{
                     if(check_lower_temps==TRUE){
                            if(temp<=ctemp)
                                   result=STATE_CRITICAL;
                            else if(temp<=wtemp)
                                   result=STATE_WARNING;
                             }
                     else{
                            if(temp>=ctemp)
                                   result=STATE_CRITICAL;
                            else if(temp>=wtemp)
                                   result=STATE_WARNING;
                             }

                     printf("Therm %s: %s = %2.1f %s\n",(result==STATE_OK)?"ok":"problem",label,temp,scale);
                      }
               }

       return result;
        }

Here is the call graph for this function:

int process_arguments ( int  argc,
char **  argv 
)
static void timeout_alarm_handler ( int  signo) [static]

Definition at line 201 of file check_hltherm.c.

                                            {

       if(signo==SIGALRM){
    
              kill(childpid[fileno(fp)],SIGKILL);
              printf("Therm problem - Check timed out after %d seconds\n",timeout_interval);
              exit(STATE_CRITICAL);
               }
        }

Here is the caller graph for this function:


Variable Documentation

Definition at line 40 of file check_hltherm.c.

double ctemp = 0.0L

Definition at line 38 of file check_hltherm.c.

FILE* fp

Definition at line 46 of file check_hltherm.c.

char label[MAX_INPUT_BUFFER] = "Temperature"

Definition at line 43 of file check_hltherm.c.

char probe[MAX_INPUT_BUFFER] = ""

Definition at line 42 of file check_hltherm.c.

char scale[MAX_INPUT_BUFFER] = "Degrees"

Definition at line 44 of file check_hltherm.c.

Definition at line 35 of file check_hltherm.c.

double wtemp = 0.0L

Definition at line 37 of file check_hltherm.c.