Back to index

nagios-plugins  1.4.16
Functions | Variables
check_mrtg.c File Reference
#include "common.h"
#include "utils.h"

Go to the source code of this file.

Functions

int process_arguments (int, char **)
int validate_arguments (void)
void print_help (void)
void print_usage (void)
int main (int argc, char **argv)

Variables

const char * progname = "check_mrtg"
const char * copyright = "1999-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
char * log_file = NULL
int expire_minutes = 0
int use_average = TRUE
int variable_number = -1
unsigned long value_warning_threshold = 0L
unsigned long value_critical_threshold = 0L
char * label
char * units

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 54 of file check_mrtg.c.

{
       int result = STATE_OK;
       FILE *fp;
       int line;
       char input_buffer[MAX_INPUT_BUFFER];
       char *temp_buffer;
       time_t current_time;
       time_t timestamp = 0L;
       unsigned long average_value_rate = 0L;
       unsigned long maximum_value_rate = 0L;
       unsigned long rate = 0L;

       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\n"));

       /* open the MRTG log file for reading */
       fp = fopen (log_file, "r");
       if (fp == NULL) {
              printf (_("Unable to open MRTG log file\n"));
              return STATE_UNKNOWN;
       }

       line = 0;
       while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {

              line++;

              /* skip the first line of the log file */
              if (line == 1)
                     continue;

              /* break out of read loop if we've passed the number of entries we want to read */
              if (line > 2)
                     break;

              /* grab the timestamp */
              temp_buffer = strtok (input_buffer, " ");
              timestamp = strtoul (temp_buffer, NULL, 10);

              /* grab the average value 1 rate */
              temp_buffer = strtok (NULL, " ");
              if (variable_number == 1)
                     average_value_rate = strtoul (temp_buffer, NULL, 10);

              /* grab the average value 2 rate */
              temp_buffer = strtok (NULL, " ");
              if (variable_number == 2)
                     average_value_rate = strtoul (temp_buffer, NULL, 10);

              /* grab the maximum value 1 rate */
              temp_buffer = strtok (NULL, " ");
              if (variable_number == 1)
                     maximum_value_rate = strtoul (temp_buffer, NULL, 10);

              /* grab the maximum value 2 rate */
              temp_buffer = strtok (NULL, " ");
              if (variable_number == 2)
                     maximum_value_rate = strtoul (temp_buffer, NULL, 10);
       }

       /* close the log file */
       fclose (fp);

       /* if we couldn't read enough data, return an unknown error */
       if (line <= 2) {
              printf (_("Unable to process MRTG log file\n"));
              return STATE_UNKNOWN;
       }

       /* make sure the MRTG data isn't too old */
       time (&current_time);
       if (expire_minutes > 0
                     && (current_time - timestamp) > (expire_minutes * 60)) {
              printf (_("MRTG data has expired (%d minutes old)\n"),
                      (int) ((current_time - timestamp) / 60));
              return STATE_WARNING;
       }

       /* else check the incoming/outgoing rates */
       if (use_average == TRUE)
              rate = average_value_rate;
       else
              rate = maximum_value_rate;

       if (rate > value_critical_threshold)
              result = STATE_CRITICAL;
       else if (rate > value_warning_threshold)
              result = STATE_WARNING;

       printf("%s. %s = %lu %s|%s\n",
              (use_average == TRUE) ? _("Avg") : _("Max"),
              label, rate, units,
              perfdata(label, (long) rate, units,
                      (int) value_warning_threshold, (long) value_warning_threshold,
                      (int) value_critical_threshold, (long) value_critical_threshold,
                      0, 0, 0, 0));

       return result;
}

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 validate_arguments ( void  )

Variable Documentation

const char* copyright = "1999-2007"

Definition at line 33 of file check_mrtg.c.

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

Definition at line 34 of file check_mrtg.c.

int expire_minutes = 0

Definition at line 45 of file check_mrtg.c.

char* label

Definition at line 50 of file check_mrtg.c.

char* log_file = NULL

Definition at line 44 of file check_mrtg.c.

const char* progname = "check_mrtg"

Definition at line 32 of file check_mrtg.c.

char* units

Definition at line 51 of file check_mrtg.c.

Definition at line 46 of file check_mrtg.c.

unsigned long value_critical_threshold = 0L

Definition at line 49 of file check_mrtg.c.

unsigned long value_warning_threshold = 0L

Definition at line 48 of file check_mrtg.c.

int variable_number = -1

Definition at line 47 of file check_mrtg.c.