diff --git a/plugins/negate.c b/plugins/negate.c
index b6effe399facbc30477bc1c100a42380c50d97ee..d08c3a309e30b868cd6dc7a51c0655d48797c5ee 100644 (file)
--- a/plugins/negate.c
+++ b/plugins/negate.c
/******************************************************************************
/******************************************************************************
- *
- * Program: Inverting plugin wrapper for Nagios
- * License: GPL
- *
- * 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.
- *
- * $Id$
- *
- *****************************************************************************/
-
-#define PROGNAME "negate"
-#define REVISION "$Revision$"
-#define COPYRIGHT "2002"
-#define AUTHOR "Karl DeBisschop"
-#define EMAIL "kdebisschop@users.sourceforge.net"
-#define SUMMARY "Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n"
-
-#define OPTIONS "\
-\[-t timeout] <definition of wrapped plugin>"
-
-#define LONGOPTIONS "\
- -t, --timeout=INTEGER\n\
- Terminate test if timeout limit is exceeded (default: %d)\n\
- [keep this less than the plugin timeout to retain CRITICAL status]\n"
-
-#define DESCRIPTION "\
-This plugin is a wrapper to take the output of another plugin and invert it.\n\
-If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\
-If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\
-Otherwise, the output state of the wrapped plugin is unchanged.\n"
-
-#define DEFAULT_TIMEOUT 9
-
-#include "common.h"
-#include "utils.h"
-#include "popen.h"
-
-char *command_line;
-static int process_arguments (int, char **);
-static int validate_arguments (void);
-static void print_usage (void);
-static void print_help (void);
-\f
-/******************************************************************************
+ 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.
-The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
-tags in the comments. With in the tags, the XML is assembled sequentially.
-You can define entities in tags. You also have all the #defines available as
-entities.
+ 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.
-Please note that all tags must be lowercase to use the DocBook XML DTD.
+ 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.
+
+ $Id$
@@-<article>
<sect1>
<title>Quick Reference</title>
@@-<article>
<sect1>
<title>Quick Reference</title>
-<!-- The refentry forms a manpage -->
<refentry>
<refentry>
-<refmeta>
-<manvolnum>5<manvolnum>
-</refmeta>
+<refmeta><manvolnum>5<manvolnum></refmeta>
<refnamdiv>
<refnamdiv>
-<refname>&PROGNAME;</refname>
+<refname>&progname;</refname>
<refpurpose>&SUMMARY;</refpurpose>
</refnamdiv>
</refentry>
<refpurpose>&SUMMARY;</refpurpose>
</refnamdiv>
</refentry>
<itemizedlist>
<listitem>Add option to do regex substitution in output text</listitem>
</itemizedlist>
<itemizedlist>
<listitem>Add option to do regex substitution in output text</listitem>
</itemizedlist>
-</sect2>
-
+</sect2>-@@
-<sect2>
-<title>Functions</title>
--@@
******************************************************************************/
******************************************************************************/
+const char *progname = "negate";
+const char *revision = "$Revision$";
+const char *copyright = "2002-2004";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
+
+#define DEFAULT_TIMEOUT 9
+
+#include "common.h"
+#include "utils.h"
+#include "popen.h"
+
+char *command_line;
+
+int process_arguments (int, char **);
+int validate_arguments (void);
+void print_help (void);
+void print_usage (void);
+
+
+
int
main (int argc, char **argv)
{
int found = 0, result = STATE_UNKNOWN;
int
main (int argc, char **argv)
{
int found = 0, result = STATE_UNKNOWN;
- char input_buffer[MAX_INPUT_BUFFER];
+ char *buf;
+
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
if (process_arguments (argc, argv) == ERROR)
if (process_arguments (argc, argv) == ERROR)
- usage ("Could not parse arguments");
+ usage4 (_("Could not parse arguments"));
/* Set signal handling and alarm */
/* Set signal handling and alarm */
- if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR) {
- printf ("Cannot catch SIGALRM");
- return STATE_UNKNOWN;
- }
- alarm (timeout_interval);
+ if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR)
+ die (STATE_UNKNOWN, _("Cannot catch SIGALRM"));
+
+ (void) alarm ((unsigned) timeout_interval);
child_process = spopen (command_line);
child_process = spopen (command_line);
- if (child_process == NULL) {
- printf ("Could not open pipe: %s\n", command_line);
- exit (STATE_UNKNOWN);
- }
+ if (child_process == NULL)
+ die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), command_line);
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
+
if (child_stderr == NULL) {
if (child_stderr == NULL) {
- printf ("Could not open stderr for %s\n", command_line);
+ printf (_("Could not open stderr for %s\n"), command_line);
}
}
- while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
+ buf = malloc(MAX_INPUT_BUFFER);
+ while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
found++;
found++;
- if (index (input_buffer, '\n')) {
- input_buffer[strcspn (input_buffer, "\n")] = 0;
- printf ("%s\n", input_buffer);
- }
- else {
- printf ("%s\n", input_buffer);
- }
+ printf ("%s", 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 problem - No data received from host\nCMD: %s\n"),\
+ argv[0], command_line);
/* close the pipe */
result = spclose (child_process);
/* WARNING if output found on stderr */
/* close the pipe */
result = spclose (child_process);
/* WARNING if output found on stderr */
- if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
+ if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
result = max_state (result, STATE_WARNING);
/* close stderr */
(void) fclose (child_stderr);
if (result == STATE_OK)
result = max_state (result, STATE_WARNING);
/* close stderr */
(void) fclose (child_stderr);
if (result == STATE_OK)
- return STATE_CRITICAL;
+ exit (STATE_CRITICAL);
else if (result == STATE_CRITICAL)
else if (result == STATE_CRITICAL)
- return STATE_OK;
+ exit (EXIT_SUCCESS);
else
else
- return result;
-}
-\f
-
-
-
-void
-print_help (void)
-{
- print_revision (PROGNAME, REVISION);
- printf
- ("Copyright (c) %s %s <%s>\n\n%s\n",
- COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
- print_usage ();
- printf
- ("\nOptions:\n" LONGOPTIONS "\n" DESCRIPTION "\n",
- DEFAULT_TIMEOUT);
- support ();
+ exit (result);
}
}
-void
-print_usage (void)
-{
- printf ("Usage:\n" " %s %s\n"
-#ifdef HAVE_GETOPT_H
- " %s (-h | --help) for detailed help\n"
- " %s (-V | --version) for version information\n",
-#else
- " %s -h for detailed help\n"
- " %s -V for version information\n",
-#endif
- PROGNAME, OPTIONS, PROGNAME, PROGNAME);
-}
-\f
-
-
/******************************************************************************
@@-
/******************************************************************************
@@-
+<sect2>
+<title>Functions</title>
+
<sect3>
<title>process_arguments</title>
<sect3>
<title>process_arguments</title>
variables.</para>
<para>Aside from the standard 'help' and 'version' options, there
variables.</para>
<para>Aside from the standard 'help' and 'version' options, there
-is a only a 'timeout' option.No validation is currently done.</para>
+is a only a 'timeout' option.</para>
</sect3>
-@@
******************************************************************************/
</sect3>
-@@
******************************************************************************/
+
+
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
int c;
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
int c;
-#ifdef HAVE_GETOPT_H
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"timeout", required_argument, 0, 't'},
{0, 0, 0, 0}
};
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"timeout", required_argument, 0, 't'},
{0, 0, 0, 0}
};
-#endif
while (1) {
while (1) {
-#ifdef HAVE_GETOPT_H
- c = getopt_long (argc, argv, "+?hVt:",
- long_options, &option_index);
-#else
- c = getopt (argc, argv, "+?hVt:");
-#endif
+ c = getopt_long (argc, argv, "+hVt:",
+ longopts, &option);
+
if (c == -1 || c == EOF)
break;
switch (c) {
case '?': /* help */
if (c == -1 || c == EOF)
break;
switch (c) {
case '?': /* help */
- usage2 ("Unknown argument", optarg);
+ usage2 (_("Unknown argument"), optarg);
+ break;
case 'h': /* help */
print_help ();
case 'h': /* help */
print_help ();
- exit (STATE_OK);
+ exit (EXIT_SUCCESS);
+ break;
case 'V': /* version */
case 'V': /* version */
- print_revision (PROGNAME, REVISION);
- exit (STATE_OK);
+ print_revision (progname, revision);
+ exit (EXIT_SUCCESS);
case 't': /* timeout period */
if (!is_integer (optarg))
case 't': /* timeout period */
if (!is_integer (optarg))
- usage2 ("Timeout Interval must be an integer", optarg);
- timeout_interval = atoi (optarg);
+ usage2 (_("Timeout interval must be a positive integer"), optarg);
+ else
+ timeout_interval = atoi (optarg);
break;
}
}
break;
}
}
- command_line = strscpy (command_line, argv[optind]);
- for (c = optind+1; c <= argc; c++) {
- command_line = ssprintf (command_line, "%s %s", command_line, argv[c]);
+ asprintf (&command_line, "%s", argv[optind]);
+ for (c = optind+1; c < argc; c++) {
+ asprintf (&command_line, "%s %s", command_line, argv[c]);
}
return validate_arguments ();
}
return validate_arguments ();
-@@
******************************************************************************/
-@@
******************************************************************************/
+
+
int
validate_arguments ()
{
int
validate_arguments ()
{
- return OK;
+ if (command_line == NULL)
+ return ERROR;
+ return STATE_OK;
}
}
-\f
/******************************************************************************
@@-
/******************************************************************************
@@-
</article>
-@@
******************************************************************************/
</article>
-@@
******************************************************************************/
+
+
+
+void
+print_help (void)
+{
+ print_revision (progname, revision);
+
+ printf (COPYRIGHT, copyright, email);
+
+ printf (_("\
+Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).\n\n"));
+
+ print_usage ();
+
+ printf (_(UT_HELP_VRSN));
+
+ printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
+
+ printf (_("\
+ [keep timeout than the plugin timeout to retain CRITICAL status]\n"));
+
+ printf (_("\
+ negate \"/usr/local/nagios/libexec/check_ping -H host\"\n\
+ Run check_ping and invert result. Must use full path to plugin\n\
+ negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"\n\
+ Use single quotes if you need to retain spaces\n"));
+
+ printf (_("\
+This plugin is a wrapper to take the output of another plugin and invert it.\n\
+If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL.\n\
+If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK.\n\
+Otherwise, the output state of the wrapped plugin is unchanged.\n"));
+
+ printf (_(UT_SUPPORT));
+}
+
+
+
+void
+print_usage (void)
+{
+ printf ("Usage: %s [-t timeout] <definition of wrapped plugin>\n",progname);
+}