New upstream version 2.3.4

This commit is contained in:
Jan Wagner 2023-10-18 07:29:37 +00:00
parent e7bdd1c6c6
commit de72f6f588
556 changed files with 90432 additions and 53391 deletions

View file

@ -51,10 +51,10 @@ noinst_LIBRARIES = libnpcommon.a
libnpcommon_a_SOURCES = utils.c netutils.c sslutils.c runcmd.c \
popen.c utils.h netutils.h popen.h common.h runcmd.c runcmd.h
BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a
BASEOBJS = libnpcommon.a ../lib/libmonitoringplug.a ../gl/libgnu.a $(LIB_CRYPTO)
NETOBJS = $(BASEOBJS) $(EXTRA_NETOBLS)
NETLIBS = $(NETOBJS) $(SOCKETLIBS)
SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS)
SSLOBJS = $(BASEOBJS) $(NETLIBS) $(SSLLIBS) $(LIB_CRYPTO)
TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir)
@ -112,7 +112,7 @@ check_tcp_LDADD = $(SSLOBJS)
check_time_LDADD = $(NETLIBS)
check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS)
check_ups_LDADD = $(NETLIBS)
check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS)
check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS) $(SYSTEMDLIBS)
check_by_ssh_LDADD = $(NETLIBS)
check_ide_smart_LDADD = $(BASEOBJS)
negate_LDADD = $(BASEOBJS)

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -141,21 +141,28 @@ main (int argc, char **argv)
if (verbose > 2)
printf ("Initializing DBI\n");
if (dbi_initialize (NULL) < 0) {
dbi_inst *instance_p;
if (dbi_initialize_r(NULL, instance_p) < 0) {
printf ("UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n");
return STATE_UNKNOWN;
}
if (instance_p == NULL) {
printf ("UNKNOWN - failed to initialize DBI.\n");
return STATE_UNKNOWN;
}
if (verbose)
printf ("Opening DBI driver '%s'\n", np_dbi_driver);
driver = dbi_driver_open (np_dbi_driver);
driver = dbi_driver_open_r(np_dbi_driver, instance_p);
if (! driver) {
printf ("UNKNOWN - failed to open DBI driver '%s'; possibly it's not installed.\n",
np_dbi_driver);
printf ("Known drivers:\n");
for (driver = dbi_driver_list (NULL); driver; driver = dbi_driver_list (driver)) {
for (driver = dbi_driver_list_r(NULL, instance_p); driver; driver = dbi_driver_list_r(driver, instance_p)) {
printf (" - %s\n", dbi_driver_get_name (driver));
}
return STATE_UNKNOWN;
@ -426,6 +433,7 @@ process_arguments (int argc, char **argv)
else
timeout_interval = atoi (optarg);
break;
case 'H': /* host */
if (!is_host (optarg))
usage2 (_("Invalid hostname/address"), optarg);

View file

@ -93,11 +93,11 @@ static int stat_remote_fs = 0;
/* Linked list of filesystem types to omit.
If the list is empty, don't exclude any types. */
static struct name_list *fs_exclude_list;
static struct regex_list *fs_exclude_list = NULL;
/* Linked list of filesystem types to check.
If the list is empty, include all types. */
static struct name_list *fs_include_list;
static struct regex_list *fs_include_list;
static struct name_list *dp_exclude_list;
@ -112,11 +112,12 @@ enum
{
SYNC_OPTION = CHAR_MAX + 1,
NO_SYNC_OPTION,
BLOCK_SIZE_OPTION
BLOCK_SIZE_OPTION,
IGNORE_MISSING
};
#ifdef _AIX
#pragma alloca
#pragma alloca
#endif
int process_arguments (int, char **);
@ -126,13 +127,10 @@ int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, ch
void print_help (void);
void print_usage (void);
double calculate_percent(uintmax_t, uintmax_t);
void stat_path (struct parameter_list *p);
bool stat_path (struct parameter_list *p);
void get_stats (struct parameter_list *p, struct fs_usage *fsp);
void get_path_stats (struct parameter_list *p, struct fs_usage *fsp);
double w_dfp = -1.0;
double c_dfp = -1.0;
char *path;
char *exclude_device;
char *units;
uintmax_t mult = 1024 * 1024;
@ -140,6 +138,7 @@ int verbose = 0;
int erronly = FALSE;
int display_mntp = FALSE;
int exact_match = FALSE;
bool ignore_missing = false;
int freespace_ignore_reserved = FALSE;
int display_inodes_perfdata = FALSE;
char *warn_freespace_units = NULL;
@ -155,6 +154,7 @@ char *crit_usedinodes_percent = NULL;
char *warn_freeinodes_percent = NULL;
char *crit_freeinodes_percent = NULL;
int path_selected = FALSE;
bool path_ignored = false;
char *group = NULL;
struct stat *stat_buf;
struct name_list *seen = NULL;
@ -166,10 +166,12 @@ main (int argc, char **argv)
int result = STATE_UNKNOWN;
int disk_result = STATE_UNKNOWN;
char *output;
char *ignored;
char *details;
char *perf;
char *perf_ilabel;
char *preamble;
char *preamble = " - free space:";
char *ignored_preamble = " - ignored paths:";
char *flag_header;
int temp_result;
@ -181,8 +183,8 @@ main (int argc, char **argv)
char mountdir[32];
#endif
preamble = strdup (" - free space:");
output = strdup ("");
ignored = strdup ("");
details = strdup ("");
perf = strdup ("");
perf_ilabel = strdup ("");
@ -203,7 +205,7 @@ main (int argc, char **argv)
/* If a list of paths has not been selected, find entire
mount list and create list of paths
*/
if (path_selected == FALSE) {
if (path_selected == FALSE && path_ignored == false) {
for (me = mount_list; me; me = me->me_next) {
if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
path = np_add_parameter(&path_select_list, me->me_mountdir);
@ -213,17 +215,40 @@ main (int argc, char **argv)
set_all_thresholds(path);
}
}
np_set_best_match(path_select_list, mount_list, exact_match);
if (path_ignored == false) {
np_set_best_match(path_select_list, mount_list, exact_match);
}
/* Error if no match found for specified paths */
temp_list = path_select_list;
while (temp_list) {
if (! temp_list->best_match) {
die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
while (path_select_list) {
if (! path_select_list->best_match && ignore_missing == true) {
/* If the first element will be deleted, the temp_list must be updated with the new start address as well */
if (path_select_list == temp_list) {
temp_list = path_select_list->name_next;
}
/* Add path argument to list of ignored paths to inform about missing paths being ignored and not alerted */
xasprintf (&ignored, "%s %s;", ignored, path_select_list->name);
/* Delete the path from the list so that it is not stat-checked later in the code. */
path_select_list = np_del_parameter(path_select_list, path_select_list->name_prev);
} else if (! path_select_list->best_match) {
/* Without --ignore-missing option, exit with Critical state. */
die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), path_select_list->name);
} else {
/* Continue jumping through the list */
path_select_list = path_select_list->name_next;
}
}
temp_list = temp_list->name_next;
path_select_list = temp_list;
if (! path_select_list && ignore_missing == true) {
result = STATE_OK;
if (verbose >= 2) {
printf ("None of the provided paths were found\n");
}
}
/* Process for every path in list */
@ -242,6 +267,10 @@ main (int argc, char **argv)
me = path->best_match;
if (!me) {
continue;
}
#ifdef __CYGWIN__
if (strncmp(path->name, "/cygdrive/", 10) != 0 || strlen(path->name) > 11)
continue;
@ -260,14 +289,18 @@ main (int argc, char **argv)
if (path->group == NULL) {
/* Skip remote filesystems if we're not interested in them */
if (me->me_remote && show_local_fs) {
if (stat_remote_fs)
stat_path(path);
if (stat_remote_fs) {
if (!stat_path(path) && ignore_missing == true) {
result = STATE_OK;
xasprintf (&ignored, "%s %s;", ignored, path->name);
}
}
continue;
/* Skip pseudo fs's if we haven't asked for all fs's */
} else if (me->me_dummy && !show_all_fs) {
continue;
/* Skip excluded fstypes */
} else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
} else if (fs_exclude_list && np_find_regmatch (fs_exclude_list, me->me_type)) {
continue;
/* Skip excluded fs's */
} else if (dp_exclude_list &&
@ -275,12 +308,18 @@ main (int argc, char **argv)
np_find_name (dp_exclude_list, me->me_mountdir))) {
continue;
/* Skip not included fstypes */
} else if (fs_include_list && !np_find_name (fs_include_list, me->me_type)) {
} else if (fs_include_list && !np_find_regmatch(fs_include_list, me->me_type)) {
continue;
}
}
stat_path(path);
if (!stat_path(path)) {
if (ignore_missing == true) {
result = STATE_OK;
xasprintf (&ignored, "%s %s;", ignored, path->name);
}
continue;
}
get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
if (fsp.fsu_blocks && strcmp ("none", me->me_mountdir)) {
@ -411,8 +450,12 @@ main (int argc, char **argv)
if (verbose >= 2)
xasprintf (&output, "%s%s", output, details);
if (strcmp(output, "") == 0 && ! erronly) {
preamble = "";
xasprintf (&output, " - No disks were found for provided parameters;");
}
printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf);
printf ("DISK %s%s%s%s%s|%s\n", state_text (result), ((erronly && result==STATE_OK)) ? "" : preamble, output, (strcmp(ignored, "") == 0) ? "" : ignored_preamble, ignored, perf);
return result;
}
@ -481,6 +524,7 @@ process_arguments (int argc, char **argv)
{"ignore-ereg-partition", required_argument, 0, 'i'},
{"ignore-eregi-path", required_argument, 0, 'I'},
{"ignore-eregi-partition", required_argument, 0, 'I'},
{"ignore-missing", no_argument, 0, IGNORE_MISSING},
{"local", no_argument, 0, 'l'},
{"stat-remote-fs", no_argument, 0, 'L'},
{"iperfdata", no_argument, 0, 'P'},
@ -499,7 +543,7 @@ process_arguments (int argc, char **argv)
if (argc < 2)
return ERROR;
np_add_name(&fs_exclude_list, "iso9660");
np_add_regex(&fs_exclude_list, "iso9660", REG_EXTENDED);
for (c = 1; c < argc; c++)
if (strcmp ("-to", argv[c]) == 0)
@ -540,7 +584,7 @@ process_arguments (int argc, char **argv)
/* Awful mistake where the range values do not make sense. Normally,
you alert if the value is within the range, but since we are using
freespace, we have to alert if outside the range. Thus we artifically
freespace, we have to alert if outside the range. Thus we artificially
force @ at the beginning of the range, so that it is backwards compatible
*/
case 'c': /* critical threshold */
@ -579,21 +623,36 @@ process_arguments (int argc, char **argv)
if (! strcasecmp (optarg, "bytes")) {
mult = (uintmax_t)1;
units = strdup ("B");
} else if ( (! strcmp (optarg, "kB")) || (!strcmp(optarg, "KiB")) ) {
} else if (!strcmp(optarg, "KiB")) {
mult = (uintmax_t)1024;
units = strdup ("kiB");
} else if ( (! strcmp (optarg, "MB")) || (!strcmp(optarg, "MiB")) ) {
units = strdup ("KiB");
} else if (! strcmp (optarg, "kB")) {
mult = (uintmax_t)1000;
units = strdup ("kB");
} else if (!strcmp(optarg, "MiB")) {
mult = (uintmax_t)1024 * 1024;
units = strdup ("MiB");
} else if ( (! strcmp (optarg, "GB")) || (!strcmp(optarg, "GiB")) ) {
} else if (! strcmp (optarg, "MB")) {
mult = (uintmax_t)1000 * 1000;
units = strdup ("MB");
} else if (!strcmp(optarg, "GiB")) {
mult = (uintmax_t)1024 * 1024 * 1024;
units = strdup ("GiB");
} else if ( (! strcmp (optarg, "TB")) || (!strcmp(optarg, "TiB")) ) {
} else if (! strcmp (optarg, "GB")){
mult = (uintmax_t)1000 * 1000 * 1000;
units = strdup ("GB");
} else if (!strcmp(optarg, "TiB")) {
mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
units = strdup ("TiB");
} else if ( (! strcmp (optarg, "PB")) || (!strcmp(optarg, "PiB")) ) {
} else if (! strcmp (optarg, "TB")) {
mult = (uintmax_t)1000 * 1000 * 1000 * 1000;
units = strdup ("TB");
} else if (!strcmp(optarg, "PiB")) {
mult = (uintmax_t)1024 * 1024 * 1024 * 1024 * 1024;
units = strdup ("PiB");
} else if (! strcmp (optarg, "PB")){
mult = (uintmax_t)1000 * 1000 * 1000 * 1000 * 1000;
units = strdup ("PB");
} else {
die (STATE_UNKNOWN, _("unit type %s not known\n"), optarg);
}
@ -632,12 +691,19 @@ process_arguments (int argc, char **argv)
/* add parameter if not found. overwrite thresholds if path has already been added */
if (! (se = np_find_parameter(path_select_list, optarg))) {
se = np_add_parameter(&path_select_list, optarg);
if (stat(optarg, &stat_buf[0]) && ignore_missing == true) {
path_ignored = true;
break;
}
}
se->group = group;
set_all_thresholds(se);
/* With autofs, it is required to stat() the path before re-populating the mount_list */
stat_path(se);
if (!stat_path(se)) {
break;
}
/* NB: We can't free the old mount_list "just like that": both list pointers and struct
* pointers are copied around. One of the reason it wasn't done yet is that other parts
* of check_disk need the same kind of cleanup so it'd better be done as a whole */
@ -650,10 +716,18 @@ process_arguments (int argc, char **argv)
np_add_name(&dp_exclude_list, optarg);
break;
case 'X': /* exclude file system type */
np_add_name(&fs_exclude_list, optarg);
err = np_add_regex(&fs_exclude_list, optarg, REG_EXTENDED);
if (err != 0) {
regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER);
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
}
break;
case 'N': /* include file system type */
np_add_name(&fs_include_list, optarg);
err = np_add_regex(&fs_include_list, optarg, REG_EXTENDED);
if (err != 0) {
regerror (err, &fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER);
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
}
break;
case 'v': /* verbose */
verbose++;
@ -718,6 +792,9 @@ process_arguments (int argc, char **argv)
cflags = default_cflags;
break;
case IGNORE_MISSING:
ignore_missing = true;
break;
case 'A':
optarg = strdup(".*");
// Intentional fallthrough
@ -729,7 +806,7 @@ process_arguments (int argc, char **argv)
crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R\n"));
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--all)\n"));
}
err = regcomp(&re, optarg, cflags);
@ -753,7 +830,11 @@ process_arguments (int argc, char **argv)
}
}
if (!fnd)
if (!fnd && ignore_missing == true) {
path_ignored = true;
/* path_selected = TRUE;*/
break;
} else if (!fnd)
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
_("Regular expression did not match any path or disk"), optarg);
@ -813,7 +894,7 @@ process_arguments (int argc, char **argv)
if (crit_usedspace_percent == NULL && argc > c && is_intnonneg (argv[c]))
crit_usedspace_percent = argv[c++];
if (argc > c && path == NULL) {
if (argc > c) {
se = np_add_parameter(&path_select_list, strdup(argv[c++]));
path_selected = TRUE;
set_all_thresholds(se);
@ -923,22 +1004,33 @@ print_help (void)
printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
printf (" %s\n", "--ignore-missing");
printf (" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible."));
printf (" %s\n", _("(Provide this option before -p / -r / --ereg-path if used)"));
printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
printf (" %s\n", "-u, --units=STRING");
printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
printf (UT_VERBOSE);
printf (" %s\n", "-X, --exclude-type=TYPE");
printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
printf (" %s\n", "-N, --include-type=TYPE");
printf (" %s\n", _("Check only filesystems of indicated type (may be repeated)"));
printf (" %s\n", "-X, --exclude-type=TYPE_REGEX");
printf (" %s\n", _("Ignore all filesystems of types matching given regex(7) (may be repeated)"));
printf (" %s\n", "-N, --include-type=TYPE_REGEX");
printf (" %s\n", _("Check only filesystems where the type matches this given regex(7) (may be repeated)"));
printf ("\n");
printf ("%s\n", _("General usage hints:"));
printf (" %s\n", _("- Arguments are positional! \"-w 5 -c 1 -p /foo -w6 -c2 -p /bar\" is not the same as"));
printf (" %s\n", _("\"-w 5 -c 1 -p /bar w6 -c2 -p /foo\"."));
printf (" %s\n", _("- The syntax is broadly: \"{thresholds a} {paths a} -C {thresholds b} {thresholds b} ...\""));
printf ("\n");
printf ("%s\n", _("Examples:"));
printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /");
printf (" %s\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB"));
printf (" %s\n\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB"));
printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -g sidDATA -r '^/oracle/SID/data.*$'");
printf (" %s\n", _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex"));
printf (" %s\n", _("are grouped which means the freespace thresholds are applied to all disks together"));
printf (" %s\n\n", _("are grouped which means the freespace thresholds are applied to all disks together"));
printf (" %s\n", "check_disk -w 100 -c 50 -C -w 1000 -c 500 -p /foo -C -w 5% -c 3% -p /bar");
printf (" %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M"));
@ -951,12 +1043,12 @@ void
print_usage (void)
{
printf ("%s\n", _("Usage:"));
printf (" %s {-w absolute_limit |-w percentage_limit% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit% | -K inode_percentage_limit } {-p path | -x device}\n", progname);
printf (" %s {-w absolute_limit |-w percentage_limit%% | -W inode_percentage_limit } {-c absolute_limit|-c percentage_limit%% | -K inode_percentage_limit } {-p path | -x device}\n", progname);
printf ("[-C] [-E] [-e] [-f] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type]\n");
printf ("[-t timeout] [-u unit] [-v] [-X type_regex] [-N type]\n");
}
void
bool
stat_path (struct parameter_list *p)
{
/* Stat entry to check that dir exists and is accessible */
@ -965,9 +1057,14 @@ stat_path (struct parameter_list *p)
if (stat (p->name, &stat_buf[0])) {
if (verbose >= 3)
printf("stat failed on %s\n", p->name);
printf("DISK %s - ", _("CRITICAL"));
die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
if (ignore_missing == true) {
return false;
} else {
printf("DISK %s - ", _("CRITICAL"));
die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
}
}
return true;
}
@ -987,7 +1084,8 @@ get_stats (struct parameter_list *p, struct fs_usage *fsp) {
continue;
#endif
if (p_list->group && ! (strcmp(p_list->group, p->group))) {
stat_path(p_list);
if (! stat_path(p_list))
continue;
get_fs_usage (p_list->best_match->me_mountdir, p_list->best_match->me_devname, &tmpfsp);
get_path_stats(p_list, &tmpfsp);
if (verbose >= 3)
@ -1045,7 +1143,7 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
p->available_to_root = fsp->fsu_bfree;
p->used = fsp->fsu_blocks - fsp->fsu_bfree;
if (freespace_ignore_reserved) {
/* option activated : we substract the root-reserved space from the total */
/* option activated : we subtract the root-reserved space from the total */
p->total = fsp->fsu_blocks - p->available_to_root + p->available;
} else {
/* default behaviour : take all the blocks into account */
@ -1056,11 +1154,11 @@ get_path_stats (struct parameter_list *p, struct fs_usage *fsp) {
p->dfree_units = p->available*fsp->fsu_blocksize/mult;
p->dtotal_units = p->total*fsp->fsu_blocksize/mult;
/* Free file nodes. Not sure the workaround is required, but in case...*/
p->inodes_free = fsp->fsu_favail > fsp->fsu_ffree ? 0 : fsp->fsu_favail;
p->inodes_free = fsp->fsu_ffree;
p->inodes_free_to_root = fsp->fsu_ffree; /* Free file nodes for root. */
p->inodes_used = fsp->fsu_files - fsp->fsu_ffree;
if (freespace_ignore_reserved) {
/* option activated : we substract the root-reserved inodes from the total */
/* option activated : we subtract the root-reserved inodes from the total */
/* not all OS report fsp->fsu_favail, only the ones with statvfs syscall */
/* for others, fsp->fsu_ffree == fsp->fsu_favail */
p->inodes_total = fsp->fsu_files - p->inodes_free_to_root + p->inodes_free;

View file

@ -75,7 +75,7 @@ main (int argc, char **argv)
{
char *command_line = NULL;
char input_buffer[MAX_INPUT_BUFFER];
char *address = NULL; /* comma seperated str with addrs/ptrs (sorted) */
char *address = NULL; /* comma separated str with addrs/ptrs (sorted) */
char **addresses = NULL;
int n_addresses = 0;
char *msg = NULL;

View file

@ -73,7 +73,7 @@ int wrta_p = FALSE;
int
main (int argc, char **argv)
{
/* normaly should be int result = STATE_UNKNOWN; */
/* normally should be int result = STATE_UNKNOWN; */
int status = STATE_UNKNOWN;
int result = 0;
@ -354,6 +354,7 @@ process_arguments (int argc, char **argv)
break;
case 'I': /* sourceip */
sourceif = strscpy (sourceif, optarg);
break;
case '4': /* IPv4 only */
address_family = AF_INET;
break;

View file

@ -353,6 +353,7 @@ process_arguments (int argc, char **argv)
usage2 (_("Port must be a positive short integer"), optarg);
else
port = atoi(optarg);
break;
case 'D': /* disable paper out check*/
check_paper_out = 0;
break;

View file

@ -198,7 +198,7 @@ test_file (char *path)
/*
* process command-line arguments
* returns true on succes, false otherwise
* returns true on success, false otherwise
*/
bool process_arguments (int argc, char **argv)
{
@ -498,6 +498,7 @@ bool process_arguments (int argc, char **argv)
break;
case 'R': /* regex */
cflags |= REG_ICASE;
// fall through
case 'r': /* regex */
strncpy (regexp, optarg, MAX_RE_SIZE - 1);
regexp[MAX_RE_SIZE - 1] = 0;
@ -1093,7 +1094,7 @@ check_http (void)
microsec_firstbyte = deltime (tv_temp);
elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6;
}
while (pos = memchr(buffer, '\0', i)) {
while ((pos = memchr(buffer, '\0', i))) {
/* replace nul character with a blank */
*pos = ' ';
}
@ -1278,7 +1279,7 @@ check_http (void)
regmatch_t chre_pmatch[1]; // We actually do not care about this, since we only want to know IF it was found
if (regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) {
if (!no_body && regexec(&chunked_header_regex, header, 1, chre_pmatch, 0) == 0) {
if (verbose) {
printf("Found chunked content\n");
}
@ -1391,7 +1392,6 @@ char *unchunk_content(const char *content) {
// https://en.wikipedia.org/wiki/Chunked_transfer_encoding
// https://www.rfc-editor.org/rfc/rfc7230#section-4.1
char *result = NULL;
size_t content_length = strlen(content);
char *start_of_chunk;
char* end_of_chunk;
long size_of_chunk;
@ -1462,7 +1462,13 @@ char *unchunk_content(const char *content) {
memcpy(result + (overall_size - size_of_chunk), start_of_chunk, size_of_chunk);
}
result[overall_size] = '\0';
if (overall_size == 0 && result == NULL) {
// We might just have received the end chunk without previous content, so result is never allocated
result = calloc(1, sizeof(char));
// No error handling here, we can only return NULL anyway
} else {
result[overall_size] = '\0';
}
return result;
}
@ -1879,7 +1885,7 @@ print_usage (void)
printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
printf (" [-J <client certificate file>] [-K <private key>]\n");
printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n");
printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n");
printf (" [-b proxy_auth] [-f <ok|warning|critical|follow|sticky|stickyport>]\n");
printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n");
printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n");
printf (" [-A string] [-k string] [-S <version>] [--sni]\n");

View file

@ -97,9 +97,6 @@ main (int argc, char *argv[])
int tls;
int version=3;
/* for entry counting */
LDAPMessage *next_entry;
int status_entries = STATE_OK;
int num_entries = 0;
@ -222,7 +219,7 @@ main (int argc, char *argv[])
/* reset the alarm handler */
alarm (0);
/* calcutate the elapsed time and compare to thresholds */
/* calculate the elapsed time and compare to thresholds */
microsec = deltime (tv);
elapsed_time = (double)microsec / 1.0e6;

View file

@ -107,7 +107,7 @@ main (int argc, char **argv)
int i;
long numcpus;
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about uninitialized arrays */
#ifndef HAVE_GETLOADAVG
char input_buffer[MAX_INPUT_BUFFER];
# ifdef HAVE_PROC_LOADAVG

View file

@ -34,7 +34,7 @@ const char *progname = "check_mysql";
const char *copyright = "1999-2011";
const char *email = "devel@monitoring-plugins.org";
#define SLAVERESULTSIZE 70
#define SLAVERESULTSIZE 96
#include "common.h"
#include "utils.h"
@ -89,6 +89,8 @@ static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
"Uptime"
};
#define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'"
thresholds *my_threshold = NULL;
int process_arguments (int, char **);
@ -108,7 +110,7 @@ main (int argc, char **argv)
char *result = NULL;
char *error = NULL;
char slaveresult[SLAVERESULTSIZE];
char slaveresult[SLAVERESULTSIZE] = { 0 };
char* perf;
perf = strdup ("");
@ -138,7 +140,10 @@ main (int argc, char **argv)
mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers);
/* establish a connection to the server and error checking */
if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
if (ignore_auth && mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR)
/* Depending on internally-selected auth plugin MySQL might return */
/* ER_ACCESS_DENIED_NO_PASSWORD_ERROR or ER_ACCESS_DENIED_ERROR. */
/* Semantically these errors are the same. */
if (ignore_auth && (mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR || mysql_errno (&mysql) == ER_ACCESS_DENIED_NO_PASSWORD_ERROR))
{
printf("MySQL OK - Version: %s (protocol %d)\n",
mysql_get_server_info(&mysql),
@ -275,11 +280,30 @@ main (int argc, char **argv)
/* Save slave status in slaveresult */
snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown");
/* Raise critical error if SQL THREAD or IO THREAD are stopped */
/* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no mysqldump threads running */
if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) {
mysql_free_result (res);
mysql_close (&mysql);
die (STATE_CRITICAL, "%s\n", slaveresult);
MYSQL_RES *res_mysqldump;
MYSQL_ROW row_mysqldump;
unsigned int mysqldump_threads = 0;
if (mysql_query (&mysql, MYSQLDUMP_THREADS_QUERY) == 0) {
/* store the result */
if ( (res_mysqldump = mysql_store_result (&mysql)) != NULL) {
if (mysql_num_rows(res_mysqldump) == 1) {
if ( (row_mysqldump = mysql_fetch_row (res_mysqldump)) != NULL) {
mysqldump_threads = atoi(row_mysqldump[0]);
}
}
/* free the result */
mysql_free_result (res_mysqldump);
}
mysql_close (&mysql);
}
if (mysqldump_threads == 0) {
die (STATE_CRITICAL, "%s\n", slaveresult);
} else {
strncat(slaveresult, " Mysqldump: in progress", SLAVERESULTSIZE-1);
}
}
if (verbose >=3) {
@ -291,7 +315,7 @@ main (int argc, char **argv)
}
/* Check Seconds Behind against threshold */
if ((seconds_behind_field != -1) && (strcmp (row[seconds_behind_field], "NULL") != 0)) {
if ((seconds_behind_field != -1) && (row[seconds_behind_field] != NULL && strcmp (row[seconds_behind_field], "NULL") != 0)) {
double value = atof(row[seconds_behind_field]);
int status;
@ -551,7 +575,7 @@ print_help (void)
printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds"));
printf (" %s\n", _("behind master"));
printf (" %s\n", "-l, --ssl");
printf (" %s\n", _("Use ssl encryptation"));
printf (" %s\n", _("Use ssl encryption"));
printf (" %s\n", "-C, --ca-cert=STRING");
printf (" %s\n", _("Path to CA signing the cert"));
printf (" %s\n", "-a, --cert=STRING");

View file

@ -341,7 +341,7 @@ int main(int argc, char **argv){
2) If the counter you're going to measure is percent-based, the code will detect
the percent sign in its name and will attribute minimum (0%) and maximum (100%)
values automagically, as well the ¨%" sign to graph units.
values automagically, as well the "%" sign to graph units.
3) OTOH, if the counter is "absolute", you'll have to provide the following
the counter unit - that is, the dimensions of the counter you're getting. Examples:

View file

@ -10,7 +10,7 @@
*
* This file contains the check_ntp plugin
*
* This plugin to check ntp servers independant of any commandline
* This plugin to check ntp servers independent of any commandline
* programs or external libraries.
*
*
@ -79,7 +79,7 @@ typedef struct {
/* this structure holds data about results from querying offset from a peer */
typedef struct {
time_t waiting; /* ts set when we started waiting for a response */
int num_responses; /* number of successfully recieved responses */
int num_responses; /* number of successfully received responses */
uint8_t stratum; /* copied verbatim from the ntp_message */
double rtdelay; /* converted from the ntp_message */
double rtdisp; /* converted from the ntp_message */
@ -100,7 +100,7 @@ typedef struct {
/* NB: not necessarily NULL terminated! */
} ntp_control_message;
/* this is an association/status-word pair found in control packet reponses */
/* this is an association/status-word pair found in control packet responses */
typedef struct {
uint16_t assoc;
uint16_t status;
@ -486,7 +486,7 @@ double offset_request(const char *host, int *status){
}
/* cleanup */
/* FIXME: Not closing the socket to avoid re-use of the local port
/* FIXME: Not closing the socket to avoid reuse of the local port
* which can cause old NTP packets to be read instead of NTP control
* packets in jitter_request(). THERE MUST BE ANOTHER WAY...
* for(j=0; j<num_hosts; j++){ close(socklist[j]); } */
@ -575,7 +575,7 @@ double jitter_request(int *status){
}
}
}
if(verbose) printf("%d candiate peers available\n", num_candidates);
if(verbose) printf("%d candidate peers available\n", num_candidates);
if(verbose && syncsource_found) printf("synchronization source found\n");
if(! syncsource_found){
*status = STATE_UNKNOWN;
@ -597,7 +597,7 @@ double jitter_request(int *status){
/* By spec, putting the variable name "jitter" in the request
* should cause the server to provide _only_ the jitter value.
* thus reducing net traffic, guaranteeing us only a single
* datagram in reply, and making intepretation much simpler
* datagram in reply, and making interpretation much simpler
*/
/* Older servers doesn't know what jitter is, so if we get an
* error on the first pass we redo it with "dispersion" */

View file

@ -86,7 +86,7 @@ typedef struct {
/* NB: not necessarily NULL terminated! */
} ntp_control_message;
/* this is an association/status-word pair found in control packet reponses */
/* this is an association/status-word pair found in control packet responses */
typedef struct {
uint16_t assoc;
uint16_t status;
@ -189,7 +189,7 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
}
/* This function does all the actual work; roughly here's what it does
* beside setting the offest, jitter and stratum passed as argument:
* beside setting the offset, jitter and stratum passed as argument:
* - offset can be negative, so if it cannot get the offset, offset_result
* is set to UNKNOWN, otherwise OK.
* - jitter and stratum are set to -1 if they cannot be retrieved so any
@ -199,7 +199,7 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
* status is pretty much useless as syncsource_found is a global variable
* used later in main to check is the server was synchronized. It works
* so I left it alone */
int ntp_request(const char *host, double *offset, int *offset_result, double *jitter, int *stratum, int *num_truechimers){
int ntp_request(double *offset, int *offset_result, double *jitter, int *stratum, int *num_truechimers){
int conn=-1, i, npeers=0, num_candidates=0;
double tmp_offset = 0;
int min_peer_sel=PEER_INCLUDED;
@ -306,7 +306,7 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji
/* Putting the wanted variable names in the request
* cause the server to provide _only_ the requested values.
* thus reducing net traffic, guaranteeing us only a single
* datagram in reply, and making intepretation much simpler
* datagram in reply, and making interpretation much simpler
*/
/* Older servers doesn't know what jitter is, so if we get an
* error on the first pass we redo it with "dispersion" */
@ -585,8 +585,8 @@ int main(int argc, char *argv[]){
/* set socket timeout */
alarm (socket_timeout);
/* This returns either OK or WARNING (See comment preceeding ntp_request) */
result = ntp_request(server_address, &offset, &offset_result, &jitter, &stratum, &num_truechimers);
/* This returns either OK or WARNING (See comment preceding ntp_request) */
result = ntp_request(&offset, &offset_result, &jitter, &stratum, &num_truechimers);
if(offset_result == STATE_UNKNOWN) {
/* if there's no sync peer (this overrides ntp_request output): */

View file

@ -81,7 +81,7 @@ typedef struct {
/* this structure holds data about results from querying offset from a peer */
typedef struct {
time_t waiting; /* ts set when we started waiting for a response */
int num_responses; /* number of successfully recieved responses */
int num_responses; /* number of successfully received responses */
uint8_t stratum; /* copied verbatim from the ntp_message */
double rtdelay; /* converted from the ntp_message */
double rtdisp; /* converted from the ntp_message */

View file

@ -1668,7 +1668,7 @@ void print_help(void)
printf ("\n");
printf ("%s\n", _("Notes:"));
printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"));
printf (" %s\n", _("- This plugin requires that the MRTGEXT.NLM file from James Drews' MRTG"));
printf (" %s\n", _(" extension for NetWare be loaded on the Novell servers you wish to check."));
printf (" %s\n", _(" (available from http://www.engr.wisc.edu/~drews/mrtg/)"));
printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds"));

View file

@ -93,7 +93,7 @@ int verbose = 0;
/******************************************************************************
The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
tags in the comments. With in the tags, the XML is assembled sequentially.
You can define entities in tags. You also have all the #defines available as
entities.
@ -517,7 +517,10 @@ print_help (void)
printf (" %s\n", _("connecting to the server. The result from the query has to be numeric."));
printf (" %s\n", _("Multiple SQL commands, separated by semicolon, are allowed but the result "));
printf (" %s\n", _("of the last command is taken into account only. The value of the first"));
printf (" %s\n\n", _("column in the first row is used as the check result."));
printf (" %s\n", _("column in the first row is used as the check result. If a second column is"));
printf (" %s\n", _("present in the result set, this is added to the plugin output with a"));
printf (" %s\n", _("prefix of \"Extra Info:\". This information can be displayed in the system"));
printf (" %s\n\n", _("executing the plugin."));
printf (" %s\n", _("See the chapter \"Monitoring Database Activity\" of the PostgreSQL manual"));
printf (" %s\n\n", _("for details about how to access internal statistics of the database server."));
@ -557,6 +560,7 @@ do_query (PGconn *conn, char *query)
PGresult *res;
char *val_str;
char *extra_info;
double value;
char *endptr = NULL;
@ -621,6 +625,12 @@ do_query (PGconn *conn, char *query)
printf ("|query=%f;%s;%s;;\n", value,
query_warning ? query_warning : "",
query_critical ? query_critical : "");
if (PQnfields (res) > 1) {
extra_info = PQgetvalue (res, 0, 1);
if (extra_info != NULL) {
printf ("Extra Info: %s\n", extra_info);
}
}
return my_status;
}

View file

@ -70,6 +70,7 @@ int options = 0; /* bitmask of filter criteria to test against */
#define PCPU 256
#define ELAPSED 512
#define EREG_ARGS 1024
#define EXCLUDE_PROGS 2048
#define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads:
ppid of procs are compared to pid of this proc*/
@ -93,6 +94,9 @@ int rss;
float pcpu;
char *statopts;
char *prog;
char *exclude_progs;
char **exclude_progs_arr = NULL;
char exclude_progs_counter = 0;
char *args;
char *input_filename = NULL;
regex_t re_args;
@ -237,8 +241,9 @@ main (int argc, char **argv)
/* Ignore self */
if ((usepid && mypid == procpid) ||
(!usepid && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino) ||
(ret == -1 && errno == ENOENT))) {
( ((!usepid) && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino)) ||
(ret == -1 && errno == ENOENT))
) {
if (verbose >= 3)
printf("not considering - is myself or gone\n");
continue;
@ -250,7 +255,26 @@ main (int argc, char **argv)
continue;
}
/* filter kernel threads (childs of KTHREAD_PARENT)*/
/* Ignore excluded processes by name */
if(options & EXCLUDE_PROGS) {
int found = 0;
int i = 0;
for(i=0; i < (exclude_progs_counter); i++) {
if(!strcmp(procprog, exclude_progs_arr[i])) {
found = 1;
}
}
if(found == 0) {
resultsum |= EXCLUDE_PROGS;
} else
{
if(verbose >= 3)
printf("excluding - by ignorelist\n");
}
}
/* filter kernel threads (children of KTHREAD_PARENT)*/
/* TODO adapt for other OSes than GNU/Linux
sorry for not doing that, but I've no other OSes to test :-( */
if (kthread_filter == 1) {
@ -409,6 +433,7 @@ process_arguments (int argc, char **argv)
{"input-file", required_argument, 0, CHAR_MAX+2},
{"no-kthreads", required_argument, 0, 'k'},
{"traditional-filter", no_argument, 0, 'T'},
{"exclude-process", required_argument, 0, 'X'},
{0, 0, 0, 0}
};
@ -417,7 +442,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T",
c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T:X:",
longopts, &option);
if (c == -1 || c == EOF)
@ -490,6 +515,23 @@ process_arguments (int argc, char **argv)
prog);
options |= PROG;
break;
case 'X':
if(exclude_progs)
break;
else
exclude_progs = optarg;
xasprintf (&fmt, _("%s%sexclude progs '%s'"), (fmt ? fmt : ""), (options ? ", " : ""),
exclude_progs);
char *p = strtok(exclude_progs, ",");
while(p){
exclude_progs_arr = realloc(exclude_progs_arr, sizeof(char*) * ++exclude_progs_counter);
exclude_progs_arr[exclude_progs_counter-1] = p;
p = strtok(NULL, ",");
}
options |= EXCLUDE_PROGS;
break;
case 'a': /* args (full path name with args) */
/* TODO: allow this to be passed in with --metric */
if (args)
@ -745,6 +787,8 @@ print_help (void)
printf (" %s\n", _("Only scan for processes with args that contain the regex STRING."));
printf (" %s\n", "-C, --command=COMMAND");
printf (" %s\n", _("Only scan for exact matches of COMMAND (without path)."));
printf (" %s\n", "-X, --exclude-process");
printf (" %s\n", _("Exclude processes which match this comma separated list"));
printf (" %s\n", "-k, --no-kthreads");
printf (" %s\n", _("Only scan for non kernel threads (works on Linux only)."));
@ -786,5 +830,5 @@ print_usage (void)
printf ("%s\n", _("Usage:"));
printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname);
printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n");
printf (" [-C command] [-k] [-t timeout] [-v]\n");
printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n");
}

View file

@ -97,7 +97,7 @@ int verbose = FALSE;
/******************************************************************************
The (psuedo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
The (pseudo?)literate programming XML is contained within \@\@\- <XML> \-\@\@
tags in the comments. With in the tags, the XML is assembled sequentially.
You can define entities in tags. You also have all the #defines available as
entities.
@ -155,7 +155,11 @@ main (int argc, char **argv)
{
struct sockaddr_storage ss;
char name[HOST_NAME_MAX];
#ifdef RC_BUFFER_LEN
char msg[RC_BUFFER_LEN];
#else
char msg[BUFFER_LEN];
#endif
SEND_DATA data;
int result = STATE_UNKNOWN;
uint32_t client_id, service;
@ -377,7 +381,7 @@ print_help (void)
printf ("\n");
printf ("%s\n", _("This plugin tests a RADIUS server to see if it is accepting connections."));
printf ("%s\n", _("The server to test must be specified in the invocation, as well as a user"));
printf ("%s\n", _("name and password. A configuration file may also be present. The format of"));
printf ("%s\n", _("name and password. A configuration file must be present. The format of"));
printf ("%s\n", _("the configuration file is described in the radiusclient library sources."));
printf ("%s\n", _("The password option presents a substantial security issue because the"));
printf ("%s\n", _("password can possibly be determined by careful watching of the command line"));

View file

@ -178,7 +178,7 @@ main (int argc, char **argv)
/* watch for the REAL connection string */
result = recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0);
buffer[result] = '\0'; /* null terminate recieved buffer */
buffer[result] = '\0'; /* null terminate received buffer */
/* return a CRITICAL status if we couldn't read any data */
if (result == -1) {
@ -436,7 +436,7 @@ print_help (void)
printf ("\n");
printf ("%s\n", _("This plugin will attempt to open an RTSP connection with the host."));
printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return"));
printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return"));
printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful connects,"));
printf ("%s\n", _("but incorrect response messages from the host result in STATE_WARNING return"));
printf ("%s\n", _("values."));

View file

@ -3,7 +3,7 @@
* Monitoring check_smtp plugin
*
* License: GPL
* Copyright (c) 2000-2007 Monitoring Plugins Development Team
* Copyright (c) 2000-2023 Monitoring Plugins Development Team
*
* Description:
*
@ -42,16 +42,18 @@ const char *email = "devel@monitoring-plugins.org";
#ifdef HAVE_SSL
int check_cert = FALSE;
int days_till_exp_warn, days_till_exp_crit;
# define my_recv(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
# define my_send(buf, len) ((use_ssl && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
# define my_recv(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_read(buf, len) : read(sd, buf, len))
# define my_send(buf, len) (((use_starttls || use_ssl) && ssl_established) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0))
#else /* ifndef HAVE_SSL */
# define my_recv(buf, len) read(sd, buf, len)
# define my_send(buf, len) send(sd, buf, len, 0)
#endif
enum {
SMTP_PORT = 25
SMTP_PORT = 25,
SMTPS_PORT = 465
};
#define PROXY_PREFIX "PROXY TCP4 0.0.0.0 0.0.0.0 25 25\r\n"
#define SMTP_EXPECT "220"
#define SMTP_HELO "HELO "
#define SMTP_EHLO "EHLO "
@ -82,6 +84,7 @@ int eflags = 0;
int errcode, excode;
int server_port = SMTP_PORT;
int server_port_option = 0;
char *server_address = NULL;
char *server_expect = NULL;
char *mail_command = NULL;
@ -102,6 +105,9 @@ double critical_time = 0;
int check_critical_time = FALSE;
int verbose = 0;
int use_ssl = FALSE;
int use_starttls = FALSE;
int use_sni = FALSE;
short use_proxy_prefix = FALSE;
short use_ehlo = FALSE;
short use_lhlo = FALSE;
short ssl_established = 0;
@ -183,6 +189,26 @@ main (int argc, char **argv)
result = my_tcp_connect (server_address, server_port, &sd);
if (result == STATE_OK) { /* we connected */
/* If requested, send PROXY header */
if (use_proxy_prefix) {
if (verbose)
printf ("Sending header %s\n", PROXY_PREFIX);
my_send(PROXY_PREFIX, strlen(PROXY_PREFIX));
}
#ifdef HAVE_SSL
if (use_ssl) {
result = np_net_ssl_init_with_hostname(sd, (use_sni ? server_address : NULL));
if (result != STATE_OK) {
printf (_("CRITICAL - Cannot create SSL context.\n"));
close(sd);
np_net_ssl_cleanup();
return STATE_CRITICAL;
} else {
ssl_established = 1;
}
}
#endif
/* watch for the SMTP connection string and */
/* return a WARNING status if we couldn't read any data */
@ -195,7 +221,7 @@ main (int argc, char **argv)
xasprintf(&server_response, "%s", buffer);
/* send the HELO/EHLO command */
send(sd, helocmd, strlen(helocmd), 0);
my_send(helocmd, strlen(helocmd));
/* allow for response to helo command to reach us */
if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) {
@ -208,14 +234,14 @@ main (int argc, char **argv)
}
}
if(use_ssl && ! supports_tls){
if(use_starttls && ! supports_tls){
printf(_("WARNING - TLS not supported by server\n"));
smtp_quit();
return STATE_WARNING;
}
#ifdef HAVE_SSL
if(use_ssl) {
if(use_starttls) {
/* send the STARTTLS command */
send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0);
@ -225,7 +251,7 @@ main (int argc, char **argv)
smtp_quit();
return STATE_UNKNOWN;
}
result = np_net_ssl_init(sd);
result = np_net_ssl_init_with_hostname(sd, (use_sni ? server_address : NULL));
if(result != STATE_OK) {
printf (_("CRITICAL - Cannot create SSL context.\n"));
close(sd);
@ -454,6 +480,10 @@ process_arguments (int argc, char **argv)
int c;
char* temp;
enum {
SNI_OPTION
};
int option = 0;
static struct option longopts[] = {
{"hostname", required_argument, 0, 'H'},
@ -475,9 +505,13 @@ process_arguments (int argc, char **argv)
{"use-ipv6", no_argument, 0, '6'},
{"help", no_argument, 0, 'h'},
{"lmtp", no_argument, 0, 'L'},
{"ssl", no_argument, 0, 's'},
{"tls", no_argument, 0, 's'},
{"starttls",no_argument,0,'S'},
{"sni", no_argument, 0, SNI_OPTION},
{"certificate",required_argument,0,'D'},
{"ignore-quit-failure",no_argument,0,'q'},
{"proxy",no_argument,0,'r'},
{0, 0, 0, 0}
};
@ -494,7 +528,7 @@ process_arguments (int argc, char **argv)
}
while (1) {
c = getopt_long (argc, argv, "+hVv46Lt:p:f:e:c:w:H:C:R:SD:F:A:U:P:q",
c = getopt_long (argc, argv, "+hVv46Lrt:p:f:e:c:w:H:C:R:sSD:F:A:U:P:q",
longopts, &option);
if (c == -1 || c == EOF)
@ -511,7 +545,7 @@ process_arguments (int argc, char **argv)
break;
case 'p': /* port */
if (is_intpos (optarg))
server_port = atoi (optarg);
server_port_option = atoi (optarg);
else
usage4 (_("Port must be a positive integer"));
break;
@ -616,11 +650,26 @@ process_arguments (int argc, char **argv)
#else
usage (_("SSL support not available - install OpenSSL and recompile"));
#endif
case 's':
/* ssl */
use_ssl = TRUE;
server_port = SMTPS_PORT;
break;
case 'S':
/* starttls */
use_ssl = TRUE;
use_starttls = TRUE;
use_ehlo = TRUE;
break;
case SNI_OPTION:
#ifdef HAVE_SSL
use_sni = TRUE;
#else
usage (_("SSL support not available - install OpenSSL and recompile"));
#endif
break;
case 'r':
use_proxy_prefix = TRUE;
break;
case 'L':
use_lhlo = TRUE;
break;
@ -667,6 +716,14 @@ process_arguments (int argc, char **argv)
if (from_arg==NULL)
from_arg = strdup(" ");
if (use_starttls && use_ssl) {
usage4 (_("Set either -s/--ssl/--tls or -S/--starttls"));
}
if (server_port_option != 0) {
server_port = server_port_option;
}
return validate_arguments ();
}
@ -819,11 +876,18 @@ print_help (void)
printf (" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")),
printf (" %s\n", "-F, --fqdn=STRING");
printf (" %s\n", _("FQDN used for HELO"));
printf (" %s\n", "-r, --proxy");
printf (" %s\n", _("Use PROXY protocol prefix for the connection."));
#ifdef HAVE_SSL
printf (" %s\n", "-D, --certificate=INTEGER[,INTEGER]");
printf (" %s\n", _("Minimum number of days a certificate has to be valid."));
printf (" %s\n", "-s, --ssl, --tls");
printf (" %s\n", _("Use SSL/TLS for the connection."));
printf (_(" Sets default port to %d.\n"), SMTPS_PORT);
printf (" %s\n", "-S, --starttls");
printf (" %s\n", _("Use STARTTLS for the connection."));
printf (" %s\n", "--sni");
printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)"));
#endif
printf (" %s\n", "-A, --authtype=STRING");
@ -844,7 +908,7 @@ print_help (void)
printf (UT_VERBOSE);
printf("\n");
printf ("%s\n", _("Successul connects return STATE_OK, refusals and timeouts return"));
printf ("%s\n", _("Successful connects return STATE_OK, refusals and timeouts return"));
printf ("%s\n", _("STATE_CRITICAL, other errors return STATE_UNKNOWN. Successful"));
printf ("%s\n", _("connects, but incorrect response messages from the host result in"));
printf ("%s\n", _("STATE_WARNING return values."));
@ -860,6 +924,6 @@ print_usage (void)
printf ("%s\n", _("Usage:"));
printf ("%s -H host [-p port] [-4|-6] [-e expect] [-C command] [-R response] [-f from addr]\n", progname);
printf ("[-A authtype -U authuser -P authpass] [-w warn] [-c crit] [-t timeout] [-q]\n");
printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-v] \n");
printf ("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-r] [--sni] [-v] \n");
}

View file

@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org";
#define DEFAULT_PRIV_PROTOCOL "DES"
#define DEFAULT_DELIMITER "="
#define DEFAULT_OUTPUT_DELIMITER " "
#define DEFAULT_BUFFER_SIZE 100
#define mark(a) ((a)!=0?"*":"")
@ -64,6 +65,7 @@ const char *email = "devel@monitoring-plugins.org";
#define L_RATE_MULTIPLIER CHAR_MAX+2
#define L_INVERT_SEARCH CHAR_MAX+3
#define L_OFFSET CHAR_MAX+4
#define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5
/* Gobble to string - stop incrementing c when c[0] match one of the
* characters in s */
@ -157,6 +159,9 @@ int perf_labels = 1;
char* ip_version = "";
double multiplier = 1.0;
char *fmtstr = "";
bool fmtstr_set = false;
char buffer[DEFAULT_BUFFER_SIZE];
bool ignore_mib_parsing_errors = false;
static char *fix_snmp_range(char *th)
{
@ -304,42 +309,55 @@ main (int argc, char **argv)
}
/* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */
command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *));
command_line[0] = snmpcmd;
command_line[1] = strdup ("-Le");
command_line[2] = strdup ("-t");
xasprintf (&command_line[3], "%d", timeout_interval);
command_line[4] = strdup ("-r");
xasprintf (&command_line[5], "%d", retries);
command_line[6] = strdup ("-m");
command_line[7] = strdup (miblist);
command_line[8] = "-v";
command_line[9] = strdup (proto);
unsigned index = 0;
command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *));
command_line[index++] = snmpcmd;
command_line[index++] = strdup ("-Le");
command_line[index++] = strdup ("-t");
xasprintf (&command_line[index++], "%d", timeout_interval);
command_line[index++] = strdup ("-r");
xasprintf (&command_line[index++], "%d", retries);
command_line[index++] = strdup ("-m");
command_line[index++] = strdup (miblist);
command_line[index++] = "-v";
command_line[index++] = strdup (proto);
xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s",
snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto);
if (ignore_mib_parsing_errors) {
command_line[index++] = "-Pe";
xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth);
}
for (i = 0; i < numcontext; i++) {
command_line[10 + i] = contextargs[i];
command_line[index++] = contextargs[i];
}
for (i = 0; i < numauthpriv; i++) {
command_line[10 + numcontext + i] = authpriv[i];
command_line[index++] = authpriv[i];
}
xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port);
xasprintf (&command_line[index++], "%s:%s", server_address, port);
/* This is just for display purposes, so it can remain a string */
xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s",
snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]",
server_address, port);
xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s",
cl_hidden_auth,
server_address,
port);
for (i = 0; i < numoids; i++) {
command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i];
command_line[index++] = oids[i];
xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
}
command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL;
command_line[index++] = NULL;
if (verbose)
if (verbose) {
printf ("%s\n", cl_hidden_auth);
}
/* Set signal handling and alarm */
if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) {
@ -420,7 +438,8 @@ main (int argc, char **argv)
}
else if (strstr (response, "INTEGER: ")) {
show = multiply (strstr (response, "INTEGER: ") + 9);
if (fmtstr != "") {
if (fmtstr_set) {
conv = fmtstr;
}
}
@ -594,8 +613,9 @@ main (int argc, char **argv)
len = sizeof(perfstr)-strlen(perfstr)-1;
strncat(perfstr, show, len>ptr-show ? ptr-show : len);
if (type)
if (strcmp(type, "") != 0) {
strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
}
if (warning_thresholds) {
strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1);
@ -706,6 +726,7 @@ process_arguments (int argc, char **argv)
{"ipv6", no_argument, 0, '6'},
{"multiplier", required_argument, 0, 'M'},
{"fmtstr", required_argument, 0, 'f'},
{"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS},
{0, 0, 0, 0}
};
@ -853,6 +874,7 @@ process_arguments (int argc, char **argv)
break;
case 'R': /* regex */
cflags = REG_ICASE;
// fall through
case 'r': /* regex */
cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
strncpy (regex_expect, optarg, sizeof (regex_expect) - 1);
@ -969,8 +991,11 @@ process_arguments (int argc, char **argv)
case 'f':
if (multiplier != 1.0) {
fmtstr=optarg;
fmtstr_set = true;
}
break;
case L_IGNORE_MIB_PARSING_ERRORS:
ignore_mib_parsing_errors = true;
}
}
@ -1169,33 +1194,33 @@ multiply (char *str)
double val;
char *conv = "%f";
if(multiplier == 1)
return(str);
if(verbose>2)
printf(" multiply input: %s\n", str);
val = strtod (str, &endptr);
if ((val == 0.0) && (endptr == str)) {
if(multiplier != 1) {
die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
}
return str;
die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
}
if(verbose>2)
printf(" multiply extracted double: %f\n", val);
val *= multiplier;
if (fmtstr != "") {
if (fmtstr_set) {
conv = fmtstr;
}
if (val == (int)val) {
sprintf(str, "%.0f", val);
snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val);
} else {
if(verbose>2)
printf(" multiply using format: %s\n", conv);
sprintf(str, conv, val);
snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val);
}
if(verbose>2)
printf(" multiply result: %s\n", str);
return str;
printf(" multiply result: %s\n", buffer);
return buffer;
}
@ -1272,7 +1297,7 @@ print_help (void)
printf (" %s\n", "--rate-multiplier");
printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute"));
printf (" %s\n", "--offset=OFFSET");
printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data"));
printf (" %s\n", _("Add/subtract the specified OFFSET to numeric sensor data"));
/* Tests Against Strings */
printf (" %s\n", "-s, --string=STRING");
@ -1304,6 +1329,9 @@ print_help (void)
printf (" %s\n", "-O, --perf-oids");
printf (" %s\n", _("Label performance data with OIDs instead of --label's"));
printf (" %s\n", "--ignore-mib-parsing-errors");
printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files"));
printf (UT_VERBOSE);
printf ("\n");

View file

@ -34,9 +34,6 @@ const char *email = "devel@monitoring-plugins.org";
#include "common.h"
#include "popen.h"
#include "utils.h"
#include <string.h>
#include <math.h>
#include <libintl.h>
#ifdef HAVE_DECL_SWAPCTL
# ifdef HAVE_SYS_PARAM_H
@ -181,7 +178,7 @@ main (int argc, char **argv)
# ifdef _AIX
if (!allswaps) {
xasprintf(&swap_command, "%s", "/usr/sbin/lsps -s");
xasprintf(&swap_format, "%s", "%f%*s %f");
xasprintf(&swap_format, "%s", "%lu%*s %lu");
conv_factor = 1;
}
# endif
@ -208,9 +205,9 @@ main (int argc, char **argv)
temp_buffer = strtok (input_buffer, " \n");
while (temp_buffer) {
if (strstr (temp_buffer, "blocks"))
sprintf (str, "%s %s", str, "%f");
sprintf (str, "%s %s", str, "%lu");
else if (strstr (temp_buffer, "dskfree"))
sprintf (str, "%s %s", str, "%f");
sprintf (str, "%s %s", str, "%lu");
else
sprintf (str, "%s %s", str, "%*s");
temp_buffer = strtok (NULL, " \n");
@ -555,7 +552,7 @@ validate_arguments (void)
}
else if ((warn.is_percentage == crit.is_percentage) && (warn.value < crit.value)) {
/* This is NOT triggered if warn and crit are different units, e.g warn is percentage
* and crit is absolut. We cannot determine the condition at this point since we
* and crit is absolute. We cannot determine the condition at this point since we
* dont know the value of total swap yet
*/
usage4(_("Warning should be more than critical"));

View file

@ -128,7 +128,7 @@ main (int argc, char **argv)
SERVICE[i] = toupper(SERVICE[i]);
}
/* set up a resonable buffer at first (will be realloc()'ed if
/* set up a reasonable buffer at first (will be realloc()'ed if
* user specifies other options) */
server_expect = calloc(sizeof(char *), 2);

View file

@ -89,7 +89,7 @@ char *ups_status;
int temp_output_c = 0;
int determine_status (void);
int get_ups_variable (const char *, char *, size_t);
int get_ups_variable (const char *, char *);
int process_arguments (int, char **);
int validate_arguments (void);
@ -189,7 +189,7 @@ main (int argc, char **argv)
}
/* get the ups utility voltage if possible */
res=get_ups_variable ("input.voltage", temp_buffer, sizeof (temp_buffer));
res=get_ups_variable ("input.voltage", temp_buffer);
if (res == NOSUCHVAR) supported_options &= ~UPS_UTILITY;
else if (res != OK)
return STATE_CRITICAL;
@ -224,7 +224,7 @@ main (int argc, char **argv)
}
/* get the ups battery percent if possible */
res=get_ups_variable ("battery.charge", temp_buffer, sizeof (temp_buffer));
res=get_ups_variable ("battery.charge", temp_buffer);
if (res == NOSUCHVAR) supported_options &= ~UPS_BATTPCT;
else if ( res != OK)
return STATE_CRITICAL;
@ -253,7 +253,7 @@ main (int argc, char **argv)
}
/* get the ups load percent if possible */
res=get_ups_variable ("ups.load", temp_buffer, sizeof (temp_buffer));
res=get_ups_variable ("ups.load", temp_buffer);
if ( res == NOSUCHVAR ) supported_options &= ~UPS_LOADPCT;
else if ( res != OK)
return STATE_CRITICAL;
@ -282,7 +282,7 @@ main (int argc, char **argv)
}
/* get the ups temperature if possible */
res=get_ups_variable ("ups.temperature", temp_buffer, sizeof (temp_buffer));
res=get_ups_variable ("ups.temperature", temp_buffer);
if ( res == NOSUCHVAR ) supported_options &= ~UPS_TEMP;
else if ( res != OK)
return STATE_CRITICAL;
@ -342,7 +342,7 @@ determine_status (void)
char *ptr;
int res;
res=get_ups_variable ("ups.status", recv_buffer, sizeof (recv_buffer));
res=get_ups_variable ("ups.status", recv_buffer);
if (res == NOSUCHVAR) return OK;
if (res != STATE_OK) {
printf ("%s\n", _("Invalid response received from host"));
@ -388,7 +388,7 @@ determine_status (void)
/* gets a variable value for a specific UPS */
int
get_ups_variable (const char *varname, char *buf, size_t buflen)
get_ups_variable (const char *varname, char *buf)
{
/* char command[MAX_INPUT_BUFFER]; */
char temp_buffer[MAX_INPUT_BUFFER];
@ -507,7 +507,7 @@ process_arguments (int argc, char **argv)
usage2 (_("Invalid hostname/address"), optarg);
}
break;
case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Farenheit) */
case 'T': /* FIXME: to be improved (ie "-T C" for Celsius or "-T F" for Fahrenheit) */
temp_output_c = 1;
break;
case 'u': /* ups name */

View file

@ -1,33 +1,33 @@
/*****************************************************************************
*
*
* Monitoring check_users plugin
*
*
* License: GPL
* Copyright (c) 2000-2012 Monitoring Plugins Development Team
*
*
* Description:
*
*
* This file contains the check_users plugin
*
*
* This plugin checks the number of users currently logged in on the local
* system and generates an error if the number exceeds the thresholds
* specified.
*
*
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*
*
*****************************************************************************/
const char *progname = "check_users";
@ -48,6 +48,11 @@ const char *email = "devel@monitoring-plugins.org";
# include "popen.h"
#endif
#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#include <systemd/sd-login.h>
#endif
#define possibly_set(a,b) ((a) == 0 ? (b) : 0)
int process_arguments (int, char **);
@ -85,6 +90,11 @@ main (int argc, char **argv)
users = 0;
#ifdef HAVE_LIBSYSTEMD
if (sd_booted () > 0)
users = sd_get_sessions (NULL);
else {
#endif
#if HAVE_WTSAPI32_H
if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
0, 1, &wtsinfo, &wtscount)) {
@ -156,6 +166,9 @@ main (int argc, char **argv)
if (spclose (child_process))
result = possibly_set (result, STATE_UNKNOWN);
#endif
#ifdef HAVE_LIBSYSTEMD
}
#endif
/* check the user count against warning and critical thresholds */
result = get_status((double)users, thlds);
@ -163,7 +176,7 @@ main (int argc, char **argv)
if (result == STATE_UNKNOWN)
printf ("%s\n", _("Unable to read output"));
else {
printf (_("USERS %s - %d users currently logged in |%s\n"),
printf (_("USERS %s - %d users currently logged in |%s\n"),
state_text(result), users,
sperfdata_int("users", users, "", warning_range,
critical_range, TRUE, 0, FALSE, 0));

View file

@ -225,18 +225,4 @@ enum {
# define __attribute__(x) /* do nothing */
#endif
/* Try sysconf(_SC_OPEN_MAX) first, as it can be higher than OPEN_MAX.
* If that fails and the macro isn't defined, we fall back to an educated
* guess. There's no guarantee that our guess is adequate and the program
* will die with SIGSEGV if it isn't and the upper boundary is breached. */
#define DEFAULT_MAXFD 256 /* fallback value if no max open files value is set */
#define MAXFD_LIMIT 8192 /* upper limit of open files */
#ifdef _SC_OPEN_MAX
static long maxfd = 0;
#elif defined(OPEN_MAX)
# define maxfd OPEN_MAX
#else /* sysconf macro unavailable, so guess (may be wildly inaccurate) */
# define maxfd DEFAULT_MAXFD
#endif
#endif /* _COMMON_H_ */

View file

@ -92,7 +92,7 @@ extern int econn_refuse_state;
extern int was_refused;
extern int address_family;
RETSIGTYPE socket_timeout_alarm_handler (int) __attribute__((noreturn));
void socket_timeout_alarm_handler (int) __attribute__((noreturn));
/* SSL-Related functionality */
#ifdef HAVE_SSL

File diff suppressed because it is too large Load diff

View file

@ -400,7 +400,7 @@ int phr_parse_request(const char *buf_start, size_t len, const char **method, si
*num_headers = 0;
/* if last_len != 0, check if the request is complete (a fast countermeasure
againt slowloris */
against slowloris */
if (last_len != 0 && is_complete(buf, buf_end, last_len, &r) == NULL) {
return r;
}
@ -435,7 +435,7 @@ static const char *parse_response(const char *buf, const char *buf_end, int *maj
}
PARSE_INT_3(status);
/* get message includig preceding space */
/* get message including preceding space */
if ((buf = get_token_to_eol(buf, buf_end, msg, msg_len, ret)) == NULL) {
return NULL;
}

View file

@ -14,7 +14,7 @@
* FILE * spopen(const char *);
* int spclose(FILE *);
*
* Code taken with liitle modification from "Advanced Programming for the Unix
* Code taken with little modification from "Advanced Programming for the Unix
* Environment" by W. Richard Stevens
*
* This is considered safe in that no shell is spawned, and the environment
@ -38,8 +38,9 @@
*
*****************************************************************************/
#include "common.h"
#include "utils.h"
#include "./common.h"
#include "./utils.h"
#include "../lib/maxfd.h"
/* extern so plugin has pid to kill exec'd process on timeouts */
extern pid_t *childpid;
@ -49,9 +50,9 @@ extern FILE *child_process;
FILE *spopen (const char *);
int spclose (FILE *);
#ifdef REDHAT_SPOPEN_ERROR
RETSIGTYPE popen_sigchld_handler (int);
void popen_sigchld_handler (int);
#endif
RETSIGTYPE popen_timeout_alarm_handler (int);
void popen_timeout_alarm_handler (int);
#include <stdarg.h> /* ANSI C header file */
#include <fcntl.h>
@ -177,8 +178,7 @@ spopen (const char *cmdstring)
}
argv[i] = NULL;
if(maxfd == 0)
maxfd = open_max();
long maxfd = mp_open_max();
if (childpid == NULL) { /* first time through */
if ((childpid = calloc ((size_t)maxfd, sizeof (pid_t))) == NULL)
@ -266,7 +266,7 @@ spclose (FILE * fp)
}
#ifdef REDHAT_SPOPEN_ERROR
RETSIGTYPE
void
popen_sigchld_handler (int signo)
{
if (signo == SIGCHLD)
@ -274,7 +274,7 @@ popen_sigchld_handler (int signo)
}
#endif
RETSIGTYPE
void
popen_timeout_alarm_handler (int signo)
{
int fh;

View file

@ -5,7 +5,7 @@
FILE *spopen (const char *);
int spclose (FILE *);
RETSIGTYPE popen_timeout_alarm_handler (int);
void popen_timeout_alarm_handler (int);
pid_t *childpid=NULL;
int *child_stderr_array=NULL;

View file

@ -44,6 +44,8 @@
# include <sys/wait.h>
#endif
#include "./utils.h"
/** macros **/
#ifndef WEXITSTATUS
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
@ -58,6 +60,8 @@
# define SIG_ERR ((Sigfunc *)-1)
#endif
#include "../lib/maxfd.h"
/* This variable must be global, since there's no way the caller
* can forcibly slay a dead or ungainly running program otherwise.
* Multithreading apps and plugins can initialize it (via NP_RUNCMD_INIT)
@ -86,8 +90,7 @@ extern void die (int, const char *, ...)
* through this api and thus achieve async-safeness throughout the api */
void np_runcmd_init(void)
{
if(maxfd == 0)
maxfd = open_max();
long maxfd = mp_open_max();
if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t));
}
@ -114,10 +117,6 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr)
env[0] = strdup("LC_ALL=C");
env[1] = '\0';
/* if no command was passed, return with no error */
if (cmdstring == NULL)
return -1;
/* make copy of command string so strtok() doesn't silently modify it */
/* (the calling program may want to access it later) */
cmdlen = strlen(cmdstring);
@ -194,6 +193,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr)
/* close all descriptors in np_pids[]
* This is executed in a separate address space (pure child),
* so we don't have to worry about async safety */
long maxfd = mp_open_max();
for (i = 0; i < maxfd; i++)
if(np_pids[i] > 0)
close (i);
@ -203,7 +203,7 @@ np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr)
}
/* parent picks up execution here */
/* close childs descriptors in our address space */
/* close children descriptors in our address space */
close(pfd[1]);
close(pfderr[1]);
@ -221,6 +221,7 @@ np_runcmd_close(int fd)
pid_t pid;
/* make sure this fd was opened by popen() */
long maxfd = mp_open_max();
if(fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0)
return -1;
@ -244,6 +245,7 @@ runcmd_timeout_alarm_handler (int signo)
if (signo == SIGALRM)
puts(_("CRITICAL - Plugin timed out while executing system call"));
long maxfd = mp_open_max();
if(np_pids) for(i = 0; i < maxfd; i++) {
if(np_pids[i] != 0) kill(np_pids[i], SIGKILL);
}

View file

@ -31,9 +31,8 @@
#include "netutils.h"
#ifdef HAVE_SSL
static SSL_CTX *c=NULL;
static SSL_CTX *ctx=NULL;
static SSL *s=NULL;
static int initialized=0;
int np_net_ssl_init(int sd) {
return np_net_ssl_init_with_hostname(sd, NULL);
@ -48,24 +47,24 @@ int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int versi
}
int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey) {
const SSL_METHOD *method = NULL;
long options = 0;
if ((ctx = SSL_CTX_new(TLS_client_method())) == NULL) {
printf("%s\n", _("CRITICAL - Cannot create SSL context."));
return STATE_CRITICAL;
}
switch (version) {
case MP_SSLv2: /* SSLv2 protocol */
#if defined(USE_GNUTLS) || defined(OPENSSL_NO_SSL2)
printf("%s\n", _("UNKNOWN - SSL protocol version 2 is not supported by your SSL library."));
return STATE_UNKNOWN;
#else
method = SSLv2_client_method();
break;
#endif
case MP_SSLv3: /* SSLv3 protocol */
#if defined(OPENSSL_NO_SSL3)
printf("%s\n", _("UNKNOWN - SSL protocol version 3 is not supported by your SSL library."));
return STATE_UNKNOWN;
#else
method = SSLv3_client_method();
SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION);
SSL_CTX_set_max_proto_version(ctx, SSL3_VERSION);
break;
#endif
case MP_TLSv1: /* TLSv1 protocol */
@ -73,7 +72,8 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int
printf("%s\n", _("UNKNOWN - TLS protocol version 1 is not supported by your SSL library."));
return STATE_UNKNOWN;
#else
method = TLSv1_client_method();
SSL_CTX_set_min_proto_version(ctx, TLS1_VERSION);
SSL_CTX_set_max_proto_version(ctx, TLS1_VERSION);
break;
#endif
case MP_TLSv1_1: /* TLSv1.1 protocol */
@ -81,7 +81,8 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int
printf("%s\n", _("UNKNOWN - TLS protocol version 1.1 is not supported by your SSL library."));
return STATE_UNKNOWN;
#else
method = TLSv1_1_client_method();
SSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION);
SSL_CTX_set_max_proto_version(ctx, TLS1_1_VERSION);
break;
#endif
case MP_TLSv1_2: /* TLSv1.2 protocol */
@ -89,7 +90,8 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int
printf("%s\n", _("UNKNOWN - TLS protocol version 1.2 is not supported by your SSL library."));
return STATE_UNKNOWN;
#else
method = TLSv1_2_client_method();
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
SSL_CTX_set_max_proto_version(ctx, TLS1_2_VERSION);
break;
#endif
case MP_TLSv1_2_OR_NEWER:
@ -97,47 +99,43 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int
printf("%s\n", _("UNKNOWN - Disabling TLSv1.1 is not supported by your SSL library."));
return STATE_UNKNOWN;
#else
options |= SSL_OP_NO_TLSv1_1;
SSL_CTX_set_min_proto_version(ctx, TLS1_2_VERSION);
break;
#endif
/* FALLTHROUGH */
case MP_TLSv1_1_OR_NEWER:
#if !defined(SSL_OP_NO_TLSv1)
printf("%s\n", _("UNKNOWN - Disabling TLSv1 is not supported by your SSL library."));
return STATE_UNKNOWN;
#else
options |= SSL_OP_NO_TLSv1;
SSL_CTX_set_min_proto_version(ctx, TLS1_1_VERSION);
break;
#endif
/* FALLTHROUGH */
case MP_TLSv1_OR_NEWER:
#if defined(SSL_OP_NO_SSLv3)
options |= SSL_OP_NO_SSLv3;
SSL_CTX_set_min_proto_version(ctx, TLS1_VERSION);
break;
#endif
/* FALLTHROUGH */
case MP_SSLv3_OR_NEWER:
#if defined(SSL_OP_NO_SSLv2)
options |= SSL_OP_NO_SSLv2;
SSL_CTX_set_min_proto_version(ctx, SSL3_VERSION);
break;
#endif
case MP_SSLv2_OR_NEWER:
/* FALLTHROUGH */
default: /* Default to auto negotiation */
method = SSLv23_client_method();
}
if (!initialized) {
/* Initialize SSL context */
SSLeay_add_ssl_algorithms();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
initialized = 1;
}
if ((c = SSL_CTX_new(method)) == NULL) {
printf("%s\n", _("CRITICAL - Cannot create SSL context."));
return STATE_CRITICAL;
}
if (cert && privkey) {
SSL_CTX_use_certificate_chain_file(c, cert);
SSL_CTX_use_PrivateKey_file(c, privkey, SSL_FILETYPE_PEM);
#ifdef USE_OPENSSL
if (!SSL_CTX_check_private_key(c)) {
if (!SSL_CTX_use_certificate_chain_file(ctx, cert)) {
#elif USE_GNUTLS
if (!SSL_CTX_use_certificate_file(ctx, cert, SSL_FILETYPE_PEM)) {
#else
#error Unported for unknown SSL library
#endif
printf ("%s\n", _("CRITICAL - Unable to open certificate chain file!\n"));
return STATE_CRITICAL;
}
SSL_CTX_use_PrivateKey_file(ctx, privkey, SSL_FILETYPE_PEM);
#ifdef USE_OPENSSL
if (!SSL_CTX_check_private_key(ctx)) {
printf ("%s\n", _("CRITICAL - Private key does not seem to match certificate!\n"));
return STATE_CRITICAL;
}
@ -146,9 +144,9 @@ int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int
#ifdef SSL_OP_NO_TICKET
options |= SSL_OP_NO_TICKET;
#endif
SSL_CTX_set_options(c, options);
SSL_CTX_set_mode(c, SSL_MODE_AUTO_RETRY);
if ((s = SSL_new(c)) != NULL) {
SSL_CTX_set_options(ctx, options);
SSL_CTX_set_mode(ctx, SSL_MODE_AUTO_RETRY);
if ((s = SSL_new(ctx)) != NULL) {
#ifdef SSL_set_tlsext_host_name
if (host_name != NULL)
SSL_set_tlsext_host_name(s, host_name);
@ -175,9 +173,9 @@ void np_net_ssl_cleanup() {
#endif
SSL_shutdown(s);
SSL_free(s);
if (c) {
SSL_CTX_free(c);
c=NULL;
if (ctx) {
SSL_CTX_free(ctx);
ctx=NULL;
}
s=NULL;
}
@ -191,17 +189,6 @@ int np_net_ssl_read(void *buf, int num) {
return SSL_read(s, buf, num);
}
int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
# ifdef USE_OPENSSL
X509 *certificate = NULL;
certificate=SSL_get_peer_certificate(s);
return(np_net_ssl_check_certificate(certificate, days_till_exp_warn, days_till_exp_crit));
# else /* ifndef USE_OPENSSL */
printf("%s\n", _("WARNING - Plugin does not support checking certificates."));
return STATE_WARNING;
# endif /* USE_OPENSSL */
}
int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit){
# ifdef USE_OPENSSL
X509_NAME *subj=NULL;
@ -328,4 +315,16 @@ int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int
# endif /* USE_OPENSSL */
}
int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
# ifdef USE_OPENSSL
X509 *certificate = NULL;
certificate=SSL_get_peer_certificate(s);
return(np_net_ssl_check_certificate(certificate, days_till_exp_warn, days_till_exp_crit));
# else /* ifndef USE_OPENSSL */
printf("%s\n", _("WARNING - Plugin does not support checking certificates."));
return STATE_WARNING;
# endif /* USE_OPENSSL */
}
#endif /* HAVE_SSL */

View file

@ -19,19 +19,19 @@ plan skip_all => "SSH_HOST and SSH_IDENTITY must be defined" unless ($ssh_servic
plan tests => 42;
# Some random check strings/response
my @responce = ('OK: Everything is fine',
my @response = ('OK: Everything is fine',
'WARNING: Hey, pick me, pick me',
'CRITICAL: Shit happens',
'UNKNOWN: What can I do for ya',
'WOOPS: What did I smoke',
);
my @responce_re;
my @response_re;
my @check;
for (@responce) {
for (@response) {
push(@check, "echo $_");
my $re_str = $_;
$re_str =~ s{(.)} { "\Q$1" }ge;
push(@responce_re, $re_str);
push(@response_re, $re_str);
}
my $result;
@ -47,7 +47,7 @@ for (my $i=0; $i<4; $i++) {
"./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[$i]; exit $i'"
);
cmp_ok($result->return_code, '==', $i, "Exit with return code $i");
is($result->output, $responce[$i], "Status text is correct for check $i");
is($result->output, $response[$i], "Status text is correct for check $i");
}
$result = NPTest->testCmd(
@ -84,7 +84,7 @@ $result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -C '$check[4]; exit 8'"
);
cmp_ok($result->return_code, '==', 8, "Exit with return code 8 (out of bounds)");
is($result->output, $responce[4], "Return proper status text even with unknown status codes");
is($result->output, $response[4], "Return proper status text even with unknown status codes");
$result = NPTest->testCmd(
"./check_by_ssh -i $ssh_key -H $ssh_service -F $ssh_conf -C 'exit 0'"
@ -108,7 +108,7 @@ my %linemap = (
foreach my $line (0, 2, 4, 6) {
my $code = $linemap{$line};
my $statline = $line+1;
is($lines[$line], "$responce[$code]", "multiple checks status text is correct for line $line");
is($lines[$line], "$response[$code]", "multiple checks status text is correct for line $line");
is($lines[$statline], "STATUS CODE: $code", "multiple check status code is correct for line $line");
}
@ -124,7 +124,7 @@ close(PASV) or die("Unable to close '/tmp/check_by_ssh.$$': $!");
cmp_ok(scalar(@pasv), '==', 1, 'One passive result for one check performed');
for (0) {
if ($pasv[$_]) {
like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $responce_re[2] . '$/', 'proper result for passive check');
like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;serv;2;' . $response_re[2] . '$/', 'proper result for passive check');
} else {
fail('proper result for passive check');
}
@ -144,7 +144,7 @@ for (0, 1, 2, 3, 4) {
if ($pasv[$_]) {
my $ret = $_;
$ret = 9 if ($_ == 4);
like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $responce_re[$_] . '$/', "proper result for passive check $_");
like($pasv[$_], '/^\[\d+\] PROCESS_SERVICE_CHECK_RESULT;flint;c' . $_ . ';' . $ret . ';' . $response_re[$_] . '$/', "proper result for passive check $_");
} else {
fail("proper result for passive check $_");
}

View file

@ -23,7 +23,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
plan tests => 78;
plan tests => 88;
}
$result = NPTest->testCmd(
@ -326,19 +326,19 @@ cmp_ok( $result->return_code, '==', 0, "grouping: exit ok if the sum of free meg
$result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all - 1) ." -c ". ($free_mb_on_all - 1) ." -p $mountpoint_valid -g group -p $mountpoint2_valid" );
cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after groupname");
# regex: exit unknown if given regex is not compileable
# regex: exit unknown if given regex is not compilable
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" );
cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable");
cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compilable");
# ignore: exit unknown, if all pathes are deselected using -i
# ignore: exit unknown, if all paths are deselected using -i
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)");
# ignore: exit unknown, if all pathes are deselected using -I
# ignore: exit unknown, if all paths are deselected using -I
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)");
# ignore: exit unknown, if all pathes are deselected using -i
# ignore: exit unknown, if all paths are deselected using -i
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'");
@ -347,7 +347,32 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mo
like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it");
unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it");
# ignore: test if all pathes are listed when ignore regex doesn't match
# ignore: test if all paths are listed when ignore regex doesn't match
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'");
like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match");
like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match");
# ignore-missing: exit okay, when fs is not accessible
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob");
like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /bob;.*$/', 'Output OK');
# ignore-missing: exit okay, when regex does not match
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
like( $result->output, '/^DISK OK - No disks were found for provided parameters;.*$/', 'Output OK');
# ignore-missing: exit okay, when fs with exact match (-E) is not found
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs");
like( $result->output, '/^DISK OK - No disks were found for provided parameters; - ignored paths: /etc;.*$/', 'Output OK');
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex)
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK');
# ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path)
$result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'");
cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching");
like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK');

View file

@ -178,13 +178,13 @@ SKIP: {
$res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -u http://$host_tcp_http -e 200,301,302");
is( $res->return_code, 0, "Proxy HTTP works");
like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficent");
like($res->output, qr/OK: Status line output matched/, "Proxy HTTP Output is sufficient");
$res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT");
is( $res->return_code, 0, "Proxy HTTP CONNECT works");
like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficient");
$res = NPTest->testCmd( "./$plugin -I $host_tcp_proxy -p $port_tcp_proxy -H $host_tls_http -S -j CONNECT:HEAD");
is( $res->return_code, 0, "Proxy HTTP CONNECT works with override method");
like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficent");
like($res->output, qr/HTTP OK:/, "Proxy HTTP CONNECT output sufficient");
}

View file

@ -25,7 +25,7 @@ $t = NPTest->testCmd( "./check_imap $host_tcp_imap -p 143 -wt 9 -ct 9 -to 10 -e
cmp_ok( $t->return_code, '==', 0, "Check old parameter options" );
$t = NPTest->testCmd( "./check_imap $host_nonresponsive" );
cmp_ok( $t->return_code, '==', 2, "Get error with non reponsive host" );
cmp_ok( $t->return_code, '==', 2, "Get error with non responsive host" );
$t = NPTest->testCmd( "./check_imap $hostname_invalid" );
cmp_ok( $t->return_code, '==', 2, "Invalid hostname" );

View file

@ -5,7 +5,7 @@
#
#
# These are the database permissions required for this test:
# GRANT SELECT ON $db.* TO $user@$host INDENTIFIED BY '$password';
# GRANT SELECT ON $db.* TO $user@$host IDENTIFIED BY '$password';
# GRANT SUPER, REPLICATION CLIENT ON *.* TO $user@$host;
# Check with:
# mysql -u$user -p$password -h$host $db
@ -23,9 +23,9 @@ plan tests => 15;
my $bad_login_output = '/Access denied for user /';
my $mysqlserver = getTestParameter("NP_MYSQL_SERVER", "A MySQL Server hostname or IP with no slaves setup");
my $mysqlsocket = getTestParameter("NP_MYSQL_SOCKET", "Full path to a MySQL Server socket with no slaves setup");
my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privleges)", "-u test -ptest");
my $mysql_login_details = getTestParameter("NP_MYSQL_LOGIN_DETAILS", "Command line parameters to specify login access (requires REPLICATION CLIENT privileges)", "-u test -ptest");
my $with_slave = getTestParameter("NP_MYSQL_WITH_SLAVE", "MySQL server with slaves setup");
my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privleges)", $mysql_login_details || "-u test -ptest");
my $with_slave_login = getTestParameter("NP_MYSQL_WITH_SLAVE_LOGIN", "Login details for server with slave (requires REPLICATION CLIENT privileges)", $mysql_login_details || "-u test -ptest");
my $result;

View file

@ -31,7 +31,7 @@ $result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver $
cmp_ok( $result->return_code, '==', 0, "Can run query");
$result = NPTest->testCmd("./check_mysql_query -H $mysqlserver $mysql_login_details");
cmp_ok( $result->return_code, '==', 3, "Missing query parmeter");
cmp_ok( $result->return_code, '==', 3, "Missing query parameter");
like( $result->output, "/Must specify a SQL query to run/", "Missing query error message");
$result = NPTest->testCmd("./check_mysql_query -q 'SELECT 1+1' -H $mysqlserver -u dummy -d mysql");

View file

@ -36,7 +36,7 @@ cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" );
like ( $result->output, $warningOutput, "Output for warning correct" );
my $now = time;
# This substitution is dependant on the testcase
# This substitution is dependent on the testcase
system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
$result = NPTest->testCmd(

View file

@ -8,12 +8,14 @@ use strict;
use Test::More;
use NPTest;
my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP",
my $host_tcp_smtp = getTestParameter( "NP_HOST_TCP_SMTP",
"A host providing an SMTP Service (a mail server)", "mailhost");
my $host_tcp_smtp_tls = getTestParameter( "NP_HOST_TCP_SMTP_TLS",
my $host_tcp_smtp_starttls = getTestParameter( "NP_HOST_TCP_SMTP_STARTTLS",
"A host providing SMTP with STARTTLS", $host_tcp_smtp);
my $host_tcp_smtp_nostarttls = getTestParameter( "NP_HOST_TCP_SMTP_NOSTARTTLS",
"A host providing SMTP without STARTTLS", "");
my $host_tcp_smtp_tls = getTestParameter( "NP_HOST_TCP_SMTP_TLS",
"A host providing SMTP with TLS", $host_tcp_smtp);
my $host_tcp_smtp_notls = getTestParameter( "NP_HOST_TCP_SMTP_NOTLS",
"A host providing SMTP without TLS", "");
my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
"The hostname of system not responsive to network requests", "10.0.0.1" );
@ -22,7 +24,7 @@ my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
"An invalid (not known to DNS) hostname", "nosuchhost" );
my $res;
plan tests => 10;
plan tests => 16;
SKIP: {
skip "No SMTP server defined", 4 unless $host_tcp_smtp;
@ -42,22 +44,38 @@ SKIP: {
local $TODO = "Output is over two lines";
like ( $res->output, qr/^SMTP WARNING/, "Correct error message" );
}
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp --ssl -p 25" );
is ($res->return_code, 2, "Check rc of connecting to $host_tcp_smtp with TLS on standard SMTP port" );
like ($res->output, qr/^CRITICAL - Cannot make SSL connection\./, "Check output of connecting to $host_tcp_smtp with TLS on standard SMTP port");
}
SKIP: {
skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls;
# SSL connection for TLS
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p 25 -S" );
skip "No SMTP server with STARTTLS defined", 1 unless $host_tcp_smtp_starttls;
# SSL connection for STARTTLS
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_starttls -p 25 -S" );
is ($res->return_code, 0, "OK, with STARTTLS" );
}
SKIP: {
skip "No SMTP server without TLS defined", 2 unless $host_tcp_smtp_notls;
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_notls -p 25 -S" );
is ($res->return_code, 1, "OK, got warning from server without TLS");
skip "No SMTP server without STARTTLS defined", 2 unless $host_tcp_smtp_nostarttls;
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_nostarttls -p 25 -S" );
is ($res->return_code, 1, "OK, got warning from server without STARTTLS");
is ($res->output, "WARNING - TLS not supported by server", "Right error message" );
}
SKIP: {
skip "No SMTP server with TLS defined", 1 unless $host_tcp_smtp_tls;
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls --ssl" );
is ($res->return_code, 0, "Check rc of connecting to $host_tcp_smtp_tls with TLS" );
like ($res->output, qr/^SMTP OK - /, "Check output of connecting to $host_tcp_smtp_tls with TLS" );
my $unused_port = 4465;
$res = NPTest->testCmd( "./check_smtp -H $host_tcp_smtp_tls -p $unused_port --ssl" );
is ($res->return_code, 2, "Check rc of connecting to $host_tcp_smtp_tls with TLS on unused port $unused_port" );
like ($res->output, qr/^connect to address $host_tcp_smtp_tls and port $unused_port: Connection refused/, "Check output of connecting to $host_tcp_smtp_tls with TLS on unused port $unused_port");
}
$res = NPTest->testCmd( "./check_smtp $host_nonresponsive" );
is ($res->return_code, 2, "CRITICAL - host non responding" );

View file

@ -26,22 +26,22 @@ $res = NPTest->testCmd( "./check_snmp -t 1" );
is( $res->return_code, 3, "No host name" );
is( $res->output, "No host specified" );
$res = NPTest->testCmd( "./check_snmp -H fakehostname" );
$res = NPTest->testCmd( "./check_snmp -H fakehostname --ignore-mib-parsing-errors" );
is( $res->return_code, 3, "No OIDs specified" );
is( $res->output, "No OIDs specified" );
$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 -U not_a_user --seclevel=rubbish" );
$res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3 -U not_a_user --seclevel=rubbish" );
is( $res->return_code, 3, "Invalid seclevel" );
like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" );
$res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3c" );
is( $res->return_code, 3, "Invalid protocol" );
like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
SKIP: {
skip "no snmp host defined", 50 if ( ! $host_snmp );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK");
$res->output =~ /^SNMP OK - (\d+)/;
@ -51,111 +51,111 @@ SKIP: {
# some more threshold tests
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1");
cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:");
cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c ~:1");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c ~:1");
cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:10");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:10");
cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c \@1:10");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c \@1:10");
cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 10:1");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 10:1");
cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" );
like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" );
like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" );
like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" );
like($res->output, "/^SNMP OK - 2 1/", "Got two values back" );
like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2");
cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" );
like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" );
like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
$res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
my $lower = $1 - 0.05;
my $higher = $1 + 0.05;
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2");
cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold");
like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0");
cmp_ok( $res->return_code, '==', 0, "Timetick used as a string");
like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1");
cmp_ok( $res->return_code, '==', 0, "snmp response without datatype");
like( $res->output, '/^SNMP OK - "(systemd|init)" \| $/', "snmp response without datatype" );
}
SKIP: {
skip "no SNMP user defined", 1 if ( ! $user_snmp );
$res = NPTest->testCmd( "./check_snmp -H $host_snmp -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv");
$res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv");
like( $res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "noAuthNoPriv security level works properly" );
}
@ -163,14 +163,14 @@ SKIP: {
# the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
SKIP: {
skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
$res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
$res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" );
like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem");
}
SKIP: {
skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
$res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
$res = NPTest->testCmd( "./check_snmp -H $hostname_invalid --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host).*/s', "String matches invalid host");
}

View file

@ -2,7 +2,7 @@
#
# Logged in Users Tests via check_users
#
# Trick: This ckeck requires at least 1 user logged in. These commands should
# Trick: This check requires at least 1 user logged in. These commands should
# leave a session open forever in the background:
#
# $ ssh -tt localhost </dev/null >/dev/null 2>/dev/null &

View file

@ -84,7 +84,7 @@ foreach my $current_state (keys(%state)) {
foreach my $new_state (keys(%state)) {
$res = NPTest->testCmd( "./negate -s --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
is( $res->return_code, $state{$new_state}, "Got fake $new_state (with substitute)" );
is( $res->output, uc($new_state).": Fake $new_state", "Substitued fake $new_state output");
is( $res->output, uc($new_state).": Fake $new_state", "Substituted fake $new_state output");
}
}

View file

@ -9,7 +9,7 @@
# Country Name (2 letter code) [AU]:DE
# State or Province Name (full name) [Some-State]:Bavaria
# Locality Name (eg, city) []:Munich
# Organization Name (eg, company) [Internet Widgits Pty Ltd]:Monitoring Plugins
# Organization Name (eg, company) [Internet Widgets Pty Ltd]:Monitoring Plugins
# Organizational Unit Name (eg, section) []:
# Common Name (e.g. server FQDN or YOUR name) []:Monitoring Plugins
# Email Address []:devel@monitoring-plugins.org

View file

@ -9,12 +9,14 @@ use strict;
use Test::More;
use NPTest;
use FindBin qw($Bin);
use IO::Socket::INET;
$ENV{'LC_TIME'} = "C";
my $common_tests = 71;
my $virtual_port_tests = 8;
my $ssl_only_tests = 12;
my $chunked_encoding_special_tests = 1;
# Check that all dependent modules are available
eval "use HTTP::Daemon 6.01;";
plan skip_all => 'HTTP::Daemon >= 6.01 required' if $@;
@ -30,7 +32,7 @@ if ($@) {
plan skip_all => "Missing required module for test: $@";
} else {
if (-x "./$plugin") {
plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests;
plan tests => $common_tests * 2 + $ssl_only_tests + $virtual_port_tests + $chunked_encoding_special_tests;
} else {
plan skip_all => "No $plugin compiled";
}
@ -51,6 +53,7 @@ my $port_http = 50000 + int(rand(1000));
my $port_https = $port_http + 1;
my $port_https_expired = $port_http + 2;
my $port_https_clientcert = $port_http + 3;
my $port_hacked_http = $port_http + 4;
# This array keeps sockets around for implementing timeouts
my @persist;
@ -72,6 +75,28 @@ if (!$pid) {
}
push @pids, $pid;
# Fork the hacked HTTP server
undef $pid;
$pid = fork;
defined $pid or die "Failed to fork";
if (!$pid) {
# this is the fork
undef @pids;
my $socket = new IO::Socket::INET (
LocalHost => '0.0.0.0',
LocalPort => $port_hacked_http,
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "cannot create socket $!n" unless $socket;
my $local_sock = $socket->sockport();
print "server waiting for client connection on port $local_sock\n";
run_hacked_http_server ( $socket );
die "hacked http server stopped";
}
push @pids, $pid;
if (exists $servers->{https}) {
# Fork a normal HTTPS server
$pid = fork;
@ -207,6 +232,37 @@ sub run_server {
}
}
sub run_hacked_http_server {
my $socket = shift;
# auto-flush on socket
$| = 1;
while(1)
{
# waiting for a new client connection
my $client_socket = $socket->accept();
# get information about a newly connected client
my $client_address = $client_socket->peerhost();
my $client_portn = $client_socket->peerport();
print "connection from $client_address:$client_portn";
# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
print "received data: $data";
# write response data to the connected client
$data = "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n";
$client_socket->send($data);
# notify client that response has been sent
shutdown($client_socket, 1);
}
}
END {
foreach my $pid (@pids) {
if ($pid) { print "Killing $pid\n"; kill "INT", $pid }
@ -222,6 +278,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
my $result;
my $command = "./$plugin -H 127.0.0.1";
run_chunked_encoding_special_test( {command => "$command -p $port_hacked_http"});
run_common_tests( { command => "$command -p $port_http" } );
SKIP: {
skip "HTTP::Daemon::SSL not installed", $common_tests + $ssl_only_tests if ! exists $servers->{https};
@ -511,3 +568,14 @@ sub run_common_tests {
};
is( $@, "", $cmd );
}
sub run_chunked_encoding_special_test {
my ($opts) = @_;
my $command = $opts->{command};
$cmd = "$command -u / -s 'ChunkedEncodingSpecialTest'";
eval {
$result = NPTest->testCmd( $cmd, 5 );
};
is( $@, "", $cmd );
}

View file

@ -8,7 +8,7 @@ use Test::More;
use NPTest;
if (-x "./check_procs") {
plan tests => 52;
plan tests => 54;
} else {
plan skip_all => "No check_procs compiled";
}
@ -34,9 +34,13 @@ is( $result->return_code, 0, "Checking no threshold breeched" );
is( $result->output, "PROCS OK: 95 processes | procs=95;100;200;0;", "Output correct" );
$result = NPTest->testCmd( "$command -C launchd -c 5" );
is( $result->return_code, 2, "Checking processes filtered by command name" );
is( $result->return_code, 2, "Checking processes matched by command name" );
is( $result->output, "PROCS CRITICAL: 6 processes with command name 'launchd' | procs=6;;5;0;", "Output correct" );
$result = NPTest->testCmd( "$command -X bash -c 5" );
is( $result->return_code, 2, "Checking processes excluded by command name" );
is( $result->output, "PROCS CRITICAL: 95 processes with exclude progs 'bash' | procs=95;;5;0;", "Output correct" );
SKIP: {
skip 'user with uid 501 required', 4 unless getpwuid(501);

View file

@ -53,7 +53,7 @@ if ($pid) {
#print "child\n";
print "Please contact SNMP at: $port_snmp\n";
close(STDERR); # Coment out to debug snmpd problems (most errors sent there are OK)
close(STDERR); # Comment out to debug snmpd problems (most errors sent there are OK)
exec("snmpd -c tests/conf/snmpd.conf -C -f -r udp:$port_snmp");
}
@ -227,7 +227,7 @@ is($res->output, 'SNMP OK - "555\"I said\"" | ', "Check string with a double quo
$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.15 -r 'CUSTOM CHECK OK'" );
is($res->return_code, 0, "String check should check whole string, not a parsed number" );
is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check witn numbers returns whole string");
is($res->output, 'SNMP OK - "CUSTOM CHECK OK: foo is 12345" | ', "String check with numbers returns whole string");
$res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.16 -w -2: -c -3:" );
is($res->return_code, 0, "Negative integer check OK" );

View file

@ -804,19 +804,3 @@ char *sperfdata_int (const char *label,
return data;
}
int
open_max (void)
{
errno = 0;
if (maxfd > 0)
return(maxfd);
if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) {
if (errno == 0)
maxfd = DEFAULT_MAXFD; /* it's indeterminate */
else
die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n"));
}
return(maxfd);
}

View file

@ -7,7 +7,7 @@
/* The purpose of this package is to provide safer alternatives to C
functions that might otherwise be vulnerable to hacking. This
currently includes a standard suite of validation routines to be sure
that an string argument acually converts to its intended type and a
that an string argument actually converts to its intended type and a
suite of string handling routine that do their own memory management
in order to resist overflow attacks. In addition, a few functions are
provided to standardize version and error reporting across the entire
@ -106,8 +106,6 @@ char *sperfdata (const char *, double, const char *, char *, char *,
char *sperfdata_int (const char *, int, const char *, char *, char *,
int, int, int, int);
int open_max (void);
/* The idea here is that, although not every plugin will use all of these,
most will or should. Therefore, for consistency, these very common
options should have only these meanings throughout the overall suite */