aboutsummaryrefslogtreecommitdiff
path: root/plugins/negate.c
diff options
context:
space:
mode:
authorGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-08-10 06:53:22 +0000
committerGravatar Karl DeBisschop <kdebisschop@users.sourceforge.net> 2003-08-10 06:53:22 +0000
commitf4f92be60c94fd4e0dd4b2b4b3101543eedb706a (patch)
tree28d25bd0ab624d82435823c940a186370947ad4d /plugins/negate.c
parentcbf702f51f839af5a8e9c66bdae7d6a3dc363ace (diff)
downloadmonitoring-plugins-f4f92be60c94fd4e0dd4b2b4b3101543eedb706a.tar.gz
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
Diffstat (limited to 'plugins/negate.c')
-rw-r--r--plugins/negate.c188
1 files changed, 91 insertions, 97 deletions
diff --git a/plugins/negate.c b/plugins/negate.c
index 3ef5ee76..c24658af 100644
--- a/plugins/negate.c
+++ b/plugins/negate.c
@@ -14,84 +14,12 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-******************************************************************************/
-
-const char *progname = "negate";
-const char *revision = "$Revision$";
-const char *copyright = "2002-2003";
-const char *email = "nagiosplug-devel@lists.sourceforge.net";
-
-#define DEFAULT_TIMEOUT 9
-
-#include "common.h"
-#include "utils.h"
-#include "popen.h"
-
-void
-print_usage (void)
-{
- printf (_("Usage: %s [-t timeout] <definition of wrapped plugin>\n"),
- progname);
- printf (_(UT_HLP_VRS), progname, progname);
-}
-
-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));
-}
-
-char *command_line;
-
-int process_arguments (int, char **);
-int validate_arguments (void);
-/******************************************************************************
-
-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.
-
-Please note that all tags must be lowercase to use the DocBook XML DTD.
-
@@-<article>
<sect1>
<title>Quick Reference</title>
-<!-- The refentry forms a manpage -->
<refentry>
-<refmeta>
-<manvolnum>5<manvolnum>
-</refmeta>
+<refmeta><manvolnum>5<manvolnum></refmeta>
<refnamdiv>
<refname>&progname;</refname>
<refpurpose>&SUMMARY;</refpurpose>
@@ -119,19 +47,33 @@ Please note that all tags must be lowercase to use the DocBook XML DTD.
<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-2003";
+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;
- char input_buffer[MAX_INPUT_BUFFER];
+ char *buf;
if (process_arguments (argc, argv) == ERROR)
usage (_("Could not parse arguments\n"));
@@ -151,27 +93,22 @@ main (int argc, char **argv)
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++;
- if (strchr (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)
- die (STATE_UNKNOWN,\
- _("%s problem - No data recieved from host\nCMD: %s\n"),\
- argv[0], command_line);
+ die (STATE_UNKNOWN,
+ _("%s problem - No data recieved from host\nCMD: %s\n"),\
+ argv[0], command_line);
/* 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 */
@@ -189,6 +126,9 @@ main (int argc, char **argv)
/******************************************************************************
@@-
+<sect2>
+<title>Functions</title>
+
<sect3>
<title>process_arguments</title>
@@ -196,7 +136,7 @@ main (int argc, char **argv)
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>
-@@
@@ -208,8 +148,8 @@ process_arguments (int argc, char **argv)
{
int c;
- 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'},
@@ -218,7 +158,7 @@ process_arguments (int argc, char **argv)
while (1) {
c = getopt_long (argc, argv, "+hVt:",
- long_options, &option_index);
+ longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -226,16 +166,19 @@ process_arguments (int argc, char **argv)
switch (c) {
case '?': /* help */
usage3 (_("Unknown argument"), optopt);
+ break;
case 'h': /* help */
print_help ();
exit (EXIT_SUCCESS);
+ break;
case 'V': /* version */
print_revision (progname, revision);
exit (EXIT_SUCCESS);
case 't': /* timeout period */
if (!is_integer (optarg))
usage2 (_("Timeout Interval must be an integer"), optarg);
- timeout_interval = atoi (optarg);
+ else
+ timeout_interval = atoi (optarg);
break;
}
}
@@ -267,7 +210,6 @@ validate_arguments ()
return ERROR;
return STATE_OK;
}
-
/******************************************************************************
@@-
@@ -276,3 +218,55 @@ validate_arguments ()
</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);
+ printf (_(UT_HLP_VRS), progname, progname);
+}