From f4f92be60c94fd4e0dd4b2b4b3101543eedb706a Mon Sep 17 00:00:00 2001 From: Karl DeBisschop Date: Sun, 10 Aug 2003 06:53:22 +0000 Subject: the last round of pedantic compiler warnings git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@676 f882894a-f735-0410-b71e-b25c423dba1c --- plugins/urlize.c | 225 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 114 insertions(+), 111 deletions(-) (limited to 'plugins/urlize.c') diff --git a/plugins/urlize.c b/plugins/urlize.c index 12fb3ec9..f4bc67b3 100644 --- a/plugins/urlize.c +++ b/plugins/urlize.c @@ -1,41 +1,20 @@ /****************************************************************************** - * - * 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 - * Written based of concept in urlize.pl - * - * Usage: urlize ... - * - * Description: - * - * This plugin wraps the text output of another command (plugin) in HTML - * 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. - * - *****************************************************************************/ + + 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. + +******************************************************************************/ const char *progname = "urlize"; const char *revision = "$Revision$"; @@ -46,12 +25,101 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "utils.h" #include "popen.h" -void -print_usage (void) +void print_help (void); +void print_usage (void); + +int +main (int argc, char **argv) { - printf (_("Usage:\n %s ... \n"), progname); + int found = 0, result = STATE_UNKNOWN; + char *url = NULL; + char *cmd; + char *buf; + + 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} + }; + + 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: + usage3 (_("Unknown argument"), optopt); + break; + } + } + + 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); + } + + buf = malloc(MAX_INPUT_BUFFER); + printf ("", argv[1]); + while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) { + found++; + printf ("%s", buf); + } + + if (!found) + die (STATE_UNKNOWN, + _("%s problem - No data recieved from host\nCMD: %s\n"), + argv[0], cmd); + + /* 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); + + printf ("\n"); + return result; } + + + + + void print_help (void) { @@ -81,80 +149,15 @@ the shell will remove the single quotes and urlize will see:\n\ You probably want:\n\ \n\ urlize http://example.com/ \"check_http -H example.com -r 'two words'\"\n")); - exit (STATE_OK); -} - -int -main (int argc, char **argv) -{ - int i = 0, found = 0, result = STATE_UNKNOWN; - char *cmd = NULL; - char input_buffer[MAX_INPUT_BUFFER]; - - if (argc < 2) { - print_usage (); - exit (STATE_UNKNOWN); - } - - if (!strcmp (argv[1], "-h") || !strcmp (argv[1], "--help")) { - print_help (); - exit (STATE_OK); - } - - if (!strcmp (argv[1], "-V") || !strcmp (argv[1], "--version")) { - print_revision (progname, revision); - exit (STATE_OK); - } - - if (argc < 2) { - print_usage (); - exit (STATE_UNKNOWN); - } - - asprintf (&cmd, "%s", argv[2]); - for (i = 3; i < argc; i++) { - asprintf (&cmd, "%s %s", cmd, argv[i]); - } - - 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); - } - - printf ("", argv[1]); - while (fgets (input_buffer, 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); - } - } - if (!found) { - printf (_("%s problem - No data recieved from host\nCMD: %s\n"), argv[0], - cmd); - exit (STATE_UNKNOWN); - } + printf (_(UT_SUPPORT)); +} - /* 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_state (result, STATE_WARNING); - /* close stderr */ - (void) fclose (child_stderr); - printf ("\n"); - return result; +void +print_usage (void) +{ + printf (_("Usage:\n %s ... \n"), progname); } -- cgit v1.2.3