Back to index

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

Go to the source code of this file.

Defines

#define EXPECT   "RTSP/1."
#define URL   ""

Enumerations

enum  { PORT = 554 }

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_real"
const char * copyright = "2000-2007"
const char * email = "nagiosplug-devel@lists.sourceforge.net"
int server_port = PORT
char * server_address
char * host_name
char * server_url = NULL
char * server_expect
int warning_time = 0
int check_warning_time = FALSE
int critical_time = 0
int check_critical_time = FALSE
int verbose = FALSE

Define Documentation

#define EXPECT   "RTSP/1."

Definition at line 43 of file check_real.c.

#define URL   ""

Definition at line 44 of file check_real.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
PORT 

Definition at line 39 of file check_real.c.

     {
       PORT   = 554
};

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 65 of file check_real.c.

{
       int sd;
       int result = STATE_UNKNOWN;
       char buffer[MAX_INPUT_BUFFER];
       char *status_line = NULL;

       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);
       time (&start_time);

       /* try to connect to the host at the given port number */
       if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
              die (STATE_CRITICAL, _("Unable to connect to %s on port %d\n"),
                                                  server_address, server_port);

       /* Part I - Server Check */

       /* send the OPTIONS request */
       sprintf (buffer, "OPTIONS rtsp://%s:%d RTSP/1.0\r\n", host_name, server_port);
       result = send (sd, buffer, strlen (buffer), 0);

       /* send the header sync */
       sprintf (buffer, "CSeq: 1\r\n");
       result = send (sd, buffer, strlen (buffer), 0);

       /* send a newline so the server knows we're done with the request */
       sprintf (buffer, "\r\n");
       result = send (sd, buffer, strlen (buffer), 0);

       /* watch for the REAL connection string */
       result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0);

       /* return a CRITICAL status if we couldn't read any data */
       if (result == -1)
              die (STATE_CRITICAL, _("No data received from %s\n"), host_name);

       /* make sure we find the response we are looking for */
       if (!strstr (buffer, server_expect)) {
              if (server_port == PORT)
                     printf ("%s\n", _("Invalid REAL response received from host"));
              else
                     printf (_("Invalid REAL response received from host on port %d\n"),
                                                 server_port);
       }
       else {
              /* else we got the REAL string, so check the return code */

              time (&end_time);

              result = STATE_OK;

              status_line = (char *) strtok (buffer, "\n");

              if (strstr (status_line, "200"))
                     result = STATE_OK;

              /* client errors result in a warning state */
              else if (strstr (status_line, "400"))
                     result = STATE_WARNING;
              else if (strstr (status_line, "401"))
                     result = STATE_WARNING;
              else if (strstr (status_line, "402"))
                     result = STATE_WARNING;
              else if (strstr (status_line, "403"))
                     result = STATE_WARNING;
              else if (strstr (status_line, "404"))
                     result = STATE_WARNING;

              /* server errors result in a critical state */
              else if (strstr (status_line, "500"))
                     result = STATE_CRITICAL;
              else if (strstr (status_line, "501"))
                     result = STATE_CRITICAL;
              else if (strstr (status_line, "502"))
                     result = STATE_CRITICAL;
              else if (strstr (status_line, "503"))
                     result = STATE_CRITICAL;

              else
                     result = STATE_UNKNOWN;
       }

       /* Part II - Check stream exists and is ok */
       if ((result == STATE_OK )&& (server_url != NULL) ) {

              /* Part I - Server Check */

              /* send the OPTIONS request */
              sprintf (buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\n", host_name,
                                           server_port, server_url);
              result = send (sd, buffer, strlen (buffer), 0);

              /* send the header sync */
              sprintf (buffer, "CSeq: 2\n");
              result = send (sd, buffer, strlen (buffer), 0);

              /* send a newline so the server knows we're done with the request */
              sprintf (buffer, "\n");
              result = send (sd, buffer, strlen (buffer), 0);

              /* watch for the REAL connection string */
              result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0);

              /* return a CRITICAL status if we couldn't read any data */
              if (result == -1) {
                     printf (_("No data received from host\n"));
                     result = STATE_CRITICAL;
              }
              else {
                     /* make sure we find the response we are looking for */
                     if (!strstr (buffer, server_expect)) {
                            if (server_port == PORT)
                                   printf ("%s\n", _("Invalid REAL response received from host"));
                            else
                                   printf (_("Invalid REAL response received from host on port %d\n"),
                                                               server_port);
                     }
                     else {

                            /* else we got the REAL string, so check the return code */

                            time (&end_time);

                            result = STATE_OK;

                            status_line = (char *) strtok (buffer, "\n");

                            if (strstr (status_line, "200"))
                                   result = STATE_OK;

                            /* client errors result in a warning state */
                            else if (strstr (status_line, "400"))
                                   result = STATE_WARNING;
                            else if (strstr (status_line, "401"))
                                   result = STATE_WARNING;
                            else if (strstr (status_line, "402"))
                                   result = STATE_WARNING;
                            else if (strstr (status_line, "403"))
                                   result = STATE_WARNING;
                            else if (strstr (status_line, "404"))
                                   result = STATE_WARNING;

                            /* server errors result in a critical state */
                            else if (strstr (status_line, "500"))
                                   result = STATE_CRITICAL;
                            else if (strstr (status_line, "501"))
                                   result = STATE_CRITICAL;
                            else if (strstr (status_line, "502"))
                                   result = STATE_CRITICAL;
                            else if (strstr (status_line, "503"))
                                   result = STATE_CRITICAL;

                            else
                                   result = STATE_UNKNOWN;
                     }
              }
       }

       /* Return results */
       if (result == STATE_OK) {

              if (check_critical_time == TRUE
                            && (end_time - start_time) > critical_time) result = STATE_CRITICAL;
              else if (check_warning_time == TRUE
                                           && (end_time - start_time) > warning_time) result =
                            STATE_WARNING;

              /* Put some HTML in here to create a dynamic link */
              printf (_("REAL %s - %d second response time\n"),
                                          state_text (result),
                                          (int) (end_time - start_time));
       }
       else
              printf ("%s\n", status_line);

       /* close the connection */
       close (sd);

       /* reset the alarm */
       alarm (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

Definition at line 59 of file check_real.c.

Definition at line 57 of file check_real.c.

const char* copyright = "2000-2007"

Definition at line 32 of file check_real.c.

int critical_time = 0

Definition at line 58 of file check_real.c.

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

Definition at line 33 of file check_real.c.

char* host_name

Definition at line 53 of file check_real.c.

const char* progname = "check_real"

Definition at line 31 of file check_real.c.

Definition at line 52 of file check_real.c.

Definition at line 55 of file check_real.c.

Definition at line 51 of file check_real.c.

char* server_url = NULL

Definition at line 54 of file check_real.c.

int verbose = FALSE

Definition at line 60 of file check_real.c.

int warning_time = 0

Definition at line 56 of file check_real.c.