Back to index

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

Go to the source code of this file.

Defines

#define PERF_CHARACTER   "|"
#define NEWLINE_CHARACTER   '\n'

Functions

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

Variables

const char * progname = "urlize"
const char * copyright = "2000-2006"
const char * email = "nagiosplug-devel@lists.sourceforge.net"

Define Documentation

#define NEWLINE_CHARACTER   '\n'

Definition at line 42 of file urlize.c.

#define PERF_CHARACTER   "|"

Definition at line 41 of file urlize.c.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 48 of file urlize.c.

{
       int found = 0, result = STATE_UNKNOWN;
       char *url = NULL;
       char *cmd;
       char *buf;
       char *nstr;
       char tstr[MAX_INPUT_BUFFER];

       int c;
       int option = 0;
       static struct option longopts[] = {
              {"help", no_argument, 0, 'h'},
              {"version", no_argument, 0, 'V'},
              {"url", required_argument, 0, 'u'},
              {0, 0, 0, 0}
       };

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

       /* Need at least 2 args */
       if (argc < 3) {
              print_help();
              exit (STATE_UNKNOWN);
       }

       while (1) {
              c = getopt_long (argc, argv, "+hVu:", longopts, &option);

              if (c == -1 || c == EOF)
                     break;

              switch (c) {
              case 'h':     /* help */
                     print_help ();
                     exit (EXIT_SUCCESS);
                     break;
              case 'V':     /* version */
                     print_revision (progname, NP_VERSION);
                     exit (EXIT_SUCCESS);
                     break;
              case 'u':
                     url = strdup (argv[optind]);
                     break;
              case '?':
              default:
                     usage5 ();
              }
       }

       if (url == NULL)
              url = strdup (argv[optind++]);

       cmd = strdup (argv[optind++]);
       for (c = optind; c < argc; c++) {
              asprintf (&cmd, "%s %s", cmd, argv[c]);
       }

       child_process = spopen (cmd);
       if (child_process == NULL) {
              printf (_("Could not open pipe: %s\n"), cmd);
              exit (STATE_UNKNOWN);
       }

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

       bzero(tstr, sizeof(tstr));
       buf = malloc(MAX_INPUT_BUFFER);
       printf ("<A href=\"%s\">", argv[1]);
       while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
              found++;
              /* Collect the string in temp str so we can tokenize */
              strcat(tstr, buf);
       }

       if (!found)
              die (STATE_UNKNOWN,
                   _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"),
                   argv[0], cmd);


       /* chop the newline character */
       if ((nstr = strchr(tstr, NEWLINE_CHARACTER)) != NULL)
              *nstr = '\0';

       /* tokenize the string for Perfdata if there is some */
       nstr = strtok(tstr, PERF_CHARACTER);
       printf ("%s", nstr);
       printf ("</A>");
       nstr = strtok(NULL, PERF_CHARACTER);
       if (nstr != NULL)
              printf (" | %s", nstr);

       /* close the pipe */
       result = spclose (child_process);

       /* WARNING if output found on stderr */
       if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
              result = max_state (result, STATE_WARNING);

       /* close stderr */
       (void) fclose (child_stderr);

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

Variable Documentation

const char* copyright = "2000-2006"

Definition at line 34 of file urlize.c.

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

Definition at line 35 of file urlize.c.

const char* progname = "urlize"

Definition at line 33 of file urlize.c.