Back to index

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

Go to the source code of this file.

Enumerations

enum  checkvar {
  NONE, LOAD1, LOAD5, LOAD15,
  CONNS, VPF, VMF, VMU,
  VMP, VKF, LTCH, CBUFF,
  CDBUFF, LRUM, DSDB, LOGINS,
  NRMH, PUPRB, UPRB, SAPENTRIES,
  OFILES, VKP, VPP, VKNP,
  VPNP, ABENDS, CSPROCS, TSYNC,
  LRUS, DCB, TCB, DSVER,
  UPTIME, NLM, NRMP, NRMM,
  NRMS, NSS1, NSS2, NSS3,
  NSS4, NSS5, NSS6, NSS7,
  NONE, LOAD1, LOAD5, LOAD15,
  DPU, PROCS, NETSTAT, UPTIME
}
enum  { PORT = 2000 }

Functions

enum checkvar int cmd_timeout
int netstat_port char
*disk_name char *process_name
char send_buffer[MAX_INPUT_BUFFER]
int 
process_arguments (int, char **)
void print_usage (void)
void print_help (void)
int main (int argc, char **argv)

Variables

const char * progname = "check_overcr"
const char * copyright = "2000-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
char * server_address = NULL
int server_port = PORT
double warning_value = 0L
double critical_value = 0L
int check_warning_value = FALSE
int check_critical_value = FALSE

Enumeration Type Documentation

anonymous enum
Enumerator:
PORT 

Definition at line 51 of file check_overcr.c.

     {
       PORT = 2000
};
enum checkvar
Enumerator:
NONE 
LOAD1 
LOAD5 
LOAD15 
CONNS 
VPF 
VMF 
VMU 
VMP 
VKF 
LTCH 
CBUFF 
CDBUFF 
LRUM 
DSDB 
LOGINS 
NRMH 
PUPRB 
UPRB 
SAPENTRIES 
OFILES 
VKP 
VPP 
VKNP 
VPNP 
ABENDS 
CSPROCS 
TSYNC 
LRUS 
DCB 
TCB 
DSVER 
UPTIME 
NLM 
NRMP 
NRMM 
NRMS 
NSS1 
NSS2 
NSS3 
NSS4 
NSS5 
NSS6 
NSS7 
NONE 
LOAD1 
LOAD5 
LOAD15 
DPU 
PROCS 
NETSTAT 
UPTIME 

Definition at line 40 of file check_overcr.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 74 of file check_overcr.c.

{
       int result = STATE_UNKNOWN;
       char recv_buffer[MAX_INPUT_BUFFER];
       char temp_buffer[MAX_INPUT_BUFFER];
       char *temp_ptr = NULL;
       int found_disk = FALSE;
       unsigned long percent_used_disk_space = 100;
       double load;
       double load_1min;
       double load_5min;
       double load_15min;
       int port_connections = 0;
       int processes = 0;
       double uptime_raw_hours;
       int uptime_raw_minutes = 0;
       int uptime_days = 0;
       int uptime_hours = 0;
       int uptime_minutes = 0;

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

       /* initialize alarm signal handling */
       signal (SIGALRM, socket_timeout_alarm_handler);

       /* set socket timeout */
       alarm (socket_timeout);

       result = process_tcp_request2 (server_address,
                                      server_port,
                                      send_buffer,
                                      recv_buffer,
                                      sizeof (recv_buffer));

       switch (vars_to_check) {

       case LOAD1:
       case LOAD5:
       case LOAD15:
       
              if (result != STATE_OK)
                     die (result, _("Unknown error fetching load data\n"));

              temp_ptr = (char *) strtok (recv_buffer, "\r\n");
              if (temp_ptr == NULL)
                     die (STATE_CRITICAL, _("Invalid response from server - no load information\n"));
              else
                     load_1min = strtod (temp_ptr, NULL);

              temp_ptr = (char *) strtok (NULL, "\r\n");
              if (temp_ptr == NULL)
                     die (STATE_CRITICAL, _("Invalid response from server after load 1\n"));
              else
                     load_5min = strtod (temp_ptr, NULL);

              temp_ptr = (char *) strtok (NULL, "\r\n");
              if (temp_ptr == NULL)
                     die (STATE_CRITICAL, _("Invalid response from server after load 5\n"));
              else
                     load_15min = strtod (temp_ptr, NULL);

              switch (vars_to_check) {
              case LOAD1:
                     strcpy (temp_buffer, "1");
                     load = load_1min;
                     break;
              case LOAD5:
                     strcpy (temp_buffer, "5");
                     load = load_5min;
                     break;
              default:
                     strcpy (temp_buffer, "15");
                     load = load_15min;
                     break;
              }

              if (check_critical_value == TRUE && (load >= critical_value))
                     result = STATE_CRITICAL;
              else if (check_warning_value == TRUE && (load >= warning_value))
                     result = STATE_WARNING;

              die (result,
                        _("Load %s - %s-min load average = %0.2f"),
                                                  state_text(result),
                        temp_buffer,
                        load);

                     break;

       case DPU:

              if (result != STATE_OK)
                     die (result, _("Unknown error fetching disk data\n"));

              for (temp_ptr = (char *) strtok (recv_buffer, " ");
                   temp_ptr != NULL;
                   temp_ptr = (char *) strtok (NULL, " ")) {

                     if (!strcmp (temp_ptr, disk_name)) {
                            found_disk = TRUE;
                            temp_ptr = (char *) strtok (NULL, "%");
                            if (temp_ptr == NULL)
                                   die (STATE_CRITICAL, _("Invalid response from server\n"));
                            else
                                   percent_used_disk_space = strtoul (temp_ptr, NULL, 10);
                            break;
                     }

                     temp_ptr = (char *) strtok (NULL, "\r\n");
              }

              /* error if we couldn't find the info for the disk */
              if (found_disk == FALSE)
                     die (STATE_CRITICAL,
                                "CRITICAL - Disk '%s' non-existent or not mounted",
                                disk_name);

              if (check_critical_value == TRUE && (percent_used_disk_space >= critical_value))
                     result = STATE_CRITICAL;
              else if (check_warning_value == TRUE && (percent_used_disk_space >= warning_value))
                     result = STATE_WARNING;

              die (result, "Disk %s - %lu%% used on %s", state_text(result), percent_used_disk_space, disk_name);

              break;

       case NETSTAT:

              if (result != STATE_OK)
                     die (result, _("Unknown error fetching network status\n"));
              else
                     port_connections = strtod (recv_buffer, NULL);

              if (check_critical_value == TRUE && (port_connections >= critical_value))
                     result = STATE_CRITICAL;
              else if (check_warning_value == TRUE && (port_connections >= warning_value))
                     result = STATE_WARNING;

              die (result,
                         _("Net %s - %d connection%s on port %d"),
                         state_text(result),
                         port_connections,
                         (port_connections == 1) ? "" : "s",
                         netstat_port);

              break;

       case PROCS:

              if (result != STATE_OK)
                     die (result, _("Unknown error fetching process status\n"));

              temp_ptr = (char *) strtok (recv_buffer, "(");
              if (temp_ptr == NULL)
                     die (STATE_CRITICAL, _("Invalid response from server\n"));

              temp_ptr = (char *) strtok (NULL, ")");
              if (temp_ptr == NULL)
                     die (STATE_CRITICAL, _("Invalid response from server\n"));
              else
                     processes = strtod (temp_ptr, NULL);

              if (check_critical_value == TRUE && (processes >= critical_value))
                     result = STATE_CRITICAL;
              else if (check_warning_value == TRUE && (processes >= warning_value))
                     result = STATE_WARNING;

              die (result,
                         _("Process %s - %d instance%s of %s running"),
                         state_text(result),
                         processes,
                         (processes == 1) ? "" : "s",
                         process_name);
              break;

       case UPTIME:

              if (result != STATE_OK)
                     return result;

              uptime_raw_hours = strtod (recv_buffer, NULL);
              uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0);

              if (check_critical_value == TRUE && (uptime_raw_minutes <= critical_value))
                     result = STATE_CRITICAL;
              else if (check_warning_value == TRUE && (uptime_raw_minutes <= warning_value))
                     result = STATE_WARNING;

              uptime_days = uptime_raw_minutes / 1440;
              uptime_raw_minutes %= 1440;
              uptime_hours = uptime_raw_minutes / 60;
              uptime_raw_minutes %= 60;
              uptime_minutes = uptime_raw_minutes;

              die (result,
                         _("Uptime %s - Up %d days %d hours %d minutes"),
                         state_text(result),
                         uptime_days,
                         uptime_hours,
                         uptime_minutes);
              break;

       default:
              die (STATE_UNKNOWN, _("Nothing to check!\n"));
              break;
       }
}

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");
}
enum checkvar int cmd_timeout int netstat_port char* disk_name char* process_name char send_buffer [MAX_INPUT_BUFFER] int process_arguments ( int  argc,
char **  argv 
) [abstract]

Variable Documentation

Definition at line 60 of file check_overcr.c.

Definition at line 59 of file check_overcr.c.

const char* copyright = "2000-2007"

Definition at line 33 of file check_overcr.c.

double critical_value = 0L

Definition at line 58 of file check_overcr.c.

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

Definition at line 34 of file check_overcr.c.

const char* progname = "check_overcr"

Definition at line 32 of file check_overcr.c.

Definition at line 55 of file check_overcr.c.

Definition at line 56 of file check_overcr.c.

double warning_value = 0L

Definition at line 57 of file check_overcr.c.