Revision: 1989
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1989&view=rev
Author: dermoth
Date: 2008-05-02 02:28:15 -0700 (Fri, 02 May 2008)
Log Message:
-----------
negate now has the ability to replace the status text as well (-s, --substitute)
Also changed:
- default timeout to 11 instead of 9 (since it's recommended to have a higher timeout, and many plugins default to 10 seconds)
- If there's no STDOUT lines returned, still returns the returned result if it's NON-ok instead of forcing it to UNKNOWN
Modified Paths:
--------------
nagiosplug/trunk/NEWS
nagiosplug/trunk/plugins/negate.c
Modified: nagiosplug/trunk/NEWS
===================================================================
--- nagiosplug/trunk/NEWS 2008-04-30 12:50:52 UTC (rev 1988)
+++ nagiosplug/trunk/NEWS 2008-05-02 09:28:15 UTC (rev 1989)
@@ -20,6 +20,7 @@
check_dns now allow to repeat -a to match multiple possibly returned address (common with load balancers)
check_mysql now try clearing password in processlist just like check_mysql_query
check_mysql and check_mysql_query now support sockets explicitely (-s, --socket)
+ negate now has the ability to replace the status text as well (-s, --substitute)
1.4.11 13th December 2007
Fixed check_http regression in 1.4.10 where following redirects to
Modified: nagiosplug/trunk/plugins/negate.c
===================================================================
--- nagiosplug/trunk/plugins/negate.c 2008-04-30 12:50:52 UTC (rev 1988)
+++ nagiosplug/trunk/plugins/negate.c 2008-05-02 09:28:15 UTC (rev 1989)
@@ -3,7 +3,7 @@
* Nagios negate plugin
*
* License: GPL
-* Copyright (c) 2002-2007 Nagios Plugins Development Team
+* Copyright (c) 2002-2008 Nagios Plugins Development Team
*
* Last Modified: $Date$
*
@@ -34,10 +34,10 @@
const char *progname = "negate";
const char *revision = "$Revision$";
-const char *copyright = "2002-2007";
+const char *copyright = "2002-2008";
const char *email = "[email protected]";
-#define DEFAULT_TIMEOUT 9
+#define DEFAULT_TIMEOUT 11
#include "common.h"
#include "utils.h"
@@ -49,6 +49,7 @@
int validate_arguments (char **);
void print_help (void);
void print_usage (void);
+int subst_text = FALSE;
static int state[4] = {
STATE_OK,
@@ -61,7 +62,7 @@
main (int argc, char **argv)
{
int found = 0, result = STATE_UNKNOWN;
- char *buf;
+ char *buf, *sub;
char **command_line;
output chld_out, chld_err;
int i;
@@ -92,10 +93,22 @@
exit (STATE_WARNING);
}
+ /* Return UNKNOWN or worse if no output is returned */
if (chld_out.lines == 0)
- die (STATE_UNKNOWN, _("No data returned from command\n"));
+ die (max_state_alt (result, STATE_UNKNOWN), _("No data returned from command\n"));
for (i = 0; i < chld_out.lines; i++) {
+ if (subst_text && result != state[result] &&
+ result >= 0 && result <= 4) {
+ /* Loop over each match found */
+ while ((sub = strstr (chld_out.line[i], state_text (result)))) {
+ /* Terminate the first part and skip over the string we'll substitute */
+ *sub = '\0';
+ sub += strlen (state_text (result));
+ /* then put everything back together */
+ asprintf (&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text (state[result]), sub);
+ }
+ }
printf ("%s\n", chld_out.line[i]);
}
@@ -123,11 +136,12 @@
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"unknown", required_argument, 0, 'u'},
+ {"substitute", no_argument, 0, 's'},
{0, 0, 0, 0}
};
while (1) {
- c = getopt_long (argc, argv, "+hVt:o:w:c:u:", longopts, &option);
+ c = getopt_long (argc, argv, "+hVt:o:w:c:u:s", longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -170,6 +184,9 @@
usage4 (_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
permute = FALSE;
break;
+ case 's': /* Substitute status text */
+ subst_text = TRUE;
+ break;
}
}
@@ -232,13 +249,15 @@
printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
printf (" %s\n", _("Keep timeout longer than the plugin timeout to retain CRITICAL status."));
- printf(" -o,--ok=STATUS\n");
- printf(" -w,--warning=STATUS\n");
- printf(" -c,--critical=STATUS\n");
- printf(" -u,--unknown=STATUS\n");
+ printf(" -o, --ok=STATUS\n");
+ printf(" -w, --warning=STATUS\n");
+ printf(" -c, --critical=STATUS\n");
+ printf(" -u, --unknown=STATUS\n");
printf(_(" STATUS can be 'OK', 'WARNING', 'CRITICAL' or 'UNKNOWN' without single\n"));
printf(_(" quotes. Numeric values are accepted. If nothing is specified, permutes\n"));
printf(_(" OK and CRITICAL.\n"));
+ printf(" -s, --substitute\n");
+ printf(_(" Substitute output text as well. Will only substitute text in CAPITALS\n"));
printf ("\n");
printf ("%s\n", _("Examples:"));
@@ -248,11 +267,11 @@
printf (" %s\n", _("This will return OK instead of WARNING and UNKNOWN instead of CRITICAL"));
printf ("\n");
printf ("%s\n", _("Notes:"));
- printf ("%s\n", _("This plugin is a wrapper to take the output of another plugin and invert it."));
- printf ("%s\n", _("The full path of the plugin must be provided."));
- printf ("%s\n", _("If the wrapped plugin returns OK, the wrapper will return CRITICAL."));
- printf ("%s\n", _("If the wrapped plugin returns CRITICAL, the wrapper will return OK."));
- printf ("%s\n", _("Otherwise, the output state of the wrapped plugin is unchanged."));
+ printf (" %s\n", _("This plugin is a wrapper to take the output of another plugin and invert it."));
+ printf (" %s\n", _("The full path of the plugin must be provided."));
+ printf (" %s\n", _("If the wrapped plugin returns OK, the wrapper will return CRITICAL."));
+ printf (" %s\n", _("If the wrapped plugin returns CRITICAL, the wrapper will return OK."));
+ printf (" %s\n", _("Otherwise, the output state of the wrapped plugin is unchanged."));
printf (_(UT_SUPPORT));
}
@@ -263,5 +282,5 @@
print_usage (void)
{
printf (_("Usage:"));
- printf ("%s [-t timeout] [-owcu STATE] <definition of wrapped plugin>\n", progname);
+ printf ("%s [-t timeout] [-owcu STATE] [-s] <definition of wrapped plugin>\n", progname);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.