Imported Upstream version 2.0
This commit is contained in:
parent
c89ccc3c74
commit
0841b5c7c7
165 changed files with 25440 additions and 4442 deletions
|
@ -2,19 +2,18 @@
|
|||
|
||||
SUBDIRS = . tests
|
||||
|
||||
noinst_LIBRARIES = libnagiosplug.a
|
||||
noinst_LIBRARIES = libmonitoringplug.a
|
||||
|
||||
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\"
|
||||
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \
|
||||
-I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
|
||||
|
||||
libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c
|
||||
libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c utils_cmd.c
|
||||
EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h
|
||||
|
||||
if USE_PARSE_INI
|
||||
libnagiosplug_a_SOURCES += parse_ini.c extra_opts.c
|
||||
libmonitoringplug_a_SOURCES += parse_ini.c extra_opts.c
|
||||
endif USE_PARSE_INI
|
||||
|
||||
INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
|
||||
|
||||
test test-debug:
|
||||
cd tests && make $@
|
||||
|
||||
|
|
|
@ -79,6 +79,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 \
|
||||
|
@ -128,11 +129,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 \
|
||||
|
@ -147,7 +149,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
|
||||
|
@ -155,15 +157,16 @@ CONFIG_HEADER = $(top_builddir)/config.h
|
|||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
libnagiosplug_a_AR = $(AR) $(ARFLAGS)
|
||||
libnagiosplug_a_LIBADD =
|
||||
am__libnagiosplug_a_SOURCES_DIST = utils_base.c utils_disk.c \
|
||||
libmonitoringplug_a_AR = $(AR) $(ARFLAGS)
|
||||
libmonitoringplug_a_LIBADD =
|
||||
am__libmonitoringplug_a_SOURCES_DIST = utils_base.c utils_disk.c \
|
||||
utils_tcp.c utils_cmd.c parse_ini.c extra_opts.c
|
||||
@USE_PARSE_INI_TRUE@am__objects_1 = parse_ini.$(OBJEXT) \
|
||||
@USE_PARSE_INI_TRUE@ extra_opts.$(OBJEXT)
|
||||
am_libnagiosplug_a_OBJECTS = utils_base.$(OBJEXT) utils_disk.$(OBJEXT) \
|
||||
utils_tcp.$(OBJEXT) utils_cmd.$(OBJEXT) $(am__objects_1)
|
||||
libnagiosplug_a_OBJECTS = $(am_libnagiosplug_a_OBJECTS)
|
||||
am_libmonitoringplug_a_OBJECTS = utils_base.$(OBJEXT) \
|
||||
utils_disk.$(OBJEXT) utils_tcp.$(OBJEXT) utils_cmd.$(OBJEXT) \
|
||||
$(am__objects_1)
|
||||
libmonitoringplug_a_OBJECTS = $(am_libmonitoringplug_a_OBJECTS)
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
|
@ -177,8 +180,8 @@ CCLD = $(CC)
|
|||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libnagiosplug_a_SOURCES)
|
||||
DIST_SOURCES = $(am__libnagiosplug_a_SOURCES_DIST)
|
||||
SOURCES = $(libmonitoringplug_a_SOURCES)
|
||||
DIST_SOURCES = $(am__libmonitoringplug_a_SOURCES_DIST)
|
||||
RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
|
||||
html-recursive info-recursive install-data-recursive \
|
||||
install-dvi-recursive install-exec-recursive \
|
||||
|
@ -337,6 +340,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@
|
||||
|
@ -702,6 +706,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@
|
||||
|
@ -731,6 +736,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@
|
||||
|
@ -842,8 +848,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@
|
||||
|
@ -934,7 +942,6 @@ LD = @LD@
|
|||
LDAPINCLUDE = @LDAPINCLUDE@
|
||||
LDAPLIBS = @LDAPLIBS@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBGNUTLS_CONFIG = @LIBGNUTLS_CONFIG@
|
||||
LIBGNU_LIBDEPS = @LIBGNU_LIBDEPS@
|
||||
LIBGNU_LTLIBDEPS = @LIBGNU_LTLIBDEPS@
|
||||
LIBICONV = @LIBICONV@
|
||||
|
@ -960,6 +967,7 @@ LTLIBMULTITHREAD = @LTLIBMULTITHREAD@
|
|||
LTLIBOBJS = @LTLIBOBJS@
|
||||
LTLIBPTH = @LTLIBPTH@
|
||||
LTLIBTHREAD = @LTLIBTHREAD@
|
||||
MAINT = @MAINT@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MANIFEST_TOOL = @MANIFEST_TOOL@
|
||||
MATHLIBS = @MATHLIBS@
|
||||
|
@ -985,6 +993,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@
|
||||
|
@ -1005,6 +1014,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@
|
||||
|
@ -1064,7 +1074,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@
|
||||
|
@ -1256,7 +1265,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@
|
||||
|
@ -1280,6 +1288,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@
|
||||
|
@ -1345,17 +1354,18 @@ top_builddir = @top_builddir@
|
|||
top_srcdir = @top_srcdir@
|
||||
with_trusted_path = @with_trusted_path@
|
||||
SUBDIRS = . tests
|
||||
noinst_LIBRARIES = libnagiosplug.a
|
||||
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\"
|
||||
libnagiosplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c \
|
||||
noinst_LIBRARIES = libmonitoringplug.a
|
||||
AM_CPPFLAGS = -DNP_STATE_DIR_PREFIX=\"$(localstatedir)\" \
|
||||
-I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
|
||||
|
||||
libmonitoringplug_a_SOURCES = utils_base.c utils_disk.c utils_tcp.c \
|
||||
utils_cmd.c $(am__append_1)
|
||||
EXTRA_DIST = utils_base.h utils_disk.h utils_tcp.h utils_cmd.h parse_ini.h extra_opts.h
|
||||
INCLUDES = -I$(srcdir) -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
|
||||
all: all-recursive
|
||||
|
||||
.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*) \
|
||||
|
@ -1380,18 +1390,18 @@ 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):
|
||||
|
||||
clean-noinstLIBRARIES:
|
||||
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
|
||||
libnagiosplug.a: $(libnagiosplug_a_OBJECTS) $(libnagiosplug_a_DEPENDENCIES) $(EXTRA_libnagiosplug_a_DEPENDENCIES)
|
||||
-rm -f libnagiosplug.a
|
||||
$(libnagiosplug_a_AR) libnagiosplug.a $(libnagiosplug_a_OBJECTS) $(libnagiosplug_a_LIBADD)
|
||||
$(RANLIB) libnagiosplug.a
|
||||
libmonitoringplug.a: $(libmonitoringplug_a_OBJECTS) $(libmonitoringplug_a_DEPENDENCIES) $(EXTRA_libmonitoringplug_a_DEPENDENCIES)
|
||||
-rm -f libmonitoringplug.a
|
||||
$(libmonitoringplug_a_AR) libmonitoringplug.a $(libmonitoringplug_a_OBJECTS) $(libmonitoringplug_a_LIBADD)
|
||||
$(RANLIB) libmonitoringplug.a
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* Nagios-plugins extra_opts library
|
||||
* Monitoring Plugins extra_opts library
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2007 Nagios Plugins Development Team
|
||||
* Copyright (c) 2007 Monitoring Plugins Development Team
|
||||
*
|
||||
* 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
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _EXTRA_OPTS_H_
|
||||
|
||||
/*
|
||||
* extra_opts.h: routines for loading nagios-plugin defaults from ini
|
||||
* extra_opts.h: routines for loading monitoring-plugin defaults from ini
|
||||
* configuration files.
|
||||
*/
|
||||
|
||||
|
|
493
lib/parse_ini.c
493
lib/parse_ini.c
|
@ -1,9 +1,9 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* Nagios-plugins parse_ini library
|
||||
* Monitoring Plugins parse_ini library
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2007 Nagios Plugins Development Team
|
||||
* Copyright (c) 2007 Monitoring Plugins Development Team
|
||||
*
|
||||
* 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
|
||||
|
@ -22,16 +22,15 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include "common.h"
|
||||
#include "idpriv.h"
|
||||
#include "utils_base.h"
|
||||
#include "parse_ini.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* TODO: die like N::P if config file is not found */
|
||||
|
||||
/* np_ini_info contains the result of parsing a "locator" in the format
|
||||
* [stanza_name][@config_filename] (check_foo@/etc/foo.ini, for example)
|
||||
*/
|
||||
|
@ -40,254 +39,314 @@ typedef struct {
|
|||
char *stanza;
|
||||
} np_ini_info;
|
||||
|
||||
static char *default_ini_file_names[] = {
|
||||
"monitoring-plugins.ini",
|
||||
"plugins.ini",
|
||||
"nagios-plugins.ini",
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *default_ini_path_names[] = {
|
||||
"/usr/local/etc/monitoring-plugins/monitoring-plugins.ini",
|
||||
"/usr/local/etc/monitoring-plugins.ini",
|
||||
"/etc/monitoring-plugins/monitoring-plugins.ini",
|
||||
"/etc/monitoring-plugins.ini",
|
||||
/* deprecated path names (for backward compatibility): */
|
||||
"/etc/nagios/plugins.ini",
|
||||
"/usr/local/nagios/etc/plugins.ini",
|
||||
"/usr/local/etc/nagios/plugins.ini",
|
||||
"/etc/opt/nagios/plugins.ini",
|
||||
"/etc/nagios-plugins.ini",
|
||||
"/usr/local/etc/nagios-plugins.ini",
|
||||
"/etc/opt/nagios-plugins.ini",
|
||||
NULL
|
||||
};
|
||||
|
||||
/* eat all characters from a FILE pointer until n is encountered */
|
||||
#define GOBBLE_TO(f, c, n) do { (c)=fgetc((f)); } while((c)!=EOF && (c)!=(n))
|
||||
|
||||
/* internal function that returns the constructed defaults options */
|
||||
static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts);
|
||||
|
||||
/* internal function that converts a single line into options format */
|
||||
static int add_option(FILE *f, np_arg_list **optlst);
|
||||
/* internal function to find default file */
|
||||
static char* default_file(void);
|
||||
/* internal function to stat() files */
|
||||
static int test_file(const char* env, int len, const char* file, char* temp_file);
|
||||
|
||||
/* parse_locator decomposes a string of the form
|
||||
/* internal functions to find default file */
|
||||
static char *default_file(void);
|
||||
static char *default_file_in_path(void);
|
||||
|
||||
/*
|
||||
* Parse_locator decomposes a string of the form
|
||||
* [stanza][@filename]
|
||||
* into its seperate parts
|
||||
* into its seperate parts.
|
||||
*/
|
||||
static void parse_locator(const char *locator, const char *def_stanza, np_ini_info *i){
|
||||
size_t locator_len=0, stanza_len=0;
|
||||
static void
|
||||
parse_locator(const char *locator, const char *def_stanza, np_ini_info *i)
|
||||
{
|
||||
size_t locator_len = 0, stanza_len = 0;
|
||||
|
||||
/* if locator is NULL we'll use default values */
|
||||
if(locator){
|
||||
locator_len=strlen(locator);
|
||||
stanza_len=strcspn(locator, "@");
|
||||
if (locator != NULL) {
|
||||
locator_len = strlen(locator);
|
||||
stanza_len = strcspn(locator, "@");
|
||||
}
|
||||
/* if a non-default stanza is provided */
|
||||
if(stanza_len>0){
|
||||
i->stanza=(char*)malloc(sizeof(char)*(stanza_len+1));
|
||||
if (stanza_len > 0) {
|
||||
i->stanza = malloc(sizeof(char) * (stanza_len + 1));
|
||||
strncpy(i->stanza, locator, stanza_len);
|
||||
i->stanza[stanza_len]='\0';
|
||||
} else { /* otherwise we use the default stanza */
|
||||
i->stanza=strdup(def_stanza);
|
||||
}
|
||||
/* if there is no @file part */
|
||||
if(stanza_len==locator_len){
|
||||
i->file=default_file();
|
||||
if(strcmp(i->file, "") == 0){
|
||||
die(STATE_UNKNOWN, _("Cannot find '%s' or '%s' in any standard location.\n"), NP_DEFAULT_INI_FILENAME1, NP_DEFAULT_INI_FILENAME2);
|
||||
}
|
||||
} else {
|
||||
i->file=strdup(&(locator[stanza_len+1]));
|
||||
}
|
||||
i->stanza[stanza_len] = '\0';
|
||||
} else /* otherwise we use the default stanza */
|
||||
i->stanza = strdup(def_stanza);
|
||||
|
||||
if(i->file==NULL || i->stanza==NULL){
|
||||
if (i->stanza == NULL)
|
||||
die(STATE_UNKNOWN, _("malloc() failed!\n"));
|
||||
}
|
||||
|
||||
/* check whether there's an @file part */
|
||||
i->file = stanza_len == locator_len
|
||||
? default_file()
|
||||
: strdup(&(locator[stanza_len + 1]));
|
||||
if (i->file == NULL || i->file[0] == '\0')
|
||||
die(STATE_UNKNOWN,
|
||||
_("Cannot find config file in any standard location.\n"));
|
||||
}
|
||||
|
||||
/* this is the externally visible function used by extra_opts */
|
||||
np_arg_list* np_get_defaults(const char *locator, const char *default_section){
|
||||
FILE *inifile=NULL;
|
||||
np_arg_list *defaults=NULL;
|
||||
/*
|
||||
* This is the externally visible function used by extra_opts.
|
||||
*/
|
||||
np_arg_list *
|
||||
np_get_defaults(const char *locator, const char *default_section)
|
||||
{
|
||||
FILE *inifile = NULL;
|
||||
np_arg_list *defaults = NULL;
|
||||
np_ini_info i;
|
||||
int is_suid_plugin = mp_suid();
|
||||
|
||||
if (is_suid_plugin && idpriv_temp_drop() == -1)
|
||||
die(STATE_UNKNOWN, _("Cannot drop privileges: %s\n"),
|
||||
strerror(errno));
|
||||
|
||||
parse_locator(locator, default_section, &i);
|
||||
/* if a file was specified or if we're using the default file */
|
||||
if(i.file != NULL && strlen(i.file) > 0){
|
||||
if(strcmp(i.file, "-")==0){
|
||||
inifile=stdin;
|
||||
} else {
|
||||
inifile=fopen(i.file, "r");
|
||||
}
|
||||
if(inifile==NULL) die(STATE_UNKNOWN, _("Can't read config file"));
|
||||
if(read_defaults(inifile, i.stanza, &defaults)==FALSE)
|
||||
die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file);
|
||||
inifile = strcmp(i.file, "-") == 0 ? stdin : fopen(i.file, "r");
|
||||
|
||||
free(i.file);
|
||||
if(inifile!=stdin) fclose(inifile);
|
||||
}
|
||||
if (inifile == NULL)
|
||||
die(STATE_UNKNOWN, _("Can't read config file: %s\n"),
|
||||
strerror(errno));
|
||||
if (read_defaults(inifile, i.stanza, &defaults) == FALSE)
|
||||
die(STATE_UNKNOWN,
|
||||
_("Invalid section '%s' in config file '%s'\n"), i.stanza,
|
||||
i.file);
|
||||
|
||||
free(i.file);
|
||||
if (inifile != stdin)
|
||||
fclose(inifile);
|
||||
free(i.stanza);
|
||||
if (is_suid_plugin && idpriv_temp_restore() == -1)
|
||||
die(STATE_UNKNOWN, _("Cannot restore privileges: %s\n"),
|
||||
strerror(errno));
|
||||
|
||||
return defaults;
|
||||
}
|
||||
|
||||
/* read_defaults is where the meat of the parsing takes place.
|
||||
/*
|
||||
* The read_defaults() function is where the meat of the parsing takes place.
|
||||
*
|
||||
* note that this may be called by a setuid binary, so we need to
|
||||
* Note that this may be called by a setuid binary, so we need to
|
||||
* be extra careful about user-supplied input (i.e. avoiding possible
|
||||
* format string vulnerabilities, etc)
|
||||
* format string vulnerabilities, etc).
|
||||
*/
|
||||
static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts){
|
||||
int c, status=FALSE;
|
||||
static int
|
||||
read_defaults(FILE *f, const char *stanza, np_arg_list **opts)
|
||||
{
|
||||
int c, status = FALSE;
|
||||
size_t i, stanza_len;
|
||||
enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate=NOSTANZA;
|
||||
enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate = NOSTANZA;
|
||||
|
||||
stanza_len=strlen(stanza);
|
||||
stanza_len = strlen(stanza);
|
||||
|
||||
/* our little stanza-parsing state machine. */
|
||||
while((c=fgetc(f))!=EOF){
|
||||
/* our little stanza-parsing state machine */
|
||||
while ((c = fgetc(f)) != EOF) {
|
||||
/* gobble up leading whitespace */
|
||||
if(isspace(c)) continue;
|
||||
switch(c){
|
||||
if (isspace(c))
|
||||
continue;
|
||||
switch (c) {
|
||||
/* globble up coment lines */
|
||||
case ';':
|
||||
case '#':
|
||||
case ';':
|
||||
case '#':
|
||||
GOBBLE_TO(f, c, '\n');
|
||||
break;
|
||||
/* start of a stanza, check to see if it matches */
|
||||
case '[':
|
||||
stanzastate = WRONGSTANZA;
|
||||
for (i = 0; i < stanza_len; i++) {
|
||||
c = fgetc(f);
|
||||
/* strip leading whitespace */
|
||||
if (i == 0)
|
||||
for (; isspace(c); c = fgetc(f))
|
||||
continue;
|
||||
/* nope, read to the end of the line */
|
||||
if (c != stanza[i]) {
|
||||
GOBBLE_TO(f, c, '\n');
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if it matched up to here and the next char is ']'... */
|
||||
if (i == stanza_len) {
|
||||
c = fgetc(f);
|
||||
/* strip trailing whitespace */
|
||||
for (; isspace(c); c = fgetc(f))
|
||||
continue;
|
||||
if (c == ']')
|
||||
stanzastate = RIGHTSTANZA;
|
||||
}
|
||||
break;
|
||||
/* otherwise, we're in the body of a stanza or a parse error */
|
||||
default:
|
||||
switch (stanzastate) {
|
||||
/* we never found the start of the first stanza, so
|
||||
* we're dealing with a config error
|
||||
*/
|
||||
case NOSTANZA:
|
||||
die(STATE_UNKNOWN, "%s\n",
|
||||
_("Config file error"));
|
||||
/* we're in a stanza, but for a different plugin */
|
||||
case WRONGSTANZA:
|
||||
GOBBLE_TO(f, c, '\n');
|
||||
break;
|
||||
/* start of a stanza. check to see if it matches */
|
||||
case '[':
|
||||
stanzastate=WRONGSTANZA;
|
||||
for(i=0; i<stanza_len; i++){
|
||||
c=fgetc(f);
|
||||
/* Strip leading whitespace */
|
||||
if(i==0) for(c; isspace(c); c=fgetc(f));
|
||||
/* nope, read to the end of the line */
|
||||
if(c!=stanza[i]) {
|
||||
GOBBLE_TO(f, c, '\n');
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* if it matched up to here and the next char is ']'... */
|
||||
if(i==stanza_len){
|
||||
c=fgetc(f);
|
||||
/* Strip trailing whitespace */
|
||||
for(c; isspace(c); c=fgetc(f));
|
||||
if(c==']') stanzastate=RIGHTSTANZA;
|
||||
}
|
||||
break;
|
||||
/* otherwise, we're in the body of a stanza or a parse error */
|
||||
default:
|
||||
switch(stanzastate){
|
||||
/* we never found the start of the first stanza, so
|
||||
* we're dealing with a config error
|
||||
*/
|
||||
case NOSTANZA:
|
||||
die(STATE_UNKNOWN, _("Config file error"));
|
||||
break;
|
||||
/* we're in a stanza, but for a different plugin */
|
||||
case WRONGSTANZA:
|
||||
GOBBLE_TO(f, c, '\n');
|
||||
break;
|
||||
/* okay, this is where we start taking the config */
|
||||
case RIGHTSTANZA:
|
||||
ungetc(c, f);
|
||||
if(add_option(f, opts)){
|
||||
die(STATE_UNKNOWN, _("Config file error"));
|
||||
}
|
||||
status=TRUE;
|
||||
break;
|
||||
/* okay, this is where we start taking the config */
|
||||
case RIGHTSTANZA:
|
||||
ungetc(c, f);
|
||||
if (add_option(f, opts)) {
|
||||
die(STATE_UNKNOWN, "%s\n",
|
||||
_("Config file error"));
|
||||
}
|
||||
status = TRUE;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* read one line of input in the format
|
||||
* Read one line of input in the format
|
||||
* ^option[[:space:]]*(=[[:space:]]*value)?
|
||||
* and creates it as a cmdline argument
|
||||
* and create it as a cmdline argument
|
||||
* --option[=value]
|
||||
* appending it to the linked list optbuf.
|
||||
*/
|
||||
static int add_option(FILE *f, np_arg_list **optlst){
|
||||
np_arg_list *opttmp=*optlst, *optnew;
|
||||
char *linebuf=NULL, *lineend=NULL, *optptr=NULL, *optend=NULL;
|
||||
char *eqptr=NULL, *valptr=NULL, *spaceptr=NULL, *valend=NULL;
|
||||
short done_reading=0, equals=0, value=0;
|
||||
size_t cfg_len=0, read_sz=8, linebuf_sz=0, read_pos=0;
|
||||
size_t opt_len=0, val_len=0;
|
||||
static int
|
||||
add_option(FILE *f, np_arg_list **optlst)
|
||||
{
|
||||
np_arg_list *opttmp = *optlst, *optnew;
|
||||
char *linebuf = NULL, *lineend = NULL, *optptr = NULL, *optend = NULL;
|
||||
char *eqptr = NULL, *valptr = NULL, *valend = NULL;
|
||||
short done_reading = 0, equals = 0, value = 0;
|
||||
size_t cfg_len = 0, read_sz = 8, linebuf_sz = 0, read_pos = 0;
|
||||
size_t opt_len = 0, val_len = 0;
|
||||
|
||||
/* read one line from the file */
|
||||
while(!done_reading){
|
||||
while (!done_reading) {
|
||||
/* grow if necessary */
|
||||
if(linebuf==NULL || read_pos+read_sz >= linebuf_sz){
|
||||
linebuf_sz=(linebuf_sz>0)?linebuf_sz<<1:read_sz;
|
||||
linebuf=realloc(linebuf, linebuf_sz);
|
||||
if(linebuf==NULL) die(STATE_UNKNOWN, _("malloc() failed!\n"));
|
||||
if (linebuf == NULL || read_pos + read_sz >= linebuf_sz) {
|
||||
linebuf_sz = linebuf_sz > 0 ? linebuf_sz << 1 : read_sz;
|
||||
linebuf = realloc(linebuf, linebuf_sz);
|
||||
if (linebuf == NULL)
|
||||
die(STATE_UNKNOWN, _("malloc() failed!\n"));
|
||||
}
|
||||
if(fgets(&linebuf[read_pos], read_sz, f)==NULL) done_reading=1;
|
||||
if (fgets(&linebuf[read_pos], (int)read_sz, f) == NULL)
|
||||
done_reading = 1;
|
||||
else {
|
||||
read_pos=strlen(linebuf);
|
||||
if(linebuf[read_pos-1]=='\n') {
|
||||
linebuf[--read_pos]='\0';
|
||||
done_reading=1;
|
||||
read_pos = strlen(linebuf);
|
||||
if (linebuf[read_pos - 1] == '\n') {
|
||||
linebuf[--read_pos] = '\0';
|
||||
done_reading = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
lineend=&linebuf[read_pos];
|
||||
/* all that to read one line. isn't C fun? :) now comes the parsing :/ */
|
||||
lineend = &linebuf[read_pos];
|
||||
/* all that to read one line, isn't C fun? :) now comes the parsing :/ */
|
||||
|
||||
/* skip leading whitespace */
|
||||
for(optptr=linebuf; optptr<lineend && isspace(*optptr); optptr++);
|
||||
for (optptr = linebuf; optptr < lineend && isspace(*optptr); optptr++)
|
||||
continue;
|
||||
/* continue to '=' or EOL, watching for spaces that might precede it */
|
||||
for(eqptr=optptr; eqptr<lineend && *eqptr!='='; eqptr++){
|
||||
if(isspace(*eqptr) && optend==NULL) optend=eqptr;
|
||||
else optend=NULL;
|
||||
for (eqptr = optptr; eqptr < lineend && *eqptr != '='; eqptr++) {
|
||||
if (isspace(*eqptr) && optend == NULL)
|
||||
optend = eqptr;
|
||||
else
|
||||
optend = NULL;
|
||||
}
|
||||
if(optend==NULL) optend=eqptr;
|
||||
if (optend == NULL)
|
||||
optend = eqptr;
|
||||
--optend;
|
||||
/* ^[[:space:]]*=foo is a syntax error */
|
||||
if(optptr==eqptr) die(STATE_UNKNOWN, _("Config file error\n"));
|
||||
if (optptr == eqptr)
|
||||
die(STATE_UNKNOWN, "%s\n", _("Config file error"));
|
||||
/* continue from '=' to start of value or EOL */
|
||||
for(valptr=eqptr+1; valptr<lineend && isspace(*valptr); valptr++);
|
||||
for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr);
|
||||
valptr++)
|
||||
continue;
|
||||
/* continue to the end of value */
|
||||
for(valend=valptr; valend<lineend; valend++);
|
||||
for (valend = valptr; valend < lineend; valend++)
|
||||
continue;
|
||||
--valend;
|
||||
/* Finally trim off trailing spaces */
|
||||
for(valend; isspace(*valend); valend--);
|
||||
/* finally trim off trailing spaces */
|
||||
for (; isspace(*valend); valend--)
|
||||
continue;
|
||||
/* calculate the length of "--foo" */
|
||||
opt_len=1+optend-optptr;
|
||||
opt_len = (size_t)(1 + optend - optptr);
|
||||
/* 1-character params needs only one dash */
|
||||
if(opt_len==1)
|
||||
cfg_len=1+(opt_len);
|
||||
if (opt_len == 1)
|
||||
cfg_len = 1 + (opt_len);
|
||||
else
|
||||
cfg_len=2+(opt_len);
|
||||
cfg_len = 2 + (opt_len);
|
||||
/* if valptr<lineend then we have to also allocate space for "=bar" */
|
||||
if(valptr<lineend) {
|
||||
equals=value=1;
|
||||
val_len=1+valend-valptr;
|
||||
cfg_len+=1+val_len;
|
||||
if (valptr < lineend) {
|
||||
equals = value = 1;
|
||||
val_len = (size_t)(1 + valend - valptr);
|
||||
cfg_len += 1 + val_len;
|
||||
}
|
||||
/* if valptr==valend then we have "=" but no "bar" */
|
||||
else if(valptr==lineend) {
|
||||
equals=1;
|
||||
cfg_len+=1;
|
||||
else if (valptr == lineend) {
|
||||
equals = 1;
|
||||
cfg_len += 1;
|
||||
}
|
||||
/* A line with no equal sign isn't valid */
|
||||
if(equals==0) die(STATE_UNKNOWN, _("Config file error\n"));
|
||||
/* a line with no equal sign isn't valid */
|
||||
if (equals == 0)
|
||||
die(STATE_UNKNOWN, "%s\n", _("Config file error"));
|
||||
|
||||
/* okay, now we have all the info we need, so we create a new np_arg_list
|
||||
* element and set the argument...
|
||||
*/
|
||||
optnew=(np_arg_list *)malloc(sizeof(np_arg_list));
|
||||
optnew->next=NULL;
|
||||
optnew = malloc(sizeof(np_arg_list));
|
||||
optnew->next = NULL;
|
||||
|
||||
read_pos=0;
|
||||
optnew->arg=(char *)malloc(cfg_len+1);
|
||||
read_pos = 0;
|
||||
optnew->arg = malloc(cfg_len + 1);
|
||||
/* 1-character params needs only one dash */
|
||||
if(opt_len==1) {
|
||||
if (opt_len == 1) {
|
||||
strncpy(&optnew->arg[read_pos], "-", 1);
|
||||
read_pos+=1;
|
||||
read_pos += 1;
|
||||
} else {
|
||||
strncpy(&optnew->arg[read_pos], "--", 2);
|
||||
read_pos+=2;
|
||||
read_pos += 2;
|
||||
}
|
||||
strncpy(&optnew->arg[read_pos], optptr, opt_len); read_pos+=opt_len;
|
||||
if(value) {
|
||||
optnew->arg[read_pos++]='=';
|
||||
strncpy(&optnew->arg[read_pos], valptr, val_len); read_pos+=val_len;
|
||||
strncpy(&optnew->arg[read_pos], optptr, opt_len);
|
||||
read_pos += opt_len;
|
||||
if (value) {
|
||||
optnew->arg[read_pos++] = '=';
|
||||
strncpy(&optnew->arg[read_pos], valptr, val_len);
|
||||
read_pos += val_len;
|
||||
}
|
||||
optnew->arg[read_pos]='\0';
|
||||
optnew->arg[read_pos] = '\0';
|
||||
|
||||
/* ...and put that to the end of the list */
|
||||
if(*optlst==NULL) {
|
||||
*optlst=optnew;
|
||||
} else {
|
||||
while(opttmp->next!=NULL) {
|
||||
opttmp=opttmp->next;
|
||||
}
|
||||
if (*optlst == NULL)
|
||||
*optlst = optnew;
|
||||
else {
|
||||
while (opttmp->next != NULL)
|
||||
opttmp = opttmp->next;
|
||||
opttmp->next = optnew;
|
||||
}
|
||||
|
||||
|
@ -295,72 +354,42 @@ static int add_option(FILE *f, np_arg_list **optlst){
|
|||
return 0;
|
||||
}
|
||||
|
||||
static char* default_file(void){
|
||||
struct stat sb;
|
||||
char *np_env=NULL, *default_file=NULL;
|
||||
char temp_file[MAX_INPUT_BUFFER];
|
||||
size_t len;
|
||||
static char *
|
||||
default_file(void)
|
||||
{
|
||||
char **p, *ini_file;
|
||||
|
||||
if((np_env=getenv("NAGIOS_CONFIG_PATH"))!=NULL) {
|
||||
/* skip any starting colon... */
|
||||
while(*np_env==':') np_env++;
|
||||
/* Look for NP_DEFAULT_INI_FILENAME1 and NP_DEFAULT_INI_FILENAME2 in
|
||||
* every PATHs defined (colon-separated).
|
||||
*/
|
||||
while((len=strcspn(np_env,":"))>0){
|
||||
/* Test NP_DEFAULT_INI_FILENAME[1-2] in current np_env token */
|
||||
if(test_file(np_env,len,NP_DEFAULT_INI_FILENAME1,temp_file)==1 ||
|
||||
test_file(np_env,len,NP_DEFAULT_INI_FILENAME2,temp_file)==1){
|
||||
default_file=strdup(temp_file);
|
||||
break;
|
||||
if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL ||
|
||||
(ini_file = default_file_in_path()) != NULL)
|
||||
return ini_file;
|
||||
for (p = default_ini_path_names; *p != NULL; p++)
|
||||
if (access(*p, F_OK) == 0)
|
||||
return *p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
default_file_in_path(void)
|
||||
{
|
||||
char *config_path, **file;
|
||||
char *dir, *ini_file, *tokens;
|
||||
|
||||
if ((config_path = getenv("NAGIOS_CONFIG_PATH")) == NULL)
|
||||
return NULL;
|
||||
/* shall we spit out a warning that NAGIOS_CONFIG_PATH is deprecated? */
|
||||
|
||||
if ((tokens = strdup(config_path)) == NULL)
|
||||
die(STATE_UNKNOWN, "%s\n", _("Insufficient Memory"));
|
||||
for (dir = strtok(tokens, ":"); dir != NULL; dir = strtok(NULL, ":")) {
|
||||
for (file = default_ini_file_names; *file != NULL; file++) {
|
||||
if ((asprintf(&ini_file, "%s/%s", dir, *file)) < 0)
|
||||
die(STATE_UNKNOWN, "%s\n", _("Insufficient Memory"));
|
||||
if (access(ini_file, F_OK) == 0) {
|
||||
free(tokens);
|
||||
return ini_file;
|
||||
}
|
||||
|
||||
/* Move on to the next token */
|
||||
np_env+=len;
|
||||
while(*np_env==':') np_env++;
|
||||
} /* while(...) */
|
||||
} /* if(getenv("NAGIOS_CONFIG_PATH")) */
|
||||
|
||||
/* Look for NP_DEFAULT_INI_FILENAME1 in NP_DEFAULT_INI_NAGIOS_PATH[1-4] */
|
||||
if(!default_file){
|
||||
if(test_file(NP_DEFAULT_INI_NAGIOS_PATH1,strlen(NP_DEFAULT_INI_NAGIOS_PATH1),NP_DEFAULT_INI_FILENAME1,temp_file)==1 ||
|
||||
test_file(NP_DEFAULT_INI_NAGIOS_PATH2,strlen(NP_DEFAULT_INI_NAGIOS_PATH2),NP_DEFAULT_INI_FILENAME1,temp_file)==1 ||
|
||||
test_file(NP_DEFAULT_INI_NAGIOS_PATH3,strlen(NP_DEFAULT_INI_NAGIOS_PATH3),NP_DEFAULT_INI_FILENAME1,temp_file)==1 ||
|
||||
test_file(NP_DEFAULT_INI_NAGIOS_PATH4,strlen(NP_DEFAULT_INI_NAGIOS_PATH4),NP_DEFAULT_INI_FILENAME1,temp_file)==1)
|
||||
default_file=strdup(temp_file);
|
||||
}
|
||||
}
|
||||
|
||||
/* Look for NP_DEFAULT_INI_FILENAME2 in NP_DEFAULT_INI_PATH[1-3] */
|
||||
if(!default_file){
|
||||
if(test_file(NP_DEFAULT_INI_PATH1,strlen(NP_DEFAULT_INI_PATH1),NP_DEFAULT_INI_FILENAME2,temp_file)==1 ||
|
||||
test_file(NP_DEFAULT_INI_PATH2,strlen(NP_DEFAULT_INI_PATH2),NP_DEFAULT_INI_FILENAME2,temp_file)==1 ||
|
||||
test_file(NP_DEFAULT_INI_PATH3,strlen(NP_DEFAULT_INI_PATH3),NP_DEFAULT_INI_FILENAME2,temp_file)==1)
|
||||
default_file=strdup(temp_file);
|
||||
}
|
||||
|
||||
/* Return default_file or empty string (should return NULL if we want plugins
|
||||
* to die there)...
|
||||
*/
|
||||
if(default_file)
|
||||
return default_file;
|
||||
return "";
|
||||
free(tokens);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* put together len bytes from env and the filename and test for its
|
||||
* existence. Returns 1 if found, 0 if not and -1 if test wasn't performed.
|
||||
*/
|
||||
static int test_file(const char* env, int len, const char* file, char* temp_file){
|
||||
struct stat sb;
|
||||
|
||||
/* test if len + filelen + '/' + '\0' fits in temp_file */
|
||||
if((len+strlen(file)+2)>MAX_INPUT_BUFFER) return -1;
|
||||
|
||||
strncpy(temp_file,env,len);
|
||||
temp_file[len]='\0';
|
||||
strncat(temp_file,"/",len+1);
|
||||
strncat(temp_file,file,len+strlen(file)+1);
|
||||
|
||||
if(stat(temp_file, &sb) != -1) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _PARSE_INI_H_
|
||||
|
||||
/*
|
||||
* parse_ini.h: routines for loading nagios-plugin defaults from ini
|
||||
* parse_ini.h: routines for loading monitoring-plugin defaults from ini
|
||||
* configuration files.
|
||||
*/
|
||||
|
||||
|
@ -13,50 +13,10 @@ typedef struct np_arg_el {
|
|||
struct np_arg_el *next;
|
||||
} np_arg_list;
|
||||
|
||||
/* FIXME: This is in plugins/common.c. Should be eventually moved to lib/
|
||||
* (although for this particular one a configure settings should be ideal)
|
||||
*/
|
||||
#ifndef MAX_INPUT_BUFFER
|
||||
# define MAX_INPUT_BUFFER 8192
|
||||
#endif /* MAX_INPUT_BUFFER */
|
||||
|
||||
/* Filenames (see below) */
|
||||
#ifndef NP_DEFAULT_INI_FILENAME1
|
||||
# define NP_DEFAULT_INI_FILENAME1 "plugins.ini"
|
||||
#endif /* NP_DEFAULT_INI_FILENAME1 */
|
||||
#ifndef NP_DEFAULT_INI_FILENAME2
|
||||
# define NP_DEFAULT_INI_FILENAME2 "nagios-plugins.ini"
|
||||
#endif /* NP_DEFAULT_INI_FILENAME2 */
|
||||
|
||||
/* Config paths ending in nagios (search for NP_DEFAULT_INI_FILENAME1) */
|
||||
#ifndef NP_DEFAULT_INI_NAGIOS_PATH1
|
||||
# define NP_DEFAULT_INI_NAGIOS_PATH1 "/etc/nagios"
|
||||
#endif /* NP_DEFAULT_INI_NAGIOS_PATH1 */
|
||||
#ifndef NP_DEFAULT_INI_NAGIOS_PATH2
|
||||
# define NP_DEFAULT_INI_NAGIOS_PATH2 "/usr/local/nagios/etc"
|
||||
#endif /* NP_DEFAULT_INI_NAGIOS_PATH2 */
|
||||
#ifndef NP_DEFAULT_INI_NAGIOS_PATH3
|
||||
# define NP_DEFAULT_INI_NAGIOS_PATH3 "/usr/local/etc/nagios"
|
||||
#endif /* NP_DEFAULT_INI_NAGIOS_PATH3 */
|
||||
#ifndef NP_DEFAULT_INI_NAGIOS_PATH4
|
||||
# define NP_DEFAULT_INI_NAGIOS_PATH4 "/etc/opt/nagios"
|
||||
#endif /* NP_DEFAULT_INI_NAGIOS_PATH4 */
|
||||
|
||||
/* Config paths not ending in nagios (search for NP_DEFAULT_INI_FILENAME2) */
|
||||
#ifndef NP_DEFAULT_INI_PATH1
|
||||
# define NP_DEFAULT_INI_PATH1 "/etc"
|
||||
#endif /* NP_DEFAULT_INI_PATH1 */
|
||||
#ifndef NP_DEFAULT_INI_PATH2
|
||||
# define NP_DEFAULT_INI_PATH2 "/usr/local/etc"
|
||||
#endif /* NP_DEFAULT_INI_PATH2 */
|
||||
#ifndef NP_DEFAULT_INI_PATH3
|
||||
# define NP_DEFAULT_INI_PATH3 "/etc/opt"
|
||||
#endif /* NP_DEFAULT_INI_PATH3 */
|
||||
|
||||
/* np_load_defaults: load the default configuration (if present) for
|
||||
* a plugin from the ini file
|
||||
*/
|
||||
np_arg_list* np_get_defaults(const char *locator, const char *default_section);
|
||||
np_arg_list *np_get_defaults(const char *locator, const char *default_section);
|
||||
|
||||
#endif /* _PARSE_INI_H_ */
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
149
lib/utils_base.c
149
lib/utils_base.c
|
@ -3,7 +3,7 @@
|
|||
* utils_base.c
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2006 Nagios Plugins Development Team
|
||||
* Copyright (c) 2006 Monitoring Plugins Development Team
|
||||
*
|
||||
* Library of useful functions for plugins
|
||||
*
|
||||
|
@ -30,56 +30,58 @@
|
|||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } }
|
||||
|
||||
nagios_plugin *this_nagios_plugin=NULL;
|
||||
monitoring_plugin *this_monitoring_plugin=NULL;
|
||||
|
||||
int _np_state_read_file(FILE *);
|
||||
|
||||
void np_init( char *plugin_name, int argc, char **argv ) {
|
||||
if (this_nagios_plugin==NULL) {
|
||||
this_nagios_plugin = calloc(1, sizeof(nagios_plugin));
|
||||
if (this_nagios_plugin==NULL) {
|
||||
if (this_monitoring_plugin==NULL) {
|
||||
this_monitoring_plugin = calloc(1, sizeof(monitoring_plugin));
|
||||
if (this_monitoring_plugin==NULL) {
|
||||
die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
|
||||
strerror(errno));
|
||||
}
|
||||
this_nagios_plugin->plugin_name = strdup(plugin_name);
|
||||
if (this_nagios_plugin->plugin_name==NULL)
|
||||
this_monitoring_plugin->plugin_name = strdup(plugin_name);
|
||||
if (this_monitoring_plugin->plugin_name==NULL)
|
||||
die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
|
||||
this_nagios_plugin->argc = argc;
|
||||
this_nagios_plugin->argv = argv;
|
||||
this_monitoring_plugin->argc = argc;
|
||||
this_monitoring_plugin->argv = argv;
|
||||
}
|
||||
}
|
||||
|
||||
void np_set_args( int argc, char **argv ) {
|
||||
if (this_nagios_plugin==NULL)
|
||||
if (this_monitoring_plugin==NULL)
|
||||
die(STATE_UNKNOWN, _("This requires np_init to be called"));
|
||||
|
||||
this_nagios_plugin->argc = argc;
|
||||
this_nagios_plugin->argv = argv;
|
||||
this_monitoring_plugin->argc = argc;
|
||||
this_monitoring_plugin->argv = argv;
|
||||
}
|
||||
|
||||
|
||||
void np_cleanup() {
|
||||
if (this_nagios_plugin!=NULL) {
|
||||
if(this_nagios_plugin->state!=NULL) {
|
||||
if(this_nagios_plugin->state->state_data) {
|
||||
np_free(this_nagios_plugin->state->state_data->data);
|
||||
np_free(this_nagios_plugin->state->state_data);
|
||||
if (this_monitoring_plugin!=NULL) {
|
||||
if(this_monitoring_plugin->state!=NULL) {
|
||||
if(this_monitoring_plugin->state->state_data) {
|
||||
np_free(this_monitoring_plugin->state->state_data->data);
|
||||
np_free(this_monitoring_plugin->state->state_data);
|
||||
}
|
||||
np_free(this_nagios_plugin->state->name);
|
||||
np_free(this_nagios_plugin->state);
|
||||
np_free(this_monitoring_plugin->state->name);
|
||||
np_free(this_monitoring_plugin->state);
|
||||
}
|
||||
np_free(this_nagios_plugin->plugin_name);
|
||||
np_free(this_nagios_plugin);
|
||||
np_free(this_monitoring_plugin->plugin_name);
|
||||
np_free(this_monitoring_plugin);
|
||||
}
|
||||
this_nagios_plugin=NULL;
|
||||
this_monitoring_plugin=NULL;
|
||||
}
|
||||
|
||||
/* Hidden function to get a pointer to this_nagios_plugin for testing */
|
||||
void _get_nagios_plugin( nagios_plugin **pointer ){
|
||||
*pointer = this_nagios_plugin;
|
||||
/* Hidden function to get a pointer to this_monitoring_plugin for testing */
|
||||
void _get_monitoring_plugin( monitoring_plugin **pointer ){
|
||||
*pointer = this_monitoring_plugin;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -89,7 +91,7 @@ die (int result, const char *fmt, ...)
|
|||
va_start (ap, fmt);
|
||||
vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
if(this_nagios_plugin!=NULL) {
|
||||
if(this_monitoring_plugin!=NULL) {
|
||||
np_cleanup();
|
||||
}
|
||||
exit (result);
|
||||
|
@ -298,19 +300,6 @@ char *np_escaped_string (const char *string) {
|
|||
|
||||
int np_check_if_root(void) { return (geteuid() == 0); }
|
||||
|
||||
int np_warn_if_not_root(void) {
|
||||
int status = np_check_if_root();
|
||||
if(!status) {
|
||||
printf(_("Warning: "));
|
||||
printf(_("This plugin must be either run as root or setuid root.\n"));
|
||||
printf(_("To run as root, you can use a tool like sudo.\n"));
|
||||
printf(_("To set the setuid permissions, use the command:\n"));
|
||||
/* XXX could we use something like progname? */
|
||||
printf("\tchmod u+s yourpluginfile\n");
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the value from key/value pairs, or return NULL. The value returned
|
||||
* can be free()ed.
|
||||
|
@ -367,6 +356,23 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
|
|||
return value;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Read a string representing a state (ok, warning... or numeric: 0, 1) and
|
||||
* return the corresponding STATE_ value or ERROR)
|
||||
*/
|
||||
int mp_translate_state (char *state_text) {
|
||||
if (!strcasecmp(state_text,"OK") || !strcmp(state_text,"0"))
|
||||
return STATE_OK;
|
||||
if (!strcasecmp(state_text,"WARNING") || !strcmp(state_text,"1"))
|
||||
return STATE_WARNING;
|
||||
if (!strcasecmp(state_text,"CRITICAL") || !strcmp(state_text,"2"))
|
||||
return STATE_CRITICAL;
|
||||
if (!strcasecmp(state_text,"UNKNOWN") || !strcmp(state_text,"3"))
|
||||
return STATE_UNKNOWN;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a string to use as a keyname, based on an md5 hash of argv, thus
|
||||
* hopefully a unique key per service/plugin invocation. Use the extra-opts
|
||||
|
@ -375,14 +381,14 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
|
|||
char *_np_state_generate_key() {
|
||||
struct sha1_ctx ctx;
|
||||
int i;
|
||||
char **argv = this_nagios_plugin->argv;
|
||||
char **argv = this_monitoring_plugin->argv;
|
||||
unsigned char result[20];
|
||||
char keyname[41];
|
||||
char *p=NULL;
|
||||
|
||||
sha1_init_ctx(&ctx);
|
||||
|
||||
for(i=0; i<this_nagios_plugin->argc; i++) {
|
||||
for(i=0; i<this_monitoring_plugin->argc; i++) {
|
||||
sha1_process_bytes(argv[i], strlen(argv[i]), &ctx);
|
||||
}
|
||||
|
||||
|
@ -401,9 +407,9 @@ char *_np_state_generate_key() {
|
|||
}
|
||||
|
||||
void _cleanup_state_data() {
|
||||
if (this_nagios_plugin->state->state_data!=NULL) {
|
||||
np_free(this_nagios_plugin->state->state_data->data);
|
||||
np_free(this_nagios_plugin->state->state_data);
|
||||
if (this_monitoring_plugin->state->state_data!=NULL) {
|
||||
np_free(this_monitoring_plugin->state->state_data->data);
|
||||
np_free(this_monitoring_plugin->state->state_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -415,9 +421,18 @@ void _cleanup_state_data() {
|
|||
char* _np_state_calculate_location_prefix(){
|
||||
char *env_dir;
|
||||
|
||||
env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY");
|
||||
if(env_dir && env_dir[0] != '\0')
|
||||
return env_dir;
|
||||
/* Do not allow passing MP_STATE_PATH in setuid plugins
|
||||
* for security reasons */
|
||||
if (mp_suid() == FALSE) {
|
||||
env_dir = getenv("MP_STATE_PATH");
|
||||
if(env_dir && env_dir[0] != '\0')
|
||||
return env_dir;
|
||||
/* This is the former ENV, for backward-compatibility */
|
||||
env_dir = getenv("NAGIOS_PLUGIN_STATE_DIRECTORY");
|
||||
if(env_dir && env_dir[0] != '\0')
|
||||
return env_dir;
|
||||
}
|
||||
|
||||
return NP_STATE_DIR_PREFIX;
|
||||
}
|
||||
|
||||
|
@ -432,7 +447,7 @@ void np_enable_state(char *keyname, int expected_data_version) {
|
|||
char *temp_keyname = NULL;
|
||||
char *p=NULL;
|
||||
|
||||
if(this_nagios_plugin==NULL)
|
||||
if(this_monitoring_plugin==NULL)
|
||||
die(STATE_UNKNOWN, _("This requires np_init to be called"));
|
||||
|
||||
this_state = (state_key *) calloc(1, sizeof(state_key));
|
||||
|
@ -456,15 +471,17 @@ void np_enable_state(char *keyname, int expected_data_version) {
|
|||
p++;
|
||||
}
|
||||
this_state->name=temp_keyname;
|
||||
this_state->plugin_name=this_nagios_plugin->plugin_name;
|
||||
this_state->plugin_name=this_monitoring_plugin->plugin_name;
|
||||
this_state->data_version=expected_data_version;
|
||||
this_state->state_data=NULL;
|
||||
|
||||
/* Calculate filename */
|
||||
asprintf(&temp_filename, "%s/%s/%s", _np_state_calculate_location_prefix(), this_nagios_plugin->plugin_name, this_state->name);
|
||||
asprintf(&temp_filename, "%s/%lu/%s/%s",
|
||||
_np_state_calculate_location_prefix(), (unsigned long)geteuid(),
|
||||
this_monitoring_plugin->plugin_name, this_state->name);
|
||||
this_state->_filename=temp_filename;
|
||||
|
||||
this_nagios_plugin->state = this_state;
|
||||
this_monitoring_plugin->state = this_state;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -479,11 +496,11 @@ state_data *np_state_read() {
|
|||
FILE *statefile;
|
||||
int rc = FALSE;
|
||||
|
||||
if(this_nagios_plugin==NULL)
|
||||
if(this_monitoring_plugin==NULL)
|
||||
die(STATE_UNKNOWN, _("This requires np_init to be called"));
|
||||
|
||||
/* Open file. If this fails, no previous state found */
|
||||
statefile = fopen( this_nagios_plugin->state->_filename, "r" );
|
||||
statefile = fopen( this_monitoring_plugin->state->_filename, "r" );
|
||||
if(statefile!=NULL) {
|
||||
|
||||
this_state_data = (state_data *) calloc(1, sizeof(state_data));
|
||||
|
@ -492,7 +509,7 @@ state_data *np_state_read() {
|
|||
strerror(errno));
|
||||
|
||||
this_state_data->data=NULL;
|
||||
this_nagios_plugin->state->state_data = this_state_data;
|
||||
this_monitoring_plugin->state->state_data = this_state_data;
|
||||
|
||||
rc = _np_state_read_file(statefile);
|
||||
|
||||
|
@ -503,10 +520,10 @@ state_data *np_state_read() {
|
|||
_cleanup_state_data();
|
||||
}
|
||||
|
||||
return this_nagios_plugin->state->state_data;
|
||||
return this_monitoring_plugin->state->state_data;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Read the state file
|
||||
*/
|
||||
int _np_state_read_file(FILE *f) {
|
||||
|
@ -544,7 +561,7 @@ int _np_state_read_file(FILE *f) {
|
|||
break;
|
||||
case STATE_DATA_VERSION:
|
||||
i=atoi(line);
|
||||
if(i != this_nagios_plugin->state->data_version)
|
||||
if(i != this_monitoring_plugin->state->data_version)
|
||||
failure++;
|
||||
else
|
||||
expected=STATE_DATA_TIME;
|
||||
|
@ -555,13 +572,13 @@ int _np_state_read_file(FILE *f) {
|
|||
if(data_time > current_time)
|
||||
failure++;
|
||||
else {
|
||||
this_nagios_plugin->state->state_data->time = data_time;
|
||||
this_monitoring_plugin->state->state_data->time = data_time;
|
||||
expected=STATE_DATA_TEXT;
|
||||
}
|
||||
break;
|
||||
case STATE_DATA_TEXT:
|
||||
this_nagios_plugin->state->state_data->data = strdup(line);
|
||||
if(this_nagios_plugin->state->state_data->data==NULL)
|
||||
this_monitoring_plugin->state->state_data->data = strdup(line);
|
||||
if(this_monitoring_plugin->state->state_data->data==NULL)
|
||||
die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno));
|
||||
expected=STATE_DATA_END;
|
||||
status=TRUE;
|
||||
|
@ -596,8 +613,8 @@ void np_state_write_string(time_t data_time, char *data_string) {
|
|||
current_time=data_time;
|
||||
|
||||
/* If file doesn't currently exist, create directories */
|
||||
if(access(this_nagios_plugin->state->_filename,F_OK)!=0) {
|
||||
asprintf(&directories, "%s", this_nagios_plugin->state->_filename);
|
||||
if(access(this_monitoring_plugin->state->_filename,F_OK)!=0) {
|
||||
asprintf(&directories, "%s", this_monitoring_plugin->state->_filename);
|
||||
if(directories==NULL)
|
||||
die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
|
||||
strerror(errno));
|
||||
|
@ -607,7 +624,7 @@ void np_state_write_string(time_t data_time, char *data_string) {
|
|||
*p='\0';
|
||||
if((access(directories,F_OK)!=0) && (mkdir(directories, S_IRWXU)!=0)) {
|
||||
/* Can't free this! Otherwise error message is wrong! */
|
||||
/* np_free(directories); */
|
||||
/* np_free(directories); */
|
||||
die(STATE_UNKNOWN, _("Cannot create directory: %s"), directories);
|
||||
}
|
||||
*p='/';
|
||||
|
@ -616,7 +633,7 @@ void np_state_write_string(time_t data_time, char *data_string) {
|
|||
np_free(directories);
|
||||
}
|
||||
|
||||
asprintf(&temp_file,"%s.XXXXXX",this_nagios_plugin->state->_filename);
|
||||
asprintf(&temp_file,"%s.XXXXXX",this_monitoring_plugin->state->_filename);
|
||||
if(temp_file==NULL)
|
||||
die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
|
||||
strerror(errno));
|
||||
|
@ -636,7 +653,7 @@ void np_state_write_string(time_t data_time, char *data_string) {
|
|||
|
||||
fprintf(fp,"# NP State file\n");
|
||||
fprintf(fp,"%d\n",NP_STATE_FORMAT_VERSION);
|
||||
fprintf(fp,"%d\n",this_nagios_plugin->state->data_version);
|
||||
fprintf(fp,"%d\n",this_monitoring_plugin->state->data_version);
|
||||
fprintf(fp,"%lu\n",current_time);
|
||||
fprintf(fp,"%s\n",data_string);
|
||||
|
||||
|
@ -654,7 +671,7 @@ void np_state_write_string(time_t data_time, char *data_string) {
|
|||
die(STATE_UNKNOWN, _("Error writing temp file"));
|
||||
}
|
||||
|
||||
if(rename(temp_file, this_nagios_plugin->state->_filename)!=0) {
|
||||
if(rename(temp_file, this_monitoring_plugin->state->_filename)!=0) {
|
||||
unlink(temp_file);
|
||||
np_free(temp_file);
|
||||
die(STATE_UNKNOWN, _("Cannot rename state temp file"));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef _UTILS_BASE_
|
||||
#define _UTILS_BASE_
|
||||
/* Header file for nagios plugins utils_base.c */
|
||||
/* Header file for Monitoring Plugins utils_base.c */
|
||||
|
||||
#include "sha1.h"
|
||||
|
||||
|
@ -52,7 +52,7 @@ typedef struct np_struct {
|
|||
state_key *state;
|
||||
int argc;
|
||||
char **argv;
|
||||
} nagios_plugin;
|
||||
} monitoring_plugin;
|
||||
|
||||
range *parse_range_string (char *);
|
||||
int _set_thresholds(thresholds **, char *, char *);
|
||||
|
@ -62,7 +62,7 @@ int check_range(double, range *);
|
|||
int get_status(double, thresholds *);
|
||||
|
||||
/* All possible characters in a threshold range */
|
||||
#define NP_THRESHOLDS_CHARS "0123456789.:@~"
|
||||
#define NP_THRESHOLDS_CHARS "-0123456789.:@~"
|
||||
|
||||
char *np_escaped_string (const char *);
|
||||
|
||||
|
@ -75,9 +75,10 @@ void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)))
|
|||
/* a simple check to see if we're running as root.
|
||||
* returns zero on failure, nonzero on success */
|
||||
int np_check_if_root(void);
|
||||
/* and a helpful wrapper around that. it returns the same status
|
||||
* code from the above function, in case it's helpful for testing */
|
||||
int np_warn_if_not_root(void);
|
||||
|
||||
/* mp_suid() returns true if the real and effective uids differs, such as when
|
||||
* running a suid plugin */
|
||||
#define mp_suid() (getuid() != geteuid())
|
||||
|
||||
/*
|
||||
* Extract the value from key/value pairs, or return NULL. The value returned
|
||||
|
@ -93,6 +94,11 @@ char *np_extract_value(const char*, const char*, char);
|
|||
*/
|
||||
#define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
|
||||
|
||||
/*
|
||||
* Read a string representing a state (ok, warning... or numeric: 0, 1) and
|
||||
* return the corresponding NP_STATE or ERROR)
|
||||
*/
|
||||
int mp_translate_state (char *);
|
||||
|
||||
void np_enable_state(char *, int);
|
||||
state_data *np_state_read();
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* Nagios run command utilities
|
||||
* Monitoring run command utilities
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2005-2006 Nagios Plugins Development Team
|
||||
* Copyright (c) 2005-2006 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description :
|
||||
*
|
||||
|
@ -390,6 +390,9 @@ cmd_file_read ( char *filename, output *out, int flags)
|
|||
|
||||
if(out)
|
||||
out->lines = _cmd_fetch_output (fd, out, flags);
|
||||
|
||||
if (close(fd) == -1)
|
||||
die( STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define _UTILS_CMD_
|
||||
|
||||
/*
|
||||
* Header file for nagios plugins utils_cmd.c
|
||||
* Header file for Monitoring Plugins utils_cmd.c
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Library for check_disk
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 1999-2007 Nagios Plugins Development Team
|
||||
* Copyright (c) 1999-2007 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Library for check_tcp
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 1999-2013 Nagios Plugins Development Team
|
||||
* Copyright (c) 1999-2013 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue