X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Furlize.c;h=5fb3aca0b2c252a515aabd0637c7ae0896f8d424;hb=25d1ee331dbe4977a4a1a756c67f32bd51d9b070;hp=f4bc67b39c1f9492261610fe314c0a28eb6e0a89;hpb=f4f92be60c94fd4e0dd4b2b4b3101543eedb706a;p=nagiosplug.git diff --git a/plugins/urlize.c b/plugins/urlize.c index f4bc67b..5fb3aca 100644 --- a/plugins/urlize.c +++ b/plugins/urlize.c @@ -1,30 +1,46 @@ -/****************************************************************************** - - 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 +* +* Description: +* +* This file contains the urlize plugin +* +* This plugin wraps the text output of another command (plugin) in HTML +* tags, thus displaying the child plugin's output as a clickable link in the +* Nagios status screen. This plugin returns the status of 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 . +* +* +*****************************************************************************/ const char *progname = "urlize"; -const char *revision = "$Revision$"; -const char *copyright = "2000-2003"; +const char *copyright = "2000-2006"; const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" #include "utils.h" #include "popen.h" +#define PERF_CHARACTER "|" +#define NEWLINE_CHARACTER '\n' + void print_help (void); void print_usage (void); @@ -35,6 +51,8 @@ main (int argc, char **argv) char *url = NULL; char *cmd; char *buf; + char *nstr; + char tstr[MAX_INPUT_BUFFER]; int c; int option = 0; @@ -45,6 +63,16 @@ main (int argc, char **argv) {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); @@ -57,7 +85,7 @@ main (int argc, char **argv) exit (EXIT_SUCCESS); break; case 'V': /* version */ - print_revision (progname, revision); + print_revision (progname, NP_VERSION); exit (EXIT_SUCCESS); break; case 'u': @@ -65,8 +93,7 @@ main (int argc, char **argv) break; case '?': default: - usage3 (_("Unknown argument"), optopt); - break; + usage5 (); } } @@ -89,18 +116,33 @@ main (int argc, char **argv) printf (_("Could not open stderr for %s\n"), cmd); } + bzero(tstr, sizeof(tstr)); buf = malloc(MAX_INPUT_BUFFER); printf ("", argv[1]); while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { found++; - printf ("%s", buf); + /* Collect the string in temp str so we can tokenize */ + strcat(tstr, buf); } if (!found) die (STATE_UNKNOWN, - _("%s problem - No data recieved from host\nCMD: %s\n"), + _("%s UNKNOWN - No data received from host\nCMD: %s\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 (""); + nstr = strtok(NULL, PERF_CHARACTER); + if (nstr != NULL) + printf (" | %s", nstr); + /* close the pipe */ result = spclose (child_process); @@ -111,53 +153,47 @@ main (int argc, char **argv) /* close stderr */ (void) fclose (child_stderr); - printf ("\n"); return result; } - - - void print_help (void) { - print_revision (progname, revision); + print_revision (progname, NP_VERSION); - printf (_("Copyright (c) 2000 Karl DeBisschop \n")); - printf (_(COPYRIGHT), copyright, email); + printf ("Copyright (c) 2000 Karl DeBisschop \n"); + printf (COPYRIGHT, copyright, email); - printf (_("\n\ -This plugin wraps the text output of another command (plugin) in HTML\n\ - 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")); + printf ("%s\n", _("This plugin wraps the text output of another command (plugin)")); + printf ("%s\n", _("in HTML tags, thus displaying the child plugin's output as a clickable link in")); + printf ("%s\n", _("the Nagios status screen. This plugin returns the status of the invoked plugin.")); + + printf ("\n\n"); print_usage (); - printf (_("\n\ -Pay close attention to quoting to ensure that the shell passes the expected\n\ -data to the plugin. For example, in:\n\ -\n\ - urlize http://example.com/ check_http -H example.com -r 'two words'\n\ -\n\ -the shell will remove the single quotes and urlize will see:\n\ -\n\ - urlize http://example.com/ check_http -H example.com -r two words\n\ -\n\ -You probably want:\n\ -\n\ - urlize http://example.com/ \"check_http -H example.com -r 'two words'\"\n")); - - printf (_(UT_SUPPORT)); -} + 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_usage (void) { - printf (_("Usage:\n %s ... \n"), progname); + printf (_("Usage:")); + printf ("%s ... \n", progname); }