Back to index

nagios-plugins  1.4.16
Defines | Functions
plugins.h File Reference
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/wait.h>

Go to the source code of this file.

Defines

#define STATE_CRITICAL   2
#define STATE_WARNING   1
#define STATE_OK   0
#define STATE_UNKNOWN   -1
#define TRUE   1
#define FALSE   0
#define EXISTS   4
#define READABLE   6
#define SATURDAY   6
#define SUNDAY   0
#define TIME_OUT   5
#define MAX_CHARS   256
#define CONFIG_DIR   "/usr/local/netsaint/config/"
#define CHECK_TELNET   "check_telnet"

Functions

int get_var (char *LINE_NAME, char *file_name, char *var_name)
void strupr (char *string_name)
void alarm_signal (int sig_num)
int open_socket (int *socket_name, char *host, int port_num, char *protocol)
int recv_socket (int *socket_name, char *expected)
int send_socket (int *socket_name, char *send_buffer)
int close_socket (int *socket_name)
void print_error (char *file_name)
int exit_error (int error_code, char *ip_address, char *protocol, int port)
int check_output_file (char *file_name)
char * get_command_name (char *command_line)
int check_consistency (float warn_value, float critical_value)

Define Documentation

#define CHECK_TELNET   "check_telnet"

Definition at line 111 of file plugins.h.

#define CONFIG_DIR   "/usr/local/netsaint/config/"

Definition at line 110 of file plugins.h.

#define EXISTS   4

Definition at line 100 of file plugins.h.

#define FALSE   0

Definition at line 99 of file plugins.h.

#define MAX_CHARS   256

Definition at line 108 of file plugins.h.

#define READABLE   6

Definition at line 101 of file plugins.h.

#define SATURDAY   6

Definition at line 103 of file plugins.h.

#define STATE_CRITICAL   2

Definition at line 93 of file plugins.h.

#define STATE_OK   0

Definition at line 95 of file plugins.h.

#define STATE_UNKNOWN   -1

Definition at line 96 of file plugins.h.

#define STATE_WARNING   1

Definition at line 94 of file plugins.h.

#define SUNDAY   0

Definition at line 104 of file plugins.h.

#define TIME_OUT   5

Definition at line 106 of file plugins.h.

#define TRUE   1

Definition at line 98 of file plugins.h.


Function Documentation

void alarm_signal ( int  sig_num)

Definition at line 148 of file plugins.h.

{
  printf("No response received from host in %d seconds, possible host down or network error.\n",TIME_OUT);
  exit(STATE_CRITICAL);
}

Here is the caller graph for this function:

int check_consistency ( float  warn_value,
float  critical_value 
)

Definition at line 412 of file plugins.h.

{

  int return_value;

  if(warn_value >= critical_value)
  {
    printf("Inconsistency in parameters: warning value %.2f >= critical value %.2f.\n", warn_value, critical_value);
    return_value = STATE_UNKNOWN;
  }
  else
  {
    return_value = STATE_OK;
  }
  return return_value;
}

Here is the caller graph for this function:

int check_output_file ( char *  file_name)

Definition at line 362 of file plugins.h.

{

  FILE *temp_fp;

  int return_value;

  struct stat file_stat;

  if (access(file_name, READABLE) != 0 )
  {
    printf("Unable to read output file for system.  ");
    return_value = STATE_UNKNOWN;
  }
  else if(stat(file_name, &file_stat) != 0)
  {
    printf("Unable to retrive status of output file %s.  ",file_name);
    return_value = STATE_UNKNOWN;
  }
  else if(file_stat.st_size == 0)
  {
    printf("Output file %s has zero size.  ",file_name);
    return_value = STATE_UNKNOWN;
  }
  else if((temp_fp=fopen(file_name,"r")) == NULL)
  {
    printf("Unable to open output file for system.  ");
    return_value = STATE_UNKNOWN;
  }
  else
  {
    fclose(temp_fp);
    return_value = STATE_OK;
  }
  return return_value;
}

Here is the caller graph for this function:

int close_socket ( int *  socket_name)

Definition at line 259 of file plugins.h.

{
  close(*socket_name);
  return STATE_OK;
}

Here is the caller graph for this function:

int exit_error ( int  error_code,
char *  ip_address,
char *  protocol,
int  port 
)

Definition at line 293 of file plugins.h.

{

  int return_value;

  switch(error_code)
  {
    case 1:
      printf("Hostname %s not found\n",ip_address);
      return_value=STATE_WARNING;
      break;
    case 2:
      printf("Hostname %s not found, but try again\n",ip_address);
      return_value=STATE_WARNING;
      break;
    case 3:
      printf("DNS error looking up hostname %s\n",ip_address);
      return_value=STATE_WARNING;
      break;
    case 4:
      printf("No ip address for host %s\n",ip_address);
      return_value=STATE_WARNING;
      break;
    case 5:
      printf("Unknow host name lookup error\n");
      return_value=STATE_WARNING;
      break;
    case 6:
      printf("Unable to map protocol %s\n",protocol);
      return_value=STATE_WARNING;
      break;
    case 7:
      printf("Unable to create socket to host %s on port %d\n",ip_address,port);
      return_value=STATE_CRITICAL;
      break;
    case 8:
      printf("Connection refused by %s on port %d\n",ip_address,port);
      return_value=STATE_CRITICAL;
      break;
    case 9:
      printf("Timed out while creating socket to host %s on port %d\n",ip_address,port);
      return_value=STATE_CRITICAL;
      break;
    case 10:
      printf("Network unreachable for host %s\n",ip_address);
      return_value=STATE_CRITICAL;
      break;
    case 11:
      printf("Unknown connect error to %s on port %d\n",ip_address,port);
      return_value=STATE_CRITICAL;
      break;
    case 12:
      printf("Could not read form port %s on host %d\n",ip_address,port);
      return_value=STATE_CRITICAL;
      break;
    case 13:
      printf("Invalid response string received from host %s on port %d\n",ip_address,port);
      return_value=STATE_WARNING;
      break;
    case 14:
      printf("Error occured while sending data to host %s on port %d\n",ip_address,port);
      return_value=STATE_WARNING;
      break;
    default:
      printf("Unknown error received from host %s on port %d\n",ip_address,port);
      return_value=STATE_UNKNOWN;
  }
  return return_value;
}

Here is the caller graph for this function:

char* get_command_name ( char *  command_line)

Definition at line 398 of file plugins.h.

{
  char *return_string;
  char *sub_string;
  if((sub_string=strrchr(command_line,'/')) != NULL)
  {
    return_string=++sub_string;
  }
  else
  {
    return_string=command_line;
  }
  return return_string;
}

Here is the caller graph for this function:

int get_var ( char *  LINE_NAME,
char *  file_name,
char *  var_name 
)

Definition at line 113 of file plugins.h.

{
  char temp_input_buffer[MAX_CHARS];
  char tok_sep[] = "|";
  char temp_var_name[MAX_CHARS];
  char *temp_var_value;

  FILE *temp_fp;

  int return_value = STATE_UNKNOWN;

  strcpy(var_name,"NOT_FOUND");

  temp_fp=fopen(file_name,"r");
  while(fgets(temp_input_buffer,MAX_CHARS-1,temp_fp) != NULL)
  {
         strcpy(temp_var_name,strtok(temp_input_buffer,tok_sep));
         temp_var_value=strtok(NULL,tok_sep);
         if(strcmp(LINE_NAME,temp_var_name) == 0)
         {
                strcpy(var_name,temp_var_value);
                return_value = STATE_OK;
         }
  }
  return return_value;
}

Here is the caller graph for this function:

int open_socket ( int *  socket_name,
char *  host,
int  port_num,
char *  protocol 
)

Definition at line 153 of file plugins.h.

{
  int return_value = STATE_OK;

  struct protoent *proto_ptr;
  struct sockaddr_in remote_addr;
  struct hostent *host_addr;

  if(isdigit(host[0]))
  {
    inet_aton(host, &remote_addr.sin_addr);
  }
  else
  {
    if((host_addr = gethostbyname(host)) == NULL)
    {
      switch(errno)
      {
        case HOST_NOT_FOUND:
          return_value = 1;
          break;
        case TRY_AGAIN:
          return_value = 2;
          break;
        case NO_RECOVERY:
          return_value = 3;
          break;
        case NO_ADDRESS:
          return_value = 4;
          break;
        default:
          return_value = 5;
      }
    }
    else
    {
      memcpy(&remote_addr.sin_addr, host_addr->h_addr, host_addr->h_length);
    }
  }

  remote_addr.sin_family=AF_INET;
  remote_addr.sin_port=htons(port_num);

  if((proto_ptr = getprotobyname(protocol)) == NULL)
  {
    return_value = 6;
  }
  if((*socket_name=socket(AF_INET,SOCK_STREAM,proto_ptr->p_proto)) < 0)
  {
    return_value = 7;
  }
  if((connect(*socket_name,(struct sockaddr *)&remote_addr,sizeof(remote_addr))) < 0)
  {
    switch(errno)
    {
      case ECONNREFUSED:
        return_value = 8;
        break;
      case ETIMEDOUT:
        return_value = 9;
        break;
      case ENETUNREACH:
        return_value = 10;
        break;
      default:
        return_value = 11;
        break;
    }
    close(*socket_name);
  }
  return return_value;
}

Here is the caller graph for this function:

void print_error ( char *  file_name)

Definition at line 264 of file plugins.h.

{
  char input_buffer[MAX_CHARS];

  FILE *temp_fp;
  
  struct stat file_stat;

  if (access(file_name, READABLE) == 0 )
  {
    if(stat(file_name, &file_stat) == 0)
    {
      if(file_stat.st_size != 0)
      {
        if((temp_fp=fopen(file_name,"r")) != NULL)
        {
          printf("The following errors were produced:  ");
          while(fgets(input_buffer,MAX_CHARS-1,temp_fp) != NULL)
          {
            printf("%s",input_buffer);
          }
          fclose(temp_fp);
        }
      }
    }
  }
  printf("\n");
  return;
}

Here is the caller graph for this function:

int recv_socket ( int *  socket_name,
char *  expected 
)

Definition at line 225 of file plugins.h.

{
  char input_buffer[MAX_CHARS];

  int return_value = STATE_OK;
  if((recv(*socket_name,&input_buffer,MAX_CHARS-1,0)) < 0)
  {
    return_value = 12;
  }
  if(strstr(input_buffer,expected) == NULL)
  {
    return_value = 13;
  }
  return return_value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int send_socket ( int *  socket_name,
char *  send_buffer 
)

Definition at line 240 of file plugins.h.

{
  int return_value = STATE_OK;
  if (strcmp(send_buffer,"\n") == 0)
  {
    if((send(*socket_name,"\n",strlen("\n"),0)) <0)
    {
      return_value = 14;
    }
  }
  else
  {
    if((send(*socket_name,&send_buffer,strlen(send_buffer),0)) <0)
    {
      return_value = 14;
    }
  }
  return return_value;
}

Here is the caller graph for this function:

void strupr ( char *  string_name)

Definition at line 139 of file plugins.h.

{
  do
  {
         *string_name=toupper(*string_name);
  }
  while(*string_name++);
  return;
}

Here is the caller graph for this function: