diff --git a/plugins/check_load.c b/plugins/check_load.c
index 7d60d2343a85d2ee1054c5f2f61ca09474b58b0b..7e1cc481e9d777b3662cf404c9f65c6322f9d6eb 100644 (file)
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
/******************************************************************************
/******************************************************************************
- *
- * CHECK_LOAD.C
- *
- * Written by Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>
- * License: GPL
- * Command line: CHECK_LOAD <wload1> <cload1> <wload5> <cload5> <wload15> <cload15>
- * First Written: 04/17/99
- *
- * Modifications:
- *
- * 05/18/1999 - Modified to work getloadavg where available, and use uptime
- * where neither proc or getloadavg are found. Also use autoconf.
- * mods by Karl DeBisschop (kdebiss@alum.mit.edu)
- * 07/01/1999 - Added some #DEFINEs to allow compilation under NetBSD, as
- * suggested by Andy Doran.
- * mods by Ethan Galstad (nagios@nagios.org)
- * 07/17/1999 - Initialized la[] array to prevent NetBSD from complaining
- * mods by Ethan Galstad (nagios@nagios.org)
- * 08/18/1999 - Integrated some code with common plugin utilities
- * mods by Ethan Galstad (nagios@nagios.org)
- * $Date$
- * Note: The load format is the same used by "uptime" and "w"
- *
- *****************************************************************************/
-
-#include "config.h"
+
+ 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$
+
+******************************************************************************/
+
+const char *progname = "check_load";
+const char *revision = "$Revision$";
+const char *copyright = "1999-2004";
+const char *email = "nagiosplug-devel@lists.sourceforge.net";
+
#include "common.h"
#include "utils.h"
#include "common.h"
#include "utils.h"
+#include "popen.h"
#ifdef HAVE_SYS_LOADAVG_H
#include <sys/loadavg.h>
#ifdef HAVE_SYS_LOADAVG_H
#include <sys/loadavg.h>
#define LOADAVG_15MIN 2
#endif /* !defined LOADAVG_1MIN */
#define LOADAVG_15MIN 2
#endif /* !defined LOADAVG_1MIN */
-#include "popen.h"
-#ifdef HAVE_PROC_LOADAVG
-
-#endif
-
-const char *progname = "check_load";
int process_arguments (int argc, char **argv);
int validate_arguments (void);
int process_arguments (int argc, char **argv);
int validate_arguments (void);
-void print_usage (void);
void print_help (void);
void print_help (void);
+void print_usage (void);
float wload1 = -1, wload5 = -1, wload15 = -1;
float cload1 = -1, cload5 = -1, cload15 = -1;
float wload1 = -1, wload5 = -1, wload15 = -1;
float cload1 = -1, cload5 = -1, cload15 = -1;
-char *status_line = "";
+char *status_line;
+
+
int
main (int argc, char **argv)
{
int
main (int argc, char **argv)
{
+ int result = STATE_UNKNOWN;
+
#if HAVE_GETLOADAVG==1
#if HAVE_GETLOADAVG==1
- int result;
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */
-#elif HAVE_PROC_LOADAVG==1
+#else
+# if HAVE_PROC_LOADAVG==1
FILE *fp;
char input_buffer[MAX_INPUT_BUFFER];
char *tmp_ptr;
FILE *fp;
char input_buffer[MAX_INPUT_BUFFER];
char *tmp_ptr;
-#else
- int result;
+# else
char input_buffer[MAX_INPUT_BUFFER];
char input_buffer[MAX_INPUT_BUFFER];
+# endif
#endif
float la1, la5, la15;
#endif
float la1, la5, la15;
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
if (process_arguments (argc, argv) == ERROR)
if (process_arguments (argc, argv) == ERROR)
- usage ("\n");
+ usage4 (_("Could not parse arguments"));
#if HAVE_GETLOADAVG==1
result = getloadavg (la, 3);
#if HAVE_GETLOADAVG==1
result = getloadavg (la, 3);
la1 = la[LOADAVG_1MIN];
la5 = la[LOADAVG_5MIN];
la15 = la[LOADAVG_15MIN];
la1 = la[LOADAVG_1MIN];
la5 = la[LOADAVG_5MIN];
la15 = la[LOADAVG_15MIN];
-#elif HAVE_PROC_LOADAVG==1
+#else
+# if HAVE_PROC_LOADAVG==1
fp = fopen (PROC_LOADAVG, "r");
if (fp == NULL) {
fp = fopen (PROC_LOADAVG, "r");
if (fp == NULL) {
- printf ("Error opening %s\n", PROC_LOADAVG);
+ printf (_("Error opening %s\n"), PROC_LOADAVG);
return STATE_UNKNOWN;
}
return STATE_UNKNOWN;
}
}
fclose (fp);
}
fclose (fp);
-#else
+# else
child_process = spopen (PATH_TO_UPTIME);
if (child_process == NULL) {
child_process = spopen (PATH_TO_UPTIME);
if (child_process == NULL) {
- printf ("Error opening %s\n", PATH_TO_UPTIME);
+ printf (_("Error opening %s\n"), PATH_TO_UPTIME);
return STATE_UNKNOWN;
}
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
if (child_stderr == NULL) {
return STATE_UNKNOWN;
}
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
if (child_stderr == NULL) {
- printf ("Could not open stderr for %s\n", PATH_TO_UPTIME);
+ printf (_("Could not open stderr for %s\n"), PATH_TO_UPTIME);
}
fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
sscanf (input_buffer, "%*[^l]load average: %f, %f, %f", &la1, &la5, &la15);
result = spclose (child_process);
if (result) {
}
fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
sscanf (input_buffer, "%*[^l]load average: %f, %f, %f", &la1, &la5, &la15);
result = spclose (child_process);
if (result) {
- printf ("Error code %d returned in %s\n", result, PATH_TO_UPTIME);
+ printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME);
return STATE_UNKNOWN;
}
return STATE_UNKNOWN;
}
+# endif
#endif
#endif
- if ((la1 == -1) || (la5 == -1) || (la15 == -1)) {
+
+ if ((la1 < 0.0) || (la5 < 0.0) || (la15 < 0.0)) {
#if HAVE_GETLOADAVG==1
#if HAVE_GETLOADAVG==1
- printf ("Error in getloadavg()\n");
-#elif HAVE_PROC_LOADAVG==1
- printf ("Error processing %s\n", PROC_LOADAVG);
+ printf (_("Error in getloadavg()\n"));
#else
#else
- printf ("Error processing %s\n", PATH_TO_UPTIME);
+# if HAVE_PROC_LOADAVG==1
+ printf (_("Error processing %s\n"), PROC_LOADAVG);
+# else
+ printf (_("Error processing %s\n"), PATH_TO_UPTIME);
+# endif
#endif
return STATE_UNKNOWN;
}
#endif
return STATE_UNKNOWN;
}
- asprintf(&status_line, "load average: %.2f, %.2f, %.2f", la1, la5, la15);
- if ((la1 >= cload1) || (la5 >= cload5) || (la15 >= cload15)) {
- printf("CRITICAL - %s\n", status_line);
- return STATE_CRITICAL;
- }
- if ((la1 >= wload1) || (la5 >= wload5) || (la15 >= wload15)) {
- printf ("WARNING - %s\n", status_line);
- return STATE_WARNING;
- }
- printf ("OK - %s\n", status_line);
+
+ asprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15);
+
+ if ((la1 >= cload1) || (la5 >= cload5) || (la15 >= cload15))
+ result = STATE_CRITICAL;
+ else if ((la1 >= wload1) || (la5 >= wload5) || (la15 >= wload15))
+ result = STATE_WARNING;
+ else
+ result = STATE_OK;
+
+ die (result,
+ "%s - %s|%s %s %s\n",
+ state_text (result),
+ status_line,
+ fperfdata ("load1", la1, "", (int)wload1, wload1, (int)cload1, cload1, TRUE, 0, FALSE, 0),
+ fperfdata ("load5", la5, "", (int)wload5, wload5, (int)cload5, cload5, TRUE, 0, FALSE, 0),
+ fperfdata ("load15", la15, "", (int)wload15, wload15, (int)cload15, cload15, TRUE, 0, FALSE, 0));
return STATE_OK;
}
return STATE_OK;
}
-
-
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
int c = 0;
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
{
int c = 0;
-#ifdef HAVE_GETOPT_H
- int option_index = 0;
- static struct option long_options[] = {
+ int option = 0;
+ static struct option longopts[] = {
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
-#endif
-
-#define OPTCHARS "Vhc:w:"
if (argc < 2)
return ERROR;
while (1) {
if (argc < 2)
return ERROR;
while (1) {
-#ifdef HAVE_GETOPT_H
- c = getopt_long (argc, argv, OPTCHARS, long_options, &option_index);
-#else
- c = getopt (argc, argv, OPTCHARS);
-#endif
+ c = getopt_long (argc, argv, "Vhc:w:", longopts, &option);
+
if (c == -1 || c == EOF)
break;
if (c == -1 || c == EOF)
break;
sscanf (optarg, "%f:%f:%f", &wload1, &wload5, &wload15) == 3)
break;
else
sscanf (optarg, "%f:%f:%f", &wload1, &wload5, &wload15) == 3)
break;
else
- usage ("Warning threshold must be float or float triplet!\n");
+ usage (_("Warning threshold must be float or float triplet!\n"));
break;
case 'c': /* critical time threshold */
if (is_intnonneg (optarg)) {
break;
case 'c': /* critical time threshold */
if (is_intnonneg (optarg)) {
sscanf (optarg, "%f:%f:%f", &cload1, &cload5, &cload15) == 3)
break;
else
sscanf (optarg, "%f:%f:%f", &cload1, &cload5, &cload15) == 3)
break;
else
- usage ("Critical threshold must be float or float triplet!\n");
+ usage (_("Critical threshold must be float or float triplet!\n"));
break;
case 'V': /* version */
break;
case 'V': /* version */
- print_revision (progname, "$Revision$");
+ print_revision (progname, revision);
exit (STATE_OK);
case 'h': /* help */
print_help ();
exit (STATE_OK);
case '?': /* help */
exit (STATE_OK);
case 'h': /* help */
print_help ();
exit (STATE_OK);
case '?': /* help */
- usage ("Invalid argument\n");
+ usage2 (_("Unknown argument"), optarg);
}
}
}
}
-
-
int
validate_arguments (void)
{
if (wload1 < 0)
int
validate_arguments (void)
{
if (wload1 < 0)
- usage ("Warning threshold for 1-minute load average is not specified\n");
+ usage (_("Warning threshold for 1-minute load average is not specified\n"));
if (wload5 < 0)
if (wload5 < 0)
- usage ("Warning threshold for 5-minute load average is not specified\n");
+ usage (_("Warning threshold for 5-minute load average is not specified\n"));
if (wload15 < 0)
if (wload15 < 0)
- usage ("Warning threshold for 15-minute load average is not specified\n");
+ usage (_("Warning threshold for 15-minute load average is not specified\n"));
if (cload1 < 0)
if (cload1 < 0)
- usage ("Critical threshold for 1-minute load average is not specified\n");
+ usage (_("Critical threshold for 1-minute load average is not specified\n"));
if (cload5 < 0)
if (cload5 < 0)
- usage ("Critical threshold for 5-minute load average is not specified\n");
+ usage (_("Critical threshold for 5-minute load average is not specified\n"));
if (cload15 < 0)
if (cload15 < 0)
- usage ("Critical threshold for 15-minute load average is not specified\n");
+ usage (_("Critical threshold for 15-minute load average is not specified\n"));
if (wload1 > cload1)
if (wload1 > cload1)
- usage ("Parameter inconsistency: 1-minute \"warning load\" greater than \"critical load\".\n");
+ usage (_("Parameter inconsistency: 1-minute \"warning load\" greater than \"critical load\".\n"));
if (wload5 > cload5)
if (wload5 > cload5)
- usage ("Parameter inconsistency: 5-minute \"warning load\" greater than \"critical load\".\n");
+ usage (_("Parameter inconsistency: 5-minute \"warning load\" greater than \"critical load\".\n"));
if (wload15 > cload15)
if (wload15 > cload15)
- usage ("Parameter inconsistency: 15-minute \"warning load\" greater than \"critical load\".\n");
+ usage (_("Parameter inconsistency: 15-minute \"warning load\" greater than \"critical load\".\n"));
return OK;
}
return OK;
}
-
-
void
void
-print_usage (void)
+print_help (void)
{
{
- printf
- ("Usage: check_load -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n"
- " check_load --version\n" " check_load --help\n");
-}
+ print_revision (progname, revision);
+
+ printf ("Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>\n");
+ printf (COPYRIGHT, copyright, email);
+ printf (_("This plugin tests the current system load average.\n\n"));
+ print_usage ();
+ printf (_(UT_HELP_VRSN));
+ printf (_("\
+ -w, --warning=WLOAD1,WLOAD5,WLOAD15\n\
+ Exit with WARNING status if load average exceeds WLOADn\n\
+ -c, --critical=CLOAD1,CLOAD5,CLOAD15\n\
+ Exit with CRITICAL status if load average exceed CLOADn\n\n\
+the load average format is the same used by \"uptime\" and \"w\"\n\n"));
+
+ printf (_(UT_SUPPORT));
+}
void
void
-print_help (void)
+print_usage (void)
{
{
- print_revision (progname, "$Revision$");
- printf
- ("Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>\n"
- "Copyright (c) 2000 Karl DeBisschop\n\n"
- "This plugin tests the current system load average.\n\n");
- print_usage ();
- printf
- ("\nOptions:\n"
- " -w, --warning=WLOAD1,WLOAD5,WLOAD15\n"
- " Exit with WARNING status if load average exceeds WLOADn\n"
- " -c, --critical=CLOAD1,CLOAD5,CLOAD15\n"
- " Exit with CRITICAL status if load average exceed CLOADn\n"
- " -h, --help\n"
- " Print detailed help screen\n"
- " -V, --version\n"
- " Print version information\n\n"
- "the load average format is the same used by \"uptime\" and \"w\"\n\n");
- support ();
+ printf ("Usage: %s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname);
}
}