Back to index

nagios-plugins  1.4.16
Enumerations | Functions | Variables
check_fping.c File Reference
#include "common.h"
#include "popen.h"
#include "netutils.h"
#include "utils.h"

Go to the source code of this file.

Enumerations

enum  { PACKET_COUNT = 1, PACKET_SIZE = 56, PL = 0, RTA = 1 }

Functions

int textscan (char *buf)
int process_arguments (int, char **)
int get_threshold (char *arg, char *rv[2])
void print_help (void)
void print_usage (void)
int main (int argc, char **argv)

Variables

const char * progname = "check_fping"
const char * copyright = "2000-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
char * server_name = NULL
int packet_size = PACKET_SIZE
int packet_count = PACKET_COUNT
int target_timeout = 0
int packet_interval = 0
int verbose = FALSE
int cpl
int wpl
double crta
double wrta
int cpl_p = FALSE
int wpl_p = FALSE
int crta_p = FALSE
int wrta_p = FALSE

Enumeration Type Documentation

anonymous enum
Enumerator:
PACKET_COUNT 
PACKET_SIZE 
PL 
RTA 

Definition at line 41 of file check_fping.c.

     {
  PACKET_COUNT = 1,
  PACKET_SIZE = 56,
  PL = 0,
  RTA = 1
};

Function Documentation

int get_threshold ( char *  arg,
char *  rv[2] 
)

Definition at line 345 of file check_fping.c.

{
  char *arg1 = NULL;
  char *arg2 = NULL;

  arg1 = strscpy (arg1, arg);
  if (strpbrk (arg1, ",:"))
    arg2 = 1 + strpbrk (arg1, ",:");

  if (arg2) {
    arg1[strcspn (arg1, ",:")] = 0;
    if (strstr (arg1, "%") && strstr (arg2, "%"))
      die (STATE_UNKNOWN,
                 _("%s: Only one threshold may be packet loss (%s)\n"), progname,
                 arg);
    if (!strstr (arg1, "%") && !strstr (arg2, "%"))
      die (STATE_UNKNOWN,
                 _("%s: Only one threshold must be packet loss (%s)\n"),
                 progname, arg);
  }

  if (arg2 && strstr (arg2, "%")) {
    rv[PL] = arg2;
    rv[RTA] = arg1;
  }
  else if (arg2) {
    rv[PL] = arg1;
    rv[RTA] = arg2;
  }
  else if (strstr (arg1, "%")) {
    rv[PL] = arg1;
  }
  else {
    rv[RTA] = arg1;
  }

  return OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file check_fping.c.

{
/* normaly should be  int result = STATE_UNKNOWN; */

  int status = STATE_UNKNOWN;
  char *server = NULL;
  char *command_line = NULL;
  char *input_buffer = NULL;
  char *option_string = "";
  input_buffer = malloc (MAX_INPUT_BUFFER);

  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  /* Parse extra opts if any */
  argv=np_extra_opts (&argc, argv, progname);

  if (process_arguments (argc, argv) == ERROR)
    usage4 (_("Could not parse arguments"));

  server = strscpy (server, server_name);

  /* compose the command */
  if (target_timeout)
    asprintf(&option_string, "%s-t %d ", option_string, target_timeout);
  if (packet_interval)
    asprintf(&option_string, "%s-p %d ", option_string, packet_interval);

  asprintf (&command_line, "%s %s-b %d -c %d %s", PATH_TO_FPING,
            option_string, packet_size, packet_count, server);

  if (verbose)
    printf ("%s\n", command_line);

  /* run the command */
  child_process = spopen (command_line);
  if (child_process == NULL) {
    printf (_("Could not open pipe: %s\n"), command_line);
    return STATE_UNKNOWN;
  }

  child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
  if (child_stderr == NULL) {
    printf (_("Could not open stderr for %s\n"), command_line);
  }

  while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
    if (verbose)
      printf ("%s", input_buffer);
    status = max_state (status, textscan (input_buffer));
  }

  /* If we get anything on STDERR, at least set warning */
  while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
    status = max_state (status, STATE_WARNING);
    if (verbose)
      printf ("%s", input_buffer);
    status = max_state (status, textscan (input_buffer));
  }
  (void) fclose (child_stderr);

  /* close the pipe */
  if (spclose (child_process))
    /* need to use max_state not max */
    status = max_state (status, STATE_WARNING);

  printf ("FPING %s - %s\n", state_text (status), server_name);

  return status;
}

Here is the call graph for this function:

void print_help ( void  )
void print_usage ( void  )

Definition at line 389 of file check_cpqarray.c.

{
  printf("cpqarrayd [options]\n");
  printf("   -h         prints this text\n");
  printf("   -d         enables debugging\n");
}
int process_arguments ( int  argc,
char **  argv 
)
int textscan ( char *  buf)

Definition at line 145 of file check_fping.c.

{
  char *rtastr = NULL;
  char *losstr = NULL;
  double loss;
  double rta;
  int status = STATE_UNKNOWN;

  if (strstr (buf, "not found")) {
    die (STATE_CRITICAL, _("FPING UNKNOW - %s not found\n"), server_name);

  }
  else if (strstr (buf, "is unreachable") || strstr (buf, "Unreachable")) {
    die (STATE_CRITICAL, _("FPING CRITICAL - %s is unreachable\n"),
               "host");

  }
  else if (strstr (buf, "is down")) {
    die (STATE_CRITICAL, _("FPING CRITICAL - %s is down\n"), server_name);

  }
  else if (strstr (buf, "is alive")) {
    status = STATE_OK;

  }
  else if (strstr (buf, "xmt/rcv/%loss") && strstr (buf, "min/avg/max")) {
    losstr = strstr (buf, "=");
    losstr = 1 + strstr (losstr, "/");
    losstr = 1 + strstr (losstr, "/");
    rtastr = strstr (buf, "min/avg/max");
    rtastr = strstr (rtastr, "=");
    rtastr = 1 + index (rtastr, '/');
    loss = strtod (losstr, NULL);
    rta = strtod (rtastr, NULL);
    if (cpl_p == TRUE && loss > cpl)
      status = STATE_CRITICAL;
    else if (crta_p == TRUE  && rta > crta)
      status = STATE_CRITICAL;
    else if (wpl_p == TRUE && loss > wpl)
      status = STATE_WARNING;
    else if (wrta_p == TRUE && rta > wrta)
      status = STATE_WARNING;
    else
      status = STATE_OK;
    die (status,
          _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"),
         state_text (status), server_name, loss, rta,
         perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100),
         fperfdata ("rta", rta/1.0e3, "s", wrta_p, wrta/1.0e3, crta_p, crta/1.0e3, TRUE, 0, FALSE, 0));

  }
  else if(strstr (buf, "xmt/rcv/%loss") ) {
    /* no min/max/avg if host was unreachable in fping v2.2.b1 */
    losstr = strstr (buf, "=");
    losstr = 1 + strstr (losstr, "/");
    losstr = 1 + strstr (losstr, "/");
    loss = strtod (losstr, NULL);
    if (atoi(losstr) == 100)
      status = STATE_CRITICAL;
    else if (cpl_p == TRUE && loss > cpl)
      status = STATE_CRITICAL;
    else if (wpl_p == TRUE && loss > wpl)
      status = STATE_WARNING;
    else
      status = STATE_OK;
    /* loss=%.0f%%;%d;%d;0;100 */
    die (status, _("FPING %s - %s (loss=%.0f%% )|%s\n"),
         state_text (status), server_name, loss ,
         perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, TRUE, 0, TRUE, 100));

  }
  else {
    status = max_state (status, STATE_WARNING);
  }

  return status;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char* copyright = "2000-2007"

Definition at line 33 of file check_fping.c.

int cpl

Definition at line 60 of file check_fping.c.

int cpl_p = FALSE

Definition at line 64 of file check_fping.c.

double crta

Definition at line 62 of file check_fping.c.

int crta_p = FALSE

Definition at line 66 of file check_fping.c.

const char* email = "nagiosplug-devel@lists.sourceforge.net"

Definition at line 34 of file check_fping.c.

Definition at line 56 of file check_fping.c.

int packet_interval = 0

Definition at line 58 of file check_fping.c.

Definition at line 55 of file check_fping.c.

const char* progname = "check_fping"

Definition at line 32 of file check_fping.c.

char* server_name = NULL

Definition at line 54 of file check_fping.c.

int target_timeout = 0

Definition at line 57 of file check_fping.c.

int verbose = FALSE

Definition at line 59 of file check_fping.c.

int wpl

Definition at line 61 of file check_fping.c.

int wpl_p = FALSE

Definition at line 65 of file check_fping.c.

double wrta

Definition at line 63 of file check_fping.c.

int wrta_p = FALSE

Definition at line 67 of file check_fping.c.