Imported Upstream version 2.0

This commit is contained in:
Jan Wagner 2014-07-11 21:01:00 +02:00
parent c89ccc3c74
commit 0841b5c7c7
165 changed files with 25440 additions and 4442 deletions

View file

@ -5,9 +5,8 @@ noinst_PROGRAMS = @EXTRA_TEST@
TESTS = @EXTRA_TEST@
check_PROGRAMS = @EXTRA_TEST@
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\"
INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \
-I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd test_base64 test_ini1 test_ini3 test_opts1 test_opts2 test_opts3
@ -28,7 +27,7 @@ endif
AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
AM_LDFLAGS = $(tap_ldflags) -ltap
LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a
LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a
SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c

View file

@ -82,6 +82,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/np_mysqlclient.m4 \
$(top_srcdir)/gl/m4/gnulib-common.m4 \
$(top_srcdir)/gl/m4/gnulib-comp.m4 \
$(top_srcdir)/gl/m4/hostent.m4 $(top_srcdir)/gl/m4/iconv.m4 \
$(top_srcdir)/gl/m4/idpriv.m4 \
$(top_srcdir)/gl/m4/include_next.m4 \
$(top_srcdir)/gl/m4/inet_ntop.m4 \
$(top_srcdir)/gl/m4/intlmacosx.m4 \
@ -131,11 +132,12 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/np_mysqlclient.m4 \
$(top_srcdir)/gl/m4/stdalign.m4 $(top_srcdir)/gl/m4/stdbool.m4 \
$(top_srcdir)/gl/m4/stddef_h.m4 $(top_srcdir)/gl/m4/stdint.m4 \
$(top_srcdir)/gl/m4/stdint_h.m4 $(top_srcdir)/gl/m4/stdio_h.m4 \
$(top_srcdir)/gl/m4/stdlib_h.m4 \
$(top_srcdir)/gl/m4/stdlib_h.m4 $(top_srcdir)/gl/m4/strcase.m4 \
$(top_srcdir)/gl/m4/strerror.m4 \
$(top_srcdir)/gl/m4/string_h.m4 $(top_srcdir)/gl/m4/strndup.m4 \
$(top_srcdir)/gl/m4/strnlen.m4 $(top_srcdir)/gl/m4/strsep.m4 \
$(top_srcdir)/gl/m4/strstr.m4 \
$(top_srcdir)/gl/m4/string_h.m4 \
$(top_srcdir)/gl/m4/strings_h.m4 \
$(top_srcdir)/gl/m4/strndup.m4 $(top_srcdir)/gl/m4/strnlen.m4 \
$(top_srcdir)/gl/m4/strsep.m4 $(top_srcdir)/gl/m4/strstr.m4 \
$(top_srcdir)/gl/m4/sys_socket_h.m4 \
$(top_srcdir)/gl/m4/sys_types_h.m4 \
$(top_srcdir)/gl/m4/sys_uio_h.m4 \
@ -150,7 +152,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/np_mysqlclient.m4 \
$(top_srcdir)/gl/m4/wcrtomb.m4 $(top_srcdir)/gl/m4/wctype_h.m4 \
$(top_srcdir)/gl/m4/wint_t.m4 $(top_srcdir)/gl/m4/xalloc.m4 \
$(top_srcdir)/gl/m4/xsize.m4 $(top_srcdir)/gl/m4/xstrndup.m4 \
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.in
$(top_srcdir)/acinclude.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/build-aux/mkinstalldirs
@ -161,52 +163,52 @@ PROGRAMS = $(noinst_PROGRAMS)
test_base64_SOURCES = test_base64.c
test_base64_OBJECTS = test_base64.$(OBJEXT)
test_base64_LDADD = $(LDADD)
test_base64_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_base64_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_cmd_SOURCES = test_cmd.c
test_cmd_OBJECTS = test_cmd.$(OBJEXT)
test_cmd_LDADD = $(LDADD)
test_cmd_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_cmd_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_disk_SOURCES = test_disk.c
test_disk_OBJECTS = test_disk.$(OBJEXT)
test_disk_LDADD = $(LDADD)
test_disk_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_disk_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_ini1_SOURCES = test_ini1.c
test_ini1_OBJECTS = test_ini1.$(OBJEXT)
test_ini1_LDADD = $(LDADD)
test_ini1_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_ini1_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_ini3_SOURCES = test_ini3.c
test_ini3_OBJECTS = test_ini3.$(OBJEXT)
test_ini3_LDADD = $(LDADD)
test_ini3_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_ini3_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_opts1_SOURCES = test_opts1.c
test_opts1_OBJECTS = test_opts1.$(OBJEXT)
test_opts1_LDADD = $(LDADD)
test_opts1_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_opts1_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_opts2_SOURCES = test_opts2.c
test_opts2_OBJECTS = test_opts2.$(OBJEXT)
test_opts2_LDADD = $(LDADD)
test_opts2_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_opts2_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_opts3_SOURCES = test_opts3.c
test_opts3_OBJECTS = test_opts3.$(OBJEXT)
test_opts3_LDADD = $(LDADD)
test_opts3_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_opts3_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_tcp_SOURCES = test_tcp.c
test_tcp_OBJECTS = test_tcp.$(OBJEXT)
test_tcp_LDADD = $(LDADD)
test_tcp_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_tcp_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
test_utils_SOURCES = test_utils.c
test_utils_OBJECTS = test_utils.$(OBJEXT)
test_utils_LDADD = $(LDADD)
test_utils_DEPENDENCIES = $(top_srcdir)/lib/libnagiosplug.a \
test_utils_DEPENDENCIES = $(top_srcdir)/lib/libmonitoringplug.a \
$(top_srcdir)/gl/libgnu.a
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
@ -346,6 +348,7 @@ GNULIB_FCLOSE = @GNULIB_FCLOSE@
GNULIB_FDATASYNC = @GNULIB_FDATASYNC@
GNULIB_FDOPEN = @GNULIB_FDOPEN@
GNULIB_FFLUSH = @GNULIB_FFLUSH@
GNULIB_FFS = @GNULIB_FFS@
GNULIB_FFSL = @GNULIB_FFSL@
GNULIB_FFSLL = @GNULIB_FFSLL@
GNULIB_FGETC = @GNULIB_FGETC@
@ -711,6 +714,7 @@ HAVE_DECL_SNPRINTF = @HAVE_DECL_SNPRINTF@
HAVE_DECL_SQRTL = @HAVE_DECL_SQRTL@
HAVE_DECL_STRDUP = @HAVE_DECL_STRDUP@
HAVE_DECL_STRERROR_R = @HAVE_DECL_STRERROR_R@
HAVE_DECL_STRNCASECMP = @HAVE_DECL_STRNCASECMP@
HAVE_DECL_STRNDUP = @HAVE_DECL_STRNDUP@
HAVE_DECL_STRNLEN = @HAVE_DECL_STRNLEN@
HAVE_DECL_STRSIGNAL = @HAVE_DECL_STRSIGNAL@
@ -740,6 +744,7 @@ HAVE_FCHDIR = @HAVE_FCHDIR@
HAVE_FCHOWNAT = @HAVE_FCHOWNAT@
HAVE_FDATASYNC = @HAVE_FDATASYNC@
HAVE_FEATURES_H = @HAVE_FEATURES_H@
HAVE_FFS = @HAVE_FFS@
HAVE_FFSL = @HAVE_FFSL@
HAVE_FFSLL = @HAVE_FFSLL@
HAVE_FMA = @HAVE_FMA@
@ -851,8 +856,10 @@ HAVE_SQRTL = @HAVE_SQRTL@
HAVE_STDINT_H = @HAVE_STDINT_H@
HAVE_STPCPY = @HAVE_STPCPY@
HAVE_STPNCPY = @HAVE_STPNCPY@
HAVE_STRCASECMP = @HAVE_STRCASECMP@
HAVE_STRCASESTR = @HAVE_STRCASESTR@
HAVE_STRCHRNUL = @HAVE_STRCHRNUL@
HAVE_STRINGS_H = @HAVE_STRINGS_H@
HAVE_STRPBRK = @HAVE_STRPBRK@
HAVE_STRPTIME = @HAVE_STRPTIME@
HAVE_STRSEP = @HAVE_STRSEP@
@ -943,7 +950,6 @@ LD = @LD@
LDAPINCLUDE = @LDAPINCLUDE@
LDAPLIBS = @LDAPLIBS@
LDFLAGS = @LDFLAGS@
LIBGNUTLS_CONFIG = @LIBGNUTLS_CONFIG@
LIBGNU_LIBDEPS = @LIBGNU_LIBDEPS@
LIBGNU_LTLIBDEPS = @LIBGNU_LTLIBDEPS@
LIBICONV = @LIBICONV@
@ -969,6 +975,7 @@ LTLIBMULTITHREAD = @LTLIBMULTITHREAD@
LTLIBOBJS = @LTLIBOBJS@
LTLIBPTH = @LTLIBPTH@
LTLIBTHREAD = @LTLIBTHREAD@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MATHLIBS = @MATHLIBS@
@ -994,6 +1001,7 @@ NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@
NEXT_AS_FIRST_DIRECTIVE_STDINT_H = @NEXT_AS_FIRST_DIRECTIVE_STDINT_H@
NEXT_AS_FIRST_DIRECTIVE_STDIO_H = @NEXT_AS_FIRST_DIRECTIVE_STDIO_H@
NEXT_AS_FIRST_DIRECTIVE_STDLIB_H = @NEXT_AS_FIRST_DIRECTIVE_STDLIB_H@
NEXT_AS_FIRST_DIRECTIVE_STRINGS_H = @NEXT_AS_FIRST_DIRECTIVE_STRINGS_H@
NEXT_AS_FIRST_DIRECTIVE_STRING_H = @NEXT_AS_FIRST_DIRECTIVE_STRING_H@
NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_SOCKET_H@
NEXT_AS_FIRST_DIRECTIVE_SYS_TYPES_H = @NEXT_AS_FIRST_DIRECTIVE_SYS_TYPES_H@
@ -1014,6 +1022,7 @@ NEXT_STDDEF_H = @NEXT_STDDEF_H@
NEXT_STDINT_H = @NEXT_STDINT_H@
NEXT_STDIO_H = @NEXT_STDIO_H@
NEXT_STDLIB_H = @NEXT_STDLIB_H@
NEXT_STRINGS_H = @NEXT_STRINGS_H@
NEXT_STRING_H = @NEXT_STRING_H@
NEXT_SYS_SOCKET_H = @NEXT_SYS_SOCKET_H@
NEXT_SYS_TYPES_H = @NEXT_SYS_TYPES_H@
@ -1073,7 +1082,6 @@ PRAGMA_SYSTEM_HEADER = @PRAGMA_SYSTEM_HEADER@
PST3CFLAGS = @PST3CFLAGS@
PTHREAD_H_DEFINES_STRUCT_TIMESPEC = @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
PTRDIFF_T_SUFFIX = @PTRDIFF_T_SUFFIX@
PYTHON = @PYTHON@
RADIUSLIBS = @RADIUSLIBS@
RANLIB = @RANLIB@
RELEASE = @RELEASE@
@ -1265,7 +1273,6 @@ SCRIPT_TEST = @SCRIPT_TEST@
SED = @SED@
SERVENT_LIB = @SERVENT_LIB@
SET_MAKE = @SET_MAKE@
SH = @SH@
SHELL = @SHELL@
SIG_ATOMIC_T_SUFFIX = @SIG_ATOMIC_T_SUFFIX@
SIZE_T_SUFFIX = @SIZE_T_SUFFIX@
@ -1289,6 +1296,7 @@ WARRANTY = @WARRANTY@
WCHAR_T_SUFFIX = @WCHAR_T_SUFFIX@
WINDOWS_64_BIT_OFF_T = @WINDOWS_64_BIT_OFF_T@
WINT_T_SUFFIX = @WINT_T_SUFFIX@
WTSAPI32LIBS = @WTSAPI32LIBS@
XGETTEXT = @XGETTEXT@
XGETTEXT_015 = @XGETTEXT_015@
XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
@ -1358,8 +1366,9 @@ noinst_PROGRAMS = @EXTRA_TEST@
# These two lines support "make check", but we use "make test"
TESTS = @EXTRA_TEST@
check_PROGRAMS = @EXTRA_TEST@
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\"
INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \
-I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
np_test_scripts = test_base64.t test_cmd.t test_disk.t test_ini1.t test_ini3.t test_opts1.t test_opts2.t test_opts3.t test_tcp.t test_utils.t
np_test_files = config-dos.ini config-opts.ini config-tiny.ini plugin.ini plugins.ini
EXTRA_DIST = $(np_test_scripts) $(np_test_files) var
@ -1369,13 +1378,13 @@ EXTRA_DIST = $(np_test_scripts) $(np_test_files) var
@USE_LIBTAP_LOCAL_TRUE@tap_ldadd = $(top_srcdir)/gl/libgnu.a
AM_CFLAGS = -g -I$(top_srcdir)/lib -I$(top_srcdir)/gl $(tap_cflags)
AM_LDFLAGS = $(tap_ldflags) -ltap
LDADD = $(top_srcdir)/lib/libnagiosplug.a $(top_srcdir)/gl/libgnu.a
LDADD = $(top_srcdir)/lib/libmonitoringplug.a $(top_srcdir)/gl/libgnu.a
SOURCES = test_utils.c test_disk.c test_tcp.c test_cmd.c test_base64.c test_ini1.c test_ini3.c test_opts1.c test_opts2.c test_opts3.c
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
@ -1400,9 +1409,9 @@ Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: $(am__configure_deps)
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_base64") {
plan skip_all => "./test_base64 not compiled - please install tap library to test";
plan skip_all => "./test_base64 not compiled - please enable libtap library to test";
}
exec "./test_base64";

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_cmd") {
plan skip_all => "./test_cmd not compiled - please install tap library to test";
plan skip_all => "./test_cmd not compiled - please enable libtap library to test";
}
exec "./test_cmd";

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_disk") {
plan skip_all => "./test_disk not compiled - please install tap library to test";
plan skip_all => "./test_disk not compiled - please enable libtap library to test";
}
exec "./test_disk";

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_ini1") {
plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test";
plan skip_all => "./test_ini not compiled - please enable libtap library and/or extra-opts to test";
}
exec "./test_ini1";

View file

@ -4,7 +4,7 @@ use strict;
use warnings;
if (! -e "./test_ini3") {
plan skip_all => "./test_ini not compiled - please install tap library and/or enable parse-ini to test";
plan skip_all => "./test_ini not compiled - please enable libtap library and/or extra-opts to test";
}
# array of argument arrays

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_opts1") {
plan skip_all => "./test_opts1 not compiled - please install tap library and/or enable parse-ini to test";
plan skip_all => "./test_opts1 not compiled - please enable libtap library and/or extra-opts to test";
}
exec "./test_opts1";

View file

@ -1,7 +1,7 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_opts2") {
plan skip_all => "./test_opts2 not compiled - please install tap library and/or enable parse-ini to test";
plan skip_all => "./test_opts2 not compiled - please enable libtap library and/or extra-opts to test";
}
$ENV{"NAGIOS_CONFIG_PATH"} = ".";
exec "./test_opts2";

View file

@ -4,7 +4,7 @@ use strict;
use warnings;
if (! -e "./test_opts3") {
plan skip_all => "./test_opts3 not compiled - please install tap library and/or enable parse-ini to test";
plan skip_all => "./test_opts3 not compiled - please enable libtap library and/or extra-opts to test";
}
# array of argument arrays

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_tcp") {
plan skip_all => "./test_tcp not compiled - please install tap library to test";
plan skip_all => "./test_tcp not compiled - please enable libtap library to test";
}
exec "./test_tcp";

View file

@ -21,6 +21,7 @@
#include "tap.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -29,31 +30,32 @@
int
main (int argc, char **argv)
{
char state_path[1024];
range *range;
double temp;
thresholds *thresholds = NULL;
int rc;
int i, rc;
char *temp_string;
state_key *temp_state_key = NULL;
state_data *temp_state_data;
time_t current_time;
plan_tests(150);
plan_tests(185);
ok( this_nagios_plugin==NULL, "nagios_plugin not initialised");
ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised");
np_init( "check_test", argc, argv );
ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised");
ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" );
ok( this_monitoring_plugin!=NULL, "monitoring_plugin now initialised");
ok( !strcmp(this_monitoring_plugin->plugin_name, "check_test"), "plugin name initialised" );
ok( this_nagios_plugin->argc==argc, "Argc set" );
ok( this_nagios_plugin->argv==argv, "Argv set" );
ok( this_monitoring_plugin->argc==argc, "Argc set" );
ok( this_monitoring_plugin->argv==argv, "Argv set" );
np_set_args(0,0);
ok( this_nagios_plugin->argc==0, "argc changed" );
ok( this_nagios_plugin->argv==0, "argv changed" );
ok( this_monitoring_plugin->argc==0, "argc changed" );
ok( this_monitoring_plugin->argv==0, "argv changed" );
np_set_args(argc, argv);
@ -182,6 +184,21 @@ main (int argc, char **argv)
ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning");
ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical");
rc = _set_thresholds(&thresholds, "-10:-2", "-30:20");
ok( rc == 0, "Thresholds ('-30:20', '-10:-2') set");
ok( thresholds->warning->start == -10, "Warning start set correctly");
ok( thresholds->warning->end == -2, "Warning end set correctly");
ok( thresholds->critical->start == -30, "Critical start set correctly");
ok( thresholds->critical->end == 20, "Critical end set correctly");
ok( get_status(-31, thresholds) == STATE_CRITICAL, "-31 - critical");
ok( get_status(-29, thresholds) == STATE_WARNING, "-29 - warning");
ok( get_status(-11, thresholds) == STATE_WARNING, "-11 - warning");
ok( get_status(-10, thresholds) == STATE_OK, "-10 - ok");
ok( get_status(-2, thresholds) == STATE_OK, "-2 - ok");
ok( get_status(-1, thresholds) == STATE_WARNING, "-1 - warning");
ok( get_status(19, thresholds) == STATE_WARNING, "19 - warning");
ok( get_status(21, thresholds) == STATE_CRITICAL, "21 - critical");
char *test;
test = np_escaped_string("bob\\n");
ok( strcmp(test, "bob\n") == 0, "bob\\n ok");
@ -296,23 +313,23 @@ main (int argc, char **argv)
diag( "You are probably running in wrong directory. Must run as ./test_utils" );
this_nagios_plugin->argc=4;
this_nagios_plugin->argv[0] = "./test_utils";
this_nagios_plugin->argv[1] = "here";
this_nagios_plugin->argv[2] = "--and";
this_nagios_plugin->argv[3] = "now";
this_monitoring_plugin->argc=4;
this_monitoring_plugin->argv[0] = "./test_utils";
this_monitoring_plugin->argv[1] = "here";
this_monitoring_plugin->argv[2] = "--and";
this_monitoring_plugin->argv[3] = "now";
temp_string = (char *) _np_state_generate_key();
ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" );
unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY");
unsetenv("MP_STATE_PATH");
temp_string = (char *) _np_state_calculate_location_prefix();
ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" );
setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1);
setenv("MP_STATE_PATH", "", 1);
temp_string = (char *) _np_state_calculate_location_prefix();
ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" );
setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1);
setenv("MP_STATE_PATH", "/usr/local/nagios/var", 1);
temp_string = (char *) _np_state_calculate_location_prefix();
ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" );
@ -320,36 +337,38 @@ main (int argc, char **argv)
ok(temp_state_key==NULL, "temp_state_key initially empty");
this_nagios_plugin->argc=1;
this_nagios_plugin->argv[0] = "./test_utils";
this_monitoring_plugin->argc=1;
this_monitoring_plugin->argv[0] = "./test_utils";
np_enable_state(NULL, 51);
temp_state_key = this_nagios_plugin->state;
temp_state_key = this_monitoring_plugin->state;
ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" );
np_enable_state("allowedchars_in_keyname", 77);
temp_state_key = this_nagios_plugin->state;
temp_state_key = this_monitoring_plugin->state;
sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/allowedchars_in_keyname", (unsigned long)geteuid());
ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
ok( !strcmp(temp_state_key->name, "allowedchars_in_keyname"), "Got key name with valid chars" );
ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/allowedchars_in_keyname"), "Got internal filename" );
ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" );
/* Don't do this test just yet. Will die */
/*
np_enable_state("bad^chars$in@here", 77);
temp_state_key = this_nagios_plugin->state;
temp_state_key = this_monitoring_plugin->state;
ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" );
*/
np_enable_state("funnykeyname", 54);
temp_state_key = this_nagios_plugin->state;
temp_state_key = this_monitoring_plugin->state;
sprintf(state_path, "/usr/local/nagios/var/%lu/check_test/funnykeyname", (unsigned long)geteuid());
ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" );
ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/funnykeyname"), "Got internal filename" );
ok( !strcmp(temp_state_key->_filename, state_path), "Got internal filename" );
ok( temp_state_key->data_version==54, "Version set" );
temp_state_data = np_state_read();
@ -367,9 +386,9 @@ main (int argc, char **argv)
temp_state_key->_filename="var/statefile";
temp_state_data = np_state_read();
ok( this_nagios_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not");
ok( this_nagios_plugin->state->state_data->time==1234567890, "Got time" );
ok( !strcmp((char *)this_nagios_plugin->state->state_data->data, "String to read"), "Data as expected" );
ok( this_monitoring_plugin->state->state_data!=NULL, "Got state data now" ) || diag("Are you running in right directory? Will get coredump next if not");
ok( this_monitoring_plugin->state->state_data->time==1234567890, "Got time" );
ok( !strcmp((char *)this_monitoring_plugin->state->state_data->data, "String to read"), "Data as expected" );
temp_state_key->data_version=53;
temp_state_data = np_state_read();
@ -379,7 +398,7 @@ main (int argc, char **argv)
temp_state_key->_filename="var/nonexistant";
temp_state_data = np_state_read();
ok( temp_state_data==NULL, "Missing file gives NULL" );
ok( this_nagios_plugin->state->state_data==NULL, "No state information" );
ok( this_monitoring_plugin->state->state_data==NULL, "No state information" );
temp_state_key->_filename="var/oldformat";
temp_state_data = np_state_read();
@ -426,7 +445,7 @@ main (int argc, char **argv)
temp_state_data = np_state_read();
/* Check time is set to current_time */
ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time");
ok(this_nagios_plugin->state->state_data->time-current_time<=1, "Has time generated from current time");
ok(this_monitoring_plugin->state->state_data->time-current_time<=1, "Has time generated from current time");
/* Don't know how to automatically test this. Need to be able to redefine die and catch the error */
@ -438,7 +457,54 @@ main (int argc, char **argv)
np_cleanup();
ok( this_nagios_plugin==NULL, "Free'd this_nagios_plugin" );
ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin");
ok(mp_suid() == FALSE, "Test aren't suid");
/* base states with random case */
char *states[] = {
"Ok",
"wArnINg",
"cRiTIcaL",
"UnKNoWN",
NULL
};
for (i=0; states[i]!=NULL; i++) {
/* out of the random case states, create the lower and upper versions + numeric string one */
char *statelower = strdup(states[i]);
char *stateupper = strdup(states[i]);
char statenum[2];
char *temp_ptr;
for (temp_ptr = statelower; *temp_ptr; temp_ptr++) {
*temp_ptr = tolower(*temp_ptr);
}
for (temp_ptr = stateupper; *temp_ptr; temp_ptr++) {
*temp_ptr = toupper(*temp_ptr);
}
snprintf(statenum, 2, "%i", i);
/* Base test names, we'll append the state string */
char testname[64] = "Translate state string: ";
int tlen = strlen(testname);
strcpy(testname+tlen, states[i]);
ok(i==mp_translate_state(states[i]), testname);
strcpy(testname+tlen, statelower);
ok(i==mp_translate_state(statelower), testname);
strcpy(testname+tlen, stateupper);
ok(i==mp_translate_state(stateupper), testname);
strcpy(testname+tlen, statenum);
ok(i==mp_translate_state(statenum), testname);
}
ok(ERROR==mp_translate_state("warningfewgw"), "Translate state string with garbage");
ok(ERROR==mp_translate_state("00"), "Translate state string: bad numeric string 1");
ok(ERROR==mp_translate_state("01"), "Translate state string: bad numeric string 2");
ok(ERROR==mp_translate_state("10"), "Translate state string: bad numeric string 3");
ok(ERROR==mp_translate_state(""), "Translate state string: empty string");
return exit_status();
}

View file

@ -1,6 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_utils") {
plan skip_all => "./test_utils not compiled - please install tap library to test";
plan skip_all => "./test_utils not compiled - please enable libtap library to test";
}
exec "./test_utils";