Imported Upstream version 1.4.12
This commit is contained in:
parent
1d1585cd09
commit
4ab9f0d24c
291 changed files with 27277 additions and 11364 deletions
170
plugins/negate.c
170
plugins/negate.c
|
@ -1,79 +1,43 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
/*****************************************************************************
|
||||
*
|
||||
* Nagios negate plugin
|
||||
*
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2002-2007 nagios-plugins team
|
||||
*
|
||||
* Last Modified: $Date: 2007-12-10 07:52:00 +0000 (Mon, 10 Dec 2007) $
|
||||
*
|
||||
* Copyright (c) 2002-2008 Nagios Plugins Development Team
|
||||
*
|
||||
* Last Modified: $Date: 2008-05-02 10:28:15 +0100 (Fri, 02 May 2008) $
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
*
|
||||
* This file contains the negate plugin
|
||||
*
|
||||
* Negates the status of a plugin (returns OK for CRITICAL, and vice-versa)
|
||||
*
|
||||
* License Information:
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
*
|
||||
* Negates the status of a plugin (returns OK for CRITICAL, and vice-versa).
|
||||
* Can also perform custom state switching.
|
||||
*
|
||||
*
|
||||
* 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
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
* $Id: negate.c 1859 2007-12-10 07:52:00Z dermoth $
|
||||
|
||||
@@-<article>
|
||||
|
||||
<sect1>
|
||||
<title>Quick Reference</title>
|
||||
<refentry>
|
||||
<refmeta><manvolnum>5<manvolnum></refmeta>
|
||||
<refnamdiv>
|
||||
<refname>&progname;</refname>
|
||||
<refpurpose>&SUMMARY;</refpurpose>
|
||||
</refnamdiv>
|
||||
</refentry>
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
<title>FAQ</title>
|
||||
</sect1>
|
||||
|
||||
<sect1>
|
||||
<title>Theory, Installation, and Operation</title>
|
||||
|
||||
<sect2>
|
||||
<title>General Description</title>
|
||||
<para>
|
||||
&DESCRIPTION;
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<sect2>
|
||||
<title>Future Enhancements</title>
|
||||
<para>ToDo List</para>
|
||||
<itemizedlist>
|
||||
<listitem>Add option to do regex substitution in output text</listitem>
|
||||
</itemizedlist>
|
||||
</sect2>-@@
|
||||
|
||||
******************************************************************************/
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Id: negate.c 1989 2008-05-02 09:28:15Z dermoth $
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
const char *progname = "negate";
|
||||
const char *revision = "$Revision: 1859 $";
|
||||
const char *copyright = "2002-2007";
|
||||
const char *revision = "$Revision: 1989 $";
|
||||
const char *copyright = "2002-2008";
|
||||
const char *email = "nagiosplug-devel@lists.sourceforge.net";
|
||||
|
||||
#define DEFAULT_TIMEOUT 9
|
||||
#define DEFAULT_TIMEOUT 11
|
||||
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
|
@ -85,6 +49,7 @@ static const char **process_arguments (int, char **);
|
|||
int validate_arguments (char **);
|
||||
void print_help (void);
|
||||
void print_usage (void);
|
||||
int subst_text = FALSE;
|
||||
|
||||
static int state[4] = {
|
||||
STATE_OK,
|
||||
|
@ -97,7 +62,7 @@ int
|
|||
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;
|
||||
|
@ -128,10 +93,22 @@ main (int argc, char **argv)
|
|||
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]);
|
||||
}
|
||||
|
||||
|
@ -142,25 +119,6 @@ main (int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@-
|
||||
<sect2>
|
||||
<title>Functions</title>
|
||||
|
||||
<sect3>
|
||||
<title>process_arguments</title>
|
||||
|
||||
<para>This function parses the command line into the needed
|
||||
variables.</para>
|
||||
|
||||
<para>Aside from the standard 'help' and 'version' options, there
|
||||
is a only a 'timeout' option.</para>
|
||||
|
||||
</sect3>
|
||||
-@@
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* process command-line arguments */
|
||||
static const char **
|
||||
|
@ -178,11 +136,12 @@ process_arguments (int argc, char **argv)
|
|||
{"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;
|
||||
|
@ -225,6 +184,9 @@ process_arguments (int argc, char **argv)
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,19 +201,6 @@ process_arguments (int argc, char **argv)
|
|||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
@@-
|
||||
<sect3>
|
||||
<title>validate_arguments</title>
|
||||
|
||||
<para>No validation is currently done.</para>
|
||||
|
||||
</sect3>
|
||||
-@@
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
|
||||
int
|
||||
validate_arguments (char **command_line)
|
||||
{
|
||||
|
@ -262,13 +211,6 @@ validate_arguments (char **command_line)
|
|||
usage4 (_("Require path to command"));
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
@@-
|
||||
</sect2>
|
||||
</sect1>
|
||||
</article>
|
||||
-@@
|
||||
******************************************************************************/
|
||||
|
||||
int
|
||||
translate_state (char *state_text)
|
||||
|
@ -307,13 +249,15 @@ print_help (void)
|
|||
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:"));
|
||||
|
@ -323,11 +267,11 @@ print_help (void)
|
|||
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));
|
||||
}
|
||||
|
@ -338,5 +282,5 @@ void
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue