diff --git a/plugins/check_load.c b/plugins/check_load.c
index 58113817008618dfb657e8da9546fb4e8b10d41c..7e1cc481e9d777b3662cf404c9f65c6322f9d6eb 100644 (file)
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
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.
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 *progname = "check_load";
const char *revision = "$Revision$";
-const char *copyright = "1999-2003";
+const char *copyright = "1999-2004";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
-
-
-\f
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 */
#else
# if HAVE_PROC_LOADAVG==1
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */
#else
# if HAVE_PROC_LOADAVG==1
char input_buffer[MAX_INPUT_BUFFER];
char *tmp_ptr;
# else
char input_buffer[MAX_INPUT_BUFFER];
char *tmp_ptr;
# else
- int result;
char input_buffer[MAX_INPUT_BUFFER];
# endif
#endif
char input_buffer[MAX_INPUT_BUFFER];
# endif
#endif
textdomain (PACKAGE);
if (process_arguments (argc, argv) == ERROR)
textdomain (PACKAGE);
if (process_arguments (argc, argv) == ERROR)
- usage ("failed processing arguments\n");
+ usage4 (_("Could not parse arguments"));
#if HAVE_GETLOADAVG==1
result = getloadavg (la, 3);
#if HAVE_GETLOADAVG==1
result = getloadavg (la, 3);
printf (_("Could not open stderr for %s\n"), PATH_TO_UPTIME);
}
fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
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);
+ sscanf (input_buffer, "%*[^l]load average: %f, %f, %f", &la1, &la5, &la15);
result = spclose (child_process);
if (result) {
result = spclose (child_process);
if (result) {
# endif
#endif
# endif
#endif
+
if ((la1 < 0.0) || (la5 < 0.0) || (la15 < 0.0)) {
#if HAVE_GETLOADAVG==1
printf (_("Error in getloadavg()\n"));
if ((la1 < 0.0) || (la5 < 0.0) || (la15 < 0.0)) {
#if HAVE_GETLOADAVG==1
printf (_("Error in getloadavg()\n"));
#endif
return STATE_UNKNOWN;
}
#endif
return STATE_UNKNOWN;
}
+
asprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15);
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);
+
+ 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;
}
-
-
-\f
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
usage (_("Critical threshold must be float or float triplet!\n"));
break;
case 'V': /* version */
usage (_("Critical threshold must be float or float triplet!\n"));
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)
{
int
validate_arguments (void)
{
-
-
-\f
void
print_help (void)
{
print_revision (progname, revision);
void
print_help (void)
{
print_revision (progname, revision);
- printf (_("Copyright (c) 1999 Felipe Gustavo de Almeida <galmeida@linux.ime.usp.br>\n"));
- printf (_(COPYRIGHT), copyright, email);
+ 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"));
printf (_("This plugin tests the current system load average.\n\n"));
void
print_usage (void)
{
void
print_usage (void)
{
- printf (_("Usage: %s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n"),
- progname);
- printf (_(UT_HLP_VRS), progname, progname);
+ printf ("Usage: %s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname);
}
}