diff --git a/plugins/urlize.c b/plugins/urlize.c
index 83c37dac94e90dbfad5cb58a0550223834ddef03..34e25c4e866d086f5eefdfcdd9c443ccf29b46ab 100644 (file)
--- a/plugins/urlize.c
+++ b/plugins/urlize.c
-/******************************************************************************
- *
- * urlize.c
- *
- * Program: plugin wrapper for Nagios
- * License: GPL
- * Copyright (c) 2000 Karl DeBisschop (kdebiss@alum.mit.edu)
- *
- * Last Modified: $Date$
- * 2000-06-01 Karl DeBisschop <karl@debisschop.net>
- * Written based of concept in urlize.pl
- *
- * Usage: urlize <url> <plugin> <arg1> ... <argN>
- *
- * Description:
- *
- * This plugin wraps the text output of another command (plugin) in HTML
- * <A> tags, thus displaying the plugin output in as a clickable link in
- * the Nagios status screen. The return status is the same as the plugin
- * invoked by urlize
- *
- * License Information:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- *****************************************************************************/
+/*****************************************************************************
+*
+* Nagios urlize plugin
+*
+* License: GPL
+* Copyright (c) 2000-2007 Nagios Plugins Development Team
+*
+* Last Modified: $Date$
+*
+* Description:
+*
+* This file contains the urlize plugin
+*
+* This plugin wraps the text output of another command (plugin) in HTML <A>
+* tags, thus displaying the plugin output in as a clickable link in the
+* Nagios status screen. The return status is the same as the invoked plugin.
+*
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* $Id$
+*
+*****************************************************************************/
+
+const char *progname = "urlize";
+const char *revision = "$Revision$";
+const char *copyright = "2000-2006";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
#include "utils.h"
#include "popen.h"
-void print_usage (char *);
-void print_help (char *);
+#define PERF_CHARACTER "|"
+#define NEWLINE_CHARACTER '\n'
+
+void print_help (void);
+void print_usage (void);
int
main (int argc, char **argv)
{
- int i = 0, found = 0, result = STATE_UNKNOWN;
- char command_line[MAX_INPUT_BUFFER] = "";
- char input_buffer[MAX_INPUT_BUFFER];
-
- if (argc < 2) {
- print_usage (my_basename (argv[0]));
+ 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);
}
- if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) {
- print_help (argv[0]);
- exit (STATE_OK);
- }
-
- if (!strcmp (argv[1], "-V") || !strcmp (argv[1], "--version")) {
- print_revision (my_basename (argv[0]), "$Revision$");
- exit (STATE_OK);
+ 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, revision);
+ exit (EXIT_SUCCESS);
+ break;
+ case 'u':
+ url = strdup (argv[optind]);
+ break;
+ case '?':
+ default:
+ usage5 ();
+ }
}
- if (argc < 2) {
- print_usage (my_basename (argv[0]));
- exit (STATE_UNKNOWN);
- }
+ if (url == NULL)
+ url = strdup (argv[optind++]);
- sprintf (command_line, "%s", argv[2]);
- for (i = 3; i < argc; i++) {
- sprintf (command_line, "%s %s", command_line, argv[i]);
+ cmd = strdup (argv[optind++]);
+ for (c = optind; c < argc; c++) {
+ asprintf (&cmd, "%s %s", cmd, argv[c]);
}
- child_process = spopen (command_line);
+ child_process = spopen (cmd);
if (child_process == NULL) {
- printf ("Could not open pipe: %s\n", command_line);
+ 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", command_line);
+ 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 (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
+ while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
found++;
- if (index (input_buffer, '\n')) {
- input_buffer[strcspn (input_buffer, "\n")] = 0;
- printf ("%s", input_buffer);
- }
- else {
- printf ("%s", input_buffer);
- }
+ /* Collect the string in temp str so we can tokenize */
+ strcat(tstr, buf);
}
- if (!found) {
- printf ("%s problem - No data recieved from host\nCMD: %s\n", argv[0],
- command_line);
- exit (STATE_UNKNOWN);
- }
+ 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 (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
- result = max (result, STATE_WARNING);
+ if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
+ result = max_state (result, STATE_WARNING);
/* close stderr */
(void) fclose (child_stderr);
- printf ("</A>\n");
return result;
}
+
+
void
-print_usage (char *cmd)
+print_help (void)
{
- printf ("Usage:\n %s <url> <plugin> <arg1> ... <argN>\n",
- my_basename (cmd));
+ print_revision (progname, revision);
+
+ printf ("Copyright (c) 2000 Karl DeBisschop <kdebisschop@users.sourceforge.net>\n");
+ printf (COPYRIGHT, copyright, email);
+
+ printf ("%s\n", _("This plugin wraps the text output of another command (plugin)"));
+ printf ("%s\n", _("in HTML <A> tags, thus displaying the plugin output in as a clickable link in"));
+ printf ("%s\n", _("the Nagios status screen. The return status is the same as the invoked plugin."));
+
+ printf ("\n\n");
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf ("\n");
+ printf ("%s\n", _("Examples:"));
+ printf ("%s\n", _("Pay close attention to quoting to ensure that the shell passes the expected"));
+ printf ("%s\n\n", _("data to the plugin. For example, in:"));
+ printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'"));
+ printf (" %s\n", _("the shell will remove the single quotes and urlize will see:"));
+ printf (" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r two words"));
+ printf (" %s\n\n", _("You probably want:"));
+ printf (" %s\n", _("urlize http://example.com/ \"check_http -H example.com -r 'two words'\""));
+
+ printf (_(UT_SUPPORT));
}
+
+
void
-print_help (char *cmd)
+print_usage (void)
{
- print_revision ("urlize", "$Revision$");
- printf
- ("Copyright (c) 2000 Karl DeBisschop (kdebiss@alum.mit.edu)\n\n"
- "\nThis plugin wraps the text output of another command (plugin) in HTML\n"
- "<A> tags, thus displaying the plugin output in as a clickable link in\n"
- "the Nagios status screen. The return status is the same as the invoked\n"
- "plugin.\n\n");
- print_usage (cmd);
- exit (STATE_OK);
+ printf (_("Usage:"));
+ printf ("%s <url> <plugin> <arg1> ... <argN>\n", progname);
}