mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-02-18 18:17:50 -05:00
Run clang-format again
This commit is contained in:
parent
a3cf9041af
commit
802e46f8ea
74 changed files with 3266 additions and 2224 deletions
|
|
@ -27,12 +27,13 @@
|
|||
|
||||
/* FIXME: copied from utils.h; we should move a bunch of libs! */
|
||||
bool is_option2(char *str) {
|
||||
if (!str)
|
||||
if (!str) {
|
||||
return false;
|
||||
else if (strspn(str, "-") == 1 || strspn(str, "-") == 2)
|
||||
} else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) {
|
||||
return true;
|
||||
else
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* this is the externally visible function used by plugins */
|
||||
|
|
@ -56,8 +57,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
|
|||
/* It is a single argument with value */
|
||||
argptr = argv[i] + 13;
|
||||
/* Delete the extra opts argument */
|
||||
for (j = i; j < *argc; j++)
|
||||
for (j = i; j < *argc; j++) {
|
||||
argv[j] = argv[j + 1];
|
||||
}
|
||||
i--;
|
||||
*argc -= 1;
|
||||
} else if (strcmp(argv[i], "--extra-opts") == 0) {
|
||||
|
|
@ -65,8 +67,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
|
|||
/* It is a argument with separate value */
|
||||
argptr = argv[i + 1];
|
||||
/* Delete the extra-opts argument/value */
|
||||
for (j = i; j < *argc - 1; j++)
|
||||
for (j = i; j < *argc - 1; j++) {
|
||||
argv[j] = argv[j + 2];
|
||||
}
|
||||
i -= 2;
|
||||
*argc -= 2;
|
||||
ea_num--;
|
||||
|
|
@ -74,8 +77,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
|
|||
/* It has no value */
|
||||
optfound = 1;
|
||||
/* Delete the extra opts argument */
|
||||
for (j = i; j < *argc; j++)
|
||||
for (j = i; j < *argc; j++) {
|
||||
argv[j] = argv[j + 1];
|
||||
}
|
||||
i--;
|
||||
*argc -= 1;
|
||||
}
|
||||
|
|
@ -94,16 +98,18 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
|
|||
/* append the list to extra_args */
|
||||
if (extra_args == NULL) {
|
||||
extra_args = ea1;
|
||||
while ((ea1 = ea1->next))
|
||||
while ((ea1 = ea1->next)) {
|
||||
ea_num++;
|
||||
}
|
||||
} else {
|
||||
ea_tmp = extra_args;
|
||||
while (ea_tmp->next) {
|
||||
ea_tmp = ea_tmp->next;
|
||||
}
|
||||
ea_tmp->next = ea1;
|
||||
while ((ea1 = ea1->next))
|
||||
while ((ea1 = ea1->next)) {
|
||||
ea_num++;
|
||||
}
|
||||
}
|
||||
ea1 = ea_tmp = NULL;
|
||||
}
|
||||
|
|
@ -116,8 +122,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
|
|||
|
||||
/* done processing arguments. now create a new argv array... */
|
||||
argv_new = (char **)malloc((ea_num + 1) * sizeof(char **));
|
||||
if (argv_new == NULL)
|
||||
if (argv_new == NULL) {
|
||||
die(STATE_UNKNOWN, _("malloc() failed!\n"));
|
||||
}
|
||||
|
||||
/* starting with program name */
|
||||
argv_new[0] = argv[0];
|
||||
|
|
@ -130,8 +137,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
|
|||
free(ea1);
|
||||
}
|
||||
/* finally the rest of the argv array */
|
||||
for (i = 1; i < *argc; i++)
|
||||
for (i = 1; i < *argc; i++) {
|
||||
argv_new[argc_new++] = argv[i];
|
||||
}
|
||||
*argc = argc_new;
|
||||
/* and terminate. */
|
||||
argv_new[argc_new] = NULL;
|
||||
|
|
|
|||
|
|
@ -31,10 +31,11 @@ long mp_open_max(void) {
|
|||
#ifdef _SC_OPEN_MAX
|
||||
errno = 0;
|
||||
if ((maxfd = sysconf(_SC_OPEN_MAX)) < 0) {
|
||||
if (errno == 0)
|
||||
if (errno == 0) {
|
||||
maxfd = DEFAULT_MAXFD; /* it's indeterminate */
|
||||
else
|
||||
} else {
|
||||
die(STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n"));
|
||||
}
|
||||
}
|
||||
#elif defined(OPEN_MAX)
|
||||
return OPEN_MAX
|
||||
|
|
|
|||
11
lib/output.c
11
lib/output.c
|
|
@ -377,7 +377,9 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
|
|||
|
||||
while (tmp_string != NULL) {
|
||||
*tmp_string = '\0';
|
||||
asprintf(&intermediate_string, "%s%s\n%s", intermediate_string,check.output, generate_indentation_string(indentation+1)); // one more indentation to make it look better
|
||||
asprintf(&intermediate_string, "%s%s\n%s", intermediate_string, check.output,
|
||||
generate_indentation_string(
|
||||
indentation + 1)); // one more indentation to make it look better
|
||||
|
||||
if (*(tmp_string + 1) != '\0') {
|
||||
check.output = tmp_string + 1;
|
||||
|
|
@ -394,13 +396,14 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
|
|||
// add the rest (if any)
|
||||
if (have_residual_chars) {
|
||||
char *tmp = check.output;
|
||||
xasprintf(&check.output, "%s\n%s%s", intermediate_string, generate_indentation_string(indentation+1), tmp);
|
||||
xasprintf(&check.output, "%s\n%s%s", intermediate_string,
|
||||
generate_indentation_string(indentation + 1), tmp);
|
||||
} else {
|
||||
check.output = intermediate_string;
|
||||
}
|
||||
}
|
||||
asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation), state_text(mp_compute_subcheck_state(check)),
|
||||
check.output);
|
||||
asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation),
|
||||
state_text(mp_compute_subcheck_state(check)), check.output);
|
||||
|
||||
subchecks = check.subchecks;
|
||||
|
||||
|
|
|
|||
112
lib/parse_ini.c
112
lib/parse_ini.c
|
|
@ -40,19 +40,22 @@ typedef struct {
|
|||
char *stanza;
|
||||
} np_ini_info;
|
||||
|
||||
static char *default_ini_file_names[] = {"monitoring-plugins.ini", "plugins.ini", "nagios-plugins.ini", NULL};
|
||||
static char *default_ini_file_names[] = {"monitoring-plugins.ini", "plugins.ini",
|
||||
"nagios-plugins.ini", NULL};
|
||||
|
||||
static char *default_ini_path_names[] = {
|
||||
"/usr/local/etc/monitoring-plugins/monitoring-plugins.ini", "/usr/local/etc/monitoring-plugins.ini",
|
||||
"/etc/monitoring-plugins/monitoring-plugins.ini", "/etc/monitoring-plugins.ini",
|
||||
"/usr/local/etc/monitoring-plugins/monitoring-plugins.ini",
|
||||
"/usr/local/etc/monitoring-plugins.ini", "/etc/monitoring-plugins/monitoring-plugins.ini",
|
||||
"/etc/monitoring-plugins.ini",
|
||||
/* deprecated path names (for backward compatibility): */
|
||||
"/etc/nagios/plugins.ini", "/usr/local/nagios/etc/plugins.ini", "/usr/local/etc/nagios/plugins.ini", "/etc/opt/nagios/plugins.ini",
|
||||
"/etc/nagios-plugins.ini", "/usr/local/etc/nagios-plugins.ini", "/etc/opt/nagios-plugins.ini", NULL};
|
||||
"/etc/nagios/plugins.ini", "/usr/local/nagios/etc/plugins.ini",
|
||||
"/usr/local/etc/nagios/plugins.ini", "/etc/opt/nagios/plugins.ini", "/etc/nagios-plugins.ini",
|
||||
"/usr/local/etc/nagios-plugins.ini", "/etc/opt/nagios-plugins.ini", NULL};
|
||||
|
||||
/* eat all characters from a FILE pointer until n is encountered */
|
||||
#define GOBBLE_TO(f, c, n) \
|
||||
do { \
|
||||
(c) = fgetc((f)); \
|
||||
#define GOBBLE_TO(f, c, n) \
|
||||
do { \
|
||||
(c) = fgetc((f)); \
|
||||
} while ((c) != EOF && (c) != (n))
|
||||
|
||||
/* internal function that returns the constructed defaults options */
|
||||
|
|
@ -87,8 +90,9 @@ static void parse_locator(const char *locator, const char *def_stanza, np_ini_in
|
|||
i->stanza = strdup(def_stanza);
|
||||
}
|
||||
|
||||
if (i->stanza == NULL)
|
||||
if (i->stanza == NULL) {
|
||||
die(STATE_UNKNOWN, _("malloc() failed!\n"));
|
||||
}
|
||||
|
||||
/* check whether there's an @file part */
|
||||
if (stanza_len == locator_len) {
|
||||
|
|
@ -99,8 +103,9 @@ static void parse_locator(const char *locator, const char *def_stanza, np_ini_in
|
|||
i->file_string_on_heap = true;
|
||||
}
|
||||
|
||||
if (i->file == NULL || i->file[0] == '\0')
|
||||
if (i->file == NULL || i->file[0] == '\0') {
|
||||
die(STATE_UNKNOWN, _("Cannot find config file in any standard location.\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -112,26 +117,31 @@ np_arg_list *np_get_defaults(const char *locator, const char *default_section) {
|
|||
np_ini_info i;
|
||||
int is_suid_plugin = mp_suid();
|
||||
|
||||
if (is_suid_plugin && idpriv_temp_drop() == -1)
|
||||
if (is_suid_plugin && idpriv_temp_drop() == -1) {
|
||||
die(STATE_UNKNOWN, _("Cannot drop privileges: %s\n"), strerror(errno));
|
||||
}
|
||||
|
||||
parse_locator(locator, default_section, &i);
|
||||
inifile = strcmp(i.file, "-") == 0 ? stdin : fopen(i.file, "r");
|
||||
|
||||
if (inifile == NULL)
|
||||
if (inifile == NULL) {
|
||||
die(STATE_UNKNOWN, _("Can't read config file: %s\n"), strerror(errno));
|
||||
if (!read_defaults(inifile, i.stanza, &defaults))
|
||||
}
|
||||
if (!read_defaults(inifile, i.stanza, &defaults)) {
|
||||
die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file);
|
||||
}
|
||||
|
||||
if (i.file_string_on_heap) {
|
||||
free(i.file);
|
||||
}
|
||||
|
||||
if (inifile != stdin)
|
||||
if (inifile != stdin) {
|
||||
fclose(inifile);
|
||||
}
|
||||
free(i.stanza);
|
||||
if (is_suid_plugin && idpriv_temp_restore() == -1)
|
||||
if (is_suid_plugin && idpriv_temp_restore() == -1) {
|
||||
die(STATE_UNKNOWN, _("Cannot restore privileges: %s\n"), strerror(errno));
|
||||
}
|
||||
|
||||
return defaults;
|
||||
}
|
||||
|
|
@ -158,8 +168,9 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) {
|
|||
/* our little stanza-parsing state machine */
|
||||
while ((c = fgetc(f)) != EOF) {
|
||||
/* gobble up leading whitespace */
|
||||
if (isspace(c))
|
||||
if (isspace(c)) {
|
||||
continue;
|
||||
}
|
||||
switch (c) {
|
||||
/* globble up comment lines */
|
||||
case ';':
|
||||
|
|
@ -172,9 +183,11 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) {
|
|||
for (i = 0; i < stanza_len; i++) {
|
||||
c = fgetc(f);
|
||||
/* strip leading whitespace */
|
||||
if (i == 0)
|
||||
for (; isspace(c); c = fgetc(f))
|
||||
if (i == 0) {
|
||||
for (; isspace(c); c = fgetc(f)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* nope, read to the end of the line */
|
||||
if (c != stanza[i]) {
|
||||
GOBBLE_TO(f, c, '\n');
|
||||
|
|
@ -185,10 +198,12 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) {
|
|||
if (i == stanza_len) {
|
||||
c = fgetc(f);
|
||||
/* strip trailing whitespace */
|
||||
for (; isspace(c); c = fgetc(f))
|
||||
for (; isspace(c); c = fgetc(f)) {
|
||||
continue;
|
||||
if (c == ']')
|
||||
}
|
||||
if (c == ']') {
|
||||
stanzastate = RIGHTSTANZA;
|
||||
}
|
||||
}
|
||||
break;
|
||||
/* otherwise, we're in the body of a stanza or a parse error */
|
||||
|
|
@ -239,12 +254,13 @@ static int add_option(FILE *f, np_arg_list **optlst) {
|
|||
if (linebuf == NULL || read_pos + read_sz >= linebuf_sz) {
|
||||
linebuf_sz = linebuf_sz > 0 ? linebuf_sz << 1 : read_sz;
|
||||
linebuf = realloc(linebuf, linebuf_sz);
|
||||
if (linebuf == NULL)
|
||||
if (linebuf == NULL) {
|
||||
die(STATE_UNKNOWN, _("malloc() failed!\n"));
|
||||
}
|
||||
}
|
||||
if (fgets(&linebuf[read_pos], (int)read_sz, f) == NULL)
|
||||
if (fgets(&linebuf[read_pos], (int)read_sz, f) == NULL) {
|
||||
done_reading = 1;
|
||||
else {
|
||||
} else {
|
||||
read_pos = strlen(linebuf);
|
||||
if (linebuf[read_pos - 1] == '\n') {
|
||||
linebuf[--read_pos] = '\0';
|
||||
|
|
@ -256,38 +272,46 @@ static int add_option(FILE *f, np_arg_list **optlst) {
|
|||
/* all that to read one line, isn't C fun? :) now comes the parsing :/ */
|
||||
|
||||
/* skip leading whitespace */
|
||||
for (optptr = linebuf; optptr < lineend && isspace(*optptr); optptr++)
|
||||
for (optptr = linebuf; optptr < lineend && isspace(*optptr); optptr++) {
|
||||
continue;
|
||||
}
|
||||
/* continue to '=' or EOL, watching for spaces that might precede it */
|
||||
for (eqptr = optptr; eqptr < lineend && *eqptr != '='; eqptr++) {
|
||||
if (isspace(*eqptr) && optend == NULL)
|
||||
if (isspace(*eqptr) && optend == NULL) {
|
||||
optend = eqptr;
|
||||
else
|
||||
} else {
|
||||
optend = NULL;
|
||||
}
|
||||
}
|
||||
if (optend == NULL)
|
||||
if (optend == NULL) {
|
||||
optend = eqptr;
|
||||
}
|
||||
--optend;
|
||||
/* ^[[:space:]]*=foo is a syntax error */
|
||||
if (optptr == eqptr)
|
||||
if (optptr == eqptr) {
|
||||
die(STATE_UNKNOWN, "%s\n", _("Config file error"));
|
||||
}
|
||||
/* continue from '=' to start of value or EOL */
|
||||
for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); valptr++)
|
||||
for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); valptr++) {
|
||||
continue;
|
||||
}
|
||||
/* continue to the end of value */
|
||||
for (valend = valptr; valend < lineend; valend++)
|
||||
for (valend = valptr; valend < lineend; valend++) {
|
||||
continue;
|
||||
}
|
||||
--valend;
|
||||
/* finally trim off trailing spaces */
|
||||
for (; isspace(*valend); valend--)
|
||||
for (; isspace(*valend); valend--) {
|
||||
continue;
|
||||
}
|
||||
/* calculate the length of "--foo" */
|
||||
opt_len = (size_t)(1 + optend - optptr);
|
||||
/* 1-character params needs only one dash */
|
||||
if (opt_len == 1)
|
||||
if (opt_len == 1) {
|
||||
cfg_len = 1 + (opt_len);
|
||||
else
|
||||
} else {
|
||||
cfg_len = 2 + (opt_len);
|
||||
}
|
||||
/* if valptr<lineend then we have to also allocate space for "=bar" */
|
||||
if (valptr < lineend) {
|
||||
equals = value = 1;
|
||||
|
|
@ -300,8 +324,9 @@ static int add_option(FILE *f, np_arg_list **optlst) {
|
|||
cfg_len += 1;
|
||||
}
|
||||
/* a line with no equal sign isn't valid */
|
||||
if (equals == 0)
|
||||
if (equals == 0) {
|
||||
die(STATE_UNKNOWN, "%s\n", _("Config file error"));
|
||||
}
|
||||
|
||||
/* okay, now we have all the info we need, so we create a new np_arg_list
|
||||
* element and set the argument...
|
||||
|
|
@ -329,11 +354,12 @@ static int add_option(FILE *f, np_arg_list **optlst) {
|
|||
optnew->arg[read_pos] = '\0';
|
||||
|
||||
/* ...and put that to the end of the list */
|
||||
if (*optlst == NULL)
|
||||
if (*optlst == NULL) {
|
||||
*optlst = optnew;
|
||||
else {
|
||||
while (opttmp->next != NULL)
|
||||
} else {
|
||||
while (opttmp->next != NULL) {
|
||||
opttmp = opttmp->next;
|
||||
}
|
||||
opttmp->next = optnew;
|
||||
}
|
||||
|
||||
|
|
@ -344,7 +370,8 @@ static int add_option(FILE *f, np_arg_list **optlst) {
|
|||
static char *default_file(void) {
|
||||
char *ini_file;
|
||||
|
||||
if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL || (ini_file = default_file_in_path()) != NULL) {
|
||||
if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL ||
|
||||
(ini_file = default_file_in_path()) != NULL) {
|
||||
return ini_file;
|
||||
}
|
||||
|
||||
|
|
@ -360,16 +387,19 @@ static char *default_file_in_path(void) {
|
|||
char *config_path, **file;
|
||||
char *dir, *ini_file, *tokens;
|
||||
|
||||
if ((config_path = getenv("NAGIOS_CONFIG_PATH")) == NULL)
|
||||
if ((config_path = getenv("NAGIOS_CONFIG_PATH")) == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
/* shall we spit out a warning that NAGIOS_CONFIG_PATH is deprecated? */
|
||||
|
||||
if ((tokens = strdup(config_path)) == NULL)
|
||||
if ((tokens = strdup(config_path)) == NULL) {
|
||||
die(STATE_UNKNOWN, "%s\n", _("Insufficient Memory"));
|
||||
}
|
||||
for (dir = strtok(tokens, ":"); dir != NULL; dir = strtok(NULL, ":")) {
|
||||
for (file = default_ini_file_names; *file != NULL; file++) {
|
||||
if ((asprintf(&ini_file, "%s/%s", dir, *file)) < 0)
|
||||
if ((asprintf(&ini_file, "%s/%s", dir, *file)) < 0) {
|
||||
die(STATE_UNKNOWN, "%s\n", _("Insufficient Memory"));
|
||||
}
|
||||
if (access(ini_file, F_OK) == 0) {
|
||||
free(tokens);
|
||||
return ini_file;
|
||||
|
|
|
|||
|
|
@ -180,117 +180,168 @@ int main(int argc, char **argv) {
|
|||
#endif
|
||||
|
||||
char random[1024] = {
|
||||
0x0b, 0x30, 0x44, 0x62, 0x7c, 0x22, 0x1f, 0x0d, 0x05, 0x67, 0x2c, 0x2a, 0x39, 0x21, 0x46, 0x08, 0x50, 0x66, 0x34, 0x37, 0x0b, 0x45,
|
||||
0x4b, 0x38, 0x32, 0x06, 0x7a, 0x3e, 0x7f, 0x0c, 0x40, 0x18, 0x6b, 0x2d, 0x60, 0x4c, 0x60, 0x0c, 0x23, 0x43, 0x3b, 0x3e, 0x1b, 0x16,
|
||||
0x04, 0x46, 0x58, 0x3f, 0x40, 0x6a, 0x11, 0x05, 0x63, 0x71, 0x14, 0x35, 0x47, 0x79, 0x13, 0x6f, 0x6b, 0x27, 0x18, 0x5b, 0x48, 0x27,
|
||||
0x3e, 0x6f, 0x15, 0x33, 0x4f, 0x3e, 0x5e, 0x51, 0x73, 0x68, 0x25, 0x0f, 0x06, 0x5b, 0x7c, 0x72, 0x75, 0x3e, 0x3f, 0x1b, 0x5c, 0x6d,
|
||||
0x6a, 0x39, 0x7c, 0x63, 0x63, 0x60, 0x6c, 0x7a, 0x33, 0x76, 0x52, 0x13, 0x25, 0x33, 0x7d, 0x65, 0x23, 0x27, 0x11, 0x06, 0x06, 0x47,
|
||||
0x71, 0x1e, 0x14, 0x74, 0x63, 0x70, 0x2d, 0x15, 0x27, 0x18, 0x51, 0x06, 0x05, 0x33, 0x11, 0x2c, 0x6b, 0x00, 0x2d, 0x77, 0x20, 0x48,
|
||||
0x0d, 0x73, 0x51, 0x45, 0x25, 0x7f, 0x7f, 0x35, 0x26, 0x2e, 0x26, 0x53, 0x24, 0x68, 0x1e, 0x0e, 0x58, 0x3a, 0x59, 0x50, 0x56, 0x37,
|
||||
0x5f, 0x66, 0x01, 0x4c, 0x5a, 0x64, 0x32, 0x50, 0x7b, 0x6a, 0x20, 0x72, 0x2b, 0x1d, 0x7e, 0x43, 0x7b, 0x61, 0x42, 0x0b, 0x61, 0x73,
|
||||
0x24, 0x79, 0x3a, 0x6b, 0x4a, 0x79, 0x6e, 0x09, 0x0f, 0x27, 0x2d, 0x0c, 0x5e, 0x32, 0x4b, 0x0d, 0x79, 0x46, 0x39, 0x21, 0x0a, 0x26,
|
||||
0x5f, 0x3a, 0x00, 0x26, 0x3f, 0x13, 0x2e, 0x7e, 0x50, 0x2b, 0x67, 0x46, 0x72, 0x3f, 0x3b, 0x01, 0x46, 0x1b, 0x0b, 0x35, 0x49, 0x39,
|
||||
0x19, 0x70, 0x3d, 0x02, 0x41, 0x0e, 0x38, 0x05, 0x76, 0x65, 0x4f, 0x31, 0x6c, 0x5e, 0x17, 0x04, 0x15, 0x36, 0x26, 0x64, 0x34, 0x14,
|
||||
0x17, 0x7c, 0x0e, 0x0b, 0x5b, 0x55, 0x53, 0x6b, 0x00, 0x42, 0x41, 0x4f, 0x02, 0x5c, 0x13, 0x0a, 0x2c, 0x2c, 0x3e, 0x10, 0x14, 0x33,
|
||||
0x45, 0x7c, 0x7a, 0x5a, 0x31, 0x61, 0x39, 0x08, 0x22, 0x6a, 0x1e, 0x0f, 0x6f, 0x1b, 0x6c, 0x13, 0x5e, 0x79, 0x20, 0x79, 0x50, 0x62,
|
||||
0x06, 0x2c, 0x76, 0x17, 0x04, 0x2b, 0x2a, 0x75, 0x1f, 0x0c, 0x37, 0x4e, 0x0f, 0x7b, 0x2d, 0x34, 0x75, 0x60, 0x31, 0x74, 0x2e, 0x0a,
|
||||
0x4a, 0x11, 0x6c, 0x49, 0x25, 0x01, 0x3a, 0x3d, 0x22, 0x1e, 0x6d, 0x18, 0x51, 0x78, 0x2d, 0x62, 0x31, 0x4c, 0x50, 0x40, 0x17, 0x4b,
|
||||
0x6f, 0x22, 0x00, 0x7f, 0x61, 0x2a, 0x34, 0x3e, 0x00, 0x5f, 0x2f, 0x5f, 0x2f, 0x14, 0x2a, 0x55, 0x27, 0x1f, 0x46, 0x1f, 0x12, 0x46,
|
||||
0x5e, 0x1e, 0x0c, 0x7c, 0x38, 0x01, 0x61, 0x64, 0x76, 0x22, 0x6e, 0x08, 0x20, 0x38, 0x4f, 0x73, 0x72, 0x55, 0x12, 0x42, 0x19, 0x50,
|
||||
0x61, 0x43, 0x77, 0x7d, 0x41, 0x2e, 0x35, 0x4f, 0x3d, 0x31, 0x28, 0x58, 0x67, 0x1b, 0x03, 0x51, 0x20, 0x32, 0x1c, 0x08, 0x6e, 0x37,
|
||||
0x75, 0x37, 0x44, 0x4f, 0x68, 0x19, 0x07, 0x64, 0x14, 0x28, 0x25, 0x2b, 0x69, 0x35, 0x18, 0x27, 0x26, 0x14, 0x13, 0x70, 0x42, 0x19,
|
||||
0x12, 0x75, 0x3e, 0x02, 0x5d, 0x7c, 0x13, 0x1f, 0x16, 0x53, 0x3b, 0x74, 0x48, 0x3c, 0x5e, 0x39, 0x6c, 0x1c, 0x1c, 0x74, 0x39, 0x1f,
|
||||
0x00, 0x1b, 0x06, 0x0a, 0x68, 0x3b, 0x52, 0x4f, 0x1e, 0x6e, 0x3c, 0x35, 0x0c, 0x38, 0x0e, 0x0b, 0x3b, 0x1a, 0x76, 0x23, 0x29, 0x53,
|
||||
0x1e, 0x5f, 0x41, 0x0c, 0x4b, 0x0a, 0x65, 0x28, 0x78, 0x67, 0x48, 0x59, 0x26, 0x6d, 0x31, 0x76, 0x23, 0x70, 0x61, 0x64, 0x3b, 0x38,
|
||||
0x79, 0x66, 0x74, 0x53, 0x2c, 0x64, 0x64, 0x54, 0x03, 0x54, 0x65, 0x44, 0x4c, 0x18, 0x4f, 0x48, 0x20, 0x4f, 0x72, 0x10, 0x3f, 0x0c,
|
||||
0x52, 0x2d, 0x03, 0x14, 0x03, 0x51, 0x42, 0x10, 0x77, 0x6a, 0x34, 0x06, 0x32, 0x03, 0x72, 0x14, 0x7c, 0x08, 0x5d, 0x52, 0x1a, 0x62,
|
||||
0x7c, 0x3e, 0x30, 0x7e, 0x5f, 0x7f, 0x54, 0x0f, 0x44, 0x49, 0x5d, 0x5e, 0x10, 0x6a, 0x06, 0x2b, 0x06, 0x53, 0x10, 0x39, 0x37, 0x32,
|
||||
0x4a, 0x4e, 0x3d, 0x2b, 0x65, 0x38, 0x39, 0x07, 0x72, 0x54, 0x64, 0x4d, 0x56, 0x6a, 0x03, 0x22, 0x70, 0x7b, 0x5f, 0x60, 0x0b, 0x2a,
|
||||
0x0b, 0x6b, 0x10, 0x64, 0x14, 0x05, 0x22, 0x00, 0x73, 0x40, 0x23, 0x5b, 0x51, 0x1f, 0x2b, 0x1a, 0x5d, 0x69, 0x7a, 0x46, 0x0c, 0x5f,
|
||||
0x32, 0x4b, 0x4a, 0x28, 0x52, 0x79, 0x5b, 0x12, 0x42, 0x18, 0x00, 0x5d, 0x27, 0x31, 0x53, 0x3c, 0x4c, 0x36, 0x4e, 0x38, 0x3f, 0x72,
|
||||
0x03, 0x71, 0x02, 0x5b, 0x36, 0x59, 0x7f, 0x75, 0x6e, 0x08, 0x54, 0x0d, 0x34, 0x1c, 0x34, 0x57, 0x5d, 0x69, 0x48, 0x00, 0x3b, 0x05,
|
||||
0x07, 0x6e, 0x27, 0x65, 0x6e, 0x40, 0x3d, 0x3a, 0x4f, 0x72, 0x5d, 0x39, 0x16, 0x0f, 0x63, 0x12, 0x12, 0x15, 0x3a, 0x70, 0x0d, 0x57,
|
||||
0x18, 0x0d, 0x5e, 0x3d, 0x22, 0x68, 0x68, 0x7c, 0x6d, 0x4f, 0x0c, 0x7b, 0x09, 0x2d, 0x4a, 0x73, 0x20, 0x47, 0x07, 0x57, 0x75, 0x5d,
|
||||
0x53, 0x70, 0x34, 0x21, 0x40, 0x57, 0x51, 0x5e, 0x49, 0x44, 0x00, 0x54, 0x27, 0x04, 0x68, 0x7e, 0x59, 0x56, 0x58, 0x74, 0x14, 0x3c,
|
||||
0x16, 0x33, 0x41, 0x16, 0x4b, 0x2f, 0x49, 0x37, 0x0a, 0x54, 0x08, 0x08, 0x1f, 0x39, 0x67, 0x76, 0x28, 0x28, 0x07, 0x1d, 0x61, 0x47,
|
||||
0x51, 0x4d, 0x75, 0x26, 0x52, 0x47, 0x47, 0x0c, 0x57, 0x58, 0x74, 0x3e, 0x62, 0x6c, 0x58, 0x3a, 0x44, 0x1e, 0x16, 0x2e, 0x21, 0x1c,
|
||||
0x73, 0x45, 0x67, 0x74, 0x4f, 0x33, 0x66, 0x0e, 0x74, 0x66, 0x26, 0x1f, 0x2e, 0x38, 0x44, 0x40, 0x7e, 0x2a, 0x50, 0x52, 0x5e, 0x43,
|
||||
0x01, 0x7a, 0x38, 0x49, 0x3c, 0x55, 0x4d, 0x5a, 0x44, 0x08, 0x26, 0x59, 0x4d, 0x45, 0x0b, 0x48, 0x0a, 0x33, 0x5e, 0x4a, 0x4d, 0x75,
|
||||
0x16, 0x17, 0x63, 0x46, 0x01, 0x2a, 0x55, 0x7b, 0x0f, 0x02, 0x73, 0x6a, 0x4b, 0x7f, 0x75, 0x65, 0x3c, 0x4c, 0x33, 0x39, 0x6c, 0x74,
|
||||
0x05, 0x60, 0x0f, 0x7f, 0x2d, 0x41, 0x4d, 0x4d, 0x46, 0x71, 0x09, 0x6f, 0x4f, 0x60, 0x15, 0x0f, 0x46, 0x73, 0x63, 0x4c, 0x5e, 0x74,
|
||||
0x30, 0x0d, 0x28, 0x43, 0x08, 0x72, 0x32, 0x04, 0x2e, 0x31, 0x29, 0x27, 0x44, 0x6d, 0x13, 0x17, 0x48, 0x0f, 0x49, 0x52, 0x10, 0x13,
|
||||
0x7f, 0x17, 0x16, 0x62, 0x79, 0x35, 0x78, 0x3e, 0x01, 0x7c, 0x2e, 0x0f, 0x76, 0x3e, 0x5e, 0x53, 0x6c, 0x5b, 0x5f, 0x7c, 0x19, 0x41,
|
||||
0x02, 0x2f, 0x17, 0x64, 0x41, 0x75, 0x10, 0x04, 0x47, 0x7c, 0x3d, 0x4b, 0x52, 0x00, 0x10, 0x5d, 0x51, 0x4e, 0x7a, 0x27, 0x25, 0x55,
|
||||
0x40, 0x12, 0x35, 0x60, 0x05, 0x1b, 0x34, 0x2d, 0x04, 0x7a, 0x6a, 0x69, 0x02, 0x79, 0x03, 0x3a, 0x2f, 0x06, 0x0a, 0x79, 0x7b, 0x12,
|
||||
0x5d, 0x7c, 0x52, 0x29, 0x47, 0x58, 0x12, 0x73, 0x3f, 0x27, 0x56, 0x05, 0x0c, 0x48, 0x32, 0x58, 0x6b, 0x57, 0x5c, 0x03, 0x64, 0x56,
|
||||
0x11, 0x52, 0x7a, 0x30, 0x36, 0x29, 0x17, 0x3b, 0x68, 0x7a, 0x7c, 0x05, 0x6b, 0x6b, 0x13, 0x6a, 0x24, 0x5c, 0x68, 0x42, 0x18, 0x32,
|
||||
0x03, 0x73, 0x6e, 0x04, 0x21, 0x2e, 0x01, 0x04, 0x63, 0x7d, 0x44, 0x41, 0x12, 0x31, 0x0b, 0x15, 0x1f, 0x70, 0x00, 0x2e, 0x66, 0x14,
|
||||
0x3c, 0x7f, 0x2b, 0x00, 0x1f, 0x0c, 0x28, 0x59, 0x0a, 0x16, 0x49, 0x5a, 0x5c, 0x64, 0x65, 0x4b, 0x11, 0x29, 0x15, 0x36, 0x5a, 0x65,
|
||||
0x19, 0x4f, 0x60, 0x23, 0x3a, 0x3a, 0x13, 0x25, 0x02, 0x78, 0x4c, 0x54};
|
||||
0x0b, 0x30, 0x44, 0x62, 0x7c, 0x22, 0x1f, 0x0d, 0x05, 0x67, 0x2c, 0x2a, 0x39, 0x21, 0x46,
|
||||
0x08, 0x50, 0x66, 0x34, 0x37, 0x0b, 0x45, 0x4b, 0x38, 0x32, 0x06, 0x7a, 0x3e, 0x7f, 0x0c,
|
||||
0x40, 0x18, 0x6b, 0x2d, 0x60, 0x4c, 0x60, 0x0c, 0x23, 0x43, 0x3b, 0x3e, 0x1b, 0x16, 0x04,
|
||||
0x46, 0x58, 0x3f, 0x40, 0x6a, 0x11, 0x05, 0x63, 0x71, 0x14, 0x35, 0x47, 0x79, 0x13, 0x6f,
|
||||
0x6b, 0x27, 0x18, 0x5b, 0x48, 0x27, 0x3e, 0x6f, 0x15, 0x33, 0x4f, 0x3e, 0x5e, 0x51, 0x73,
|
||||
0x68, 0x25, 0x0f, 0x06, 0x5b, 0x7c, 0x72, 0x75, 0x3e, 0x3f, 0x1b, 0x5c, 0x6d, 0x6a, 0x39,
|
||||
0x7c, 0x63, 0x63, 0x60, 0x6c, 0x7a, 0x33, 0x76, 0x52, 0x13, 0x25, 0x33, 0x7d, 0x65, 0x23,
|
||||
0x27, 0x11, 0x06, 0x06, 0x47, 0x71, 0x1e, 0x14, 0x74, 0x63, 0x70, 0x2d, 0x15, 0x27, 0x18,
|
||||
0x51, 0x06, 0x05, 0x33, 0x11, 0x2c, 0x6b, 0x00, 0x2d, 0x77, 0x20, 0x48, 0x0d, 0x73, 0x51,
|
||||
0x45, 0x25, 0x7f, 0x7f, 0x35, 0x26, 0x2e, 0x26, 0x53, 0x24, 0x68, 0x1e, 0x0e, 0x58, 0x3a,
|
||||
0x59, 0x50, 0x56, 0x37, 0x5f, 0x66, 0x01, 0x4c, 0x5a, 0x64, 0x32, 0x50, 0x7b, 0x6a, 0x20,
|
||||
0x72, 0x2b, 0x1d, 0x7e, 0x43, 0x7b, 0x61, 0x42, 0x0b, 0x61, 0x73, 0x24, 0x79, 0x3a, 0x6b,
|
||||
0x4a, 0x79, 0x6e, 0x09, 0x0f, 0x27, 0x2d, 0x0c, 0x5e, 0x32, 0x4b, 0x0d, 0x79, 0x46, 0x39,
|
||||
0x21, 0x0a, 0x26, 0x5f, 0x3a, 0x00, 0x26, 0x3f, 0x13, 0x2e, 0x7e, 0x50, 0x2b, 0x67, 0x46,
|
||||
0x72, 0x3f, 0x3b, 0x01, 0x46, 0x1b, 0x0b, 0x35, 0x49, 0x39, 0x19, 0x70, 0x3d, 0x02, 0x41,
|
||||
0x0e, 0x38, 0x05, 0x76, 0x65, 0x4f, 0x31, 0x6c, 0x5e, 0x17, 0x04, 0x15, 0x36, 0x26, 0x64,
|
||||
0x34, 0x14, 0x17, 0x7c, 0x0e, 0x0b, 0x5b, 0x55, 0x53, 0x6b, 0x00, 0x42, 0x41, 0x4f, 0x02,
|
||||
0x5c, 0x13, 0x0a, 0x2c, 0x2c, 0x3e, 0x10, 0x14, 0x33, 0x45, 0x7c, 0x7a, 0x5a, 0x31, 0x61,
|
||||
0x39, 0x08, 0x22, 0x6a, 0x1e, 0x0f, 0x6f, 0x1b, 0x6c, 0x13, 0x5e, 0x79, 0x20, 0x79, 0x50,
|
||||
0x62, 0x06, 0x2c, 0x76, 0x17, 0x04, 0x2b, 0x2a, 0x75, 0x1f, 0x0c, 0x37, 0x4e, 0x0f, 0x7b,
|
||||
0x2d, 0x34, 0x75, 0x60, 0x31, 0x74, 0x2e, 0x0a, 0x4a, 0x11, 0x6c, 0x49, 0x25, 0x01, 0x3a,
|
||||
0x3d, 0x22, 0x1e, 0x6d, 0x18, 0x51, 0x78, 0x2d, 0x62, 0x31, 0x4c, 0x50, 0x40, 0x17, 0x4b,
|
||||
0x6f, 0x22, 0x00, 0x7f, 0x61, 0x2a, 0x34, 0x3e, 0x00, 0x5f, 0x2f, 0x5f, 0x2f, 0x14, 0x2a,
|
||||
0x55, 0x27, 0x1f, 0x46, 0x1f, 0x12, 0x46, 0x5e, 0x1e, 0x0c, 0x7c, 0x38, 0x01, 0x61, 0x64,
|
||||
0x76, 0x22, 0x6e, 0x08, 0x20, 0x38, 0x4f, 0x73, 0x72, 0x55, 0x12, 0x42, 0x19, 0x50, 0x61,
|
||||
0x43, 0x77, 0x7d, 0x41, 0x2e, 0x35, 0x4f, 0x3d, 0x31, 0x28, 0x58, 0x67, 0x1b, 0x03, 0x51,
|
||||
0x20, 0x32, 0x1c, 0x08, 0x6e, 0x37, 0x75, 0x37, 0x44, 0x4f, 0x68, 0x19, 0x07, 0x64, 0x14,
|
||||
0x28, 0x25, 0x2b, 0x69, 0x35, 0x18, 0x27, 0x26, 0x14, 0x13, 0x70, 0x42, 0x19, 0x12, 0x75,
|
||||
0x3e, 0x02, 0x5d, 0x7c, 0x13, 0x1f, 0x16, 0x53, 0x3b, 0x74, 0x48, 0x3c, 0x5e, 0x39, 0x6c,
|
||||
0x1c, 0x1c, 0x74, 0x39, 0x1f, 0x00, 0x1b, 0x06, 0x0a, 0x68, 0x3b, 0x52, 0x4f, 0x1e, 0x6e,
|
||||
0x3c, 0x35, 0x0c, 0x38, 0x0e, 0x0b, 0x3b, 0x1a, 0x76, 0x23, 0x29, 0x53, 0x1e, 0x5f, 0x41,
|
||||
0x0c, 0x4b, 0x0a, 0x65, 0x28, 0x78, 0x67, 0x48, 0x59, 0x26, 0x6d, 0x31, 0x76, 0x23, 0x70,
|
||||
0x61, 0x64, 0x3b, 0x38, 0x79, 0x66, 0x74, 0x53, 0x2c, 0x64, 0x64, 0x54, 0x03, 0x54, 0x65,
|
||||
0x44, 0x4c, 0x18, 0x4f, 0x48, 0x20, 0x4f, 0x72, 0x10, 0x3f, 0x0c, 0x52, 0x2d, 0x03, 0x14,
|
||||
0x03, 0x51, 0x42, 0x10, 0x77, 0x6a, 0x34, 0x06, 0x32, 0x03, 0x72, 0x14, 0x7c, 0x08, 0x5d,
|
||||
0x52, 0x1a, 0x62, 0x7c, 0x3e, 0x30, 0x7e, 0x5f, 0x7f, 0x54, 0x0f, 0x44, 0x49, 0x5d, 0x5e,
|
||||
0x10, 0x6a, 0x06, 0x2b, 0x06, 0x53, 0x10, 0x39, 0x37, 0x32, 0x4a, 0x4e, 0x3d, 0x2b, 0x65,
|
||||
0x38, 0x39, 0x07, 0x72, 0x54, 0x64, 0x4d, 0x56, 0x6a, 0x03, 0x22, 0x70, 0x7b, 0x5f, 0x60,
|
||||
0x0b, 0x2a, 0x0b, 0x6b, 0x10, 0x64, 0x14, 0x05, 0x22, 0x00, 0x73, 0x40, 0x23, 0x5b, 0x51,
|
||||
0x1f, 0x2b, 0x1a, 0x5d, 0x69, 0x7a, 0x46, 0x0c, 0x5f, 0x32, 0x4b, 0x4a, 0x28, 0x52, 0x79,
|
||||
0x5b, 0x12, 0x42, 0x18, 0x00, 0x5d, 0x27, 0x31, 0x53, 0x3c, 0x4c, 0x36, 0x4e, 0x38, 0x3f,
|
||||
0x72, 0x03, 0x71, 0x02, 0x5b, 0x36, 0x59, 0x7f, 0x75, 0x6e, 0x08, 0x54, 0x0d, 0x34, 0x1c,
|
||||
0x34, 0x57, 0x5d, 0x69, 0x48, 0x00, 0x3b, 0x05, 0x07, 0x6e, 0x27, 0x65, 0x6e, 0x40, 0x3d,
|
||||
0x3a, 0x4f, 0x72, 0x5d, 0x39, 0x16, 0x0f, 0x63, 0x12, 0x12, 0x15, 0x3a, 0x70, 0x0d, 0x57,
|
||||
0x18, 0x0d, 0x5e, 0x3d, 0x22, 0x68, 0x68, 0x7c, 0x6d, 0x4f, 0x0c, 0x7b, 0x09, 0x2d, 0x4a,
|
||||
0x73, 0x20, 0x47, 0x07, 0x57, 0x75, 0x5d, 0x53, 0x70, 0x34, 0x21, 0x40, 0x57, 0x51, 0x5e,
|
||||
0x49, 0x44, 0x00, 0x54, 0x27, 0x04, 0x68, 0x7e, 0x59, 0x56, 0x58, 0x74, 0x14, 0x3c, 0x16,
|
||||
0x33, 0x41, 0x16, 0x4b, 0x2f, 0x49, 0x37, 0x0a, 0x54, 0x08, 0x08, 0x1f, 0x39, 0x67, 0x76,
|
||||
0x28, 0x28, 0x07, 0x1d, 0x61, 0x47, 0x51, 0x4d, 0x75, 0x26, 0x52, 0x47, 0x47, 0x0c, 0x57,
|
||||
0x58, 0x74, 0x3e, 0x62, 0x6c, 0x58, 0x3a, 0x44, 0x1e, 0x16, 0x2e, 0x21, 0x1c, 0x73, 0x45,
|
||||
0x67, 0x74, 0x4f, 0x33, 0x66, 0x0e, 0x74, 0x66, 0x26, 0x1f, 0x2e, 0x38, 0x44, 0x40, 0x7e,
|
||||
0x2a, 0x50, 0x52, 0x5e, 0x43, 0x01, 0x7a, 0x38, 0x49, 0x3c, 0x55, 0x4d, 0x5a, 0x44, 0x08,
|
||||
0x26, 0x59, 0x4d, 0x45, 0x0b, 0x48, 0x0a, 0x33, 0x5e, 0x4a, 0x4d, 0x75, 0x16, 0x17, 0x63,
|
||||
0x46, 0x01, 0x2a, 0x55, 0x7b, 0x0f, 0x02, 0x73, 0x6a, 0x4b, 0x7f, 0x75, 0x65, 0x3c, 0x4c,
|
||||
0x33, 0x39, 0x6c, 0x74, 0x05, 0x60, 0x0f, 0x7f, 0x2d, 0x41, 0x4d, 0x4d, 0x46, 0x71, 0x09,
|
||||
0x6f, 0x4f, 0x60, 0x15, 0x0f, 0x46, 0x73, 0x63, 0x4c, 0x5e, 0x74, 0x30, 0x0d, 0x28, 0x43,
|
||||
0x08, 0x72, 0x32, 0x04, 0x2e, 0x31, 0x29, 0x27, 0x44, 0x6d, 0x13, 0x17, 0x48, 0x0f, 0x49,
|
||||
0x52, 0x10, 0x13, 0x7f, 0x17, 0x16, 0x62, 0x79, 0x35, 0x78, 0x3e, 0x01, 0x7c, 0x2e, 0x0f,
|
||||
0x76, 0x3e, 0x5e, 0x53, 0x6c, 0x5b, 0x5f, 0x7c, 0x19, 0x41, 0x02, 0x2f, 0x17, 0x64, 0x41,
|
||||
0x75, 0x10, 0x04, 0x47, 0x7c, 0x3d, 0x4b, 0x52, 0x00, 0x10, 0x5d, 0x51, 0x4e, 0x7a, 0x27,
|
||||
0x25, 0x55, 0x40, 0x12, 0x35, 0x60, 0x05, 0x1b, 0x34, 0x2d, 0x04, 0x7a, 0x6a, 0x69, 0x02,
|
||||
0x79, 0x03, 0x3a, 0x2f, 0x06, 0x0a, 0x79, 0x7b, 0x12, 0x5d, 0x7c, 0x52, 0x29, 0x47, 0x58,
|
||||
0x12, 0x73, 0x3f, 0x27, 0x56, 0x05, 0x0c, 0x48, 0x32, 0x58, 0x6b, 0x57, 0x5c, 0x03, 0x64,
|
||||
0x56, 0x11, 0x52, 0x7a, 0x30, 0x36, 0x29, 0x17, 0x3b, 0x68, 0x7a, 0x7c, 0x05, 0x6b, 0x6b,
|
||||
0x13, 0x6a, 0x24, 0x5c, 0x68, 0x42, 0x18, 0x32, 0x03, 0x73, 0x6e, 0x04, 0x21, 0x2e, 0x01,
|
||||
0x04, 0x63, 0x7d, 0x44, 0x41, 0x12, 0x31, 0x0b, 0x15, 0x1f, 0x70, 0x00, 0x2e, 0x66, 0x14,
|
||||
0x3c, 0x7f, 0x2b, 0x00, 0x1f, 0x0c, 0x28, 0x59, 0x0a, 0x16, 0x49, 0x5a, 0x5c, 0x64, 0x65,
|
||||
0x4b, 0x11, 0x29, 0x15, 0x36, 0x5a, 0x65, 0x19, 0x4f, 0x60, 0x23, 0x3a, 0x3a, 0x13, 0x25,
|
||||
0x02, 0x78, 0x4c, 0x54};
|
||||
char b64_known[1369] = {
|
||||
0x43, 0x7a, 0x42, 0x45, 0x59, 0x6e, 0x77, 0x69, 0x48, 0x77, 0x30, 0x46, 0x5a, 0x79, 0x77, 0x71, 0x4f, 0x53, 0x46, 0x47, 0x43, 0x46,
|
||||
0x42, 0x6d, 0x4e, 0x44, 0x63, 0x4c, 0x52, 0x55, 0x73, 0x34, 0x4d, 0x67, 0x5a, 0x36, 0x50, 0x6e, 0x38, 0x4d, 0x51, 0x42, 0x68, 0x72,
|
||||
0x4c, 0x57, 0x42, 0x4d, 0x59, 0x41, 0x77, 0x6a, 0x51, 0x7a, 0x73, 0x2b, 0x47, 0x78, 0x59, 0x45, 0x52, 0x6c, 0x67, 0x2f, 0x51, 0x47,
|
||||
0x6f, 0x52, 0x42, 0x57, 0x4e, 0x78, 0x46, 0x44, 0x56, 0x48, 0x65, 0x52, 0x4e, 0x76, 0x61, 0x79, 0x63, 0x59, 0x57, 0x30, 0x67, 0x6e,
|
||||
0x50, 0x6d, 0x38, 0x56, 0x4d, 0x30, 0x38, 0x2b, 0x58, 0x6c, 0x46, 0x7a, 0x61, 0x43, 0x55, 0x50, 0x42, 0x6c, 0x74, 0x38, 0x63, 0x6e,
|
||||
0x55, 0x2b, 0x50, 0x78, 0x74, 0x63, 0x62, 0x57, 0x6f, 0x35, 0x66, 0x47, 0x4e, 0x6a, 0x59, 0x47, 0x78, 0x36, 0x4d, 0x33, 0x5a, 0x53,
|
||||
0x45, 0x79, 0x55, 0x7a, 0x66, 0x57, 0x55, 0x6a, 0x4a, 0x78, 0x45, 0x47, 0x42, 0x6b, 0x64, 0x78, 0x48, 0x68, 0x52, 0x30, 0x59, 0x33,
|
||||
0x41, 0x74, 0x46, 0x53, 0x63, 0x59, 0x55, 0x51, 0x59, 0x46, 0x4d, 0x78, 0x45, 0x73, 0x61, 0x77, 0x41, 0x74, 0x64, 0x79, 0x42, 0x49,
|
||||
0x44, 0x58, 0x4e, 0x52, 0x52, 0x53, 0x56, 0x2f, 0x66, 0x7a, 0x55, 0x6d, 0x4c, 0x69, 0x5a, 0x54, 0x4a, 0x47, 0x67, 0x65, 0x44, 0x6c,
|
||||
0x67, 0x36, 0x57, 0x56, 0x42, 0x57, 0x4e, 0x31, 0x39, 0x6d, 0x41, 0x55, 0x78, 0x61, 0x5a, 0x44, 0x4a, 0x51, 0x65, 0x32, 0x6f, 0x67,
|
||||
0x63, 0x69, 0x73, 0x64, 0x66, 0x6b, 0x4e, 0x37, 0x59, 0x55, 0x49, 0x4c, 0x59, 0x58, 0x4d, 0x6b, 0x65, 0x54, 0x70, 0x72, 0x53, 0x6e,
|
||||
0x6c, 0x75, 0x43, 0x51, 0x38, 0x6e, 0x4c, 0x51, 0x78, 0x65, 0x4d, 0x6b, 0x73, 0x4e, 0x65, 0x55, 0x59, 0x35, 0x49, 0x51, 0x6f, 0x6d,
|
||||
0x58, 0x7a, 0x6f, 0x41, 0x4a, 0x6a, 0x38, 0x54, 0x4c, 0x6e, 0x35, 0x51, 0x4b, 0x32, 0x64, 0x47, 0x63, 0x6a, 0x38, 0x37, 0x41, 0x55,
|
||||
0x59, 0x62, 0x43, 0x7a, 0x56, 0x4a, 0x4f, 0x52, 0x6c, 0x77, 0x50, 0x51, 0x4a, 0x42, 0x44, 0x6a, 0x67, 0x46, 0x64, 0x6d, 0x56, 0x50,
|
||||
0x4d, 0x57, 0x78, 0x65, 0x46, 0x77, 0x51, 0x56, 0x4e, 0x69, 0x5a, 0x6b, 0x4e, 0x42, 0x51, 0x58, 0x66, 0x41, 0x34, 0x4c, 0x57, 0x31,
|
||||
0x56, 0x54, 0x61, 0x77, 0x42, 0x43, 0x51, 0x55, 0x38, 0x43, 0x58, 0x42, 0x4d, 0x4b, 0x4c, 0x43, 0x77, 0x2b, 0x45, 0x42, 0x51, 0x7a,
|
||||
0x52, 0x58, 0x78, 0x36, 0x57, 0x6a, 0x46, 0x68, 0x4f, 0x51, 0x67, 0x69, 0x61, 0x68, 0x34, 0x50, 0x62, 0x78, 0x74, 0x73, 0x45, 0x31,
|
||||
0x35, 0x35, 0x49, 0x48, 0x6c, 0x51, 0x59, 0x67, 0x59, 0x73, 0x64, 0x68, 0x63, 0x45, 0x4b, 0x79, 0x70, 0x31, 0x48, 0x77, 0x77, 0x33,
|
||||
0x54, 0x67, 0x39, 0x37, 0x4c, 0x54, 0x52, 0x31, 0x59, 0x44, 0x46, 0x30, 0x4c, 0x67, 0x70, 0x4b, 0x45, 0x57, 0x78, 0x4a, 0x4a, 0x51,
|
||||
0x45, 0x36, 0x50, 0x53, 0x49, 0x65, 0x62, 0x52, 0x68, 0x52, 0x65, 0x43, 0x31, 0x69, 0x4d, 0x55, 0x78, 0x51, 0x51, 0x42, 0x64, 0x4c,
|
||||
0x62, 0x79, 0x49, 0x41, 0x66, 0x32, 0x45, 0x71, 0x4e, 0x44, 0x34, 0x41, 0x58, 0x79, 0x39, 0x66, 0x4c, 0x78, 0x51, 0x71, 0x56, 0x53,
|
||||
0x63, 0x66, 0x52, 0x68, 0x38, 0x53, 0x52, 0x6c, 0x34, 0x65, 0x44, 0x48, 0x77, 0x34, 0x41, 0x57, 0x46, 0x6b, 0x64, 0x69, 0x4a, 0x75,
|
||||
0x43, 0x43, 0x41, 0x34, 0x54, 0x33, 0x4e, 0x79, 0x56, 0x52, 0x4a, 0x43, 0x47, 0x56, 0x42, 0x68, 0x51, 0x33, 0x64, 0x39, 0x51, 0x53,
|
||||
0x34, 0x31, 0x54, 0x7a, 0x30, 0x78, 0x4b, 0x46, 0x68, 0x6e, 0x47, 0x77, 0x4e, 0x52, 0x49, 0x44, 0x49, 0x63, 0x43, 0x47, 0x34, 0x33,
|
||||
0x64, 0x54, 0x64, 0x45, 0x54, 0x32, 0x67, 0x5a, 0x42, 0x32, 0x51, 0x55, 0x4b, 0x43, 0x55, 0x72, 0x61, 0x54, 0x55, 0x59, 0x4a, 0x79,
|
||||
0x59, 0x55, 0x45, 0x33, 0x42, 0x43, 0x47, 0x52, 0x4a, 0x31, 0x50, 0x67, 0x4a, 0x64, 0x66, 0x42, 0x4d, 0x66, 0x46, 0x6c, 0x4d, 0x37,
|
||||
0x64, 0x45, 0x67, 0x38, 0x58, 0x6a, 0x6c, 0x73, 0x48, 0x42, 0x78, 0x30, 0x4f, 0x52, 0x38, 0x41, 0x47, 0x77, 0x59, 0x4b, 0x61, 0x44,
|
||||
0x74, 0x53, 0x54, 0x78, 0x35, 0x75, 0x50, 0x44, 0x55, 0x4d, 0x4f, 0x41, 0x34, 0x4c, 0x4f, 0x78, 0x70, 0x32, 0x49, 0x79, 0x6c, 0x54,
|
||||
0x48, 0x6c, 0x39, 0x42, 0x44, 0x45, 0x73, 0x4b, 0x5a, 0x53, 0x68, 0x34, 0x5a, 0x30, 0x68, 0x5a, 0x4a, 0x6d, 0x30, 0x78, 0x64, 0x69,
|
||||
0x4e, 0x77, 0x59, 0x57, 0x51, 0x37, 0x4f, 0x48, 0x6c, 0x6d, 0x64, 0x46, 0x4d, 0x73, 0x5a, 0x47, 0x52, 0x55, 0x41, 0x31, 0x52, 0x6c,
|
||||
0x52, 0x45, 0x77, 0x59, 0x54, 0x30, 0x67, 0x67, 0x54, 0x33, 0x49, 0x51, 0x50, 0x77, 0x78, 0x53, 0x4c, 0x51, 0x4d, 0x55, 0x41, 0x31,
|
||||
0x46, 0x43, 0x45, 0x48, 0x64, 0x71, 0x4e, 0x41, 0x59, 0x79, 0x41, 0x33, 0x49, 0x55, 0x66, 0x41, 0x68, 0x64, 0x55, 0x68, 0x70, 0x69,
|
||||
0x66, 0x44, 0x34, 0x77, 0x66, 0x6c, 0x39, 0x2f, 0x56, 0x41, 0x39, 0x45, 0x53, 0x56, 0x31, 0x65, 0x45, 0x47, 0x6f, 0x47, 0x4b, 0x77,
|
||||
0x5a, 0x54, 0x45, 0x44, 0x6b, 0x33, 0x4d, 0x6b, 0x70, 0x4f, 0x50, 0x53, 0x74, 0x6c, 0x4f, 0x44, 0x6b, 0x48, 0x63, 0x6c, 0x52, 0x6b,
|
||||
0x54, 0x56, 0x5a, 0x71, 0x41, 0x79, 0x4a, 0x77, 0x65, 0x31, 0x39, 0x67, 0x43, 0x79, 0x6f, 0x4c, 0x61, 0x78, 0x42, 0x6b, 0x46, 0x41,
|
||||
0x55, 0x69, 0x41, 0x48, 0x4e, 0x41, 0x49, 0x31, 0x74, 0x52, 0x48, 0x79, 0x73, 0x61, 0x58, 0x57, 0x6c, 0x36, 0x52, 0x67, 0x78, 0x66,
|
||||
0x4d, 0x6b, 0x74, 0x4b, 0x4b, 0x46, 0x4a, 0x35, 0x57, 0x78, 0x4a, 0x43, 0x47, 0x41, 0x42, 0x64, 0x4a, 0x7a, 0x46, 0x54, 0x50, 0x45,
|
||||
0x77, 0x32, 0x54, 0x6a, 0x67, 0x2f, 0x63, 0x67, 0x4e, 0x78, 0x41, 0x6c, 0x73, 0x32, 0x57, 0x58, 0x39, 0x31, 0x62, 0x67, 0x68, 0x55,
|
||||
0x44, 0x54, 0x51, 0x63, 0x4e, 0x46, 0x64, 0x64, 0x61, 0x55, 0x67, 0x41, 0x4f, 0x77, 0x55, 0x48, 0x62, 0x69, 0x64, 0x6c, 0x62, 0x6b,
|
||||
0x41, 0x39, 0x4f, 0x6b, 0x39, 0x79, 0x58, 0x54, 0x6b, 0x57, 0x44, 0x32, 0x4d, 0x53, 0x45, 0x68, 0x55, 0x36, 0x63, 0x41, 0x31, 0x58,
|
||||
0x47, 0x41, 0x31, 0x65, 0x50, 0x53, 0x4a, 0x6f, 0x61, 0x48, 0x78, 0x74, 0x54, 0x77, 0x78, 0x37, 0x43, 0x53, 0x31, 0x4b, 0x63, 0x79,
|
||||
0x42, 0x48, 0x42, 0x31, 0x64, 0x31, 0x58, 0x56, 0x4e, 0x77, 0x4e, 0x43, 0x46, 0x41, 0x56, 0x31, 0x46, 0x65, 0x53, 0x55, 0x51, 0x41,
|
||||
0x56, 0x43, 0x63, 0x45, 0x61, 0x48, 0x35, 0x5a, 0x56, 0x6c, 0x68, 0x30, 0x46, 0x44, 0x77, 0x57, 0x4d, 0x30, 0x45, 0x57, 0x53, 0x79,
|
||||
0x39, 0x4a, 0x4e, 0x77, 0x70, 0x55, 0x43, 0x41, 0x67, 0x66, 0x4f, 0x57, 0x64, 0x32, 0x4b, 0x43, 0x67, 0x48, 0x48, 0x57, 0x46, 0x48,
|
||||
0x55, 0x55, 0x31, 0x31, 0x4a, 0x6c, 0x4a, 0x48, 0x52, 0x77, 0x78, 0x58, 0x57, 0x48, 0x51, 0x2b, 0x59, 0x6d, 0x78, 0x59, 0x4f, 0x6b,
|
||||
0x51, 0x65, 0x46, 0x69, 0x34, 0x68, 0x48, 0x48, 0x4e, 0x46, 0x5a, 0x33, 0x52, 0x50, 0x4d, 0x32, 0x59, 0x4f, 0x64, 0x47, 0x59, 0x6d,
|
||||
0x48, 0x79, 0x34, 0x34, 0x52, 0x45, 0x42, 0x2b, 0x4b, 0x6c, 0x42, 0x53, 0x58, 0x6b, 0x4d, 0x42, 0x65, 0x6a, 0x68, 0x4a, 0x50, 0x46,
|
||||
0x56, 0x4e, 0x57, 0x6b, 0x51, 0x49, 0x4a, 0x6c, 0x6c, 0x4e, 0x52, 0x51, 0x74, 0x49, 0x43, 0x6a, 0x4e, 0x65, 0x53, 0x6b, 0x31, 0x31,
|
||||
0x46, 0x68, 0x64, 0x6a, 0x52, 0x67, 0x45, 0x71, 0x56, 0x58, 0x73, 0x50, 0x41, 0x6e, 0x4e, 0x71, 0x53, 0x33, 0x39, 0x31, 0x5a, 0x54,
|
||||
0x78, 0x4d, 0x4d, 0x7a, 0x6c, 0x73, 0x64, 0x41, 0x56, 0x67, 0x44, 0x33, 0x38, 0x74, 0x51, 0x55, 0x31, 0x4e, 0x52, 0x6e, 0x45, 0x4a,
|
||||
0x62, 0x30, 0x39, 0x67, 0x46, 0x51, 0x39, 0x47, 0x63, 0x32, 0x4e, 0x4d, 0x58, 0x6e, 0x51, 0x77, 0x44, 0x53, 0x68, 0x44, 0x43, 0x48,
|
||||
0x49, 0x79, 0x42, 0x43, 0x34, 0x78, 0x4b, 0x53, 0x64, 0x45, 0x62, 0x52, 0x4d, 0x58, 0x53, 0x41, 0x39, 0x4a, 0x55, 0x68, 0x41, 0x54,
|
||||
0x66, 0x78, 0x63, 0x57, 0x59, 0x6e, 0x6b, 0x31, 0x65, 0x44, 0x34, 0x42, 0x66, 0x43, 0x34, 0x50, 0x64, 0x6a, 0x35, 0x65, 0x55, 0x32,
|
||||
0x78, 0x62, 0x58, 0x33, 0x77, 0x5a, 0x51, 0x51, 0x49, 0x76, 0x46, 0x32, 0x52, 0x42, 0x64, 0x52, 0x41, 0x45, 0x52, 0x33, 0x77, 0x39,
|
||||
0x53, 0x31, 0x49, 0x41, 0x45, 0x46, 0x31, 0x52, 0x54, 0x6e, 0x6f, 0x6e, 0x4a, 0x56, 0x56, 0x41, 0x45, 0x6a, 0x56, 0x67, 0x42, 0x52,
|
||||
0x73, 0x30, 0x4c, 0x51, 0x52, 0x36, 0x61, 0x6d, 0x6b, 0x43, 0x65, 0x51, 0x4d, 0x36, 0x4c, 0x77, 0x59, 0x4b, 0x65, 0x58, 0x73, 0x53,
|
||||
0x58, 0x58, 0x78, 0x53, 0x4b, 0x55, 0x64, 0x59, 0x45, 0x6e, 0x4d, 0x2f, 0x4a, 0x31, 0x59, 0x46, 0x44, 0x45, 0x67, 0x79, 0x57, 0x47,
|
||||
0x74, 0x58, 0x58, 0x41, 0x4e, 0x6b, 0x56, 0x68, 0x46, 0x53, 0x65, 0x6a, 0x41, 0x32, 0x4b, 0x52, 0x63, 0x37, 0x61, 0x48, 0x70, 0x38,
|
||||
0x42, 0x57, 0x74, 0x72, 0x45, 0x32, 0x6f, 0x6b, 0x58, 0x47, 0x68, 0x43, 0x47, 0x44, 0x49, 0x44, 0x63, 0x32, 0x34, 0x45, 0x49, 0x53,
|
||||
0x34, 0x42, 0x42, 0x47, 0x4e, 0x39, 0x52, 0x45, 0x45, 0x53, 0x4d, 0x51, 0x73, 0x56, 0x48, 0x33, 0x41, 0x41, 0x4c, 0x6d, 0x59, 0x55,
|
||||
0x50, 0x48, 0x38, 0x72, 0x41, 0x42, 0x38, 0x4d, 0x4b, 0x46, 0x6b, 0x4b, 0x46, 0x6b, 0x6c, 0x61, 0x58, 0x47, 0x52, 0x6c, 0x53, 0x78,
|
||||
0x45, 0x70, 0x46, 0x54, 0x5a, 0x61, 0x5a, 0x52, 0x6c, 0x50, 0x59, 0x43, 0x4d, 0x36, 0x4f, 0x68, 0x4d, 0x6c, 0x41, 0x6e, 0x68, 0x4d,
|
||||
0x56, 0x41, 0x3d, 0x3d, 0x00};
|
||||
0x43, 0x7a, 0x42, 0x45, 0x59, 0x6e, 0x77, 0x69, 0x48, 0x77, 0x30, 0x46, 0x5a, 0x79, 0x77,
|
||||
0x71, 0x4f, 0x53, 0x46, 0x47, 0x43, 0x46, 0x42, 0x6d, 0x4e, 0x44, 0x63, 0x4c, 0x52, 0x55,
|
||||
0x73, 0x34, 0x4d, 0x67, 0x5a, 0x36, 0x50, 0x6e, 0x38, 0x4d, 0x51, 0x42, 0x68, 0x72, 0x4c,
|
||||
0x57, 0x42, 0x4d, 0x59, 0x41, 0x77, 0x6a, 0x51, 0x7a, 0x73, 0x2b, 0x47, 0x78, 0x59, 0x45,
|
||||
0x52, 0x6c, 0x67, 0x2f, 0x51, 0x47, 0x6f, 0x52, 0x42, 0x57, 0x4e, 0x78, 0x46, 0x44, 0x56,
|
||||
0x48, 0x65, 0x52, 0x4e, 0x76, 0x61, 0x79, 0x63, 0x59, 0x57, 0x30, 0x67, 0x6e, 0x50, 0x6d,
|
||||
0x38, 0x56, 0x4d, 0x30, 0x38, 0x2b, 0x58, 0x6c, 0x46, 0x7a, 0x61, 0x43, 0x55, 0x50, 0x42,
|
||||
0x6c, 0x74, 0x38, 0x63, 0x6e, 0x55, 0x2b, 0x50, 0x78, 0x74, 0x63, 0x62, 0x57, 0x6f, 0x35,
|
||||
0x66, 0x47, 0x4e, 0x6a, 0x59, 0x47, 0x78, 0x36, 0x4d, 0x33, 0x5a, 0x53, 0x45, 0x79, 0x55,
|
||||
0x7a, 0x66, 0x57, 0x55, 0x6a, 0x4a, 0x78, 0x45, 0x47, 0x42, 0x6b, 0x64, 0x78, 0x48, 0x68,
|
||||
0x52, 0x30, 0x59, 0x33, 0x41, 0x74, 0x46, 0x53, 0x63, 0x59, 0x55, 0x51, 0x59, 0x46, 0x4d,
|
||||
0x78, 0x45, 0x73, 0x61, 0x77, 0x41, 0x74, 0x64, 0x79, 0x42, 0x49, 0x44, 0x58, 0x4e, 0x52,
|
||||
0x52, 0x53, 0x56, 0x2f, 0x66, 0x7a, 0x55, 0x6d, 0x4c, 0x69, 0x5a, 0x54, 0x4a, 0x47, 0x67,
|
||||
0x65, 0x44, 0x6c, 0x67, 0x36, 0x57, 0x56, 0x42, 0x57, 0x4e, 0x31, 0x39, 0x6d, 0x41, 0x55,
|
||||
0x78, 0x61, 0x5a, 0x44, 0x4a, 0x51, 0x65, 0x32, 0x6f, 0x67, 0x63, 0x69, 0x73, 0x64, 0x66,
|
||||
0x6b, 0x4e, 0x37, 0x59, 0x55, 0x49, 0x4c, 0x59, 0x58, 0x4d, 0x6b, 0x65, 0x54, 0x70, 0x72,
|
||||
0x53, 0x6e, 0x6c, 0x75, 0x43, 0x51, 0x38, 0x6e, 0x4c, 0x51, 0x78, 0x65, 0x4d, 0x6b, 0x73,
|
||||
0x4e, 0x65, 0x55, 0x59, 0x35, 0x49, 0x51, 0x6f, 0x6d, 0x58, 0x7a, 0x6f, 0x41, 0x4a, 0x6a,
|
||||
0x38, 0x54, 0x4c, 0x6e, 0x35, 0x51, 0x4b, 0x32, 0x64, 0x47, 0x63, 0x6a, 0x38, 0x37, 0x41,
|
||||
0x55, 0x59, 0x62, 0x43, 0x7a, 0x56, 0x4a, 0x4f, 0x52, 0x6c, 0x77, 0x50, 0x51, 0x4a, 0x42,
|
||||
0x44, 0x6a, 0x67, 0x46, 0x64, 0x6d, 0x56, 0x50, 0x4d, 0x57, 0x78, 0x65, 0x46, 0x77, 0x51,
|
||||
0x56, 0x4e, 0x69, 0x5a, 0x6b, 0x4e, 0x42, 0x51, 0x58, 0x66, 0x41, 0x34, 0x4c, 0x57, 0x31,
|
||||
0x56, 0x54, 0x61, 0x77, 0x42, 0x43, 0x51, 0x55, 0x38, 0x43, 0x58, 0x42, 0x4d, 0x4b, 0x4c,
|
||||
0x43, 0x77, 0x2b, 0x45, 0x42, 0x51, 0x7a, 0x52, 0x58, 0x78, 0x36, 0x57, 0x6a, 0x46, 0x68,
|
||||
0x4f, 0x51, 0x67, 0x69, 0x61, 0x68, 0x34, 0x50, 0x62, 0x78, 0x74, 0x73, 0x45, 0x31, 0x35,
|
||||
0x35, 0x49, 0x48, 0x6c, 0x51, 0x59, 0x67, 0x59, 0x73, 0x64, 0x68, 0x63, 0x45, 0x4b, 0x79,
|
||||
0x70, 0x31, 0x48, 0x77, 0x77, 0x33, 0x54, 0x67, 0x39, 0x37, 0x4c, 0x54, 0x52, 0x31, 0x59,
|
||||
0x44, 0x46, 0x30, 0x4c, 0x67, 0x70, 0x4b, 0x45, 0x57, 0x78, 0x4a, 0x4a, 0x51, 0x45, 0x36,
|
||||
0x50, 0x53, 0x49, 0x65, 0x62, 0x52, 0x68, 0x52, 0x65, 0x43, 0x31, 0x69, 0x4d, 0x55, 0x78,
|
||||
0x51, 0x51, 0x42, 0x64, 0x4c, 0x62, 0x79, 0x49, 0x41, 0x66, 0x32, 0x45, 0x71, 0x4e, 0x44,
|
||||
0x34, 0x41, 0x58, 0x79, 0x39, 0x66, 0x4c, 0x78, 0x51, 0x71, 0x56, 0x53, 0x63, 0x66, 0x52,
|
||||
0x68, 0x38, 0x53, 0x52, 0x6c, 0x34, 0x65, 0x44, 0x48, 0x77, 0x34, 0x41, 0x57, 0x46, 0x6b,
|
||||
0x64, 0x69, 0x4a, 0x75, 0x43, 0x43, 0x41, 0x34, 0x54, 0x33, 0x4e, 0x79, 0x56, 0x52, 0x4a,
|
||||
0x43, 0x47, 0x56, 0x42, 0x68, 0x51, 0x33, 0x64, 0x39, 0x51, 0x53, 0x34, 0x31, 0x54, 0x7a,
|
||||
0x30, 0x78, 0x4b, 0x46, 0x68, 0x6e, 0x47, 0x77, 0x4e, 0x52, 0x49, 0x44, 0x49, 0x63, 0x43,
|
||||
0x47, 0x34, 0x33, 0x64, 0x54, 0x64, 0x45, 0x54, 0x32, 0x67, 0x5a, 0x42, 0x32, 0x51, 0x55,
|
||||
0x4b, 0x43, 0x55, 0x72, 0x61, 0x54, 0x55, 0x59, 0x4a, 0x79, 0x59, 0x55, 0x45, 0x33, 0x42,
|
||||
0x43, 0x47, 0x52, 0x4a, 0x31, 0x50, 0x67, 0x4a, 0x64, 0x66, 0x42, 0x4d, 0x66, 0x46, 0x6c,
|
||||
0x4d, 0x37, 0x64, 0x45, 0x67, 0x38, 0x58, 0x6a, 0x6c, 0x73, 0x48, 0x42, 0x78, 0x30, 0x4f,
|
||||
0x52, 0x38, 0x41, 0x47, 0x77, 0x59, 0x4b, 0x61, 0x44, 0x74, 0x53, 0x54, 0x78, 0x35, 0x75,
|
||||
0x50, 0x44, 0x55, 0x4d, 0x4f, 0x41, 0x34, 0x4c, 0x4f, 0x78, 0x70, 0x32, 0x49, 0x79, 0x6c,
|
||||
0x54, 0x48, 0x6c, 0x39, 0x42, 0x44, 0x45, 0x73, 0x4b, 0x5a, 0x53, 0x68, 0x34, 0x5a, 0x30,
|
||||
0x68, 0x5a, 0x4a, 0x6d, 0x30, 0x78, 0x64, 0x69, 0x4e, 0x77, 0x59, 0x57, 0x51, 0x37, 0x4f,
|
||||
0x48, 0x6c, 0x6d, 0x64, 0x46, 0x4d, 0x73, 0x5a, 0x47, 0x52, 0x55, 0x41, 0x31, 0x52, 0x6c,
|
||||
0x52, 0x45, 0x77, 0x59, 0x54, 0x30, 0x67, 0x67, 0x54, 0x33, 0x49, 0x51, 0x50, 0x77, 0x78,
|
||||
0x53, 0x4c, 0x51, 0x4d, 0x55, 0x41, 0x31, 0x46, 0x43, 0x45, 0x48, 0x64, 0x71, 0x4e, 0x41,
|
||||
0x59, 0x79, 0x41, 0x33, 0x49, 0x55, 0x66, 0x41, 0x68, 0x64, 0x55, 0x68, 0x70, 0x69, 0x66,
|
||||
0x44, 0x34, 0x77, 0x66, 0x6c, 0x39, 0x2f, 0x56, 0x41, 0x39, 0x45, 0x53, 0x56, 0x31, 0x65,
|
||||
0x45, 0x47, 0x6f, 0x47, 0x4b, 0x77, 0x5a, 0x54, 0x45, 0x44, 0x6b, 0x33, 0x4d, 0x6b, 0x70,
|
||||
0x4f, 0x50, 0x53, 0x74, 0x6c, 0x4f, 0x44, 0x6b, 0x48, 0x63, 0x6c, 0x52, 0x6b, 0x54, 0x56,
|
||||
0x5a, 0x71, 0x41, 0x79, 0x4a, 0x77, 0x65, 0x31, 0x39, 0x67, 0x43, 0x79, 0x6f, 0x4c, 0x61,
|
||||
0x78, 0x42, 0x6b, 0x46, 0x41, 0x55, 0x69, 0x41, 0x48, 0x4e, 0x41, 0x49, 0x31, 0x74, 0x52,
|
||||
0x48, 0x79, 0x73, 0x61, 0x58, 0x57, 0x6c, 0x36, 0x52, 0x67, 0x78, 0x66, 0x4d, 0x6b, 0x74,
|
||||
0x4b, 0x4b, 0x46, 0x4a, 0x35, 0x57, 0x78, 0x4a, 0x43, 0x47, 0x41, 0x42, 0x64, 0x4a, 0x7a,
|
||||
0x46, 0x54, 0x50, 0x45, 0x77, 0x32, 0x54, 0x6a, 0x67, 0x2f, 0x63, 0x67, 0x4e, 0x78, 0x41,
|
||||
0x6c, 0x73, 0x32, 0x57, 0x58, 0x39, 0x31, 0x62, 0x67, 0x68, 0x55, 0x44, 0x54, 0x51, 0x63,
|
||||
0x4e, 0x46, 0x64, 0x64, 0x61, 0x55, 0x67, 0x41, 0x4f, 0x77, 0x55, 0x48, 0x62, 0x69, 0x64,
|
||||
0x6c, 0x62, 0x6b, 0x41, 0x39, 0x4f, 0x6b, 0x39, 0x79, 0x58, 0x54, 0x6b, 0x57, 0x44, 0x32,
|
||||
0x4d, 0x53, 0x45, 0x68, 0x55, 0x36, 0x63, 0x41, 0x31, 0x58, 0x47, 0x41, 0x31, 0x65, 0x50,
|
||||
0x53, 0x4a, 0x6f, 0x61, 0x48, 0x78, 0x74, 0x54, 0x77, 0x78, 0x37, 0x43, 0x53, 0x31, 0x4b,
|
||||
0x63, 0x79, 0x42, 0x48, 0x42, 0x31, 0x64, 0x31, 0x58, 0x56, 0x4e, 0x77, 0x4e, 0x43, 0x46,
|
||||
0x41, 0x56, 0x31, 0x46, 0x65, 0x53, 0x55, 0x51, 0x41, 0x56, 0x43, 0x63, 0x45, 0x61, 0x48,
|
||||
0x35, 0x5a, 0x56, 0x6c, 0x68, 0x30, 0x46, 0x44, 0x77, 0x57, 0x4d, 0x30, 0x45, 0x57, 0x53,
|
||||
0x79, 0x39, 0x4a, 0x4e, 0x77, 0x70, 0x55, 0x43, 0x41, 0x67, 0x66, 0x4f, 0x57, 0x64, 0x32,
|
||||
0x4b, 0x43, 0x67, 0x48, 0x48, 0x57, 0x46, 0x48, 0x55, 0x55, 0x31, 0x31, 0x4a, 0x6c, 0x4a,
|
||||
0x48, 0x52, 0x77, 0x78, 0x58, 0x57, 0x48, 0x51, 0x2b, 0x59, 0x6d, 0x78, 0x59, 0x4f, 0x6b,
|
||||
0x51, 0x65, 0x46, 0x69, 0x34, 0x68, 0x48, 0x48, 0x4e, 0x46, 0x5a, 0x33, 0x52, 0x50, 0x4d,
|
||||
0x32, 0x59, 0x4f, 0x64, 0x47, 0x59, 0x6d, 0x48, 0x79, 0x34, 0x34, 0x52, 0x45, 0x42, 0x2b,
|
||||
0x4b, 0x6c, 0x42, 0x53, 0x58, 0x6b, 0x4d, 0x42, 0x65, 0x6a, 0x68, 0x4a, 0x50, 0x46, 0x56,
|
||||
0x4e, 0x57, 0x6b, 0x51, 0x49, 0x4a, 0x6c, 0x6c, 0x4e, 0x52, 0x51, 0x74, 0x49, 0x43, 0x6a,
|
||||
0x4e, 0x65, 0x53, 0x6b, 0x31, 0x31, 0x46, 0x68, 0x64, 0x6a, 0x52, 0x67, 0x45, 0x71, 0x56,
|
||||
0x58, 0x73, 0x50, 0x41, 0x6e, 0x4e, 0x71, 0x53, 0x33, 0x39, 0x31, 0x5a, 0x54, 0x78, 0x4d,
|
||||
0x4d, 0x7a, 0x6c, 0x73, 0x64, 0x41, 0x56, 0x67, 0x44, 0x33, 0x38, 0x74, 0x51, 0x55, 0x31,
|
||||
0x4e, 0x52, 0x6e, 0x45, 0x4a, 0x62, 0x30, 0x39, 0x67, 0x46, 0x51, 0x39, 0x47, 0x63, 0x32,
|
||||
0x4e, 0x4d, 0x58, 0x6e, 0x51, 0x77, 0x44, 0x53, 0x68, 0x44, 0x43, 0x48, 0x49, 0x79, 0x42,
|
||||
0x43, 0x34, 0x78, 0x4b, 0x53, 0x64, 0x45, 0x62, 0x52, 0x4d, 0x58, 0x53, 0x41, 0x39, 0x4a,
|
||||
0x55, 0x68, 0x41, 0x54, 0x66, 0x78, 0x63, 0x57, 0x59, 0x6e, 0x6b, 0x31, 0x65, 0x44, 0x34,
|
||||
0x42, 0x66, 0x43, 0x34, 0x50, 0x64, 0x6a, 0x35, 0x65, 0x55, 0x32, 0x78, 0x62, 0x58, 0x33,
|
||||
0x77, 0x5a, 0x51, 0x51, 0x49, 0x76, 0x46, 0x32, 0x52, 0x42, 0x64, 0x52, 0x41, 0x45, 0x52,
|
||||
0x33, 0x77, 0x39, 0x53, 0x31, 0x49, 0x41, 0x45, 0x46, 0x31, 0x52, 0x54, 0x6e, 0x6f, 0x6e,
|
||||
0x4a, 0x56, 0x56, 0x41, 0x45, 0x6a, 0x56, 0x67, 0x42, 0x52, 0x73, 0x30, 0x4c, 0x51, 0x52,
|
||||
0x36, 0x61, 0x6d, 0x6b, 0x43, 0x65, 0x51, 0x4d, 0x36, 0x4c, 0x77, 0x59, 0x4b, 0x65, 0x58,
|
||||
0x73, 0x53, 0x58, 0x58, 0x78, 0x53, 0x4b, 0x55, 0x64, 0x59, 0x45, 0x6e, 0x4d, 0x2f, 0x4a,
|
||||
0x31, 0x59, 0x46, 0x44, 0x45, 0x67, 0x79, 0x57, 0x47, 0x74, 0x58, 0x58, 0x41, 0x4e, 0x6b,
|
||||
0x56, 0x68, 0x46, 0x53, 0x65, 0x6a, 0x41, 0x32, 0x4b, 0x52, 0x63, 0x37, 0x61, 0x48, 0x70,
|
||||
0x38, 0x42, 0x57, 0x74, 0x72, 0x45, 0x32, 0x6f, 0x6b, 0x58, 0x47, 0x68, 0x43, 0x47, 0x44,
|
||||
0x49, 0x44, 0x63, 0x32, 0x34, 0x45, 0x49, 0x53, 0x34, 0x42, 0x42, 0x47, 0x4e, 0x39, 0x52,
|
||||
0x45, 0x45, 0x53, 0x4d, 0x51, 0x73, 0x56, 0x48, 0x33, 0x41, 0x41, 0x4c, 0x6d, 0x59, 0x55,
|
||||
0x50, 0x48, 0x38, 0x72, 0x41, 0x42, 0x38, 0x4d, 0x4b, 0x46, 0x6b, 0x4b, 0x46, 0x6b, 0x6c,
|
||||
0x61, 0x58, 0x47, 0x52, 0x6c, 0x53, 0x78, 0x45, 0x70, 0x46, 0x54, 0x5a, 0x61, 0x5a, 0x52,
|
||||
0x6c, 0x50, 0x59, 0x43, 0x4d, 0x36, 0x4f, 0x68, 0x4d, 0x6c, 0x41, 0x6e, 0x68, 0x4d, 0x56,
|
||||
0x41, 0x3d, 0x3d, 0x00};
|
||||
char *b64_test;
|
||||
|
||||
plan_tests(1);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ int main(int argc, char **argv) {
|
|||
result = cmd_run_array(command_line, &chld_out, &chld_err, 0);
|
||||
ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines");
|
||||
ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines");
|
||||
ok(strcmp(chld_out.line[0], "this is test one") == 0, "(array) Check for expected stdout output");
|
||||
ok(strcmp(chld_out.line[0], "this is test one") == 0,
|
||||
"(array) Check for expected stdout output");
|
||||
ok(result == 0, "(array) Checking exit code");
|
||||
|
||||
/* ensure everything is empty again */
|
||||
|
|
@ -82,7 +83,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines");
|
||||
ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines");
|
||||
ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output");
|
||||
ok(strcmp(chld_out.line[0], "this is test one") == 0,
|
||||
"(string) Check for expected stdout output");
|
||||
ok(result == 0, "(string) Checking exit code");
|
||||
|
||||
diag("Running plain echo command, set two");
|
||||
|
|
@ -104,7 +106,8 @@ int main(int argc, char **argv) {
|
|||
result = cmd_run_array(command_line, &chld_out, &chld_err, 0);
|
||||
ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines");
|
||||
ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines");
|
||||
ok(strcmp(chld_out.line[0], "this is test two") == 0, "(array) Check for expected stdout output");
|
||||
ok(strcmp(chld_out.line[0], "this is test two") == 0,
|
||||
"(array) Check for expected stdout output");
|
||||
ok(result == 0, "(array) Checking exit code");
|
||||
|
||||
/* ensure everything is empty again */
|
||||
|
|
@ -119,7 +122,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines");
|
||||
ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines");
|
||||
ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output");
|
||||
ok(strcmp(chld_out.line[0], "this is test one") == 0,
|
||||
"(string) Check for expected stdout output");
|
||||
ok(result == 0, "(string) Checking exit code");
|
||||
|
||||
/* ensure everything is empty again */
|
||||
|
|
@ -130,7 +134,8 @@ int main(int argc, char **argv) {
|
|||
ok(chld_err.lines == 0, "(initialised) Checking stderr is reset");
|
||||
ok(result == UNSET, "(initialised) Checking exit code is reset");
|
||||
|
||||
/* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */
|
||||
/* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line
|
||||
* output */
|
||||
command_line[0] = strdup("/bin/echo");
|
||||
command_line[1] = strdup("this is a test via echo\nline two\nit's line 3");
|
||||
command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated");
|
||||
|
|
@ -138,9 +143,12 @@ int main(int argc, char **argv) {
|
|||
result = cmd_run_array(command_line, &chld_out, &chld_err, 0);
|
||||
ok(chld_out.lines == 3, "(array) Check for expected number of stdout lines");
|
||||
ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines");
|
||||
ok(strcmp(chld_out.line[0], "this is a test via echo") == 0, "(array) Check line 1 for expected stdout output");
|
||||
ok(strcmp(chld_out.line[1], "line two") == 0, "(array) Check line 2 for expected stdout output");
|
||||
ok(strcmp(chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0,
|
||||
ok(strcmp(chld_out.line[0], "this is a test via echo") == 0,
|
||||
"(array) Check line 1 for expected stdout output");
|
||||
ok(strcmp(chld_out.line[1], "line two") == 0,
|
||||
"(array) Check line 2 for expected stdout output");
|
||||
ok(strcmp(chld_out.line[2],
|
||||
"it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0,
|
||||
"(array) Check line 3 for expected stdout output");
|
||||
ok(result == 0, "(array) Checking exit code");
|
||||
|
||||
|
|
@ -171,7 +179,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing...");
|
||||
ok(chld_err.lines == 1, "...but does give an error line");
|
||||
ok(strstr(chld_err.line[0], "non-existent-file") != NULL, "And missing filename is in error message");
|
||||
ok(strstr(chld_err.line[0], "non-existent-file") != NULL,
|
||||
"And missing filename is in error message");
|
||||
ok(result != 0, "Get non-zero return code from /bin/sh");
|
||||
|
||||
/* ensure everything is empty again */
|
||||
|
|
|
|||
|
|
@ -110,7 +110,8 @@ void test_two_subchecks(void) {
|
|||
sc1.output = "foobar";
|
||||
sc1 = mp_set_subcheck_state(sc1, STATE_WARNING);
|
||||
|
||||
ok(mp_compute_subcheck_state(sc1) == STATE_WARNING, "Test subcheck state directly after setting it");
|
||||
ok(mp_compute_subcheck_state(sc1) == STATE_WARNING,
|
||||
"Test subcheck state directly after setting it");
|
||||
|
||||
mp_perfdata pd1 = perfdata_init();
|
||||
|
||||
|
|
@ -129,7 +130,8 @@ void test_two_subchecks(void) {
|
|||
|
||||
mp_add_subcheck_to_subcheck(&sc1, sc2);
|
||||
|
||||
ok(mp_compute_subcheck_state(sc1) == STATE_WARNING, "Test subcheck state after adding a subcheck");
|
||||
ok(mp_compute_subcheck_state(sc1) == STATE_WARNING,
|
||||
"Test subcheck state after adding a subcheck");
|
||||
|
||||
mp_check check = mp_check_init();
|
||||
mp_add_subcheck_to_check(&check, sc1);
|
||||
|
|
|
|||
|
|
@ -42,8 +42,9 @@ char *list2str(np_arg_list *optlst) {
|
|||
free(optltmp);
|
||||
}
|
||||
/* Strip last whitespace */
|
||||
if (strlen(optstr) > 1)
|
||||
if (strlen(optstr) > 1) {
|
||||
optstr[strlen(optstr) - 1] = '\0';
|
||||
}
|
||||
|
||||
return optstr;
|
||||
}
|
||||
|
|
@ -54,15 +55,18 @@ int main(int argc, char **argv) {
|
|||
plan_tests(12);
|
||||
|
||||
optstr = list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
|
||||
ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
|
||||
ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"),
|
||||
"config-tiny.ini's section as expected");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("@./config-tiny.ini", "section"));
|
||||
ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific");
|
||||
ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"),
|
||||
"Used default section name, without specific");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
|
||||
ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
|
||||
ok(!strcmp(optstr, "--something else=blah --remove=whitespace"),
|
||||
"config-tiny.ini's Section Two as expected");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk"));
|
||||
|
|
@ -70,15 +74,18 @@ int main(int argc, char **argv) {
|
|||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk"));
|
||||
ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name");
|
||||
ok(!strcmp(optstr, "--this=that"),
|
||||
"config-tiny.ini's section2 with whitespace before section name");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk"));
|
||||
ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name");
|
||||
ok(!strcmp(optstr, "--this=that"),
|
||||
"config-tiny.ini's section3 with whitespace after section name");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk"));
|
||||
ok(!strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected");
|
||||
ok(!strcmp(optstr, "--username=operator --password=secret"),
|
||||
"plugin.ini's check_mysql as expected");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk"));
|
||||
|
|
@ -90,29 +97,39 @@ int main(int argc, char **argv) {
|
|||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk"));
|
||||
ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected");
|
||||
ok(!strcmp(optstr, "--something else=blah --remove=whitespace"),
|
||||
"config-dos.ini's Section Two as expected");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk"));
|
||||
ok(!strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file");
|
||||
ok(!strcmp(optstr, "--foo=bar --bar=foo"),
|
||||
"plugin.ini's section_twice defined twice in the file");
|
||||
my_free(optstr);
|
||||
|
||||
optstr = list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp"));
|
||||
ok(!strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar "
|
||||
ok(!strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar "
|
||||
"BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar "
|
||||
"BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo "
|
||||
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda --expect=Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo "
|
||||
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar "
|
||||
"BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo "
|
||||
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo "
|
||||
"bar BAZ yadda yadda yadda --jail"),
|
||||
"Long options");
|
||||
my_free(optstr);
|
||||
|
|
|
|||
|
|
@ -47,16 +47,18 @@ void my_free(int *argc, char **newargv, char **argv) {
|
|||
printf("'%s' ", newargv[i]);
|
||||
/* Stop freeing when we get to the start of the original array */
|
||||
if (freeflag) {
|
||||
if (newargv[i] == argv[1])
|
||||
if (newargv[i] == argv[1]) {
|
||||
freeflag = 0;
|
||||
else
|
||||
} else {
|
||||
free(newargv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
/* Free only if it's a different array */
|
||||
if (newargv != argv)
|
||||
if (newargv != argv) {
|
||||
free(newargv);
|
||||
}
|
||||
*argc = 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -69,8 +71,9 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
|
|||
return 0;
|
||||
}
|
||||
for (i = 0; i <= i1; i++) {
|
||||
if (a1[i] == NULL && a2[i] == NULL)
|
||||
if (a1[i] == NULL && a2[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (a1[i] == NULL || a2[i] == NULL) {
|
||||
printf(" Argument # %i null in one array!\n", i);
|
||||
return 0;
|
||||
|
|
@ -110,27 +113,36 @@ int main(int argc, char **argv) {
|
|||
{
|
||||
char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *)NULL};
|
||||
argc_test = 2;
|
||||
char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *)NULL};
|
||||
char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank",
|
||||
(char *)NULL};
|
||||
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
|
||||
ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section");
|
||||
my_free(&argc_test, argv_new, argv_test);
|
||||
}
|
||||
|
||||
{
|
||||
char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *)NULL};
|
||||
char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts",
|
||||
"sect2@./config-opts.ini", (char *)NULL};
|
||||
argc_test = 4;
|
||||
char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *)NULL};
|
||||
char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that",
|
||||
(char *)NULL};
|
||||
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
|
||||
ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice");
|
||||
my_free(&argc_test, argv_new, argv_test);
|
||||
}
|
||||
|
||||
{
|
||||
char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini",
|
||||
"--arg2", (char *)NULL};
|
||||
char *argv_test[] = {"prog_name",
|
||||
"--arg1=val1",
|
||||
"--extra-opts=@./config-opts.ini",
|
||||
"--extra-opts",
|
||||
"sect1@./config-opts.ini",
|
||||
"--arg2",
|
||||
(char *)NULL};
|
||||
argc_test = 6;
|
||||
char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two",
|
||||
"--arg1=val1", "--arg2", (char *)NULL};
|
||||
char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!",
|
||||
"--blank", "--one=two", "--arg1=val1",
|
||||
"--arg2", (char *)NULL};
|
||||
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
|
||||
ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections");
|
||||
my_free(&argc_test, argv_new, argv_test);
|
||||
|
|
|
|||
|
|
@ -30,16 +30,18 @@ void my_free(int *argc, char **newargv, char **argv) {
|
|||
printf("'%s' ", newargv[i]);
|
||||
/* Stop freeing when we get to the start of the original array */
|
||||
if (freeflag) {
|
||||
if (newargv[i] == argv[1])
|
||||
if (newargv[i] == argv[1]) {
|
||||
freeflag = 0;
|
||||
else
|
||||
} else {
|
||||
free(newargv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
/* Free only if it's a different array */
|
||||
if (newargv != argv)
|
||||
if (newargv != argv) {
|
||||
free(newargv);
|
||||
}
|
||||
*argc = 0;
|
||||
}
|
||||
|
||||
|
|
@ -51,8 +53,9 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
|
|||
return 0;
|
||||
}
|
||||
for (i = 0; i <= i1; i++) {
|
||||
if (a1[i] == NULL && a2[i] == NULL)
|
||||
if (a1[i] == NULL && a2[i] == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (a1[i] == NULL || a2[i] == NULL) {
|
||||
printf(" Argument # %i null in one array!\n", i);
|
||||
return 0;
|
||||
|
|
@ -90,7 +93,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
{
|
||||
char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *)NULL};
|
||||
char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1",
|
||||
"--arg3", "val2", (char *)NULL};
|
||||
argc_test = 5;
|
||||
char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *)NULL};
|
||||
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
|
||||
|
|
@ -108,30 +112,39 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
{
|
||||
char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *)NULL};
|
||||
char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines",
|
||||
(char *)NULL};
|
||||
argc_test = 3;
|
||||
char *argv_known[] = {
|
||||
"check_tcp",
|
||||
"--timeout=10",
|
||||
"--escape",
|
||||
"--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar "
|
||||
"BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda",
|
||||
"--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar "
|
||||
"BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo "
|
||||
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda",
|
||||
"--jail",
|
||||
(char *)NULL};
|
||||
char *argv_known[] = {"check_tcp",
|
||||
"--timeout=10",
|
||||
"--escape",
|
||||
"--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda "
|
||||
"Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar "
|
||||
"BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda",
|
||||
"--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
|
||||
"yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
|
||||
"yadda yadda Foo bar "
|
||||
"BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo "
|
||||
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
|
||||
"yadda yadda yadda Foo bar BAZ yadda yadda yadda",
|
||||
"--jail",
|
||||
(char *)NULL};
|
||||
argv_new = np_extra_opts(&argc_test, argv_test, "check_tcp");
|
||||
ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test");
|
||||
my_free(&argc_test, argv_new, argv_test);
|
||||
|
|
|
|||
|
|
@ -32,19 +32,28 @@ int main(void) {
|
|||
server_expect[1] = strdup("bb");
|
||||
server_expect[2] = strdup("CC");
|
||||
|
||||
ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
|
||||
ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
|
||||
NP_MATCH_SUCCESS,
|
||||
"Test matching any string at the beginning (first expect string)");
|
||||
ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
|
||||
ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
|
||||
NP_MATCH_SUCCESS,
|
||||
"Test matching any string at the beginning (second expect string)");
|
||||
ok(np_expect_match("b", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_RETRY,
|
||||
"Test matching any string at the beginning (substring match)");
|
||||
ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE,
|
||||
ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
|
||||
NP_MATCH_FAILURE,
|
||||
"Test with strings not matching at the beginning");
|
||||
ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, "Test matching any string");
|
||||
ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, "Test not matching any string");
|
||||
ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS,
|
||||
ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
|
||||
NP_MATCH_FAILURE,
|
||||
"Test matching any string");
|
||||
ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY,
|
||||
"Test not matching any string");
|
||||
ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) ==
|
||||
NP_MATCH_SUCCESS,
|
||||
"Test matching all strings");
|
||||
ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, "Test not matching all strings");
|
||||
ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) ==
|
||||
NP_MATCH_RETRY,
|
||||
"Test not matching all strings");
|
||||
ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY,
|
||||
"Test not matching any string (testing all)");
|
||||
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ bool check_range(double value, range *my_range) {
|
|||
yes = false;
|
||||
}
|
||||
|
||||
if (!my_range->end_infinity&& !my_range->start_infinity) {
|
||||
if (!my_range->end_infinity && !my_range->start_infinity) {
|
||||
if ((my_range->start <= value) && (value <= my_range->end)) {
|
||||
return no;
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ bool check_range(double value, range *my_range) {
|
|||
return yes;
|
||||
}
|
||||
|
||||
if (my_range->start_infinity && !my_range->end_infinity ) {
|
||||
if (my_range->start_infinity && !my_range->end_infinity) {
|
||||
if (value <= my_range->end) {
|
||||
return no;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ extern char **environ;
|
|||
#endif
|
||||
|
||||
#ifndef WIFEXITED
|
||||
# define WIFEXITED(stat_val) (((stat_val)&255) == 0)
|
||||
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
||||
#endif
|
||||
|
||||
/* 4.3BSD Reno <signal.h> doesn't define SIG_ERR */
|
||||
|
|
@ -103,8 +103,9 @@ void cmd_init(void) {
|
|||
maxfd = MAXFD_LIMIT;
|
||||
}
|
||||
|
||||
if (!_cmd_pids)
|
||||
if (!_cmd_pids) {
|
||||
_cmd_pids = calloc(maxfd, sizeof(pid_t));
|
||||
}
|
||||
}
|
||||
|
||||
/* Start running a command, array style */
|
||||
|
|
@ -116,13 +117,15 @@ static int _cmd_open(char *const *argv, int *pfd, int *pfderr) {
|
|||
|
||||
int i = 0;
|
||||
|
||||
if (!_cmd_pids)
|
||||
if (!_cmd_pids) {
|
||||
CMD_INIT;
|
||||
}
|
||||
|
||||
setenv("LC_ALL", "C", 1);
|
||||
|
||||
if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0)
|
||||
if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0) {
|
||||
return -1; /* errno set by the failing function */
|
||||
}
|
||||
|
||||
/* child runs exceve() and _exit. */
|
||||
if (pid == 0) {
|
||||
|
|
@ -147,9 +150,11 @@ static int _cmd_open(char *const *argv, int *pfd, int *pfderr) {
|
|||
* 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 (_cmd_pids[i] > 0)
|
||||
for (i = 0; i < maxfd; i++) {
|
||||
if (_cmd_pids[i] > 0) {
|
||||
close(i);
|
||||
}
|
||||
}
|
||||
|
||||
execve(argv[0], argv, environ);
|
||||
_exit(STATE_UNKNOWN);
|
||||
|
|
@ -172,17 +177,21 @@ static int _cmd_close(int fd) {
|
|||
|
||||
/* make sure the provided fd was opened */
|
||||
long maxfd = mp_open_max();
|
||||
if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0)
|
||||
if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
_cmd_pids[fd] = 0;
|
||||
if (close(fd) == -1)
|
||||
if (close(fd) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* EINTR is ok (sort of), everything else is bad */
|
||||
while (waitpid(pid, &status, 0) < 0)
|
||||
if (errno != EINTR)
|
||||
while (waitpid(pid, &status, 0) < 0) {
|
||||
if (errno != EINTR) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* return child's termination status */
|
||||
return (WIFEXITED(status)) ? WEXITSTATUS(status) : -1;
|
||||
|
|
@ -212,15 +221,17 @@ static int _cmd_fetch_output(int fd, output *op, int flags) {
|
|||
|
||||
/* some plugins may want to keep output unbroken, and some commands
|
||||
* will yield no output, so return here for those */
|
||||
if (flags & CMD_NO_ARRAYS || !op->buf || !op->buflen)
|
||||
if (flags & CMD_NO_ARRAYS || !op->buf || !op->buflen) {
|
||||
return op->buflen;
|
||||
}
|
||||
|
||||
/* and some may want both */
|
||||
if (flags & CMD_NO_ASSOC) {
|
||||
buf = malloc(op->buflen);
|
||||
memcpy(buf, op->buf, op->buflen);
|
||||
} else
|
||||
} else {
|
||||
buf = op->buf;
|
||||
}
|
||||
|
||||
op->line = NULL;
|
||||
op->lens = NULL;
|
||||
|
|
@ -241,8 +252,9 @@ static int _cmd_fetch_output(int fd, output *op, int flags) {
|
|||
op->line[lineno] = &buf[i];
|
||||
|
||||
/* hop to next newline or end of buffer */
|
||||
while (buf[i] != '\n' && i < op->buflen)
|
||||
while (buf[i] != '\n' && i < op->buflen) {
|
||||
i++;
|
||||
}
|
||||
buf[i] = '\0';
|
||||
|
||||
/* calculate the string length using pointer difference */
|
||||
|
|
@ -262,30 +274,36 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) {
|
|||
char *cmd = NULL;
|
||||
char *str = NULL;
|
||||
|
||||
if (cmdstring == NULL)
|
||||
if (cmdstring == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* initialize the structs */
|
||||
if (out)
|
||||
if (out) {
|
||||
memset(out, 0, sizeof(output));
|
||||
if (err)
|
||||
}
|
||||
if (err) {
|
||||
memset(err, 0, sizeof(output));
|
||||
}
|
||||
|
||||
/* make copy of command string so strtok() doesn't silently modify it */
|
||||
/* (the calling program may want to access it later) */
|
||||
cmdlen = strlen(cmdstring);
|
||||
if ((cmd = malloc(cmdlen + 1)) == NULL)
|
||||
if ((cmd = malloc(cmdlen + 1)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(cmd, cmdstring, cmdlen);
|
||||
cmd[cmdlen] = '\0';
|
||||
|
||||
/* This is not a shell, so we don't handle "???" */
|
||||
if (strstr(cmdstring, "\""))
|
||||
if (strstr(cmdstring, "\"")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allow single quotes, but only if non-whitesapce doesn't occur on both sides */
|
||||
if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''"))
|
||||
if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* each arg must be whitespace-separated, so args can be a maximum
|
||||
* of (len / 2) + 1. We add 1 extra to the mix for NULL termination */
|
||||
|
|
@ -304,8 +322,9 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) {
|
|||
|
||||
if (strstr(str, "'") == str) { /* handle SIMPLE quoted strings */
|
||||
str++;
|
||||
if (!strstr(str, "'"))
|
||||
if (!strstr(str, "'")) {
|
||||
return -1; /* balanced? */
|
||||
}
|
||||
cmd = 1 + strstr(str, "'");
|
||||
str[strcspn(str, "'")] = 0;
|
||||
} else {
|
||||
|
|
@ -317,8 +336,9 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) {
|
|||
}
|
||||
}
|
||||
|
||||
if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n"))
|
||||
if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n")) {
|
||||
cmd = NULL;
|
||||
}
|
||||
|
||||
argv[i++] = str;
|
||||
}
|
||||
|
|
@ -330,50 +350,61 @@ int cmd_run_array(char *const *argv, output *out, output *err, int flags) {
|
|||
int fd, pfd_out[2], pfd_err[2];
|
||||
|
||||
/* initialize the structs */
|
||||
if (out)
|
||||
if (out) {
|
||||
memset(out, 0, sizeof(output));
|
||||
if (err)
|
||||
}
|
||||
if (err) {
|
||||
memset(err, 0, sizeof(output));
|
||||
}
|
||||
|
||||
if ((fd = _cmd_open(argv, pfd_out, pfd_err)) == -1)
|
||||
if ((fd = _cmd_open(argv, pfd_out, pfd_err)) == -1) {
|
||||
die(STATE_UNKNOWN, _("Could not open pipe: %s\n"), argv[0]);
|
||||
}
|
||||
|
||||
if (out)
|
||||
if (out) {
|
||||
out->lines = _cmd_fetch_output(pfd_out[0], out, flags);
|
||||
if (err)
|
||||
}
|
||||
if (err) {
|
||||
err->lines = _cmd_fetch_output(pfd_err[0], err, flags);
|
||||
}
|
||||
|
||||
return _cmd_close(fd);
|
||||
}
|
||||
|
||||
int cmd_file_read(const char *filename, output *out, int flags) {
|
||||
int fd;
|
||||
if (out)
|
||||
if (out) {
|
||||
memset(out, 0, sizeof(output));
|
||||
}
|
||||
|
||||
if ((fd = open(filename, O_RDONLY)) == -1) {
|
||||
die(STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno));
|
||||
}
|
||||
|
||||
if (out)
|
||||
if (out) {
|
||||
out->lines = _cmd_fetch_output(fd, out, flags);
|
||||
}
|
||||
|
||||
if (close(fd) == -1)
|
||||
if (close(fd) == -1) {
|
||||
die(STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void timeout_alarm_handler(int signo) {
|
||||
if (signo == SIGALRM) {
|
||||
printf(_("%s - Plugin timed out after %d seconds\n"), state_text(timeout_state), timeout_interval);
|
||||
printf(_("%s - Plugin timed out after %d seconds\n"), state_text(timeout_state),
|
||||
timeout_interval);
|
||||
|
||||
long maxfd = mp_open_max();
|
||||
if (_cmd_pids)
|
||||
if (_cmd_pids) {
|
||||
for (long int i = 0; i < maxfd; i++) {
|
||||
if (_cmd_pids[i] != 0)
|
||||
if (_cmd_pids[i] != 0) {
|
||||
kill(_cmd_pids[i], SIGKILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(timeout_state);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,18 +29,21 @@
|
|||
#include "common.h"
|
||||
#include "utils_tcp.h"
|
||||
|
||||
#define VERBOSE(message) \
|
||||
do { \
|
||||
if (flags & NP_MATCH_VERBOSE) \
|
||||
puts(message); \
|
||||
#define VERBOSE(message) \
|
||||
do { \
|
||||
if (flags & NP_MATCH_VERBOSE) \
|
||||
puts(message); \
|
||||
} while (0)
|
||||
|
||||
enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count, int flags) {
|
||||
enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count,
|
||||
int flags) {
|
||||
int i, match = 0, partial = 0;
|
||||
|
||||
for (i = 0; i < expect_count; i++) {
|
||||
if (flags & NP_MATCH_VERBOSE)
|
||||
printf("looking for [%s] %s [%s]\n", server_expect[i], (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status);
|
||||
if (flags & NP_MATCH_VERBOSE) {
|
||||
printf("looking for [%s] %s [%s]\n", server_expect[i],
|
||||
(flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status);
|
||||
}
|
||||
|
||||
if (flags & NP_MATCH_EXACT) {
|
||||
if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) {
|
||||
|
|
@ -60,10 +63,12 @@ enum np_match_result np_expect_match(char *status, char **server_expect, int exp
|
|||
VERBOSE("couldn't find it");
|
||||
}
|
||||
|
||||
if ((flags & NP_MATCH_ALL && match == expect_count) || (!(flags & NP_MATCH_ALL) && match >= 1))
|
||||
if ((flags & NP_MATCH_ALL && match == expect_count) ||
|
||||
(!(flags & NP_MATCH_ALL) && match >= 1)) {
|
||||
return NP_MATCH_SUCCESS;
|
||||
else if (partial > 0 || !(flags & NP_MATCH_EXACT))
|
||||
} else if (partial > 0 || !(flags & NP_MATCH_EXACT)) {
|
||||
return NP_MATCH_RETRY;
|
||||
else
|
||||
} else {
|
||||
return NP_MATCH_FAILURE;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ enum np_match_result {
|
|||
NP_MATCH_RETRY
|
||||
};
|
||||
|
||||
enum np_match_result np_expect_match(char *status, char **server_expect, int server_expect_count, int flags);
|
||||
enum np_match_result np_expect_match(char *status, char **server_expect, int server_expect_count,
|
||||
int flags);
|
||||
|
|
|
|||
|
|
@ -127,17 +127,17 @@ static long mac_addr_dlpi(const char *, int, u_char *);
|
|||
#define MAX_DHCP_OPTIONS_LENGTH 312
|
||||
|
||||
typedef struct dhcp_packet_struct {
|
||||
uint8_t op; /* packet type */
|
||||
uint8_t htype; /* type of hardware address for this machine (Ethernet, etc) */
|
||||
uint8_t hlen; /* length of hardware address (of this machine) */
|
||||
uint8_t hops; /* hops */
|
||||
uint32_t xid; /* random transaction id number - chosen by this machine */
|
||||
uint16_t secs; /* seconds used in timing */
|
||||
uint16_t flags; /* flags */
|
||||
struct in_addr ciaddr; /* IP address of this machine (if we already have one) */
|
||||
struct in_addr yiaddr; /* IP address of this machine (offered by the DHCP server) */
|
||||
struct in_addr siaddr; /* IP address of next server */
|
||||
struct in_addr giaddr; /* IP address of DHCP relay */
|
||||
uint8_t op; /* packet type */
|
||||
uint8_t htype; /* type of hardware address for this machine (Ethernet, etc) */
|
||||
uint8_t hlen; /* length of hardware address (of this machine) */
|
||||
uint8_t hops; /* hops */
|
||||
uint32_t xid; /* random transaction id number - chosen by this machine */
|
||||
uint16_t secs; /* seconds used in timing */
|
||||
uint16_t flags; /* flags */
|
||||
struct in_addr ciaddr; /* IP address of this machine (if we already have one) */
|
||||
struct in_addr yiaddr; /* IP address of this machine (offered by the DHCP server) */
|
||||
struct in_addr siaddr; /* IP address of next server */
|
||||
struct in_addr giaddr; /* IP address of DHCP relay */
|
||||
unsigned char chaddr[MAX_DHCP_CHADDR_LENGTH]; /* hardware address of this machine */
|
||||
char sname[MAX_DHCP_SNAME_LENGTH]; /* name of DHCP server */
|
||||
char file[MAX_DHCP_FILE_LENGTH]; /* boot file name (used for diskless booting?) */
|
||||
|
|
@ -199,7 +199,8 @@ static void print_help(void);
|
|||
static void resolve_host(const char * /*in*/, struct in_addr * /*out*/);
|
||||
static unsigned char *mac_aton(const char * /*string*/);
|
||||
static void print_hardware_address(const unsigned char * /*address*/);
|
||||
static int get_hardware_address(int /*sock*/, char * /*interface_name*/, unsigned char *client_hardware_address);
|
||||
static int get_hardware_address(int /*sock*/, char * /*interface_name*/,
|
||||
unsigned char *client_hardware_address);
|
||||
|
||||
typedef struct get_ip_address_wrapper {
|
||||
int error;
|
||||
|
|
@ -211,32 +212,40 @@ typedef struct send_dhcp_discover_wrapper {
|
|||
int error;
|
||||
uint32_t packet_xid;
|
||||
} send_dhcp_discover_wrapper;
|
||||
static send_dhcp_discover_wrapper send_dhcp_discover(int socket, bool unicast, struct in_addr dhcp_ip, struct in_addr requested_address,
|
||||
bool request_specific_address, struct in_addr my_ip,
|
||||
unsigned char *client_hardware_address);
|
||||
static send_dhcp_discover_wrapper
|
||||
send_dhcp_discover(int socket, bool unicast, struct in_addr dhcp_ip,
|
||||
struct in_addr requested_address, bool request_specific_address,
|
||||
struct in_addr my_ip, unsigned char *client_hardware_address);
|
||||
typedef struct get_dhcp_offer_wrapper {
|
||||
int error;
|
||||
int valid_responses;
|
||||
dhcp_offer *dhcp_offer_list;
|
||||
} get_dhcp_offer_wrapper;
|
||||
static get_dhcp_offer_wrapper get_dhcp_offer(int /*sock*/, int dhcpoffer_timeout, uint32_t packet_xid, dhcp_offer *dhcp_offer_list,
|
||||
static get_dhcp_offer_wrapper get_dhcp_offer(int /*sock*/, int dhcpoffer_timeout,
|
||||
uint32_t packet_xid, dhcp_offer *dhcp_offer_list,
|
||||
const unsigned char *client_hardware_address);
|
||||
|
||||
static mp_subcheck get_results(bool exclusive, int requested_servers, struct in_addr requested_address, bool request_specific_address,
|
||||
requested_server *requested_server_list, int valid_responses, dhcp_offer *dhcp_offer_list);
|
||||
static mp_subcheck get_results(bool exclusive, int requested_servers,
|
||||
struct in_addr requested_address, bool request_specific_address,
|
||||
requested_server *requested_server_list, int valid_responses,
|
||||
dhcp_offer *dhcp_offer_list);
|
||||
|
||||
typedef struct add_dhcp_offer_wrapper {
|
||||
int error;
|
||||
dhcp_offer *dhcp_offer_list;
|
||||
} add_dhcp_offer_wrapper;
|
||||
static add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr /*source*/, dhcp_packet * /*offer_packet*/, dhcp_offer *dhcp_offer_list);
|
||||
static add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr /*source*/,
|
||||
dhcp_packet * /*offer_packet*/,
|
||||
dhcp_offer *dhcp_offer_list);
|
||||
static int free_dhcp_offer_list(dhcp_offer *dhcp_offer_list);
|
||||
static int free_requested_server_list(requested_server *requested_server_list);
|
||||
|
||||
static int create_dhcp_socket(bool /*unicast*/, char *network_interface_name);
|
||||
static int close_dhcp_socket(int /*sock*/);
|
||||
static int send_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/, struct sockaddr_in * /*dest*/);
|
||||
static int receive_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/, int /*timeout*/, struct sockaddr_in * /*address*/);
|
||||
static int send_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/,
|
||||
struct sockaddr_in * /*dest*/);
|
||||
static int receive_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/,
|
||||
int /*timeout*/, struct sockaddr_in * /*address*/);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
setlocale(LC_ALL, "");
|
||||
|
|
@ -271,7 +280,8 @@ int main(int argc, char **argv) {
|
|||
struct in_addr my_ip = {0};
|
||||
|
||||
if (config.unicast_mode) { /* get IP address of client machine */
|
||||
get_ip_address_wrapper tmp_get_ip = get_ip_address(dhcp_socket, config.network_interface_name);
|
||||
get_ip_address_wrapper tmp_get_ip =
|
||||
get_ip_address(dhcp_socket, config.network_interface_name);
|
||||
if (tmp_get_ip.error == OK) {
|
||||
my_ip = tmp_get_ip.my_ip;
|
||||
} else {
|
||||
|
|
@ -281,8 +291,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* send DHCPDISCOVER packet */
|
||||
send_dhcp_discover_wrapper disco_res = send_dhcp_discover(dhcp_socket, config.unicast_mode, config.dhcp_ip, config.requested_address,
|
||||
config.request_specific_address, my_ip, client_hardware_address);
|
||||
send_dhcp_discover_wrapper disco_res = send_dhcp_discover(
|
||||
dhcp_socket, config.unicast_mode, config.dhcp_ip, config.requested_address,
|
||||
config.request_specific_address, my_ip, client_hardware_address);
|
||||
|
||||
if (disco_res.error != OK) {
|
||||
// DO something?
|
||||
|
|
@ -290,8 +301,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* wait for a DHCPOFFER packet */
|
||||
get_dhcp_offer_wrapper offer_res =
|
||||
get_dhcp_offer(dhcp_socket, config.dhcpoffer_timeout, disco_res.packet_xid, NULL, client_hardware_address);
|
||||
get_dhcp_offer_wrapper offer_res = get_dhcp_offer(
|
||||
dhcp_socket, config.dhcpoffer_timeout, disco_res.packet_xid, NULL, client_hardware_address);
|
||||
|
||||
int valid_responses = 0;
|
||||
dhcp_offer *dhcp_offer_list = NULL;
|
||||
|
|
@ -308,8 +319,10 @@ int main(int argc, char **argv) {
|
|||
mp_check overall = mp_check_init();
|
||||
|
||||
/* determine state/plugin output to return */
|
||||
mp_subcheck sc_res = get_results(config.exclusive_mode, config.num_of_requested_servers, config.requested_address,
|
||||
config.request_specific_address, config.requested_server_list, valid_responses, dhcp_offer_list);
|
||||
mp_subcheck sc_res =
|
||||
get_results(config.exclusive_mode, config.num_of_requested_servers,
|
||||
config.requested_address, config.request_specific_address,
|
||||
config.requested_server_list, valid_responses, dhcp_offer_list);
|
||||
mp_add_subcheck_to_check(&overall, sc_res);
|
||||
/* free allocated memory */
|
||||
free_dhcp_offer_list(dhcp_offer_list);
|
||||
|
|
@ -357,17 +370,20 @@ int get_hardware_address(int sock, char *interface_name, unsigned char *client_h
|
|||
}
|
||||
|
||||
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
|
||||
printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"), interface_name, strerror(errno));
|
||||
printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"),
|
||||
interface_name, strerror(errno));
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
if ((buf = malloc(len)) == NULL) {
|
||||
printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"), interface_name, strerror(errno));
|
||||
printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"),
|
||||
interface_name, strerror(errno));
|
||||
exit(4);
|
||||
}
|
||||
|
||||
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
|
||||
printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"), interface_name, strerror(errno));
|
||||
printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"),
|
||||
interface_name, strerror(errno));
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
|
|
@ -398,12 +414,16 @@ int get_hardware_address(int sock, char *interface_name, unsigned char *client_h
|
|||
unit = atoi(p);
|
||||
strncat(dev, interface_name, 6);
|
||||
} else {
|
||||
printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg lnc0.\n"), interface_name);
|
||||
printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg "
|
||||
"lnc0.\n"),
|
||||
interface_name);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
stat = mac_addr_dlpi(dev, unit, client_hardware_address);
|
||||
if (stat != 0) {
|
||||
printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
|
||||
printf(
|
||||
_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"),
|
||||
dev, unit);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
|
|
@ -415,7 +435,9 @@ int get_hardware_address(int sock, char *interface_name, unsigned char *client_h
|
|||
|
||||
stat = mac_addr_dlpi(dev, unit, client_hardware_address);
|
||||
if (stat != 0) {
|
||||
printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
|
||||
printf(
|
||||
_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"),
|
||||
dev, unit);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
/* Kompf 2000-2003 */
|
||||
|
|
@ -463,8 +485,10 @@ get_ip_address_wrapper get_ip_address(int sock, char *interface_name) {
|
|||
}
|
||||
|
||||
/* sends a DHCPDISCOVER broadcast message in an attempt to find DHCP servers */
|
||||
static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, struct in_addr dhcp_ip, struct in_addr requested_address,
|
||||
bool request_specific_address, struct in_addr my_ip,
|
||||
static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, struct in_addr dhcp_ip,
|
||||
struct in_addr requested_address,
|
||||
bool request_specific_address,
|
||||
struct in_addr my_ip,
|
||||
unsigned char *client_hardware_address) {
|
||||
dhcp_packet discover_packet = {0};
|
||||
/* boot request flag (backward compatible with BOOTP servers) */
|
||||
|
|
@ -506,8 +530,9 @@ static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, str
|
|||
|
||||
unsigned short opts = 4;
|
||||
/* DHCP message type is embedded in options field */
|
||||
discover_packet.options[opts++] = DHCP_OPTION_MESSAGE_TYPE; /* DHCP message type option identifier */
|
||||
discover_packet.options[opts++] = '\x01'; /* DHCP message option length in bytes */
|
||||
discover_packet.options[opts++] =
|
||||
DHCP_OPTION_MESSAGE_TYPE; /* DHCP message type option identifier */
|
||||
discover_packet.options[opts++] = '\x01'; /* DHCP message option length in bytes */
|
||||
discover_packet.options[opts++] = DHCPDISCOVER;
|
||||
|
||||
/* the IP address we're requesting */
|
||||
|
|
@ -535,8 +560,10 @@ static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, str
|
|||
};
|
||||
|
||||
if (verbose) {
|
||||
printf(_("DHCPDISCOVER to %s port %d\n"), inet_ntoa(sockaddr_broadcast.sin_addr), ntohs(sockaddr_broadcast.sin_port));
|
||||
printf("DHCPDISCOVER XID: %u (0x%X)\n", ntohl(discover_packet.xid), ntohl(discover_packet.xid));
|
||||
printf(_("DHCPDISCOVER to %s port %d\n"), inet_ntoa(sockaddr_broadcast.sin_addr),
|
||||
ntohs(sockaddr_broadcast.sin_port));
|
||||
printf("DHCPDISCOVER XID: %u (0x%X)\n", ntohl(discover_packet.xid),
|
||||
ntohl(discover_packet.xid));
|
||||
printf("DHCDISCOVER ciaddr: %s\n", inet_ntoa(discover_packet.ciaddr));
|
||||
printf("DHCDISCOVER yiaddr: %s\n", inet_ntoa(discover_packet.yiaddr));
|
||||
printf("DHCDISCOVER siaddr: %s\n", inet_ntoa(discover_packet.siaddr));
|
||||
|
|
@ -554,7 +581,8 @@ static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, str
|
|||
}
|
||||
|
||||
/* waits for a DHCPOFFER message from one or more DHCP servers */
|
||||
get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t packet_xid, dhcp_offer *dhcp_offer_list,
|
||||
get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t packet_xid,
|
||||
dhcp_offer *dhcp_offer_list,
|
||||
const unsigned char *client_hardware_address) {
|
||||
time_t start_time;
|
||||
time(&start_time);
|
||||
|
|
@ -578,7 +606,8 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
|
|||
dhcp_packet offer_packet = {0};
|
||||
|
||||
result = OK;
|
||||
result = receive_dhcp_packet(&offer_packet, sizeof(offer_packet), sock, dhcpoffer_timeout, &source);
|
||||
result = receive_dhcp_packet(&offer_packet, sizeof(offer_packet), sock, dhcpoffer_timeout,
|
||||
&source);
|
||||
|
||||
if (result != OK) {
|
||||
if (verbose) {
|
||||
|
|
@ -607,8 +636,9 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
|
|||
/* check packet xid to see if its the same as the one we used in the discover packet */
|
||||
if (ntohl(offer_packet.xid) != packet_xid) {
|
||||
if (verbose) {
|
||||
printf(_("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"), ntohl(offer_packet.xid),
|
||||
packet_xid);
|
||||
printf(
|
||||
_("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"),
|
||||
ntohl(offer_packet.xid), packet_xid);
|
||||
}
|
||||
|
||||
continue;
|
||||
|
|
@ -648,7 +678,8 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
|
|||
printf("DHCPOFFER giaddr: %s\n", inet_ntoa(offer_packet.giaddr));
|
||||
}
|
||||
|
||||
add_dhcp_offer_wrapper add_res = add_dhcp_offer(source.sin_addr, &offer_packet, dhcp_offer_list);
|
||||
add_dhcp_offer_wrapper add_res =
|
||||
add_dhcp_offer(source.sin_addr, &offer_packet, dhcp_offer_list);
|
||||
if (add_res.error != OK) {
|
||||
// TODO
|
||||
} else {
|
||||
|
|
@ -673,7 +704,8 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
|
|||
|
||||
/* sends a DHCP packet */
|
||||
int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in *dest) {
|
||||
int result = sendto(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)dest, sizeof(*dest));
|
||||
int result =
|
||||
sendto(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)dest, sizeof(*dest));
|
||||
|
||||
if (verbose) {
|
||||
printf(_("send_dhcp_packet result: %d\n"), result);
|
||||
|
|
@ -687,7 +719,8 @@ int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in
|
|||
}
|
||||
|
||||
/* receives a DHCP packet */
|
||||
int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address) {
|
||||
int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout,
|
||||
struct sockaddr_in *address) {
|
||||
/* wait for data to arrive (up time timeout) */
|
||||
struct timeval timeout_val = {
|
||||
.tv_sec = timeout,
|
||||
|
|
@ -711,7 +744,8 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st
|
|||
|
||||
struct sockaddr_in source_address = {0};
|
||||
socklen_t address_size = sizeof(source_address);
|
||||
int recv_result = recvfrom(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)&source_address, &address_size);
|
||||
int recv_result = recvfrom(sock, (char *)buffer, buffer_size, 0,
|
||||
(struct sockaddr *)&source_address, &address_size);
|
||||
if (verbose) {
|
||||
printf("recv_result: %d\n", recv_result);
|
||||
}
|
||||
|
|
@ -775,7 +809,8 @@ int create_dhcp_socket(bool unicast, char *network_interface_name) {
|
|||
strncpy(interface.ifr_ifrn.ifrn_name, network_interface_name, IFNAMSIZ - 1);
|
||||
interface.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = '\0';
|
||||
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (char *)&interface, sizeof(interface)) < 0) {
|
||||
printf(_("Error: Could not bind socket to interface %s. Check your privileges...\n"), network_interface_name);
|
||||
printf(_("Error: Could not bind socket to interface %s. Check your privileges...\n"),
|
||||
network_interface_name);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
|
|
@ -786,7 +821,8 @@ int create_dhcp_socket(bool unicast, char *network_interface_name) {
|
|||
|
||||
/* bind the socket */
|
||||
if (bind(sock, (struct sockaddr *)&myname, sizeof(myname)) < 0) {
|
||||
printf(_("Error: Could not bind to DHCP socket (port %d)! Check your privileges...\n"), DHCP_CLIENT_PORT);
|
||||
printf(_("Error: Could not bind to DHCP socket (port %d)! Check your privileges...\n"),
|
||||
DHCP_CLIENT_PORT);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
|
|
@ -800,7 +836,8 @@ int close_dhcp_socket(int sock) {
|
|||
}
|
||||
|
||||
/* adds a requested server address to list in memory */
|
||||
int add_requested_server(struct in_addr server_address, int *requested_servers, requested_server **requested_server_list) {
|
||||
int add_requested_server(struct in_addr server_address, int *requested_servers,
|
||||
requested_server **requested_server_list) {
|
||||
requested_server *new_server = (requested_server *)malloc(sizeof(requested_server));
|
||||
if (new_server == NULL) {
|
||||
return ERROR;
|
||||
|
|
@ -822,7 +859,8 @@ int add_requested_server(struct in_addr server_address, int *requested_servers,
|
|||
}
|
||||
|
||||
/* adds a DHCP OFFER to list in memory */
|
||||
add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet, dhcp_offer *dhcp_offer_list) {
|
||||
add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet,
|
||||
dhcp_offer *dhcp_offer_list) {
|
||||
if (offer_packet == NULL) {
|
||||
add_dhcp_offer_wrapper tmp = {
|
||||
.error = ERROR,
|
||||
|
|
@ -859,15 +897,18 @@ add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr source, dhcp_packet *offer_
|
|||
dhcp_lease_time = ntohl(dhcp_lease_time);
|
||||
break;
|
||||
case DHCP_OPTION_RENEWAL_TIME:
|
||||
memcpy(&dhcp_renewal_time, &offer_packet->options[dchp_opt_idx], sizeof(dhcp_renewal_time));
|
||||
memcpy(&dhcp_renewal_time, &offer_packet->options[dchp_opt_idx],
|
||||
sizeof(dhcp_renewal_time));
|
||||
dhcp_renewal_time = ntohl(dhcp_renewal_time);
|
||||
break;
|
||||
case DHCP_OPTION_REBINDING_TIME:
|
||||
memcpy(&dhcp_rebinding_time, &offer_packet->options[dchp_opt_idx], sizeof(dhcp_rebinding_time));
|
||||
memcpy(&dhcp_rebinding_time, &offer_packet->options[dchp_opt_idx],
|
||||
sizeof(dhcp_rebinding_time));
|
||||
dhcp_rebinding_time = ntohl(dhcp_rebinding_time);
|
||||
break;
|
||||
case DHCP_OPTION_SERVER_IDENTIFIER:
|
||||
memcpy(&serv_ident.s_addr, &offer_packet->options[dchp_opt_idx], sizeof(serv_ident.s_addr));
|
||||
memcpy(&serv_ident.s_addr, &offer_packet->options[dchp_opt_idx],
|
||||
sizeof(serv_ident.s_addr));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -955,7 +996,8 @@ int free_dhcp_offer_list(dhcp_offer *dhcp_offer_list) {
|
|||
/* frees memory allocated to requested server list */
|
||||
int free_requested_server_list(requested_server *requested_server_list) {
|
||||
requested_server *next_server;
|
||||
for (requested_server *this_server = requested_server_list; this_server != NULL; this_server = next_server) {
|
||||
for (requested_server *this_server = requested_server_list; this_server != NULL;
|
||||
this_server = next_server) {
|
||||
next_server = this_server->next;
|
||||
free(this_server);
|
||||
}
|
||||
|
|
@ -964,8 +1006,10 @@ int free_requested_server_list(requested_server *requested_server_list) {
|
|||
}
|
||||
|
||||
/* gets state and plugin output to return */
|
||||
mp_subcheck get_results(bool exclusive, const int requested_servers, const struct in_addr requested_address, bool request_specific_address,
|
||||
requested_server *requested_server_list, int valid_responses, dhcp_offer *dhcp_offer_list) {
|
||||
mp_subcheck get_results(bool exclusive, const int requested_servers,
|
||||
const struct in_addr requested_address, bool request_specific_address,
|
||||
requested_server *requested_server_list, int valid_responses,
|
||||
dhcp_offer *dhcp_offer_list) {
|
||||
mp_subcheck sc_dhcp_results = mp_subcheck_init();
|
||||
sc_dhcp_results = mp_set_subcheck_default_state(sc_dhcp_results, STATE_OK);
|
||||
|
||||
|
|
@ -995,22 +1039,28 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
/* checks responses from requested servers */
|
||||
int requested_responses = 0;
|
||||
if (requested_servers > 0) {
|
||||
for (requested_server *temp_server = requested_server_list; temp_server != NULL; temp_server = temp_server->next) {
|
||||
for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL; temp_offer = temp_offer->next) {
|
||||
for (requested_server *temp_server = requested_server_list; temp_server != NULL;
|
||||
temp_server = temp_server->next) {
|
||||
for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL;
|
||||
temp_offer = temp_offer->next) {
|
||||
/* get max lease time we were offered */
|
||||
if (temp_offer->lease_time > max_lease_time || temp_offer->lease_time == DHCP_INFINITE_TIME) {
|
||||
if (temp_offer->lease_time > max_lease_time ||
|
||||
temp_offer->lease_time == DHCP_INFINITE_TIME) {
|
||||
max_lease_time = temp_offer->lease_time;
|
||||
}
|
||||
|
||||
/* see if we got the address we requested */
|
||||
if (!memcmp(&requested_address, &temp_offer->offered_address, sizeof(requested_address))) {
|
||||
if (!memcmp(&requested_address, &temp_offer->offered_address,
|
||||
sizeof(requested_address))) {
|
||||
received_requested_address = true;
|
||||
}
|
||||
|
||||
/* see if the servers we wanted a response from, talked to us or not */
|
||||
if (!memcmp(&temp_offer->server_address, &temp_server->server_address, sizeof(temp_server->server_address))) {
|
||||
if (!memcmp(&temp_offer->server_address, &temp_server->server_address,
|
||||
sizeof(temp_server->server_address))) {
|
||||
if (verbose) {
|
||||
printf(_("DHCP Server Match: Offerer=%s"), inet_ntoa(temp_offer->server_address));
|
||||
printf(_("DHCP Server Match: Offerer=%s"),
|
||||
inet_ntoa(temp_offer->server_address));
|
||||
printf(_(" Requested=%s"), inet_ntoa(temp_server->server_address));
|
||||
if (temp_server->answered) {
|
||||
printf(_(" (duplicate)"));
|
||||
|
|
@ -1028,7 +1078,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
}
|
||||
|
||||
/* exclusive mode: check for undesired offers */
|
||||
for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL; temp_offer = temp_offer->next) {
|
||||
for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL;
|
||||
temp_offer = temp_offer->next) {
|
||||
if (!temp_offer->desired) {
|
||||
undesired_offer = temp_offer; /* Checks only for the first undesired offer */
|
||||
break; /* no further checks needed */
|
||||
|
|
@ -1036,7 +1087,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
}
|
||||
|
||||
mp_subcheck sc_rqust_srvs = mp_subcheck_init();
|
||||
xasprintf(&sc_rqust_srvs.output, "%d of %d requested servers responded", requested_responses, requested_servers);
|
||||
xasprintf(&sc_rqust_srvs.output, "%d of %d requested servers responded",
|
||||
requested_responses, requested_servers);
|
||||
|
||||
if (requested_responses == requested_servers) {
|
||||
sc_rqust_srvs = mp_set_subcheck_state(sc_rqust_srvs, STATE_OK);
|
||||
|
|
@ -1053,14 +1105,17 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
|
||||
} else {
|
||||
/* else check and see if we got our requested address from any server */
|
||||
for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL; temp_offer = temp_offer->next) {
|
||||
for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL;
|
||||
temp_offer = temp_offer->next) {
|
||||
/* get max lease time we were offered */
|
||||
if (temp_offer->lease_time > max_lease_time || temp_offer->lease_time == DHCP_INFINITE_TIME) {
|
||||
if (temp_offer->lease_time > max_lease_time ||
|
||||
temp_offer->lease_time == DHCP_INFINITE_TIME) {
|
||||
max_lease_time = temp_offer->lease_time;
|
||||
}
|
||||
|
||||
/* see if we got the address we requested */
|
||||
if (!memcmp(&requested_address, &temp_offer->offered_address, sizeof(requested_address))) {
|
||||
if (!memcmp(&requested_address, &temp_offer->offered_address,
|
||||
sizeof(requested_address))) {
|
||||
received_requested_address = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1069,7 +1124,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
if (max_lease_time == DHCP_INFINITE_TIME) {
|
||||
xasprintf(&sc_dhcp_results.output, "%s, max lease time = Infinity", sc_dhcp_results.output);
|
||||
} else {
|
||||
xasprintf(&sc_dhcp_results.output, "%s, max lease time = %" PRIu32 " seconds", sc_dhcp_results.output, max_lease_time);
|
||||
xasprintf(&sc_dhcp_results.output, "%s, max lease time = %" PRIu32 " seconds",
|
||||
sc_dhcp_results.output, max_lease_time);
|
||||
}
|
||||
|
||||
if (exclusive) {
|
||||
|
|
@ -1083,8 +1139,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
// Get the addresses for printout
|
||||
// 1.address of the sending server
|
||||
char server_address[INET_ADDRSTRLEN];
|
||||
const char *server_address_transformed =
|
||||
inet_ntop(AF_INET, &undesired_offer->server_address, server_address, sizeof(server_address));
|
||||
const char *server_address_transformed = inet_ntop(
|
||||
AF_INET, &undesired_offer->server_address, server_address, sizeof(server_address));
|
||||
|
||||
if (server_address != server_address_transformed) {
|
||||
die(STATE_UNKNOWN, "inet_ntop failed");
|
||||
|
|
@ -1093,13 +1149,15 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
// 2.address offered
|
||||
char offered_address[INET_ADDRSTRLEN];
|
||||
const char *offered_address_transformed =
|
||||
inet_ntop(AF_INET, &undesired_offer->offered_address, offered_address, sizeof(offered_address));
|
||||
inet_ntop(AF_INET, &undesired_offer->offered_address, offered_address,
|
||||
sizeof(offered_address));
|
||||
|
||||
if (offered_address != offered_address_transformed) {
|
||||
die(STATE_UNKNOWN, "inet_ntop failed");
|
||||
}
|
||||
|
||||
xasprintf(&sc_rogue_server.output, "Rogue DHCP Server detected! Server %s offered %s", server_address, offered_address);
|
||||
xasprintf(&sc_rogue_server.output, "Rogue DHCP Server detected! Server %s offered %s",
|
||||
server_address, offered_address);
|
||||
} else {
|
||||
sc_rogue_server = mp_set_subcheck_state(sc_rogue_server, STATE_OK);
|
||||
xasprintf(&sc_rogue_server.output, "No Rogue DHCP Server detected");
|
||||
|
|
@ -1112,10 +1170,12 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
|
|||
|
||||
if (received_requested_address) {
|
||||
sc_rqustd_addr = mp_set_subcheck_state(sc_rqustd_addr, STATE_OK);
|
||||
xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was offered", inet_ntoa(requested_address));
|
||||
xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was offered",
|
||||
inet_ntoa(requested_address));
|
||||
} else {
|
||||
sc_rqustd_addr = mp_set_subcheck_state(sc_rqustd_addr, STATE_WARNING);
|
||||
xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was NOT offered", inet_ntoa(requested_address));
|
||||
xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was NOT offered",
|
||||
inet_ntoa(requested_address));
|
||||
}
|
||||
|
||||
mp_add_subcheck_to_subcheck(&sc_dhcp_results, sc_rqustd_addr);
|
||||
|
|
@ -1138,18 +1198,19 @@ process_arguments_wrapper process_arguments(int argc, char **argv) {
|
|||
};
|
||||
|
||||
int option_index = 0;
|
||||
static struct option long_options[] = {{"serverip", required_argument, 0, 's'},
|
||||
{"requestedip", required_argument, 0, 'r'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"interface", required_argument, 0, 'i'},
|
||||
{"mac", required_argument, 0, 'm'},
|
||||
{"unicast", no_argument, 0, 'u'},
|
||||
{"exclusive", no_argument, 0, 'x'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"output-format", required_argument, 0, output_format_index},
|
||||
{0, 0, 0, 0}};
|
||||
static struct option long_options[] = {
|
||||
{"serverip", required_argument, 0, 's'},
|
||||
{"requestedip", required_argument, 0, 'r'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"interface", required_argument, 0, 'i'},
|
||||
{"mac", required_argument, 0, 'm'},
|
||||
{"unicast", no_argument, 0, 'u'},
|
||||
{"exclusive", no_argument, 0, 'x'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"output-format", required_argument, 0, output_format_index},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_dhcp_config config = check_dhcp_config_init();
|
||||
int option_char = 0;
|
||||
|
|
@ -1163,7 +1224,8 @@ process_arguments_wrapper process_arguments(int argc, char **argv) {
|
|||
switch (option_char) {
|
||||
case 's': /* DHCP server address */
|
||||
resolve_host(optarg, &config.dhcp_ip);
|
||||
add_requested_server(config.dhcp_ip, &config.num_of_requested_servers, &config.requested_server_list);
|
||||
add_requested_server(config.dhcp_ip, &config.num_of_requested_servers,
|
||||
&config.requested_server_list);
|
||||
break;
|
||||
|
||||
case 'r': /* address we are requested from DHCP servers */
|
||||
|
|
@ -1187,7 +1249,8 @@ process_arguments_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
|
||||
case 'i': /* interface name */
|
||||
strncpy(config.network_interface_name, optarg, sizeof(config.network_interface_name) - 1);
|
||||
strncpy(config.network_interface_name, optarg,
|
||||
sizeof(config.network_interface_name) - 1);
|
||||
config.network_interface_name[sizeof(config.network_interface_name) - 1] = '\x0';
|
||||
break;
|
||||
|
||||
|
|
@ -1289,7 +1352,8 @@ static int put_ctrl(int fd, int len, int pri) {
|
|||
|
||||
ctl.len = len;
|
||||
if (putmsg(fd, &ctl, 0, pri) < 0) {
|
||||
printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"), strerror(errno));
|
||||
printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"),
|
||||
strerror(errno));
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
|
|
@ -1302,7 +1366,8 @@ static int put_both(int fd, int clen, int dlen, int pri) {
|
|||
ctl.len = clen;
|
||||
dat.len = dlen;
|
||||
if (putmsg(fd, &ctl, &dat, pri) < 0) {
|
||||
printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"), strerror(errno));
|
||||
printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"),
|
||||
strerror(errno));
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
|
|
@ -1314,7 +1379,8 @@ static int dl_open(const char *dev, int unit, int *fd) {
|
|||
dl_attach_req_t *attach_req = (dl_attach_req_t *)ctl_area;
|
||||
|
||||
if ((*fd = open(dev, O_RDWR)) == -1) {
|
||||
printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"), dev, strerror(errno));
|
||||
printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"),
|
||||
dev, strerror(errno));
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
attach_req->dl_primitive = DL_ATTACH_REQ;
|
||||
|
|
@ -1338,7 +1404,8 @@ static int dl_bind(int fd, int sap, u_char *addr) {
|
|||
put_ctrl(fd, sizeof(dl_bind_req_t), 0);
|
||||
get_msg(fd);
|
||||
if (GOT_ERR == check_ctrl(DL_BIND_ACK)) {
|
||||
printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"), strerror(errno));
|
||||
printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"),
|
||||
strerror(errno));
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
bcopy((u_char *)bind_ack + bind_ack->dl_addr_offset, addr, bind_ack->dl_addr_length);
|
||||
|
|
@ -1455,7 +1522,8 @@ void print_help(void) {
|
|||
printf(" %s\n", "-u, --unicast");
|
||||
printf(" %s\n", _("Unicast testing: mimic a DHCP relay, requires -s"));
|
||||
printf(" %s\n", "-x, --exclusive");
|
||||
printf(" %s\n", _("Only requested DHCP server may response (rogue DHCP server detection), requires -s"));
|
||||
printf(" %s\n",
|
||||
_("Only requested DHCP server may response (rogue DHCP server detection), requires -s"));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ typedef struct icmp_ping_data {
|
|||
|
||||
/* 80 msec packet interval by default */
|
||||
// DEPRECATED, remove when removing the option
|
||||
#define DEFAULT_PKT_INTERVAL 80000
|
||||
#define DEFAULT_PKT_INTERVAL 80000
|
||||
|
||||
#define DEFAULT_TARGET_INTERVAL 0
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,45 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* pst3
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2008 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* This file contains the pst3 executable. This is a replacement ps command
|
||||
* for Solaris to get output which provides a long argument listing, which
|
||||
* is not possible with the standard ps command (due to truncation). /usr/ucb/ps
|
||||
* also has issues where some fields run into each other.
|
||||
*
|
||||
* This executable works by reading process address structures, so needs
|
||||
* to be executed as root
|
||||
*
|
||||
* Originally written by R.W.Ingraham
|
||||
* Rewritten by Duncan Ferguson (Altinity Ltd, June 2008)
|
||||
* The rewrite was necessary as /dev/kmem is not available within
|
||||
* non-global zones on Solaris 10
|
||||
*
|
||||
* Details for rewrite came from
|
||||
* source of /usr/ucb/ps on Solaris:
|
||||
* http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbcmd/ps/ps.c#argvoff
|
||||
* usenet group posting
|
||||
* http://groups.google.com/group/comp.unix.solaris/tree/browse_frm/month/2001-09/bfa40c08bac819a2?rnum=141&_done=%2Fgroup%2Fcomp.unix.solaris%2Fbrowse_frm%2Fmonth%2F2001-09%3F
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*****************************************************************************/
|
||||
*
|
||||
* pst3
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2008 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* This file contains the pst3 executable. This is a replacement ps command
|
||||
* for Solaris to get output which provides a long argument listing, which
|
||||
* is not possible with the standard ps command (due to truncation). /usr/ucb/ps
|
||||
* also has issues where some fields run into each other.
|
||||
*
|
||||
* This executable works by reading process address structures, so needs
|
||||
* to be executed as root
|
||||
*
|
||||
* Originally written by R.W.Ingraham
|
||||
* Rewritten by Duncan Ferguson (Altinity Ltd, June 2008)
|
||||
* The rewrite was necessary as /dev/kmem is not available within
|
||||
* non-global zones on Solaris 10
|
||||
*
|
||||
* Details for rewrite came from
|
||||
* source of /usr/ucb/ps on Solaris:
|
||||
* http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbcmd/ps/ps.c#argvoff
|
||||
* usenet group posting
|
||||
* http://groups.google.com/group/comp.unix.solaris/tree/browse_frm/month/2001-09/bfa40c08bac819a2?rnum=141&_done=%2Fgroup%2Fcomp.unix.solaris%2Fbrowse_frm%2Fmonth%2F2001-09%3F
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -55,14 +55,14 @@
|
|||
* Constants
|
||||
*/
|
||||
|
||||
#define PROC_DIR "/proc"
|
||||
#define ARGS 30
|
||||
#define PROC_DIR "/proc"
|
||||
#define ARGS 30
|
||||
|
||||
/*
|
||||
* Globals
|
||||
*/
|
||||
|
||||
static char * szProg;
|
||||
static char *szProg;
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
|
|
@ -71,192 +71,179 @@ void usage();
|
|||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
DIR *procdir;
|
||||
struct dirent *proc;
|
||||
char ps_name[ARGS];
|
||||
char as_name[ARGS];
|
||||
psinfo_t psinfo;
|
||||
int main(int argc, char **argv) {
|
||||
DIR *procdir;
|
||||
struct dirent *proc;
|
||||
char ps_name[ARGS];
|
||||
char as_name[ARGS];
|
||||
psinfo_t psinfo;
|
||||
|
||||
/* Set our program name global */
|
||||
if ((szProg = strrchr(argv[0], '/')) != NULL)
|
||||
szProg++;
|
||||
else
|
||||
szProg = argv[0];
|
||||
/* Set our program name global */
|
||||
if ((szProg = strrchr(argv[0], '/')) != NULL) {
|
||||
szProg++;
|
||||
} else {
|
||||
szProg = argv[0];
|
||||
}
|
||||
|
||||
/* if given any parameters, print out help */
|
||||
if(argc > 1) {
|
||||
(void)usage();
|
||||
exit(1);
|
||||
}
|
||||
/* if given any parameters, print out help */
|
||||
if (argc > 1) {
|
||||
(void)usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Make sure that our euid is root */
|
||||
if (geteuid() != 0)
|
||||
{
|
||||
fprintf(stderr, "%s: This program can only be run by the root user!\n", szProg);
|
||||
exit(1);
|
||||
}
|
||||
/* Make sure that our euid is root */
|
||||
if (geteuid() != 0) {
|
||||
fprintf(stderr, "%s: This program can only be run by the root user!\n", szProg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((procdir = opendir(PROC_DIR)) == NULL) {
|
||||
fprintf(stderr, "%s: cannot open PROC directory %s\n", szProg, PROC_DIR);
|
||||
exit(1);
|
||||
}
|
||||
if ((procdir = opendir(PROC_DIR)) == NULL) {
|
||||
fprintf(stderr, "%s: cannot open PROC directory %s\n", szProg, PROC_DIR);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Display column headings */
|
||||
printf("%c %5s %5s %5s %6s %6s %4s %s %s\n",
|
||||
'S',
|
||||
"UID",
|
||||
"PID",
|
||||
"PPID",
|
||||
"VSZ",
|
||||
"RSS",
|
||||
"%CPU",
|
||||
"COMMAND",
|
||||
"ARGS"
|
||||
);
|
||||
/* Display column headings */
|
||||
printf("%c %5s %5s %5s %6s %6s %4s %s %s\n", 'S', "UID", "PID", "PPID", "VSZ", "RSS", "%CPU",
|
||||
"COMMAND", "ARGS");
|
||||
|
||||
/* Zip through all of the process entries */
|
||||
while((proc = readdir(procdir))) {
|
||||
int ps_fd;
|
||||
int as_fd;
|
||||
off_t argoff;
|
||||
int i;
|
||||
char *args;
|
||||
char *procname;
|
||||
char *ptr;
|
||||
int argslen;
|
||||
uintptr_t args_addr;;
|
||||
uintptr_t *args_vecs;;
|
||||
int args_count;
|
||||
/* Zip through all of the process entries */
|
||||
while ((proc = readdir(procdir))) {
|
||||
int ps_fd;
|
||||
int as_fd;
|
||||
off_t argoff;
|
||||
int i;
|
||||
char *args;
|
||||
char *procname;
|
||||
char *ptr;
|
||||
int argslen;
|
||||
uintptr_t args_addr;
|
||||
;
|
||||
uintptr_t *args_vecs;
|
||||
;
|
||||
int args_count;
|
||||
|
||||
if(proc->d_name[0] == '.')
|
||||
continue;
|
||||
if (proc->d_name[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
|
||||
sprintf(ps_name,"%s/%s/%s",PROC_DIR,proc->d_name,"psinfo");
|
||||
sprintf(as_name,"%s/%s/%s",PROC_DIR,proc->d_name,"as");
|
||||
try_again:
|
||||
if((ps_fd = open(ps_name, O_RDONLY)) == -1)
|
||||
continue;
|
||||
sprintf(ps_name, "%s/%s/%s", PROC_DIR, proc->d_name, "psinfo");
|
||||
sprintf(as_name, "%s/%s/%s", PROC_DIR, proc->d_name, "as");
|
||||
try_again:
|
||||
if ((ps_fd = open(ps_name, O_RDONLY)) == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if((as_fd = open(as_name, O_RDONLY)) == -1) {
|
||||
close(ps_fd);
|
||||
continue;
|
||||
}
|
||||
if ((as_fd = open(as_name, O_RDONLY)) == -1) {
|
||||
close(ps_fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(read(ps_fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) {
|
||||
int err = errno;
|
||||
close(ps_fd);
|
||||
close(as_fd);
|
||||
if(err == EAGAIN) goto try_again;
|
||||
if(err != ENOENT)
|
||||
fprintf(stderr, "%s: read() on %s: %s\n", szProg,
|
||||
ps_name, strerror(err));
|
||||
continue;
|
||||
}
|
||||
close(ps_fd);
|
||||
if (read(ps_fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) {
|
||||
int err = errno;
|
||||
close(ps_fd);
|
||||
close(as_fd);
|
||||
if (err == EAGAIN) {
|
||||
goto try_again;
|
||||
}
|
||||
if (err != ENOENT) {
|
||||
fprintf(stderr, "%s: read() on %s: %s\n", szProg, ps_name, strerror(err));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
close(ps_fd);
|
||||
|
||||
/* system process, ignore since the previous version did */
|
||||
if(
|
||||
psinfo.pr_nlwp == 0 ||
|
||||
strcmp(psinfo.pr_lwp.pr_clname, "SYS") == 0
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
/* system process, ignore since the previous version did */
|
||||
if (psinfo.pr_nlwp == 0 || strcmp(psinfo.pr_lwp.pr_clname, "SYS") == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get the procname to match previous versions */
|
||||
procname = strdup(psinfo.pr_psargs);
|
||||
if((ptr = strchr(procname, ' ')) != NULL)
|
||||
*ptr = '\0';
|
||||
if((ptr = strrchr(procname, '/')) != NULL)
|
||||
ptr++;
|
||||
else
|
||||
ptr = procname;
|
||||
/* get the procname to match previous versions */
|
||||
procname = strdup(psinfo.pr_psargs);
|
||||
if ((ptr = strchr(procname, ' ')) != NULL) {
|
||||
*ptr = '\0';
|
||||
}
|
||||
if ((ptr = strrchr(procname, '/')) != NULL) {
|
||||
ptr++;
|
||||
} else {
|
||||
ptr = procname;
|
||||
}
|
||||
|
||||
/*
|
||||
* print out what we currently know
|
||||
*/
|
||||
printf("%c %5d %5d %5d %6lu %6lu %4.1f %s ",
|
||||
psinfo.pr_lwp.pr_sname,
|
||||
psinfo.pr_euid,
|
||||
psinfo.pr_pid,
|
||||
psinfo.pr_ppid,
|
||||
psinfo.pr_size,
|
||||
psinfo.pr_rssize,
|
||||
((float)(psinfo.pr_pctcpu) / 0x8000 * 100.0),
|
||||
ptr
|
||||
);
|
||||
free(procname);
|
||||
/*
|
||||
* print out what we currently know
|
||||
*/
|
||||
printf("%c %5d %5d %5d %6lu %6lu %4.1f %s ", psinfo.pr_lwp.pr_sname, psinfo.pr_euid,
|
||||
psinfo.pr_pid, psinfo.pr_ppid, psinfo.pr_size, psinfo.pr_rssize,
|
||||
((float)(psinfo.pr_pctcpu) / 0x8000 * 100.0), ptr);
|
||||
free(procname);
|
||||
|
||||
/*
|
||||
* and now for the command line stuff
|
||||
*/
|
||||
/*
|
||||
* and now for the command line stuff
|
||||
*/
|
||||
|
||||
args_addr = psinfo.pr_argv;
|
||||
args_count = psinfo.pr_argc;
|
||||
args_vecs = malloc(args_count * sizeof(uintptr_t));
|
||||
args_addr = psinfo.pr_argv;
|
||||
args_count = psinfo.pr_argc;
|
||||
args_vecs = malloc(args_count * sizeof(uintptr_t));
|
||||
|
||||
if(psinfo.pr_dmodel == PR_MODEL_NATIVE) {
|
||||
/* this process matches target process */
|
||||
pread(as_fd,args_vecs, args_count * sizeof(uintptr_t),
|
||||
args_addr);
|
||||
} else {
|
||||
/* this process is 64bit, target process is 32 bit*/
|
||||
caddr32_t *args_vecs32 = (caddr32_t *)args_vecs;
|
||||
pread(as_fd,args_vecs32,args_count * sizeof(caddr32_t),
|
||||
args_addr);
|
||||
for (i=args_count-1;i>=0;--i)
|
||||
args_vecs[i]=args_vecs32[i];
|
||||
}
|
||||
if (psinfo.pr_dmodel == PR_MODEL_NATIVE) {
|
||||
/* this process matches target process */
|
||||
pread(as_fd, args_vecs, args_count * sizeof(uintptr_t), args_addr);
|
||||
} else {
|
||||
/* this process is 64bit, target process is 32 bit*/
|
||||
caddr32_t *args_vecs32 = (caddr32_t *)args_vecs;
|
||||
pread(as_fd, args_vecs32, args_count * sizeof(caddr32_t), args_addr);
|
||||
for (i = args_count - 1; i >= 0; --i) {
|
||||
args_vecs[i] = args_vecs32[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* now read in the args - if what we read in fills buffer
|
||||
* resize buffer and reread that bit again
|
||||
*/
|
||||
argslen=ARGS;
|
||||
args=malloc(argslen+1);
|
||||
for(i=0;i<args_count;i++) {
|
||||
memset(args,'\0',argslen+1);
|
||||
if(pread(as_fd, args, argslen, args_vecs[i]) <= 0) {
|
||||
break;
|
||||
}
|
||||
args[argslen]='\0';
|
||||
if(strlen(args) == argslen){
|
||||
argslen += ARGS;
|
||||
args = realloc(args, argslen + 1);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
printf(" %s", args);
|
||||
}
|
||||
free(args_vecs);
|
||||
free(args);
|
||||
close(as_fd);
|
||||
printf("\n");
|
||||
}
|
||||
/*
|
||||
* now read in the args - if what we read in fills buffer
|
||||
* resize buffer and reread that bit again
|
||||
*/
|
||||
argslen = ARGS;
|
||||
args = malloc(argslen + 1);
|
||||
for (i = 0; i < args_count; i++) {
|
||||
memset(args, '\0', argslen + 1);
|
||||
if (pread(as_fd, args, argslen, args_vecs[i]) <= 0) {
|
||||
break;
|
||||
}
|
||||
args[argslen] = '\0';
|
||||
if (strlen(args) == argslen) {
|
||||
argslen += ARGS;
|
||||
args = realloc(args, argslen + 1);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
printf(" %s", args);
|
||||
}
|
||||
free(args_vecs);
|
||||
free(args);
|
||||
close(as_fd);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
(void) closedir(procdir);
|
||||
(void)closedir(procdir);
|
||||
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
void usage() {
|
||||
printf("%s: Help output\n\n", szProg);
|
||||
printf("If this program is given any arguments, this help is displayed.\n");
|
||||
printf("This command is used to print out the full command line for all\n");
|
||||
printf("running processes because /usr/bin/ps is limited to 80 chars and\n");
|
||||
printf("/usr/ucb/ps can merge columns together.\n\n");
|
||||
printf("Columns are:\n");
|
||||
printf("\tS - State of process - see 'ps' man page\n");
|
||||
printf("\tUID - UID of the process owner\n");
|
||||
printf("\tPID - PID of the process\n");
|
||||
printf("\tPPID - PID of the parent process\n");
|
||||
printf("\tVSZ - Virtual memory usage (kilobytes)\n");
|
||||
printf("\tRSS - Real memory usage (kilobytes)\n");
|
||||
printf("\t%%CPU - CPU usage\n");
|
||||
printf("\tCOMMAND - Command being run\n");
|
||||
printf("\tARGS - Full command line with arguments\n");
|
||||
return;
|
||||
printf("%s: Help output\n\n", szProg);
|
||||
printf("If this program is given any arguments, this help is displayed.\n");
|
||||
printf("This command is used to print out the full command line for all\n");
|
||||
printf("running processes because /usr/bin/ps is limited to 80 chars and\n");
|
||||
printf("/usr/ucb/ps can merge columns together.\n\n");
|
||||
printf("Columns are:\n");
|
||||
printf("\tS - State of process - see 'ps' man page\n");
|
||||
printf("\tUID - UID of the process owner\n");
|
||||
printf("\tPID - PID of the process\n");
|
||||
printf("\tPPID - PID of the parent process\n");
|
||||
printf("\tVSZ - Virtual memory usage (kilobytes)\n");
|
||||
printf("\tRSS - Real memory usage (kilobytes)\n");
|
||||
printf("\t%%CPU - CPU usage\n");
|
||||
printf("\tCOMMAND - Command being run\n");
|
||||
printf("\tARGS - Full command line with arguments\n");
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ typedef struct {
|
|||
check_by_ssh_config config;
|
||||
} check_by_ssh_config_wrapper;
|
||||
static check_by_ssh_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
|
||||
static check_by_ssh_config_wrapper validate_arguments(check_by_ssh_config_wrapper /*config_wrapper*/);
|
||||
static check_by_ssh_config_wrapper
|
||||
validate_arguments(check_by_ssh_config_wrapper /*config_wrapper*/);
|
||||
|
||||
static command_construct comm_append(command_construct /*cmd*/, const char * /*str*/);
|
||||
static void print_help(void);
|
||||
|
|
@ -90,7 +91,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* SSH returns 255 if connection attempt fails; include the first line of error output */
|
||||
if (result == 255 && config.unknown_timeout) {
|
||||
printf(_("SSH connection failed: %s\n"), chld_err.lines > 0 ? chld_err.line[0] : "(no error output)");
|
||||
printf(_("SSH connection failed: %s\n"),
|
||||
chld_err.lines > 0 ? chld_err.line[0] : "(no error output)");
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +136,8 @@ int main(int argc, char **argv) {
|
|||
puts(chld_out.line[i]);
|
||||
}
|
||||
} else {
|
||||
printf(_("%s - check_by_ssh: Remote command '%s' returned status %d\n"), state_text(result), config.remotecmd, result);
|
||||
printf(_("%s - check_by_ssh: Remote command '%s' returned status %d\n"),
|
||||
state_text(result), config.remotecmd, result);
|
||||
}
|
||||
return result; /* return error status from remote command */
|
||||
}
|
||||
|
|
@ -160,9 +163,11 @@ int main(int argc, char **argv) {
|
|||
die(STATE_UNKNOWN, _("%s: Error parsing output\n"), progname);
|
||||
}
|
||||
|
||||
if (config.service[commands] && status_text && sscanf(chld_out.line[i], "STATUS CODE: %d", &cresult) == 1) {
|
||||
fprintf(file_pointer, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, config.host_shortname,
|
||||
config.service[commands++], cresult, status_text);
|
||||
if (config.service[commands] && status_text &&
|
||||
sscanf(chld_out.line[i], "STATUS CODE: %d", &cresult) == 1) {
|
||||
fprintf(file_pointer, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
|
||||
(int)local_time, config.host_shortname, config.service[commands++], cresult,
|
||||
status_text);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,34 +177,35 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* process command-line arguments */
|
||||
check_by_ssh_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"fork", no_argument, 0, 'f'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"unknown-timeout", no_argument, 0, 'U'},
|
||||
{"host", required_argument, 0, 'H'}, /* backward compatibility */
|
||||
{"hostname", required_argument, 0, 'H'},
|
||||
{"port", required_argument, 0, 'p'},
|
||||
{"output", required_argument, 0, 'O'},
|
||||
{"name", required_argument, 0, 'n'},
|
||||
{"services", required_argument, 0, 's'},
|
||||
{"identity", required_argument, 0, 'i'},
|
||||
{"user", required_argument, 0, 'u'},
|
||||
{"logname", required_argument, 0, 'l'},
|
||||
{"command", required_argument, 0, 'C'},
|
||||
{"skip", optional_argument, 0, 'S'}, /* backwards compatibility */
|
||||
{"skip-stdout", optional_argument, 0, 'S'},
|
||||
{"skip-stderr", optional_argument, 0, 'E'},
|
||||
{"warn-on-stderr", no_argument, 0, 'W'},
|
||||
{"proto1", no_argument, 0, '1'},
|
||||
{"proto2", no_argument, 0, '2'},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"ssh-option", required_argument, 0, 'o'},
|
||||
{"quiet", no_argument, 0, 'q'},
|
||||
{"configfile", optional_argument, 0, 'F'},
|
||||
{0, 0, 0, 0}};
|
||||
static struct option longopts[] = {
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"fork", no_argument, 0, 'f'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"unknown-timeout", no_argument, 0, 'U'},
|
||||
{"host", required_argument, 0, 'H'}, /* backward compatibility */
|
||||
{"hostname", required_argument, 0, 'H'},
|
||||
{"port", required_argument, 0, 'p'},
|
||||
{"output", required_argument, 0, 'O'},
|
||||
{"name", required_argument, 0, 'n'},
|
||||
{"services", required_argument, 0, 's'},
|
||||
{"identity", required_argument, 0, 'i'},
|
||||
{"user", required_argument, 0, 'u'},
|
||||
{"logname", required_argument, 0, 'l'},
|
||||
{"command", required_argument, 0, 'C'},
|
||||
{"skip", optional_argument, 0, 'S'}, /* backwards compatibility */
|
||||
{"skip-stdout", optional_argument, 0, 'S'},
|
||||
{"skip-stderr", optional_argument, 0, 'E'},
|
||||
{"warn-on-stderr", no_argument, 0, 'W'},
|
||||
{"proto1", no_argument, 0, '1'},
|
||||
{"proto2", no_argument, 0, '2'},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"ssh-option", required_argument, 0, 'o'},
|
||||
{"quiet", no_argument, 0, 'q'},
|
||||
{"configfile", optional_argument, 0, 'F'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_by_ssh_config_wrapper result = {
|
||||
.errorcode = OK,
|
||||
|
|
@ -221,7 +227,8 @@ check_by_ssh_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
int option = 0;
|
||||
while (true) {
|
||||
int opt_index = getopt_long(argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, &option);
|
||||
int opt_index =
|
||||
getopt_long(argc, argv, "Vvh1246fqt:UH:O:p:i:u:l:C:S::E::n:s:o:F:", longopts, &option);
|
||||
|
||||
if (opt_index == -1 || opt_index == EOF) {
|
||||
break;
|
||||
|
|
@ -266,11 +273,13 @@ check_by_ssh_config_wrapper process_arguments(int argc, char **argv) {
|
|||
char *p2;
|
||||
|
||||
p1 = optarg;
|
||||
result.config.service = realloc(result.config.service, (++result.config.number_of_services) * sizeof(char *));
|
||||
result.config.service = realloc(result.config.service,
|
||||
(++result.config.number_of_services) * sizeof(char *));
|
||||
while ((p2 = index(p1, ':'))) {
|
||||
*p2 = '\0';
|
||||
result.config.service[result.config.number_of_services - 1] = p1;
|
||||
result.config.service = realloc(result.config.service, (++result.config.number_of_services) * sizeof(char *));
|
||||
result.config.service = realloc(
|
||||
result.config.service, (++result.config.number_of_services) * sizeof(char *));
|
||||
p1 = p2 + 1;
|
||||
}
|
||||
result.config.service[result.config.number_of_services - 1] = p1;
|
||||
|
|
@ -309,7 +318,8 @@ check_by_ssh_config_wrapper process_arguments(int argc, char **argv) {
|
|||
case 'C': /* Command for remote machine */
|
||||
result.config.commands++;
|
||||
if (result.config.commands > 1) {
|
||||
xasprintf(&result.config.remotecmd, "%s;echo STATUS CODE: $?;", result.config.remotecmd);
|
||||
xasprintf(&result.config.remotecmd, "%s;echo STATUS CODE: $?;",
|
||||
result.config.remotecmd);
|
||||
}
|
||||
xasprintf(&result.config.remotecmd, "%s%s", result.config.remotecmd, optarg);
|
||||
break;
|
||||
|
|
@ -396,7 +406,8 @@ command_construct comm_append(command_construct cmd, const char *str) {
|
|||
die(STATE_UNKNOWN, _("%s: Argument limit of %d exceeded\n"), progname, NP_MAXARGS);
|
||||
}
|
||||
|
||||
if ((cmd.commargv = (char **)realloc(cmd.commargv, (cmd.commargc + 1) * sizeof(char *))) == NULL) {
|
||||
if ((cmd.commargv = (char **)realloc(cmd.commargv, (cmd.commargc + 1) * sizeof(char *))) ==
|
||||
NULL) {
|
||||
die(STATE_UNKNOWN, _("Can not (re)allocate 'commargv' buffer\n"));
|
||||
}
|
||||
|
||||
|
|
@ -412,12 +423,18 @@ check_by_ssh_config_wrapper validate_arguments(check_by_ssh_config_wrapper confi
|
|||
return config_wrapper;
|
||||
}
|
||||
|
||||
if (config_wrapper.config.passive && config_wrapper.config.commands != config_wrapper.config.number_of_services) {
|
||||
die(STATE_UNKNOWN, _("%s: In passive mode, you must provide a service name for each command.\n"), progname);
|
||||
if (config_wrapper.config.passive &&
|
||||
config_wrapper.config.commands != config_wrapper.config.number_of_services) {
|
||||
die(STATE_UNKNOWN,
|
||||
_("%s: In passive mode, you must provide a service name for each command.\n"),
|
||||
progname);
|
||||
}
|
||||
|
||||
if (config_wrapper.config.passive && config_wrapper.config.host_shortname == NULL) {
|
||||
die(STATE_UNKNOWN, _("%s: In passive mode, you must provide the host short name from the monitoring configs.\n"), progname);
|
||||
die(STATE_UNKNOWN,
|
||||
_("%s: In passive mode, you must provide the host short name from the monitoring "
|
||||
"configs.\n"),
|
||||
progname);
|
||||
}
|
||||
|
||||
return config_wrapper;
|
||||
|
|
@ -454,7 +471,8 @@ void print_help(void) {
|
|||
printf(" %s\n", "-W, --warn-on-stderr]");
|
||||
printf(" %s\n", _("Exit with an warning, if there is an output on STDERR"));
|
||||
printf(" %s\n", "-f");
|
||||
printf(" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always return OK if ssh is executed"));
|
||||
printf(" %s\n", _("tells ssh to fork rather than create a tty [optional]. This will always "
|
||||
"return OK if ssh is executed"));
|
||||
printf(" %s\n", "-C, --command='COMMAND STRING'");
|
||||
printf(" %s\n", _("command to execute on the remote machine"));
|
||||
printf(" %s\n", "-l, --logname=USERNAME");
|
||||
|
|
@ -490,7 +508,9 @@ void print_help(void) {
|
|||
printf(" %s\n", _("all of -O, -s, and -n options (servicelist order must match '-C'options)"));
|
||||
printf("\n");
|
||||
printf("%s\n", _("Examples:"));
|
||||
printf(" %s\n", "$ check_by_ssh -H localhost -n lh -s c1:c2:c3 -C uptime -C uptime -C uptime -O /tmp/foo");
|
||||
printf(
|
||||
" %s\n",
|
||||
"$ check_by_ssh -H localhost -n lh -s c1:c2:c3 -C uptime -C uptime -C uptime -O /tmp/foo");
|
||||
printf(" %s\n", "$ cat /tmp/foo");
|
||||
printf(" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c1;0; up 2 days");
|
||||
printf(" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c2;0; up 2 days");
|
||||
|
|
|
|||
|
|
@ -112,25 +112,30 @@ int main(int argc, char **argv) {
|
|||
int return_code = STATE_OK;
|
||||
/* return the status of the cluster */
|
||||
if (config.check_type == CHECK_SERVICES) {
|
||||
return_code = get_status(total_services_warning + total_services_unknown + total_services_critical, config.thresholds);
|
||||
printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n", state_text(return_code),
|
||||
(config.label == NULL) ? "Service cluster" : config.label, total_services_ok, total_services_warning, total_services_unknown,
|
||||
return_code =
|
||||
get_status(total_services_warning + total_services_unknown + total_services_critical,
|
||||
config.thresholds);
|
||||
printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
|
||||
state_text(return_code), (config.label == NULL) ? "Service cluster" : config.label,
|
||||
total_services_ok, total_services_warning, total_services_unknown,
|
||||
total_services_critical);
|
||||
} else {
|
||||
return_code = get_status(total_hosts_down + total_hosts_unreachable, config.thresholds);
|
||||
printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n", state_text(return_code),
|
||||
(config.label == NULL) ? "Host cluster" : config.label, total_hosts_up, total_hosts_down, total_hosts_unreachable);
|
||||
(config.label == NULL) ? "Host cluster" : config.label, total_hosts_up,
|
||||
total_hosts_down, total_hosts_unreachable);
|
||||
}
|
||||
|
||||
exit(return_code);
|
||||
}
|
||||
|
||||
check_cluster_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {{"data", required_argument, 0, 'd'}, {"warning", required_argument, 0, 'w'},
|
||||
{"critical", required_argument, 0, 'c'}, {"label", required_argument, 0, 'l'},
|
||||
{"host", no_argument, 0, 'h'}, {"service", no_argument, 0, 's'},
|
||||
{"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'H'}, {0, 0, 0, 0}};
|
||||
static struct option longopts[] = {
|
||||
{"data", required_argument, 0, 'd'}, {"warning", required_argument, 0, 'w'},
|
||||
{"critical", required_argument, 0, 'c'}, {"label", required_argument, 0, 'l'},
|
||||
{"host", no_argument, 0, 'h'}, {"service", no_argument, 0, 's'},
|
||||
{"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'H'}, {0, 0, 0, 0}};
|
||||
|
||||
check_cluster_config_wrapper result = {
|
||||
.errorcode = OK,
|
||||
|
|
@ -251,7 +256,8 @@ void print_help(void) {
|
|||
printf("\n");
|
||||
printf("%s\n", _("Examples:"));
|
||||
printf(" %s\n", "check_cluster -s -d 2,0,2,0 -c @3:");
|
||||
printf(" %s\n", _("Will alert critical if there are 3 or more service data points in a non-OK"));
|
||||
printf(" %s\n",
|
||||
_("Will alert critical if there are 3 or more service data points in a non-OK"));
|
||||
printf(" %s\n", _("state."));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
|
|||
|
|
@ -71,8 +71,9 @@ static double timediff(struct timeval /*start*/, struct timeval /*end*/);
|
|||
|
||||
static void np_dbi_print_error(dbi_conn /*conn*/, char * /*fmt*/, ...);
|
||||
|
||||
static mp_state_enum do_query(dbi_conn /*conn*/, const char ** /*res_val_str*/, double * /*res_val*/, double * /*res_time*/, mp_dbi_metric /*metric*/,
|
||||
mp_dbi_type /*type*/, char * /*np_dbi_query*/);
|
||||
static mp_state_enum do_query(dbi_conn /*conn*/, const char ** /*res_val_str*/,
|
||||
double * /*res_val*/, double * /*res_time*/, mp_dbi_metric /*metric*/,
|
||||
mp_dbi_type /*type*/, char * /*np_dbi_query*/);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int status = STATE_UNKNOWN;
|
||||
|
|
@ -118,7 +119,8 @@ int main(int argc, char **argv) {
|
|||
dbi_inst *instance_p = {0};
|
||||
|
||||
if (dbi_initialize_r(NULL, instance_p) < 0) {
|
||||
printf("UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n");
|
||||
printf(
|
||||
"UNKNOWN - failed to initialize DBI; possibly you don't have any drivers installed.\n");
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
|
@ -133,10 +135,12 @@ int main(int argc, char **argv) {
|
|||
|
||||
driver = dbi_driver_open_r(config.dbi_driver, instance_p);
|
||||
if (!driver) {
|
||||
printf("UNKNOWN - failed to open DBI driver '%s'; possibly it's not installed.\n", config.dbi_driver);
|
||||
printf("UNKNOWN - failed to open DBI driver '%s'; possibly it's not installed.\n",
|
||||
config.dbi_driver);
|
||||
|
||||
printf("Known drivers:\n");
|
||||
for (driver = dbi_driver_list_r(NULL, instance_p); driver; driver = dbi_driver_list_r(driver, instance_p)) {
|
||||
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;
|
||||
|
|
@ -156,7 +160,8 @@ int main(int argc, char **argv) {
|
|||
const char *opt;
|
||||
|
||||
if (verbose > 1) {
|
||||
printf("Setting DBI driver option '%s' to '%s'\n", config.dbi_options[i].key, config.dbi_options[i].value);
|
||||
printf("Setting DBI driver option '%s' to '%s'\n", config.dbi_options[i].key,
|
||||
config.dbi_options[i].value);
|
||||
}
|
||||
|
||||
if (!dbi_conn_set_option(conn, config.dbi_options[i].key, config.dbi_options[i].value)) {
|
||||
|
|
@ -164,10 +169,12 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
/* else: status != 0 */
|
||||
|
||||
np_dbi_print_error(conn, "UNKNOWN - failed to set option '%s' to '%s'", config.dbi_options[i].key, config.dbi_options[i].value);
|
||||
np_dbi_print_error(conn, "UNKNOWN - failed to set option '%s' to '%s'",
|
||||
config.dbi_options[i].key, config.dbi_options[i].value);
|
||||
printf("Known driver options:\n");
|
||||
|
||||
for (opt = dbi_conn_get_option_list(conn, NULL); opt; opt = dbi_conn_get_option_list(conn, opt)) {
|
||||
for (opt = dbi_conn_get_option_list(conn, NULL); opt;
|
||||
opt = dbi_conn_get_option_list(conn, opt)) {
|
||||
printf(" - %s\n", opt);
|
||||
}
|
||||
dbi_conn_close(conn);
|
||||
|
|
@ -230,14 +237,16 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (dbi_conn_select_db(conn, config.dbi_database)) {
|
||||
np_dbi_print_error(conn, "UNKNOWN - failed to select database '%s'", config.dbi_database);
|
||||
np_dbi_print_error(conn, "UNKNOWN - failed to select database '%s'",
|
||||
config.dbi_database);
|
||||
return STATE_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.dbi_query) {
|
||||
/* execute query */
|
||||
status = do_query(conn, &query_val_str, &query_val, &query_time, config.metric, config.type, config.dbi_query);
|
||||
status = do_query(conn, &query_val_str, &query_val, &query_time, config.metric, config.type,
|
||||
config.dbi_query);
|
||||
if (status != STATE_OK) {
|
||||
/* do_query prints an error message in this case */
|
||||
return status;
|
||||
|
|
@ -281,7 +290,8 @@ int main(int argc, char **argv) {
|
|||
/* In case of METRIC_QUERY_RESULT, isnan(query_val) indicates an error
|
||||
* which should have been reported and handled (abort) before
|
||||
* ... unless we expected a string to be returned */
|
||||
assert((config.metric != METRIC_QUERY_RESULT) || (!isnan(query_val)) || (config.type == TYPE_STRING));
|
||||
assert((config.metric != METRIC_QUERY_RESULT) || (!isnan(query_val)) ||
|
||||
(config.type == TYPE_STRING));
|
||||
|
||||
assert((config.type != TYPE_STRING) || (config.expect || config.expect_re_str));
|
||||
|
||||
|
|
@ -289,12 +299,14 @@ int main(int argc, char **argv) {
|
|||
if (config.dbi_query) {
|
||||
if (config.type == TYPE_STRING) {
|
||||
assert(config.expect || config.expect_re_str);
|
||||
printf(", '%s' returned '%s' in %fs", config.dbi_query, query_val_str ? query_val_str : "<nothing>", query_time);
|
||||
printf(", '%s' returned '%s' in %fs", config.dbi_query,
|
||||
query_val_str ? query_val_str : "<nothing>", query_time);
|
||||
if (status != STATE_OK) {
|
||||
if (config.expect) {
|
||||
printf(" (expected '%s')", config.expect);
|
||||
} else if (config.expect_re_str) {
|
||||
printf(" (expected regex /%s/%s)", config.expect_re_str, ((config.expect_re_cflags & REG_ICASE) ? "i" : ""));
|
||||
printf(" (expected regex /%s/%s)", config.expect_re_str,
|
||||
((config.expect_re_cflags & REG_ICASE) ? "i" : ""));
|
||||
}
|
||||
}
|
||||
} else if (isnan(query_val)) {
|
||||
|
|
@ -304,18 +316,31 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
printf(" | conntime=%fs;%s;%s;0; server_version=%u;%s;%s;0;", conn_time,
|
||||
((config.metric == METRIC_CONN_TIME) && config.warning_range) ? config.warning_range : "",
|
||||
((config.metric == METRIC_CONN_TIME) && config.critical_range) ? config.critical_range : "", server_version,
|
||||
((config.metric == METRIC_SERVER_VERSION) && config.warning_range) ? config.warning_range : "",
|
||||
((config.metric == METRIC_SERVER_VERSION) && config.critical_range) ? config.critical_range : "");
|
||||
printf(
|
||||
" | conntime=%fs;%s;%s;0; server_version=%u;%s;%s;0;", conn_time,
|
||||
((config.metric == METRIC_CONN_TIME) && config.warning_range) ? config.warning_range : "",
|
||||
((config.metric == METRIC_CONN_TIME) && config.critical_range) ? config.critical_range : "",
|
||||
server_version,
|
||||
((config.metric == METRIC_SERVER_VERSION) && config.warning_range) ? config.warning_range
|
||||
: "",
|
||||
((config.metric == METRIC_SERVER_VERSION) && config.critical_range) ? config.critical_range
|
||||
: "");
|
||||
if (config.dbi_query) {
|
||||
if (!isnan(query_val)) { /* this is also true when -e is used */
|
||||
printf(" query=%f;%s;%s;;", query_val, ((config.metric == METRIC_QUERY_RESULT) && config.warning_range) ? config.warning_range : "",
|
||||
((config.metric == METRIC_QUERY_RESULT) && config.critical_range) ? config.critical_range : "");
|
||||
printf(" query=%f;%s;%s;;", query_val,
|
||||
((config.metric == METRIC_QUERY_RESULT) && config.warning_range)
|
||||
? config.warning_range
|
||||
: "",
|
||||
((config.metric == METRIC_QUERY_RESULT) && config.critical_range)
|
||||
? config.critical_range
|
||||
: "");
|
||||
}
|
||||
printf(" querytime=%fs;%s;%s;0;", query_time, ((config.metric == METRIC_QUERY_TIME) && config.warning_range) ? config.warning_range : "",
|
||||
((config.metric == METRIC_QUERY_TIME) && config.critical_range) ? config.critical_range : "");
|
||||
printf(" querytime=%fs;%s;%s;0;", query_time,
|
||||
((config.metric == METRIC_QUERY_TIME) && config.warning_range) ? config.warning_range
|
||||
: "",
|
||||
((config.metric == METRIC_QUERY_TIME) && config.critical_range)
|
||||
? config.critical_range
|
||||
: "");
|
||||
}
|
||||
printf("\n");
|
||||
return status;
|
||||
|
|
@ -442,7 +467,8 @@ check_dbi_config_wrapper process_arguments(int argc, char **argv) {
|
|||
*value = '\0';
|
||||
++value;
|
||||
|
||||
new = realloc(result.config.dbi_options, (result.config.dbi_options_num + 1) * sizeof(*new));
|
||||
new = realloc(result.config.dbi_options,
|
||||
(result.config.dbi_options_num + 1) * sizeof(*new));
|
||||
if (!new) {
|
||||
printf("UNKNOWN - failed to reallocate memory\n");
|
||||
exit(STATE_UNKNOWN);
|
||||
|
|
@ -464,7 +490,8 @@ check_dbi_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
set_thresholds(&result.config.dbi_thresholds, result.config.warning_range, result.config.critical_range);
|
||||
set_thresholds(&result.config.dbi_thresholds, result.config.warning_range,
|
||||
result.config.critical_range);
|
||||
|
||||
return validate_arguments(result);
|
||||
}
|
||||
|
|
@ -474,21 +501,28 @@ check_dbi_config_wrapper validate_arguments(check_dbi_config_wrapper config_wrap
|
|||
usage("Must specify a DBI driver");
|
||||
}
|
||||
|
||||
if (((config_wrapper.config.metric == METRIC_QUERY_RESULT) || (config_wrapper.config.metric == METRIC_QUERY_TIME)) &&
|
||||
if (((config_wrapper.config.metric == METRIC_QUERY_RESULT) ||
|
||||
(config_wrapper.config.metric == METRIC_QUERY_TIME)) &&
|
||||
(!config_wrapper.config.dbi_query)) {
|
||||
usage("Must specify a query to execute (metric == QUERY_RESULT)");
|
||||
}
|
||||
|
||||
if ((config_wrapper.config.metric != METRIC_CONN_TIME) && (config_wrapper.config.metric != METRIC_SERVER_VERSION) &&
|
||||
(config_wrapper.config.metric != METRIC_QUERY_RESULT) && (config_wrapper.config.metric != METRIC_QUERY_TIME)) {
|
||||
if ((config_wrapper.config.metric != METRIC_CONN_TIME) &&
|
||||
(config_wrapper.config.metric != METRIC_SERVER_VERSION) &&
|
||||
(config_wrapper.config.metric != METRIC_QUERY_RESULT) &&
|
||||
(config_wrapper.config.metric != METRIC_QUERY_TIME)) {
|
||||
usage("Invalid metric specified");
|
||||
}
|
||||
|
||||
if (config_wrapper.config.expect && (config_wrapper.config.warning_range || config_wrapper.config.critical_range || config_wrapper.config.expect_re_str)) {
|
||||
if (config_wrapper.config.expect &&
|
||||
(config_wrapper.config.warning_range || config_wrapper.config.critical_range ||
|
||||
config_wrapper.config.expect_re_str)) {
|
||||
usage("Do not mix -e and -w/-c/-r/-R");
|
||||
}
|
||||
|
||||
if (config_wrapper.config.expect_re_str && (config_wrapper.config.warning_range || config_wrapper.config.critical_range || config_wrapper.config.expect)) {
|
||||
if (config_wrapper.config.expect_re_str &&
|
||||
(config_wrapper.config.warning_range || config_wrapper.config.critical_range ||
|
||||
config_wrapper.config.expect)) {
|
||||
usage("Do not mix -r/-R and -w/-c/-e");
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +530,8 @@ check_dbi_config_wrapper validate_arguments(check_dbi_config_wrapper config_wrap
|
|||
usage("Option -e requires metric QUERY_RESULT");
|
||||
}
|
||||
|
||||
if (config_wrapper.config.expect_re_str && (config_wrapper.config.metric != METRIC_QUERY_RESULT)) {
|
||||
if (config_wrapper.config.expect_re_str &&
|
||||
(config_wrapper.config.metric != METRIC_QUERY_RESULT)) {
|
||||
usage("Options -r/-R require metric QUERY_RESULT");
|
||||
}
|
||||
|
||||
|
|
@ -607,7 +642,8 @@ void print_usage(void) {
|
|||
printf(" [-e <string>] [-r|-R <regex>]\n");
|
||||
}
|
||||
|
||||
const char *get_field_str(dbi_conn conn, dbi_result res, unsigned short field_type, mp_dbi_metric metric, mp_dbi_type type) {
|
||||
const char *get_field_str(dbi_conn conn, dbi_result res, unsigned short field_type,
|
||||
mp_dbi_metric metric, mp_dbi_type type) {
|
||||
const char *str;
|
||||
|
||||
if (field_type != DBI_TYPE_STRING) {
|
||||
|
|
@ -630,7 +666,8 @@ const char *get_field_str(dbi_conn conn, dbi_result res, unsigned short field_ty
|
|||
return str;
|
||||
}
|
||||
|
||||
double get_field(dbi_conn conn, dbi_result res, unsigned short *field_type, mp_dbi_metric metric, mp_dbi_type type) {
|
||||
double get_field(dbi_conn conn, dbi_result res, unsigned short *field_type, mp_dbi_metric metric,
|
||||
mp_dbi_type type) {
|
||||
double val = NAN;
|
||||
|
||||
if (*field_type == DBI_TYPE_INTEGER) {
|
||||
|
|
@ -679,7 +716,8 @@ double get_field(dbi_conn conn, dbi_result res, unsigned short *field_type, mp_d
|
|||
return val;
|
||||
}
|
||||
|
||||
mp_state_enum get_query_result(dbi_conn conn, dbi_result res, const char **res_val_str, double *res_val, mp_dbi_metric metric, mp_dbi_type type) {
|
||||
mp_state_enum get_query_result(dbi_conn conn, dbi_result res, const char **res_val_str,
|
||||
double *res_val, mp_dbi_metric metric, mp_dbi_type type) {
|
||||
unsigned short field_type;
|
||||
double val = NAN;
|
||||
|
||||
|
|
@ -747,8 +785,8 @@ mp_state_enum get_query_result(dbi_conn conn, dbi_result res, const char **res_v
|
|||
return STATE_OK;
|
||||
}
|
||||
|
||||
mp_state_enum do_query(dbi_conn conn, const char **res_val_str, double *res_val, double *res_time, mp_dbi_metric metric, mp_dbi_type type,
|
||||
char *np_dbi_query) {
|
||||
mp_state_enum do_query(dbi_conn conn, const char **res_val_str, double *res_val, double *res_time,
|
||||
mp_dbi_metric metric, mp_dbi_type type, char *np_dbi_query) {
|
||||
dbi_result res;
|
||||
|
||||
struct timeval timeval_start;
|
||||
|
|
|
|||
|
|
@ -81,8 +81,9 @@ int main(int argc, char **argv) {
|
|||
|
||||
char *command_line;
|
||||
/* get the command to run */
|
||||
xasprintf(&command_line, "%s %s %s -p %d @%s %s %s +retry=%d +time=%d", PATH_TO_DIG, config.dig_args, config.query_transport,
|
||||
config.server_port, config.dns_server, config.query_address, config.record_type, config.number_tries, timeout_interval_dig);
|
||||
xasprintf(&command_line, "%s %s %s -p %d @%s %s %s +retry=%d +time=%d", PATH_TO_DIG,
|
||||
config.dig_args, config.query_transport, config.server_port, config.dns_server,
|
||||
config.query_address, config.record_type, config.number_tries, timeout_interval_dig);
|
||||
|
||||
alarm(timeout_interval);
|
||||
struct timeval start_time;
|
||||
|
|
@ -118,8 +119,9 @@ int main(int argc, char **argv) {
|
|||
printf("%s\n", chld_out.line[i]);
|
||||
}
|
||||
|
||||
if (strcasestr(chld_out.line[i], (config.expected_address == NULL ? config.query_address : config.expected_address)) !=
|
||||
NULL) {
|
||||
if (strcasestr(chld_out.line[i], (config.expected_address == NULL
|
||||
? config.query_address
|
||||
: config.expected_address)) != NULL) {
|
||||
msg = chld_out.line[i];
|
||||
result = STATE_OK;
|
||||
|
||||
|
|
@ -174,8 +176,9 @@ int main(int argc, char **argv) {
|
|||
|
||||
printf("DNS %s - %.3f seconds response time (%s)|%s\n", state_text(result), elapsed_time,
|
||||
msg ? msg : _("Probably a non-existent host/domain"),
|
||||
fperfdata("time", elapsed_time, "s", (config.warning_interval > UNDEFINED), config.warning_interval,
|
||||
(config.critical_interval > UNDEFINED), config.critical_interval, true, 0, false, 0));
|
||||
fperfdata("time", elapsed_time, "s", (config.warning_interval > UNDEFINED),
|
||||
config.warning_interval, (config.critical_interval > UNDEFINED),
|
||||
config.critical_interval, true, 0, false, 0));
|
||||
exit(result);
|
||||
}
|
||||
|
||||
|
|
@ -335,7 +338,8 @@ void print_help(void) {
|
|||
printf(" %s\n", "-T, --record_type=STRING");
|
||||
printf(" %s\n", _("Record type to lookup (default: A)"));
|
||||
printf(" %s\n", "-a, --expected_address=STRING");
|
||||
printf(" %s\n", _("An address expected to be in the answer section. If not set, uses whatever"));
|
||||
printf(" %s\n",
|
||||
_("An address expected to be in the answer section. If not set, uses whatever"));
|
||||
printf(" %s\n", _("was in -l"));
|
||||
printf(" %s\n", "-A, --dig-arguments=STRING");
|
||||
printf(" %s\n", _("Pass STRING as argument(s) to dig"));
|
||||
|
|
|
|||
|
|
@ -78,18 +78,21 @@ typedef struct {
|
|||
} check_disk_config_wrapper;
|
||||
static check_disk_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
|
||||
|
||||
static void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units, char *crit_freespace_units,
|
||||
char *warn_freespace_percent, char *crit_freespace_percent, char *warn_freeinodes_percent,
|
||||
static void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units,
|
||||
char *crit_freespace_units, char *warn_freespace_percent,
|
||||
char *crit_freespace_percent, char *warn_freeinodes_percent,
|
||||
char *crit_freeinodes_percent);
|
||||
static double calculate_percent(uintmax_t /*value*/, uintmax_t /*total*/);
|
||||
static bool stat_path(parameter_list_elem * /*parameters*/, bool /*ignore_missing*/);
|
||||
|
||||
/*
|
||||
* Puts the values from a struct fs_usage into a parameter_list with an additional flag to control how reserved
|
||||
* and inodes should be judged (ignored or not)
|
||||
* Puts the values from a struct fs_usage into a parameter_list with an additional flag to control
|
||||
* how reserved and inodes should be judged (ignored or not)
|
||||
*/
|
||||
static parameter_list_elem get_path_stats(parameter_list_elem parameters, struct fs_usage fsp, bool freespace_ignore_reserved);
|
||||
static mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_inodes_perfdata, byte_unit unit);
|
||||
static parameter_list_elem get_path_stats(parameter_list_elem parameters, struct fs_usage fsp,
|
||||
bool freespace_ignore_reserved);
|
||||
static mp_subcheck evaluate_filesystem(measurement_unit measurement_unit,
|
||||
bool display_inodes_perfdata, byte_unit unit);
|
||||
|
||||
void print_usage(void);
|
||||
static void print_help(void);
|
||||
|
|
@ -111,7 +114,6 @@ const byte_unit TeraBytes_factor = 1000000000000;
|
|||
const byte_unit PetaBytes_factor = 1000000000000000;
|
||||
const byte_unit ExaBytes_factor = 1000000000000000000;
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
|
|
@ -140,7 +142,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (!config.path_ignored) {
|
||||
mp_int_fs_list_set_best_match(config.path_select_list, config.mount_list, config.exact_match);
|
||||
mp_int_fs_list_set_best_match(config.path_select_list, config.mount_list,
|
||||
config.exact_match);
|
||||
}
|
||||
|
||||
// Error if no match found for specified paths
|
||||
|
|
@ -203,20 +206,23 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (path->group == NULL) {
|
||||
if (config.fs_exclude_list && np_find_regmatch(config.fs_exclude_list, mount_entry->me_type)) {
|
||||
if (config.fs_exclude_list &&
|
||||
np_find_regmatch(config.fs_exclude_list, mount_entry->me_type)) {
|
||||
// Skip excluded fs's
|
||||
path = mp_int_fs_list_del(&config.path_select_list, path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (config.device_path_exclude_list && (np_find_name(config.device_path_exclude_list, mount_entry->me_devname) ||
|
||||
np_find_name(config.device_path_exclude_list, mount_entry->me_mountdir))) {
|
||||
if (config.device_path_exclude_list &&
|
||||
(np_find_name(config.device_path_exclude_list, mount_entry->me_devname) ||
|
||||
np_find_name(config.device_path_exclude_list, mount_entry->me_mountdir))) {
|
||||
// Skip excluded device or mount paths
|
||||
path = mp_int_fs_list_del(&config.path_select_list, path);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (config.fs_include_list && !np_find_regmatch(config.fs_include_list, mount_entry->me_type)) {
|
||||
if (config.fs_include_list &&
|
||||
!np_find_regmatch(config.fs_include_list, mount_entry->me_type)) {
|
||||
// Skip not included fstypes
|
||||
path = mp_int_fs_list_del(&config.path_select_list, path);
|
||||
continue;
|
||||
|
|
@ -259,8 +265,8 @@ int main(int argc, char **argv) {
|
|||
if (verbose >= 3) {
|
||||
printf("For %s, used_units=%lu free_units=%lu total_units=%lu "
|
||||
"fsp.fsu_blocksize=%lu\n",
|
||||
mount_entry->me_mountdir, filesystem->used_bytes, filesystem->free_bytes, filesystem->total_bytes,
|
||||
fsp.fsu_blocksize);
|
||||
mount_entry->me_mountdir, filesystem->used_bytes, filesystem->free_bytes,
|
||||
filesystem->total_bytes, fsp.fsu_blocksize);
|
||||
}
|
||||
} else {
|
||||
// failed to retrieve file system data or not mounted?
|
||||
|
|
@ -285,12 +291,14 @@ int main(int argc, char **argv) {
|
|||
measurement_unit_list *measurements = NULL;
|
||||
measurement_unit_list *current = NULL;
|
||||
// create measuring units, because of groups
|
||||
for (parameter_list_elem *filesystem = config.path_select_list.first; filesystem; filesystem = mp_int_fs_list_get_next(filesystem)) {
|
||||
for (parameter_list_elem *filesystem = config.path_select_list.first; filesystem;
|
||||
filesystem = mp_int_fs_list_get_next(filesystem)) {
|
||||
assert(filesystem->best_match != NULL);
|
||||
|
||||
if (filesystem->group == NULL) {
|
||||
// create a measurement unit for the fs
|
||||
measurement_unit unit = create_measurement_unit_from_filesystem(*filesystem, config.display_mntp);
|
||||
measurement_unit unit =
|
||||
create_measurement_unit_from_filesystem(*filesystem, config.display_mntp);
|
||||
if (measurements == NULL) {
|
||||
measurements = current = add_measurement_list(NULL, unit);
|
||||
} else {
|
||||
|
|
@ -300,14 +308,17 @@ int main(int argc, char **argv) {
|
|||
// Grouped elements are consecutive
|
||||
if (measurements == NULL) {
|
||||
// first entry
|
||||
measurement_unit unit = create_measurement_unit_from_filesystem(*filesystem, config.display_mntp);
|
||||
measurement_unit unit =
|
||||
create_measurement_unit_from_filesystem(*filesystem, config.display_mntp);
|
||||
unit.name = strdup(filesystem->group);
|
||||
measurements = current = add_measurement_list(NULL, unit);
|
||||
} else {
|
||||
// if this is the first element of a group, the name of the previous entry is different
|
||||
// if this is the first element of a group, the name of the previous entry is
|
||||
// different
|
||||
if (strcmp(filesystem->group, current->unit.name) != 0) {
|
||||
// so, this must be the first element of a group
|
||||
measurement_unit unit = create_measurement_unit_from_filesystem(*filesystem, config.display_mntp);
|
||||
measurement_unit unit =
|
||||
create_measurement_unit_from_filesystem(*filesystem, config.display_mntp);
|
||||
unit.name = filesystem->group;
|
||||
current = add_measurement_list(measurements, unit);
|
||||
|
||||
|
|
@ -322,7 +333,8 @@ int main(int argc, char **argv) {
|
|||
/* Process for every path in list */
|
||||
if (measurements != NULL) {
|
||||
for (measurement_unit_list *unit = measurements; unit; unit = unit->next) {
|
||||
mp_subcheck unit_sc = evaluate_filesystem(unit->unit, config.display_inodes_perfdata, config.display_unit);
|
||||
mp_subcheck unit_sc = evaluate_filesystem(unit->unit, config.display_inodes_perfdata,
|
||||
config.display_unit);
|
||||
mp_add_subcheck_to_check(&overall, unit_sc);
|
||||
}
|
||||
} else {
|
||||
|
|
@ -433,7 +445,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
while (true) {
|
||||
int option = 0;
|
||||
int option_index = getopt_long(argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option);
|
||||
int option_index = getopt_long(
|
||||
argc, argv, "+?VqhvefCt:c:w:K:W:u:p:x:X:N:mklLPg:R:r:i:I:MEAn", longopts, &option);
|
||||
|
||||
if (option_index == -1 || option_index == EOF) {
|
||||
break;
|
||||
|
|
@ -578,9 +591,10 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.display_inodes_perfdata = true;
|
||||
break;
|
||||
case 'p': /* select path */ {
|
||||
if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || crit_freespace_percent ||
|
||||
warn_freeinodes_percent || crit_freeinodes_percent)) {
|
||||
die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
|
||||
if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
|
||||
crit_freespace_percent || warn_freeinodes_percent || crit_freeinodes_percent)) {
|
||||
die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"),
|
||||
_("Must set a threshold value before using -p\n"));
|
||||
}
|
||||
|
||||
/* add parameter if not found. overwrite thresholds if path has already been added */
|
||||
|
|
@ -595,7 +609,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
// }
|
||||
}
|
||||
search_entry->group = group;
|
||||
set_all_thresholds(search_entry, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent,
|
||||
set_all_thresholds(search_entry, warn_freespace_units, crit_freespace_units,
|
||||
warn_freespace_percent, crit_freespace_percent,
|
||||
|
||||
warn_freeinodes_percent, crit_freeinodes_percent);
|
||||
|
||||
|
|
@ -603,7 +618,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
// if (!stat_path(se, result.config.ignore_missing)) {
|
||||
// break;
|
||||
// }
|
||||
mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list, result.config.exact_match);
|
||||
mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list,
|
||||
result.config.exact_match);
|
||||
|
||||
path_selected = true;
|
||||
} break;
|
||||
|
|
@ -615,7 +631,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (err != 0) {
|
||||
char errbuf[MAX_INPUT_BUFFER];
|
||||
regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"),
|
||||
_("Could not compile regular expression"), errbuf);
|
||||
}
|
||||
break;
|
||||
case 'N': /* include file system type */
|
||||
|
|
@ -623,7 +640,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (err != 0) {
|
||||
char errbuf[MAX_INPUT_BUFFER];
|
||||
regerror(err, &result.config.fs_exclude_list->regex, errbuf, MAX_INPUT_BUFFER);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"),
|
||||
_("Could not compile regular expression"), errbuf);
|
||||
}
|
||||
} break;
|
||||
case 'v': /* verbose */
|
||||
|
|
@ -638,7 +656,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
case 'E':
|
||||
if (path_selected) {
|
||||
die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n"));
|
||||
die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"),
|
||||
_("Must set -E before selecting paths\n"));
|
||||
}
|
||||
result.config.exact_match = true;
|
||||
break;
|
||||
|
|
@ -647,7 +666,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
case 'g':
|
||||
if (path_selected) {
|
||||
die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n"));
|
||||
die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"),
|
||||
_("Must set group value before selecting paths\n"));
|
||||
}
|
||||
group = optarg;
|
||||
break;
|
||||
|
|
@ -657,14 +677,16 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
case 'i': {
|
||||
if (!path_selected) {
|
||||
die(STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"),
|
||||
_("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly"));
|
||||
_("Paths need to be selected before using -i/-I. Use -A to select all paths "
|
||||
"explicitly"));
|
||||
}
|
||||
regex_t regex;
|
||||
int err = regcomp(®ex, optarg, cflags);
|
||||
if (err != 0) {
|
||||
char errbuf[MAX_INPUT_BUFFER];
|
||||
regerror(err, ®ex, errbuf, MAX_INPUT_BUFFER);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"),
|
||||
_("Could not compile regular expression"), errbuf);
|
||||
}
|
||||
|
||||
for (parameter_list_elem *elem = result.config.path_select_list.first; elem;) {
|
||||
|
|
@ -695,10 +717,11 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
cflags |= REG_ICASE;
|
||||
// Intentional fallthrough
|
||||
case 'r': {
|
||||
if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent || crit_freespace_percent ||
|
||||
warn_freeinodes_percent || crit_freeinodes_percent)) {
|
||||
if (!(warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
|
||||
crit_freespace_percent || warn_freeinodes_percent || crit_freeinodes_percent)) {
|
||||
die(STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"),
|
||||
_("Must set a threshold value before using -r/-R/-A (--ereg-path/--eregi-path/--all)\n"));
|
||||
_("Must set a threshold value before using -r/-R/-A "
|
||||
"(--ereg-path/--eregi-path/--all)\n"));
|
||||
}
|
||||
|
||||
regex_t regex;
|
||||
|
|
@ -706,7 +729,8 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (err != 0) {
|
||||
char errbuf[MAX_INPUT_BUFFER];
|
||||
regerror(err, ®ex, errbuf, MAX_INPUT_BUFFER);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"),
|
||||
_("Could not compile regular expression"), errbuf);
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
|
|
@ -714,16 +738,21 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (np_regex_match_mount_entry(me, ®ex)) {
|
||||
found = true;
|
||||
if (verbose >= 3) {
|
||||
printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
|
||||
printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir,
|
||||
optarg);
|
||||
}
|
||||
|
||||
/* add parameter if not found. overwrite thresholds if path has already been added */
|
||||
/* add parameter if not found. overwrite thresholds if path has already been
|
||||
* added */
|
||||
parameter_list_elem *se = NULL;
|
||||
if (!(se = mp_int_fs_list_find(result.config.path_select_list, me->me_mountdir))) {
|
||||
se = mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir);
|
||||
if (!(se = mp_int_fs_list_find(result.config.path_select_list,
|
||||
me->me_mountdir))) {
|
||||
se =
|
||||
mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir);
|
||||
}
|
||||
se->group = group;
|
||||
set_all_thresholds(se, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent,
|
||||
set_all_thresholds(se, warn_freespace_units, crit_freespace_units,
|
||||
warn_freespace_percent, crit_freespace_percent,
|
||||
warn_freeinodes_percent, crit_freeinodes_percent);
|
||||
}
|
||||
}
|
||||
|
|
@ -735,11 +764,13 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
}
|
||||
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"), _("Regular expression did not match any path or disk"), optarg);
|
||||
die(STATE_UNKNOWN, "DISK %s: %s - %s\n", _("UNKNOWN"),
|
||||
_("Regular expression did not match any path or disk"), optarg);
|
||||
}
|
||||
|
||||
path_selected = true;
|
||||
mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list, result.config.exact_match);
|
||||
mp_int_fs_list_set_best_match(result.config.path_select_list, result.config.mount_list,
|
||||
result.config.exact_match);
|
||||
cflags = default_cflags;
|
||||
|
||||
} break;
|
||||
|
|
@ -747,16 +778,20 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.display_mntp = true;
|
||||
break;
|
||||
case 'C': {
|
||||
/* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
|
||||
/* add all mount entries to path_select list if no partitions have been explicitly
|
||||
* defined using -p */
|
||||
if (!path_selected) {
|
||||
parameter_list_elem *path;
|
||||
for (struct mount_entry *me = result.config.mount_list; me; me = me->me_next) {
|
||||
if (!(path = mp_int_fs_list_find(result.config.path_select_list, me->me_mountdir))) {
|
||||
path = mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir);
|
||||
if (!(path = mp_int_fs_list_find(result.config.path_select_list,
|
||||
me->me_mountdir))) {
|
||||
path =
|
||||
mp_int_fs_list_append(&result.config.path_select_list, me->me_mountdir);
|
||||
}
|
||||
path->best_match = me;
|
||||
path->group = group;
|
||||
set_all_thresholds(path, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent,
|
||||
set_all_thresholds(path, warn_freespace_units, crit_freespace_units,
|
||||
warn_freespace_percent, crit_freespace_percent,
|
||||
warn_freeinodes_percent, crit_freeinodes_percent);
|
||||
}
|
||||
}
|
||||
|
|
@ -843,10 +878,12 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (verbose > 0) {
|
||||
printf("Got an positional filesystem: %s\n", argv[index]);
|
||||
}
|
||||
struct parameter_list *se = mp_int_fs_list_append(&result.config.path_select_list, strdup(argv[index++]));
|
||||
struct parameter_list *se =
|
||||
mp_int_fs_list_append(&result.config.path_select_list, strdup(argv[index++]));
|
||||
path_selected = true;
|
||||
set_all_thresholds(se, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent,
|
||||
warn_freeinodes_percent, crit_freeinodes_percent);
|
||||
set_all_thresholds(se, warn_freespace_units, crit_freespace_units, warn_freespace_percent,
|
||||
crit_freespace_percent, warn_freeinodes_percent,
|
||||
crit_freeinodes_percent);
|
||||
}
|
||||
|
||||
// If a list of paths has not been explicitly selected, find entire
|
||||
|
|
@ -864,18 +901,21 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
path->best_match = me;
|
||||
path->group = group;
|
||||
set_all_thresholds(path, warn_freespace_units, crit_freespace_units, warn_freespace_percent, crit_freespace_percent,
|
||||
set_all_thresholds(path, warn_freespace_units, crit_freespace_units,
|
||||
warn_freespace_percent, crit_freespace_percent,
|
||||
warn_freeinodes_percent, crit_freeinodes_percent);
|
||||
}
|
||||
}
|
||||
|
||||
// Set thresholds to the appropriate unit
|
||||
for (parameter_list_elem *tmp = result.config.path_select_list.first; tmp; tmp = mp_int_fs_list_get_next(tmp)) {
|
||||
for (parameter_list_elem *tmp = result.config.path_select_list.first; tmp;
|
||||
tmp = mp_int_fs_list_get_next(tmp)) {
|
||||
|
||||
mp_perfdata_value factor = mp_create_pd_value(unit);
|
||||
|
||||
if (tmp->freespace_units.critical_is_set) {
|
||||
tmp->freespace_units.critical = mp_range_multiply(tmp->freespace_units.critical, factor);
|
||||
tmp->freespace_units.critical =
|
||||
mp_range_multiply(tmp->freespace_units.critical, factor);
|
||||
}
|
||||
if (tmp->freespace_units.warning_is_set) {
|
||||
tmp->freespace_units.warning = mp_range_multiply(tmp->freespace_units.warning, factor);
|
||||
|
|
@ -885,8 +925,10 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
|
|||
return result;
|
||||
}
|
||||
|
||||
void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units, char *crit_freespace_units, char *warn_freespace_percent,
|
||||
char *crit_freespace_percent, char *warn_freeinodes_percent, char *crit_freeinodes_percent) {
|
||||
void set_all_thresholds(parameter_list_elem *path, char *warn_freespace_units,
|
||||
char *crit_freespace_units, char *warn_freespace_percent,
|
||||
char *crit_freespace_percent, char *warn_freeinodes_percent,
|
||||
char *crit_freeinodes_percent) {
|
||||
mp_range_parsed tmp;
|
||||
|
||||
if (warn_freespace_units) {
|
||||
|
|
@ -927,7 +969,8 @@ void print_help(void) {
|
|||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("This plugin checks the amount of used disk space on a mounted file system"));
|
||||
printf("%s\n", _("and generates an alert if free space is less than one of the threshold values"));
|
||||
printf("%s\n",
|
||||
_("and generates an alert if free space is less than one of the threshold values"));
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
|
|
@ -949,7 +992,8 @@ void print_help(void) {
|
|||
printf(" %s\n", "-K, --icritical=PERCENT%");
|
||||
printf(" %s\n", _("Exit with CRITICAL status if less than PERCENT of inode space is free"));
|
||||
printf(" %s\n", "-p, --path=PATH, --partition=PARTITION");
|
||||
printf(" %s\n", _("Mount point or block device as emitted by the mount(8) command (may be repeated)"));
|
||||
printf(" %s\n",
|
||||
_("Mount point or block device as emitted by the mount(8) command (may be repeated)"));
|
||||
printf(" %s\n", "-x, --exclude_device=PATH <STRING>");
|
||||
printf(" %s\n", _("Ignore device (only works if -p unspecified)"));
|
||||
printf(" %s\n", "-C, --clear");
|
||||
|
|
@ -963,71 +1007,88 @@ void print_help(void) {
|
|||
printf(" %s\n", "-P, --iperfdata");
|
||||
printf(" %s\n", _("Display inode usage in perfdata"));
|
||||
printf(" %s\n", "-g, --group=NAME");
|
||||
printf(" %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together"));
|
||||
printf(" %s\n",
|
||||
_("Group paths. Thresholds apply to (free-)space of all partitions together"));
|
||||
printf(" %s\n", "-l, --local");
|
||||
printf(" %s\n", _("Only check local filesystems"));
|
||||
printf(" %s\n", "-L, --stat-remote-fs");
|
||||
printf(" %s\n", _("Only check local filesystems against thresholds. Yet call stat on remote filesystems"));
|
||||
printf(
|
||||
" %s\n",
|
||||
_("Only check local filesystems against thresholds. Yet call stat on remote filesystems"));
|
||||
printf(" %s\n", _("to test if they are accessible (e.g. to detect Stale NFS Handles)"));
|
||||
printf(" %s\n", "-M, --mountpoint");
|
||||
printf(" %s\n", _("Display the (block) device instead of the mount point"));
|
||||
printf(" %s\n", "-A, --all");
|
||||
printf(" %s\n", _("Explicitly select all paths. This is equivalent to -R '.*'"));
|
||||
printf(" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION");
|
||||
printf(" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)"));
|
||||
printf(" %s\n",
|
||||
_("Case insensitive regular expression for path/partition (may be repeated)"));
|
||||
printf(" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION");
|
||||
printf(" %s\n", _("Regular expression for path or partition (may be repeated)"));
|
||||
printf(" %s\n", "-I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION");
|
||||
printf(" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
|
||||
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",
|
||||
_("Regular expression to ignore selected path or partition (may be repeated)"));
|
||||
printf(" %s\n", "-n, --ignore-missing");
|
||||
printf(" %s\n", _("Return OK if no filesystem matches, filesystem does not exist or is inaccessible."));
|
||||
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", _("Select the unit used for the absolute value thresholds"));
|
||||
printf(
|
||||
" %s\n",
|
||||
_("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", \"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)"));
|
||||
printf(" %s\n", _("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", "
|
||||
"\"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)"));
|
||||
printf(" %s\n", "-k, --kilobytes");
|
||||
printf(" %s\n", _("Same as '--units kB'"));
|
||||
printf(" %s\n", "--display-unit");
|
||||
printf(" %s\n", _("Select the unit used for in the output"));
|
||||
printf(
|
||||
" %s\n",
|
||||
_("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", \"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)"));
|
||||
printf(" %s\n", _("Choose one of \"bytes\", \"KiB\", \"kB\", \"MiB\", \"MB\", \"GiB\", "
|
||||
"\"GB\", \"TiB\", \"TB\", \"PiB\", \"PB\" (default: MiB)"));
|
||||
printf(" %s\n", "-m, --megabytes");
|
||||
printf(" %s\n", _("Same as '--units MB'"));
|
||||
printf(UT_VERBOSE);
|
||||
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",
|
||||
_("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(
|
||||
" %s\n",
|
||||
_("Check only filesystems where the type matches this given regex(7) (may be repeated)"));
|
||||
printf(UT_OUTPUT_FORMAT);
|
||||
|
||||
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",
|
||||
_("- 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(" %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\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\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 -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\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"));
|
||||
printf(" %s\n",
|
||||
_("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M"));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
}
|
||||
|
||||
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 "
|
||||
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");
|
||||
|
|
@ -1049,13 +1110,15 @@ bool stat_path(parameter_list_elem *parameters, bool ignore_missing) {
|
|||
return false;
|
||||
}
|
||||
printf("DISK %s - ", _("CRITICAL"));
|
||||
die(STATE_CRITICAL, _("%s %s: %s\n"), parameters->name, _("is not accessible"), strerror(errno));
|
||||
die(STATE_CRITICAL, _("%s %s: %s\n"), parameters->name, _("is not accessible"),
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static parameter_list_elem get_path_stats(parameter_list_elem parameters, const struct fs_usage fsp, bool freespace_ignore_reserved) {
|
||||
static parameter_list_elem get_path_stats(parameter_list_elem parameters, const struct fs_usage fsp,
|
||||
bool freespace_ignore_reserved) {
|
||||
uintmax_t available = fsp.fsu_bavail;
|
||||
uintmax_t available_to_root = fsp.fsu_bfree;
|
||||
uintmax_t used = fsp.fsu_blocks - fsp.fsu_bfree;
|
||||
|
|
@ -1082,7 +1145,8 @@ static parameter_list_elem get_path_stats(parameter_list_elem parameters, const
|
|||
/* 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 */
|
||||
parameters.inodes_total = fsp.fsu_files - parameters.inodes_free_to_root + parameters.inodes_free;
|
||||
parameters.inodes_total =
|
||||
fsp.fsu_files - parameters.inodes_free_to_root + parameters.inodes_free;
|
||||
} else {
|
||||
/* default behaviour : take all the inodes into account */
|
||||
parameters.inodes_total = fsp.fsu_files;
|
||||
|
|
@ -1091,7 +1155,8 @@ static parameter_list_elem get_path_stats(parameter_list_elem parameters, const
|
|||
return parameters;
|
||||
}
|
||||
|
||||
mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_inodes_perfdata, byte_unit unit) {
|
||||
mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_inodes_perfdata,
|
||||
byte_unit unit) {
|
||||
mp_subcheck result = mp_subcheck_init();
|
||||
result = mp_set_subcheck_default_state(result, STATE_UNKNOWN);
|
||||
xasprintf(&result.output, "%s", measurement_unit.name);
|
||||
|
|
@ -1108,10 +1173,12 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_
|
|||
freespace_bytes_sc = mp_set_subcheck_default_state(freespace_bytes_sc, STATE_OK);
|
||||
|
||||
if (unit != Humanized) {
|
||||
xasprintf(&freespace_bytes_sc.output, "Free space absolute: %ju%s (of %ju%s)", (uintmax_t)(measurement_unit.free_bytes / unit),
|
||||
get_unit_string(unit), (uintmax_t)(measurement_unit.total_bytes / unit), get_unit_string(unit));
|
||||
xasprintf(&freespace_bytes_sc.output, "Free space absolute: %ju%s (of %ju%s)",
|
||||
(uintmax_t)(measurement_unit.free_bytes / unit), get_unit_string(unit),
|
||||
(uintmax_t)(measurement_unit.total_bytes / unit), get_unit_string(unit));
|
||||
} else {
|
||||
xasprintf(&freespace_bytes_sc.output, "Free space absolute: %s (of %s)", humanize_byte_value(measurement_unit.free_bytes, false),
|
||||
xasprintf(&freespace_bytes_sc.output, "Free space absolute: %s (of %s)",
|
||||
humanize_byte_value(measurement_unit.free_bytes, false),
|
||||
humanize_byte_value((unsigned long long)measurement_unit.total_bytes, false));
|
||||
}
|
||||
|
||||
|
|
@ -1127,29 +1194,37 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_
|
|||
// special case for absolute space thresholds here:
|
||||
// if absolute values are not set, compute the thresholds from percentage thresholds
|
||||
mp_thresholds temp_thlds = measurement_unit.freespace_bytes_thresholds;
|
||||
if (!temp_thlds.critical_is_set && measurement_unit.freespace_percent_thresholds.critical_is_set) {
|
||||
if (!temp_thlds.critical_is_set &&
|
||||
measurement_unit.freespace_percent_thresholds.critical_is_set) {
|
||||
mp_range tmp_range = measurement_unit.freespace_percent_thresholds.critical;
|
||||
|
||||
if (!tmp_range.end_infinity) {
|
||||
tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 * measurement_unit.total_bytes);
|
||||
tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 *
|
||||
measurement_unit.total_bytes);
|
||||
}
|
||||
|
||||
if (!tmp_range.start_infinity) {
|
||||
tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 * measurement_unit.total_bytes);
|
||||
tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 *
|
||||
measurement_unit.total_bytes);
|
||||
}
|
||||
measurement_unit.freespace_bytes_thresholds = mp_thresholds_set_crit(measurement_unit.freespace_bytes_thresholds, tmp_range);
|
||||
measurement_unit.freespace_bytes_thresholds =
|
||||
mp_thresholds_set_crit(measurement_unit.freespace_bytes_thresholds, tmp_range);
|
||||
used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds);
|
||||
}
|
||||
|
||||
if (!temp_thlds.warning_is_set && measurement_unit.freespace_percent_thresholds.warning_is_set) {
|
||||
if (!temp_thlds.warning_is_set &&
|
||||
measurement_unit.freespace_percent_thresholds.warning_is_set) {
|
||||
mp_range tmp_range = measurement_unit.freespace_percent_thresholds.warning;
|
||||
if (!tmp_range.end_infinity) {
|
||||
tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 * measurement_unit.total_bytes);
|
||||
tmp_range.end = mp_create_pd_value(mp_get_pd_value(tmp_range.end) / 100 *
|
||||
measurement_unit.total_bytes);
|
||||
}
|
||||
if (!tmp_range.start_infinity) {
|
||||
tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 * measurement_unit.total_bytes);
|
||||
tmp_range.start = mp_create_pd_value(mp_get_pd_value(tmp_range.start) / 100 *
|
||||
measurement_unit.total_bytes);
|
||||
}
|
||||
measurement_unit.freespace_bytes_thresholds = mp_thresholds_set_warn(measurement_unit.freespace_bytes_thresholds, tmp_range);
|
||||
measurement_unit.freespace_bytes_thresholds =
|
||||
mp_thresholds_set_warn(measurement_unit.freespace_bytes_thresholds, tmp_range);
|
||||
used_space = mp_pd_set_thresholds(used_space, measurement_unit.freespace_bytes_thresholds);
|
||||
}
|
||||
|
||||
|
|
@ -1161,15 +1236,18 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_
|
|||
mp_subcheck freespace_percent_sc = mp_subcheck_init();
|
||||
freespace_percent_sc = mp_set_subcheck_default_state(freespace_percent_sc, STATE_OK);
|
||||
|
||||
double free_percentage = calculate_percent(measurement_unit.free_bytes, measurement_unit.total_bytes);
|
||||
double free_percentage =
|
||||
calculate_percent(measurement_unit.free_bytes, measurement_unit.total_bytes);
|
||||
xasprintf(&freespace_percent_sc.output, "Free space percentage: %g%%", free_percentage);
|
||||
|
||||
// Using perfdata here just to get to the test result
|
||||
mp_perfdata free_space_percent_pd = perfdata_init();
|
||||
free_space_percent_pd.value = mp_create_pd_value(free_percentage);
|
||||
free_space_percent_pd = mp_pd_set_thresholds(free_space_percent_pd, measurement_unit.freespace_percent_thresholds);
|
||||
free_space_percent_pd =
|
||||
mp_pd_set_thresholds(free_space_percent_pd, measurement_unit.freespace_percent_thresholds);
|
||||
|
||||
freespace_percent_sc = mp_set_subcheck_state(freespace_percent_sc, mp_get_pd_status(free_space_percent_pd));
|
||||
freespace_percent_sc =
|
||||
mp_set_subcheck_state(freespace_percent_sc, mp_get_pd_status(free_space_percent_pd));
|
||||
mp_add_subcheck_to_subcheck(&result, freespace_percent_sc);
|
||||
|
||||
// ================
|
||||
|
|
@ -1181,35 +1259,41 @@ mp_subcheck evaluate_filesystem(measurement_unit measurement_unit, bool display_
|
|||
mp_subcheck freeindodes_percent_sc = mp_subcheck_init();
|
||||
freeindodes_percent_sc = mp_set_subcheck_default_state(freeindodes_percent_sc, STATE_OK);
|
||||
|
||||
double free_inode_percentage = calculate_percent(measurement_unit.inodes_free, measurement_unit.inodes_total);
|
||||
double free_inode_percentage =
|
||||
calculate_percent(measurement_unit.inodes_free, measurement_unit.inodes_total);
|
||||
|
||||
if (verbose > 0) {
|
||||
printf("free inode percentage computed: %g\n", free_inode_percentage);
|
||||
}
|
||||
|
||||
xasprintf(&freeindodes_percent_sc.output, "Inodes free: %g%% (%ju of %ju)", free_inode_percentage, measurement_unit.inodes_free,
|
||||
xasprintf(&freeindodes_percent_sc.output, "Inodes free: %g%% (%ju of %ju)",
|
||||
free_inode_percentage, measurement_unit.inodes_free,
|
||||
measurement_unit.inodes_total);
|
||||
|
||||
mp_perfdata inodes_pd = perfdata_init();
|
||||
xasprintf(&inodes_pd.label, "%s (inodes)", measurement_unit.name);
|
||||
inodes_pd = mp_set_pd_value(inodes_pd, measurement_unit.inodes_used);
|
||||
inodes_pd = mp_set_pd_max_value(inodes_pd, mp_create_pd_value(measurement_unit.inodes_total));
|
||||
inodes_pd =
|
||||
mp_set_pd_max_value(inodes_pd, mp_create_pd_value(measurement_unit.inodes_total));
|
||||
inodes_pd = mp_set_pd_min_value(inodes_pd, mp_create_pd_value(0));
|
||||
|
||||
mp_thresholds absolut_inode_thresholds = measurement_unit.freeinodes_percent_thresholds;
|
||||
|
||||
if (absolut_inode_thresholds.critical_is_set) {
|
||||
absolut_inode_thresholds.critical =
|
||||
mp_range_multiply(absolut_inode_thresholds.critical, mp_create_pd_value(measurement_unit.inodes_total / 100));
|
||||
mp_range_multiply(absolut_inode_thresholds.critical,
|
||||
mp_create_pd_value(measurement_unit.inodes_total / 100));
|
||||
}
|
||||
if (absolut_inode_thresholds.warning_is_set) {
|
||||
absolut_inode_thresholds.warning =
|
||||
mp_range_multiply(absolut_inode_thresholds.warning, mp_create_pd_value(measurement_unit.inodes_total / 100));
|
||||
mp_range_multiply(absolut_inode_thresholds.warning,
|
||||
mp_create_pd_value(measurement_unit.inodes_total / 100));
|
||||
}
|
||||
|
||||
inodes_pd = mp_pd_set_thresholds(inodes_pd, absolut_inode_thresholds);
|
||||
|
||||
freeindodes_percent_sc = mp_set_subcheck_state(freeindodes_percent_sc, mp_get_pd_status(inodes_pd));
|
||||
freeindodes_percent_sc =
|
||||
mp_set_subcheck_state(freeindodes_percent_sc, mp_get_pd_status(inodes_pd));
|
||||
if (display_inodes_perfdata) {
|
||||
mp_add_perfdata_to_subcheck(&freeindodes_percent_sc, inodes_pd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,7 +126,8 @@ bool np_find_regmatch(struct regex_list *list, const char *name) {
|
|||
/* Emulate a full match as if surrounded with ^( )$
|
||||
by checking whether the match spans the whole name */
|
||||
regmatch_t dummy_match;
|
||||
if (!regexec(&list->regex, name, 1, &dummy_match, 0) && dummy_match.rm_so == 0 && dummy_match.rm_eo == len) {
|
||||
if (!regexec(&list->regex, name, 1, &dummy_match, 0) && dummy_match.rm_so == 0 &&
|
||||
dummy_match.rm_eo == len) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -144,7 +145,8 @@ bool np_seen_name(struct name_list *list, const char *name) {
|
|||
}
|
||||
|
||||
bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re) {
|
||||
return ((regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0) || (regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0));
|
||||
return ((regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0) ||
|
||||
(regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0));
|
||||
}
|
||||
|
||||
check_disk_config check_disk_config_init() {
|
||||
|
|
@ -264,7 +266,8 @@ measurement_unit_list *add_measurement_list(measurement_unit_list *list, measure
|
|||
return new;
|
||||
}
|
||||
|
||||
measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, parameter_list_elem filesystem) {
|
||||
measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit,
|
||||
parameter_list_elem filesystem) {
|
||||
|
||||
unit.free_bytes += filesystem.free_bytes;
|
||||
unit.used_bytes += filesystem.used_bytes;
|
||||
|
|
@ -277,7 +280,8 @@ measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, param
|
|||
return unit;
|
||||
}
|
||||
|
||||
measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, bool display_mntp) {
|
||||
measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem,
|
||||
bool display_mntp) {
|
||||
measurement_unit result = measurement_unit_init();
|
||||
if (!display_mntp) {
|
||||
result.name = strdup(filesystem.best_match->me_mountdir);
|
||||
|
|
@ -469,17 +473,20 @@ parameter_list_elem *mp_int_fs_list_get_next(parameter_list_elem *current) {
|
|||
return current->next;
|
||||
}
|
||||
|
||||
void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, bool exact) {
|
||||
void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list,
|
||||
bool exact) {
|
||||
for (parameter_list_elem *elem = list.first; elem; elem = mp_int_fs_list_get_next(elem)) {
|
||||
if (!elem->best_match) {
|
||||
size_t name_len = strlen(elem->name);
|
||||
struct mount_entry *best_match = NULL;
|
||||
|
||||
/* set best match if path name exactly matches a mounted device name */
|
||||
for (struct mount_entry *mount_entry = mount_list; mount_entry; mount_entry = mount_entry->me_next) {
|
||||
for (struct mount_entry *mount_entry = mount_list; mount_entry;
|
||||
mount_entry = mount_entry->me_next) {
|
||||
if (strcmp(mount_entry->me_devname, elem->name) == 0) {
|
||||
struct fs_usage fsp;
|
||||
if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >= 0) {
|
||||
if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >=
|
||||
0) {
|
||||
best_match = mount_entry;
|
||||
}
|
||||
}
|
||||
|
|
@ -488,15 +495,18 @@ void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mou
|
|||
/* set best match by directory name if no match was found by devname */
|
||||
if (!best_match) {
|
||||
size_t best_match_len = 0;
|
||||
for (struct mount_entry *mount_entry = mount_list; mount_entry; mount_entry = mount_entry->me_next) {
|
||||
for (struct mount_entry *mount_entry = mount_list; mount_entry;
|
||||
mount_entry = mount_entry->me_next) {
|
||||
size_t len = strlen(mount_entry->me_mountdir);
|
||||
|
||||
if ((!exact && (best_match_len <= len && len <= name_len &&
|
||||
(len == 1 || strncmp(mount_entry->me_mountdir, elem->name, len) == 0))) ||
|
||||
if ((!exact &&
|
||||
(best_match_len <= len && len <= name_len &&
|
||||
(len == 1 || strncmp(mount_entry->me_mountdir, elem->name, len) == 0))) ||
|
||||
(exact && strcmp(mount_entry->me_mountdir, elem->name) == 0)) {
|
||||
struct fs_usage fsp;
|
||||
|
||||
if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >= 0) {
|
||||
if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >=
|
||||
0) {
|
||||
best_match = mount_entry;
|
||||
best_match_len = len;
|
||||
}
|
||||
|
|
@ -507,7 +517,8 @@ void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mou
|
|||
if (best_match) {
|
||||
elem->best_match = best_match;
|
||||
} else {
|
||||
elem->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
|
||||
elem->best_match =
|
||||
NULL; /* Not sure why this is needed as it should be null on initialisation */
|
||||
}
|
||||
|
||||
// No filesystem without a mount_entry!
|
||||
|
|
|
|||
|
|
@ -141,12 +141,15 @@ parameter_list_elem *mp_int_fs_list_append(filesystem_list *list, const char *na
|
|||
parameter_list_elem *mp_int_fs_list_find(filesystem_list list, const char *name);
|
||||
parameter_list_elem *mp_int_fs_list_del(filesystem_list *list, parameter_list_elem *item);
|
||||
parameter_list_elem *mp_int_fs_list_get_next(parameter_list_elem *current);
|
||||
void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, bool exact);
|
||||
void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list,
|
||||
bool exact);
|
||||
|
||||
measurement_unit measurement_unit_init();
|
||||
measurement_unit_list *add_measurement_list(measurement_unit_list *list, measurement_unit elem);
|
||||
measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, parameter_list_elem filesystem);
|
||||
measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, bool display_mntp);
|
||||
measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit,
|
||||
parameter_list_elem filesystem);
|
||||
measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem,
|
||||
bool display_mntp);
|
||||
|
||||
int search_parameter_list(parameter_list_elem *list, const char *name);
|
||||
bool np_regex_match_mount_entry(struct mount_entry *, regex_t *);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ typedef struct {
|
|||
} check_dns_config_wrapper;
|
||||
static check_dns_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
|
||||
static check_dns_config_wrapper validate_arguments(check_dns_config_wrapper /*config_wrapper*/);
|
||||
static mp_state_enum error_scan(char * /*input_buffer*/, bool * /*is_nxdomain*/, const char /*dns_server*/[ADDRESS_LENGTH]);
|
||||
static mp_state_enum error_scan(char * /*input_buffer*/, bool * /*is_nxdomain*/,
|
||||
const char /*dns_server*/[ADDRESS_LENGTH]);
|
||||
static bool ip_match_cidr(const char * /*addr*/, const char * /*cidr_ro*/);
|
||||
static unsigned long ip2long(const char * /*src*/);
|
||||
static void print_help(void);
|
||||
|
|
@ -127,7 +128,8 @@ int main(int argc, char **argv) {
|
|||
puts(chld_out.line[i]);
|
||||
}
|
||||
|
||||
if (strcasestr(chld_out.line[i], ".in-addr.arpa") || strcasestr(chld_out.line[i], ".ip6.arpa")) {
|
||||
if (strcasestr(chld_out.line[i], ".in-addr.arpa") ||
|
||||
strcasestr(chld_out.line[i], ".ip6.arpa")) {
|
||||
if ((strstr(chld_out.line[i], "canonical name = ") != NULL)) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -145,7 +147,8 @@ int main(int argc, char **argv) {
|
|||
if (strstr(chld_out.line[i], "Server:") && strlen(config.dns_server) > 0) {
|
||||
char *temp_buffer = strchr(chld_out.line[i], ':');
|
||||
if (temp_buffer == NULL) {
|
||||
die(STATE_UNKNOWN, _("'%s' returned a weirdly formatted Server line\n"), NSLOOKUP_COMMAND);
|
||||
die(STATE_UNKNOWN, _("'%s' returned a weirdly formatted Server line\n"),
|
||||
NSLOOKUP_COMMAND);
|
||||
}
|
||||
|
||||
temp_buffer++;
|
||||
|
|
@ -157,21 +160,25 @@ int main(int argc, char **argv) {
|
|||
|
||||
strip(temp_buffer);
|
||||
if (strlen(temp_buffer) == 0) {
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - '%s' returned empty server string\n"), NSLOOKUP_COMMAND);
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - '%s' returned empty server string\n"),
|
||||
NSLOOKUP_COMMAND);
|
||||
}
|
||||
|
||||
if (strcmp(temp_buffer, config.dns_server) != 0) {
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - No response from DNS %s\n"), config.dns_server);
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - No response from DNS %s\n"),
|
||||
config.dns_server);
|
||||
}
|
||||
}
|
||||
|
||||
/* the server is responding, we just got the host name... */
|
||||
if (strstr(chld_out.line[i], "Name:")) {
|
||||
parse_address = true;
|
||||
} else if (parse_address && (strstr(chld_out.line[i], "Address:") || strstr(chld_out.line[i], "Addresses:"))) {
|
||||
} else if (parse_address && (strstr(chld_out.line[i], "Address:") ||
|
||||
strstr(chld_out.line[i], "Addresses:"))) {
|
||||
char *temp_buffer = strchr(chld_out.line[i], ':');
|
||||
if (temp_buffer == NULL) {
|
||||
die(STATE_UNKNOWN, _("'%s' returned a weirdly formatted Address line\n"), NSLOOKUP_COMMAND);
|
||||
die(STATE_UNKNOWN, _("'%s' returned a weirdly formatted Address line\n"),
|
||||
NSLOOKUP_COMMAND);
|
||||
}
|
||||
|
||||
temp_buffer++;
|
||||
|
|
@ -183,7 +190,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
strip(temp_buffer);
|
||||
if (strlen(temp_buffer) == 0) {
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - '%s' returned empty host name string\n"), NSLOOKUP_COMMAND);
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - '%s' returned empty host name string\n"),
|
||||
NSLOOKUP_COMMAND);
|
||||
}
|
||||
|
||||
addresses[n_addresses++] = strdup(temp_buffer);
|
||||
|
|
@ -209,7 +217,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (error_scan(chld_err.line[i], &is_nxdomain, config.dns_server) != STATE_OK) {
|
||||
result = max_state(result, error_scan(chld_err.line[i], &is_nxdomain, config.dns_server));
|
||||
result =
|
||||
max_state(result, error_scan(chld_err.line[i], &is_nxdomain, config.dns_server));
|
||||
msg = strchr(input_buffer, ':');
|
||||
if (msg) {
|
||||
msg++;
|
||||
|
|
@ -242,7 +251,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
*adrp = 0;
|
||||
} else {
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - '%s' msg parsing exited with no address\n"), NSLOOKUP_COMMAND);
|
||||
die(STATE_CRITICAL, _("DNS CRITICAL - '%s' msg parsing exited with no address\n"),
|
||||
NSLOOKUP_COMMAND);
|
||||
}
|
||||
|
||||
/* compare to expected address */
|
||||
|
|
@ -255,7 +265,8 @@ int main(int argc, char **argv) {
|
|||
for (size_t i = 0; i < config.expected_address_cnt; i++) {
|
||||
/* check if we get a match on 'raw' ip or cidr */
|
||||
for (size_t j = 0; j < n_addresses; j++) {
|
||||
if (strcmp(addresses[j], config.expected_address[i]) == 0 || ip_match_cidr(addresses[j], config.expected_address[i])) {
|
||||
if (strcmp(addresses[j], config.expected_address[i]) == 0 ||
|
||||
ip_match_cidr(addresses[j], config.expected_address[i])) {
|
||||
result = STATE_OK;
|
||||
addr_match &= ~(1 << j);
|
||||
expect_match &= ~(1 << i);
|
||||
|
|
@ -279,7 +290,8 @@ int main(int argc, char **argv) {
|
|||
if (config.expect_nxdomain) {
|
||||
if (!is_nxdomain) {
|
||||
result = STATE_CRITICAL;
|
||||
xasprintf(&msg, _("Domain '%s' was found by the server: '%s'\n"), config.query_address, address);
|
||||
xasprintf(&msg, _("Domain '%s' was found by the server: '%s'\n"), config.query_address,
|
||||
address);
|
||||
} else {
|
||||
if (address != NULL) {
|
||||
free(address);
|
||||
|
|
@ -291,7 +303,8 @@ int main(int argc, char **argv) {
|
|||
/* check if authoritative */
|
||||
if (result == STATE_OK && config.expect_authority && non_authoritative) {
|
||||
result = STATE_CRITICAL;
|
||||
xasprintf(&msg, _("server %s is not authoritative for %s"), config.dns_server, config.query_address);
|
||||
xasprintf(&msg, _("server %s is not authoritative for %s"), config.dns_server,
|
||||
config.query_address);
|
||||
}
|
||||
|
||||
long microsec = deltime(tv);
|
||||
|
|
@ -306,24 +319,36 @@ int main(int argc, char **argv) {
|
|||
} else if (result == STATE_CRITICAL) {
|
||||
printf("DNS %s: ", _("CRITICAL"));
|
||||
}
|
||||
printf(ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time), elapsed_time);
|
||||
printf(ngettext("%.3f second response time", "%.3f seconds response time", elapsed_time),
|
||||
elapsed_time);
|
||||
printf(_(". %s returns %s"), config.query_address, address);
|
||||
if ((config.time_thresholds->warning != NULL) && (config.time_thresholds->critical != NULL)) {
|
||||
printf("|%s\n", fperfdata("time", elapsed_time, "s", true, config.time_thresholds->warning->end, true,
|
||||
if ((config.time_thresholds->warning != NULL) &&
|
||||
(config.time_thresholds->critical != NULL)) {
|
||||
printf("|%s\n",
|
||||
fperfdata("time", elapsed_time, "s", true, config.time_thresholds->warning->end,
|
||||
true, config.time_thresholds->critical->end, true, 0, false, 0));
|
||||
} else if ((config.time_thresholds->warning == NULL) &&
|
||||
(config.time_thresholds->critical != NULL)) {
|
||||
printf("|%s\n", fperfdata("time", elapsed_time, "s", false, 0, true,
|
||||
config.time_thresholds->critical->end, true, 0, false, 0));
|
||||
} else if ((config.time_thresholds->warning == NULL) && (config.time_thresholds->critical != NULL)) {
|
||||
printf("|%s\n", fperfdata("time", elapsed_time, "s", false, 0, true, config.time_thresholds->critical->end, true, 0, false, 0));
|
||||
} else if ((config.time_thresholds->warning != NULL) && (config.time_thresholds->critical == NULL)) {
|
||||
printf("|%s\n", fperfdata("time", elapsed_time, "s", true, config.time_thresholds->warning->end, false, 0, true, 0, false, 0));
|
||||
} else if ((config.time_thresholds->warning != NULL) &&
|
||||
(config.time_thresholds->critical == NULL)) {
|
||||
printf("|%s\n",
|
||||
fperfdata("time", elapsed_time, "s", true, config.time_thresholds->warning->end,
|
||||
false, 0, true, 0, false, 0));
|
||||
} else {
|
||||
printf("|%s\n", fperfdata("time", elapsed_time, "s", false, 0, false, 0, true, 0, false, 0));
|
||||
printf("|%s\n",
|
||||
fperfdata("time", elapsed_time, "s", false, 0, false, 0, true, 0, false, 0));
|
||||
}
|
||||
} else if (result == STATE_WARNING) {
|
||||
printf(_("DNS WARNING - %s\n"), !strcmp(msg, "") ? _(" Probably a non-existent host/domain") : msg);
|
||||
printf(_("DNS WARNING - %s\n"),
|
||||
!strcmp(msg, "") ? _(" Probably a non-existent host/domain") : msg);
|
||||
} else if (result == STATE_CRITICAL) {
|
||||
printf(_("DNS CRITICAL - %s\n"), !strcmp(msg, "") ? _(" Probably a non-existent host/domain") : msg);
|
||||
printf(_("DNS CRITICAL - %s\n"),
|
||||
!strcmp(msg, "") ? _(" Probably a non-existent host/domain") : msg);
|
||||
} else {
|
||||
printf(_("DNS UNKNOWN - %s\n"), !strcmp(msg, "") ? _(" Probably a non-existent host/domain") : msg);
|
||||
printf(_("DNS UNKNOWN - %s\n"),
|
||||
!strcmp(msg, "") ? _(" Probably a non-existent host/domain") : msg);
|
||||
}
|
||||
|
||||
exit(result);
|
||||
|
|
@ -342,29 +367,34 @@ bool ip_match_cidr(const char *addr, const char *cidr_ro) {
|
|||
mask = atoi(mask_c);
|
||||
|
||||
/* https://www.cryptobells.com/verifying-ips-in-a-subnet-in-php/ */
|
||||
return (ip2long(addr) & ~((1 << (32 - mask)) - 1)) == (ip2long(subnet) >> (32 - mask)) << (32 - mask);
|
||||
return (ip2long(addr) & ~((1 << (32 - mask)) - 1)) == (ip2long(subnet) >> (32 - mask))
|
||||
<< (32 - mask);
|
||||
}
|
||||
|
||||
unsigned long ip2long(const char *src) {
|
||||
unsigned long ip[4];
|
||||
/* http://computer-programming-forum.com/47-c-language/1376ffb92a12c471.htm */
|
||||
return (sscanf(src, "%3lu.%3lu.%3lu.%3lu", &ip[0], &ip[1], &ip[2], &ip[3]) == 4 && ip[0] < 256 && ip[1] < 256 && ip[2] < 256 &&
|
||||
ip[3] < 256)
|
||||
return (sscanf(src, "%3lu.%3lu.%3lu.%3lu", &ip[0], &ip[1], &ip[2], &ip[3]) == 4 &&
|
||||
ip[0] < 256 && ip[1] < 256 && ip[2] < 256 && ip[3] < 256)
|
||||
? ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3]
|
||||
: 0;
|
||||
}
|
||||
|
||||
mp_state_enum error_scan(char *input_buffer, bool *is_nxdomain, const char dns_server[ADDRESS_LENGTH]) {
|
||||
mp_state_enum error_scan(char *input_buffer, bool *is_nxdomain,
|
||||
const char dns_server[ADDRESS_LENGTH]) {
|
||||
|
||||
const int nxdomain = strstr(input_buffer, "Non-existent") || strstr(input_buffer, "** server can't find") ||
|
||||
const int nxdomain = strstr(input_buffer, "Non-existent") ||
|
||||
strstr(input_buffer, "** server can't find") ||
|
||||
strstr(input_buffer, "** Can't find") || strstr(input_buffer, "NXDOMAIN");
|
||||
if (nxdomain) {
|
||||
*is_nxdomain = true;
|
||||
}
|
||||
|
||||
/* the DNS lookup timed out */
|
||||
if (strstr(input_buffer, _("Note: nslookup is deprecated and may be removed from future releases.")) ||
|
||||
strstr(input_buffer, _("Consider using the `dig' or `host' programs instead. Run nslookup with")) ||
|
||||
if (strstr(input_buffer,
|
||||
_("Note: nslookup is deprecated and may be removed from future releases.")) ||
|
||||
strstr(input_buffer,
|
||||
_("Consider using the `dig' or `host' programs instead. Run nslookup with")) ||
|
||||
strstr(input_buffer, _("the `-sil[ent]' option to prevent this message from appearing."))) {
|
||||
return STATE_OK;
|
||||
}
|
||||
|
|
@ -382,8 +412,9 @@ mp_state_enum error_scan(char *input_buffer, bool *is_nxdomain, const char dns_s
|
|||
}
|
||||
|
||||
/* Connection was refused */
|
||||
else if (strstr(input_buffer, "Connection refused") || strstr(input_buffer, "Couldn't find server") ||
|
||||
strstr(input_buffer, "Refused") || (strstr(input_buffer, "** server can't find") && strstr(input_buffer, ": REFUSED"))) {
|
||||
else if (strstr(input_buffer, "Connection refused") ||
|
||||
strstr(input_buffer, "Couldn't find server") || strstr(input_buffer, "Refused") ||
|
||||
(strstr(input_buffer, "** server can't find") && strstr(input_buffer, ": REFUSED"))) {
|
||||
die(STATE_CRITICAL, _("Connection to DNS %s was refused\n"), dns_server);
|
||||
}
|
||||
|
||||
|
|
@ -504,20 +535,24 @@ check_dns_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (strchr(optarg, ',') != NULL) {
|
||||
char *comma = strchr(optarg, ',');
|
||||
while (comma != NULL) {
|
||||
result.config.expected_address =
|
||||
(char **)realloc(result.config.expected_address, (result.config.expected_address_cnt + 1) * sizeof(char **));
|
||||
result.config.expected_address[result.config.expected_address_cnt] = strndup(optarg, comma - optarg);
|
||||
result.config.expected_address = (char **)realloc(
|
||||
result.config.expected_address,
|
||||
(result.config.expected_address_cnt + 1) * sizeof(char **));
|
||||
result.config.expected_address[result.config.expected_address_cnt] =
|
||||
strndup(optarg, comma - optarg);
|
||||
result.config.expected_address_cnt++;
|
||||
optarg = comma + 1;
|
||||
comma = strchr(optarg, ',');
|
||||
}
|
||||
result.config.expected_address =
|
||||
(char **)realloc(result.config.expected_address, (result.config.expected_address_cnt + 1) * sizeof(char **));
|
||||
(char **)realloc(result.config.expected_address,
|
||||
(result.config.expected_address_cnt + 1) * sizeof(char **));
|
||||
result.config.expected_address[result.config.expected_address_cnt] = strdup(optarg);
|
||||
result.config.expected_address_cnt++;
|
||||
} else {
|
||||
result.config.expected_address =
|
||||
(char **)realloc(result.config.expected_address, (result.config.expected_address_cnt + 1) * sizeof(char **));
|
||||
(char **)realloc(result.config.expected_address,
|
||||
(result.config.expected_address_cnt + 1) * sizeof(char **));
|
||||
result.config.expected_address[result.config.expected_address_cnt] = strdup(optarg);
|
||||
result.config.expected_address_cnt++;
|
||||
}
|
||||
|
|
@ -586,9 +621,11 @@ void print_help(void) {
|
|||
printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
|
||||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("This plugin uses the nslookup program to obtain the IP address for the given host/domain query."));
|
||||
printf("%s\n", _("This plugin uses the nslookup program to obtain the IP address for the given "
|
||||
"host/domain query."));
|
||||
printf("%s\n", _("An optional DNS server to use may be specified."));
|
||||
printf("%s\n", _("If no DNS server is specified, the default server(s) specified in /etc/resolv.conf will be used."));
|
||||
printf("%s\n", _("If no DNS server is specified, the default server(s) specified in "
|
||||
"/etc/resolv.conf will be used."));
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
|
|
@ -602,11 +639,14 @@ void print_help(void) {
|
|||
printf(" -s, --server=HOST\n");
|
||||
printf(" %s\n", _("Optional DNS server you want to use for the lookup"));
|
||||
printf(" -a, --expected-address=IP-ADDRESS|CIDR|HOST\n");
|
||||
printf(" %s\n", _("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end"));
|
||||
printf(" %s\n", _("with a dot (.). This option can be repeated multiple times (Returns OK if any"));
|
||||
printf(" %s\n",
|
||||
_("Optional IP-ADDRESS/CIDR you expect the DNS server to return. HOST must end"));
|
||||
printf(" %s\n",
|
||||
_("with a dot (.). This option can be repeated multiple times (Returns OK if any"));
|
||||
printf(" %s\n", _("value matches)."));
|
||||
printf(" -n, --expect-nxdomain\n");
|
||||
printf(" %s\n", _("Expect the DNS server to return NXDOMAIN (i.e. the domain was not found)"));
|
||||
printf(" %s\n",
|
||||
_("Expect the DNS server to return NXDOMAIN (i.e. the domain was not found)"));
|
||||
printf(" %s\n", _("Cannot be used together with -a"));
|
||||
printf(" -A, --expect-authority\n");
|
||||
printf(" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup"));
|
||||
|
|
@ -615,7 +655,8 @@ void print_help(void) {
|
|||
printf(" -c, --critical=seconds\n");
|
||||
printf(" %s\n", _("Return critical if elapsed time exceeds value. Default off"));
|
||||
printf(" -L, --all\n");
|
||||
printf(" %s\n", _("Return critical if the list of expected addresses does not match all addresses"));
|
||||
printf(" %s\n",
|
||||
_("Return critical if the list of expected addresses does not match all addresses"));
|
||||
printf(" %s\n", _("returned. Default off"));
|
||||
|
||||
printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
|
||||
|
|
@ -625,5 +666,7 @@ void print_help(void) {
|
|||
|
||||
void print_usage(void) {
|
||||
printf("%s\n", _("Usage:"));
|
||||
printf("%s -H host [-s server] [-a expected-address] [-n] [-A] [-t timeout] [-w warn] [-c crit] [-L]\n", progname);
|
||||
printf("%s -H host [-s server] [-a expected-address] [-n] [-A] [-t timeout] [-w warn] [-c "
|
||||
"crit] [-L]\n",
|
||||
progname);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,18 +45,19 @@ int main(int argc, char **argv) {
|
|||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
||||
if (argc < 2)
|
||||
if (argc < 2) {
|
||||
usage4(_("Could not parse arguments"));
|
||||
else if (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "--version") == 0) {
|
||||
} else if (strcmp(argv[1], "-V") == 0 || strcmp(argv[1], "--version") == 0) {
|
||||
print_revision(progname, NP_VERSION);
|
||||
exit(STATE_UNKNOWN);
|
||||
} else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
|
||||
print_help();
|
||||
exit(STATE_UNKNOWN);
|
||||
} else if (!is_integer(argv[1]))
|
||||
} else if (!is_integer(argv[1])) {
|
||||
usage4(_("Arguments to check_dummy must be an integer"));
|
||||
else
|
||||
} else {
|
||||
result = atoi(argv[1]);
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
case STATE_OK:
|
||||
|
|
@ -78,8 +79,9 @@ int main(int argc, char **argv) {
|
|||
return STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (argc >= 3)
|
||||
if (argc >= 3) {
|
||||
printf(": %s", argv[2]);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
|
@ -92,7 +94,8 @@ void print_help(void) {
|
|||
printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
|
||||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("This plugin will simply return the state corresponding to the numeric value"));
|
||||
printf("%s\n",
|
||||
_("This plugin will simply return the state corresponding to the numeric value"));
|
||||
|
||||
printf("%s\n", _("of the <state> argument with optional text"));
|
||||
|
||||
|
|
|
|||
|
|
@ -46,8 +46,9 @@ enum {
|
|||
RTA = 1
|
||||
};
|
||||
|
||||
static mp_state_enum textscan(char *buf, const char * /*server_name*/, bool /*crta_p*/, double /*crta*/, bool /*wrta_p*/, double /*wrta*/,
|
||||
bool /*cpl_p*/, int /*cpl*/, bool /*wpl_p*/, int /*wpl*/, bool /*alive_p*/);
|
||||
static mp_state_enum textscan(char *buf, const char * /*server_name*/, bool /*crta_p*/,
|
||||
double /*crta*/, bool /*wrta_p*/, double /*wrta*/, bool /*cpl_p*/,
|
||||
int /*cpl*/, bool /*wpl_p*/, int /*wpl*/, bool /*alive_p*/);
|
||||
|
||||
typedef struct {
|
||||
int errorcode;
|
||||
|
|
@ -133,9 +134,11 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (config.icmp_timestamp) {
|
||||
// no packet size settable for ICMP timestamp
|
||||
xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count, server);
|
||||
xasprintf(&command_line, "%s %s -c %d %s", fping_prog, option_string, config.packet_count,
|
||||
server);
|
||||
} else {
|
||||
xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string, config.packet_size, config.packet_count, server);
|
||||
xasprintf(&command_line, "%s %s-b %d -c %d %s", fping_prog, option_string,
|
||||
config.packet_size, config.packet_count, server);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
|
|
@ -160,8 +163,9 @@ int main(int argc, char **argv) {
|
|||
if (verbose) {
|
||||
printf("%s", input_buffer);
|
||||
}
|
||||
status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p, config.crta, config.wrta_p, config.wrta,
|
||||
config.cpl_p, config.cpl, config.wpl_p, config.wpl, config.alive_p));
|
||||
status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p,
|
||||
config.crta, config.wrta_p, config.wrta, config.cpl_p,
|
||||
config.cpl, config.wpl_p, config.wpl, config.alive_p));
|
||||
}
|
||||
|
||||
/* If we get anything on STDERR, at least set warning */
|
||||
|
|
@ -170,8 +174,9 @@ int main(int argc, char **argv) {
|
|||
if (verbose) {
|
||||
printf("%s", input_buffer);
|
||||
}
|
||||
status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p, config.crta, config.wrta_p, config.wrta,
|
||||
config.cpl_p, config.cpl, config.wpl_p, config.wpl, config.alive_p));
|
||||
status = max_state(status, textscan(input_buffer, config.server_name, config.crta_p,
|
||||
config.crta, config.wrta_p, config.wrta, config.cpl_p,
|
||||
config.cpl, config.wpl_p, config.wpl, config.alive_p));
|
||||
}
|
||||
(void)fclose(child_stderr);
|
||||
|
||||
|
|
@ -200,8 +205,8 @@ int main(int argc, char **argv) {
|
|||
return status;
|
||||
}
|
||||
|
||||
mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double crta, bool wrta_p, double wrta, bool cpl_p, int cpl,
|
||||
bool wpl_p, int wpl, bool alive_p) {
|
||||
mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double crta, bool wrta_p,
|
||||
double wrta, bool cpl_p, int cpl, bool wpl_p, int wpl, bool alive_p) {
|
||||
/* stops testing after the first successful reply. */
|
||||
double rta;
|
||||
double loss;
|
||||
|
|
@ -214,7 +219,8 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c
|
|||
die(STATE_OK, _("FPING %s - %s (rta=%f ms)|%s\n"), state_text(STATE_OK), server_name, rta,
|
||||
/* No loss since we only waited for the first reply
|
||||
perfdata ("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, true, 0, true, 100), */
|
||||
fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0, false, 0));
|
||||
fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0,
|
||||
false, 0));
|
||||
}
|
||||
|
||||
mp_state_enum status = STATE_UNKNOWN;
|
||||
|
|
@ -255,9 +261,11 @@ mp_state_enum textscan(char *buf, const char *server_name, bool crta_p, double c
|
|||
} else {
|
||||
status = STATE_OK;
|
||||
}
|
||||
die(status, _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), state_text(status), server_name, loss, rta,
|
||||
die(status, _("FPING %s - %s (loss=%.0f%%, rta=%f ms)|%s %s\n"), state_text(status),
|
||||
server_name, loss, rta,
|
||||
perfdata("loss", (long int)loss, "%", wpl_p, wpl, cpl_p, cpl, false, 0, false, 0),
|
||||
fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0, false, 0));
|
||||
fperfdata("rta", rta / 1.0e3, "s", wrta_p, wrta / 1.0e3, crta_p, crta / 1.0e3, true, 0,
|
||||
false, 0));
|
||||
|
||||
} else if (strstr(buf, "xmt/rcv/%loss")) {
|
||||
/* no min/max/avg if host was unreachable in fping v2.2.b1 */
|
||||
|
|
@ -350,7 +358,8 @@ check_fping_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
|
||||
while (true) {
|
||||
int option_index = getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option);
|
||||
int option_index =
|
||||
getopt_long(argc, argv, "+hVvaH:S:c:w:b:n:T:i:I:M:R:46", longopts, &option);
|
||||
|
||||
if (option_index == -1 || option_index == EOF || option_index == 1) {
|
||||
break;
|
||||
|
|
@ -487,10 +496,12 @@ int get_threshold(char *arg, char *rv[2]) {
|
|||
if (arg2) {
|
||||
arg1[strcspn(arg1, ",:")] = 0;
|
||||
if (strstr(arg1, "%") && strstr(arg2, "%")) {
|
||||
die(STATE_UNKNOWN, _("%s: Only one threshold may be packet loss (%s)\n"), progname, arg);
|
||||
die(STATE_UNKNOWN, _("%s: Only one threshold may be packet loss (%s)\n"), progname,
|
||||
arg);
|
||||
}
|
||||
if (!strstr(arg1, "%") && !strstr(arg2, "%")) {
|
||||
die(STATE_UNKNOWN, _("%s: Only one threshold must be packet loss (%s)\n"), progname, arg);
|
||||
die(STATE_UNKNOWN, _("%s: Only one threshold must be packet loss (%s)\n"), progname,
|
||||
arg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -516,7 +527,8 @@ void print_help(void) {
|
|||
printf("Copyright (c) 1999 Didi Rieder <adrieder@sbox.tu-graz.ac.at>\n");
|
||||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("This plugin will use the fping command to ping the specified host for a fast check"));
|
||||
printf("%s\n",
|
||||
_("This plugin will use the fping command to ping the specified host for a fast check"));
|
||||
|
||||
printf("%s\n", _("Note that it is necessary to set the suid flag on fping."));
|
||||
|
||||
|
|
@ -530,7 +542,8 @@ void print_help(void) {
|
|||
printf(UT_IPv46);
|
||||
|
||||
printf(" %s\n", "-H, --hostname=HOST");
|
||||
printf(" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, reducing system load)"));
|
||||
printf(" %s\n", _("name or IP Address of host to ping (IP Address bypasses name lookup, "
|
||||
"reducing system load)"));
|
||||
printf(" %s\n", "-w, --warning=THRESHOLD");
|
||||
printf(" %s\n", _("warning threshold pair"));
|
||||
printf(" %s\n", "-c, --critical=THRESHOLD");
|
||||
|
|
@ -544,7 +557,8 @@ void print_help(void) {
|
|||
printf(" %s\n", "-T, --target-timeout=INTEGER");
|
||||
printf(" %s (default: fping's default for -t)\n", _("Target timeout (ms)"));
|
||||
printf(" %s\n", "-i, --interval=INTEGER");
|
||||
printf(" %s (default: fping's default for -p)\n", _("Interval (ms) between sending packets"));
|
||||
printf(" %s (default: fping's default for -p)\n",
|
||||
_("Interval (ms) between sending packets"));
|
||||
printf(" %s\n", "-S, --sourceip=HOST");
|
||||
printf(" %s\n", _("name or IP Address of sourceip"));
|
||||
printf(" %s\n", "-I, --sourceif=IF");
|
||||
|
|
@ -565,7 +579,8 @@ void print_help(void) {
|
|||
#endif
|
||||
printf(UT_VERBOSE);
|
||||
printf("\n");
|
||||
printf(" %s\n", _("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));
|
||||
printf(" %s\n",
|
||||
_("THRESHOLD is <rta>,<pl>%% where <rta> is the round trip average travel time (ms)"));
|
||||
printf(" %s\n", _("which triggers a WARNING or CRITICAL state, and <pl> is the percentage of"));
|
||||
printf(" %s\n", _("packet loss to trigger an alarm state."));
|
||||
|
||||
|
|
@ -577,5 +592,6 @@ void print_help(void) {
|
|||
|
||||
void print_usage(void) {
|
||||
printf("%s\n", _("Usage:"));
|
||||
printf(" %s <host_address> -w limit -c limit [-b size] [-n number] [-T number] [-i number]\n", progname);
|
||||
printf(" %s <host_address> -w limit -c limit [-b size] [-n number] [-T number] [-i number]\n",
|
||||
progname);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ typedef struct {
|
|||
unsigned int fwmark;
|
||||
bool fwmark_set;
|
||||
|
||||
|
||||
// only available with fping version >= 5.3
|
||||
// Setting icmp_timestamp tells fping to use ICMP Timestamp (ICMP type 13) instead
|
||||
// of ICMP Echo
|
||||
|
|
|
|||
|
|
@ -77,7 +77,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* create the command line to execute */
|
||||
char *command_line = NULL;
|
||||
xasprintf(&command_line, "%s -raw %s -%s %s", PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, config.game_type, config.server_ip);
|
||||
xasprintf(&command_line, "%s -raw %s -%s %s", PATH_TO_QSTAT, QSTAT_DATA_DELIMITER,
|
||||
config.game_type, config.server_ip);
|
||||
|
||||
if (config.port) {
|
||||
xasprintf(&command_line, "%s:%-d", command_line, config.port);
|
||||
|
|
@ -130,11 +131,13 @@ int main(int argc, char **argv) {
|
|||
printf(_("CRITICAL - Game server timeout\n"));
|
||||
result = STATE_CRITICAL;
|
||||
} else {
|
||||
printf("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", ret[config.qstat_game_players], ret[config.qstat_game_players_max],
|
||||
ret[config.qstat_game_field], ret[config.qstat_map_field], ret[config.qstat_ping_field],
|
||||
perfdata("players", atol(ret[config.qstat_game_players]), "", false, 0, false, 0, true, 0, true,
|
||||
atol(ret[config.qstat_game_players_max])),
|
||||
fperfdata("ping", strtod(ret[config.qstat_ping_field], NULL), "", false, 0, false, 0, true, 0, false, 0));
|
||||
printf("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", ret[config.qstat_game_players],
|
||||
ret[config.qstat_game_players_max], ret[config.qstat_game_field],
|
||||
ret[config.qstat_map_field], ret[config.qstat_ping_field],
|
||||
perfdata("players", atol(ret[config.qstat_game_players]), "", false, 0, false, 0,
|
||||
true, 0, true, atol(ret[config.qstat_game_players_max])),
|
||||
fperfdata("ping", strtod(ret[config.qstat_ping_field], NULL), "", false, 0, false, 0,
|
||||
true, 0, false, 0));
|
||||
}
|
||||
|
||||
exit(result);
|
||||
|
|
@ -144,19 +147,20 @@ int main(int argc, char **argv) {
|
|||
#define max_players_field_index 130
|
||||
|
||||
check_game_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option long_opts[] = {{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"hostname", required_argument, 0, 'H'},
|
||||
{"port", required_argument, 0, 'P'},
|
||||
{"game-type", required_argument, 0, 'G'},
|
||||
{"map-field", required_argument, 0, 'm'},
|
||||
{"ping-field", required_argument, 0, 'p'},
|
||||
{"game-field", required_argument, 0, 'g'},
|
||||
{"players-field", required_argument, 0, players_field_index},
|
||||
{"max-players-field", required_argument, 0, max_players_field_index},
|
||||
{0, 0, 0, 0}};
|
||||
static struct option long_opts[] = {
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"hostname", required_argument, 0, 'H'},
|
||||
{"port", required_argument, 0, 'P'},
|
||||
{"game-type", required_argument, 0, 'G'},
|
||||
{"map-field", required_argument, 0, 'm'},
|
||||
{"ping-field", required_argument, 0, 'p'},
|
||||
{"game-field", required_argument, 0, 'g'},
|
||||
{"players-field", required_argument, 0, players_field_index},
|
||||
{"max-players-field", required_argument, 0, max_players_field_index},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_game_config_wrapper result = {
|
||||
.config = check_game_config_init(),
|
||||
|
|
@ -216,21 +220,24 @@ check_game_config_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
case 'p': /* index of ping field */
|
||||
result.config.qstat_ping_field = atoi(optarg);
|
||||
if (result.config.qstat_ping_field < 0 || result.config.qstat_ping_field > QSTAT_MAX_RETURN_ARGS) {
|
||||
if (result.config.qstat_ping_field < 0 ||
|
||||
result.config.qstat_ping_field > QSTAT_MAX_RETURN_ARGS) {
|
||||
result.errorcode = ERROR;
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
case 'm': /* index on map field */
|
||||
result.config.qstat_map_field = atoi(optarg);
|
||||
if (result.config.qstat_map_field < 0 || result.config.qstat_map_field > QSTAT_MAX_RETURN_ARGS) {
|
||||
if (result.config.qstat_map_field < 0 ||
|
||||
result.config.qstat_map_field > QSTAT_MAX_RETURN_ARGS) {
|
||||
result.errorcode = ERROR;
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
case 'g': /* index of game field */
|
||||
result.config.qstat_game_field = atoi(optarg);
|
||||
if (result.config.qstat_game_field < 0 || result.config.qstat_game_field > QSTAT_MAX_RETURN_ARGS) {
|
||||
if (result.config.qstat_game_field < 0 ||
|
||||
result.config.qstat_game_field > QSTAT_MAX_RETURN_ARGS) {
|
||||
result.errorcode = ERROR;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -240,14 +247,16 @@ check_game_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (result.config.qstat_game_players_max == 0) {
|
||||
result.config.qstat_game_players_max = result.config.qstat_game_players - 1;
|
||||
}
|
||||
if (result.config.qstat_game_players < 0 || result.config.qstat_game_players > QSTAT_MAX_RETURN_ARGS) {
|
||||
if (result.config.qstat_game_players < 0 ||
|
||||
result.config.qstat_game_players > QSTAT_MAX_RETURN_ARGS) {
|
||||
result.errorcode = ERROR;
|
||||
return result;
|
||||
}
|
||||
break;
|
||||
case max_players_field_index: /* index of max players field */
|
||||
result.config.qstat_game_players_max = atoi(optarg);
|
||||
if (result.config.qstat_game_players_max < 0 || result.config.qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) {
|
||||
if (result.config.qstat_game_players_max < 0 ||
|
||||
result.config.qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) {
|
||||
result.errorcode = ERROR;
|
||||
return result;
|
||||
}
|
||||
|
|
@ -286,7 +295,7 @@ void print_help(void) {
|
|||
printf(UT_HELP_VRSN);
|
||||
printf(UT_EXTRA_OPTS);
|
||||
printf(" -H, --hostname=ADDRESS\n"
|
||||
" Host name, IP Address, or unix socket (must be an absolute path)\n");
|
||||
" Host name, IP Address, or unix socket (must be an absolute path)\n");
|
||||
printf(" %s\n", "-P");
|
||||
printf(" %s\n", _("Optional port to connect to"));
|
||||
printf(" %s\n", "-g");
|
||||
|
|
@ -300,8 +309,10 @@ void print_help(void) {
|
|||
|
||||
printf("\n");
|
||||
printf("%s\n", _("Notes:"));
|
||||
printf(" %s\n", _("This plugin uses the 'qstat' command, the popular game server status query tool."));
|
||||
printf(" %s\n", _("If you don't have the package installed, you will need to download it from"));
|
||||
printf(" %s\n",
|
||||
_("This plugin uses the 'qstat' command, the popular game server status query tool."));
|
||||
printf(" %s\n",
|
||||
_("If you don't have the package installed, you will need to download it from"));
|
||||
printf(" %s\n", _("https://github.com/multiplay/qstat before you can use this plugin."));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
@ -309,7 +320,8 @@ void print_help(void) {
|
|||
|
||||
void print_usage(void) {
|
||||
printf("%s\n", _("Usage:"));
|
||||
printf(" %s [-hvV] [-P port] [-t timeout] [-g game_field] [-m map_field] [-p ping_field] [-G game-time] [-H hostname] <game> "
|
||||
printf(" %s [-hvV] [-P port] [-t timeout] [-g game_field] [-m map_field] [-p ping_field] [-G "
|
||||
"game-time] [-H hostname] <game> "
|
||||
"<ip_address>\n",
|
||||
progname);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,13 +85,16 @@ int main(int argc, char **argv) {
|
|||
char query_string[512];
|
||||
/* removed ' 2>1' at end of command 10/27/1999 - EG */
|
||||
/* create the query string */
|
||||
sprintf(query_string, "%s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0", HPJD_LINE_STATUS, HPJD_PAPER_STATUS,
|
||||
HPJD_INTERVENTION_REQUIRED, HPJD_GD_PERIPHERAL_ERROR, HPJD_GD_PAPER_JAM, HPJD_GD_PAPER_OUT, HPJD_GD_TONER_LOW,
|
||||
HPJD_GD_PAGE_PUNT, HPJD_GD_MEMORY_OUT, HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY);
|
||||
sprintf(query_string, "%s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0 %s.0",
|
||||
HPJD_LINE_STATUS, HPJD_PAPER_STATUS, HPJD_INTERVENTION_REQUIRED,
|
||||
HPJD_GD_PERIPHERAL_ERROR, HPJD_GD_PAPER_JAM, HPJD_GD_PAPER_OUT, HPJD_GD_TONER_LOW,
|
||||
HPJD_GD_PAGE_PUNT, HPJD_GD_MEMORY_OUT, HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT,
|
||||
HPJD_GD_STATUS_DISPLAY);
|
||||
|
||||
/* get the command to run */
|
||||
char command_line[1024];
|
||||
sprintf(command_line, "%s -OQa -m : -v 1 -c %s %s:%u %s", PATH_TO_SNMPGET, config.community, config.address, config.port, query_string);
|
||||
sprintf(command_line, "%s -OQa -m : -v 1 -c %s %s:%u %s", PATH_TO_SNMPGET, config.community,
|
||||
config.address, config.port, query_string);
|
||||
|
||||
/* run the command */
|
||||
child_process = spopen(command_line);
|
||||
|
|
@ -177,7 +180,8 @@ int main(int argc, char **argv) {
|
|||
strcpy(display_message, temp_buffer + 1);
|
||||
break;
|
||||
default: /* fold multiline message */
|
||||
strncat(display_message, input_buffer, sizeof(display_message) - strlen(display_message) - 1);
|
||||
strncat(display_message, input_buffer,
|
||||
sizeof(display_message) - strlen(display_message) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
#ifdef HAVE_LDAP_SET_OPTION
|
||||
/* set ldap options */
|
||||
if (ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &config.ld_protocol) != LDAP_OPT_SUCCESS) {
|
||||
if (ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &config.ld_protocol) !=
|
||||
LDAP_OPT_SUCCESS) {
|
||||
printf(_("Could not set protocol version %d\n"), config.ld_protocol);
|
||||
return STATE_CRITICAL;
|
||||
}
|
||||
|
|
@ -135,7 +136,8 @@ int main(int argc, char *argv[]) {
|
|||
} else if (config.starttls) {
|
||||
#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S)
|
||||
/* ldap with startTLS: set option version */
|
||||
if (ldap_get_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS) {
|
||||
if (ldap_get_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version) ==
|
||||
LDAP_OPT_SUCCESS) {
|
||||
if (version < LDAP_VERSION3) {
|
||||
version = LDAP_VERSION3;
|
||||
ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version);
|
||||
|
|
@ -156,7 +158,8 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
/* bind to the ldap server */
|
||||
if (ldap_bind_s(ldap_connection, config.ld_binddn, config.ld_passwd, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) {
|
||||
if (ldap_bind_s(ldap_connection, config.ld_binddn, config.ld_passwd, LDAP_AUTH_SIMPLE) !=
|
||||
LDAP_SUCCESS) {
|
||||
if (verbose) {
|
||||
ldap_perror(ldap_connection, "ldap_bind");
|
||||
}
|
||||
|
|
@ -168,8 +171,10 @@ int main(int argc, char *argv[]) {
|
|||
int num_entries = 0;
|
||||
/* do a search of all objectclasses in the base dn */
|
||||
if (ldap_search_s(ldap_connection, config.ld_base,
|
||||
(config.crit_entries != NULL || config.warn_entries != NULL) ? LDAP_SCOPE_SUBTREE : LDAP_SCOPE_BASE, config.ld_attr,
|
||||
NULL, 0, &result) != LDAP_SUCCESS) {
|
||||
(config.crit_entries != NULL || config.warn_entries != NULL)
|
||||
? LDAP_SCOPE_SUBTREE
|
||||
: LDAP_SCOPE_BASE,
|
||||
config.ld_attr, NULL, 0, &result) != LDAP_SUCCESS) {
|
||||
if (verbose) {
|
||||
ldap_perror(ldap_connection, "ldap_search");
|
||||
}
|
||||
|
|
@ -215,14 +220,16 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
/* print out the result */
|
||||
if (config.crit_entries != NULL || config.warn_entries != NULL) {
|
||||
printf(_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), state_text(status), num_entries, elapsed_time,
|
||||
fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time, config.crit_time_set, config.crit_time, true, 0,
|
||||
false, 0),
|
||||
sperfdata("entries", (double)num_entries, "", config.warn_entries, config.crit_entries, true, 0.0, false, 0.0));
|
||||
printf(_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), state_text(status),
|
||||
num_entries, elapsed_time,
|
||||
fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time,
|
||||
config.crit_time_set, config.crit_time, true, 0, false, 0),
|
||||
sperfdata("entries", (double)num_entries, "", config.warn_entries,
|
||||
config.crit_entries, true, 0.0, false, 0.0));
|
||||
} else {
|
||||
printf(_("LDAP %s - %.3f seconds response time|%s\n"), state_text(status), elapsed_time,
|
||||
fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time, config.crit_time_set, config.crit_time, true, 0,
|
||||
false, 0));
|
||||
fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time,
|
||||
config.crit_time_set, config.crit_time, true, 0, false, 0));
|
||||
}
|
||||
|
||||
exit(status);
|
||||
|
|
@ -273,7 +280,8 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
int option = 0;
|
||||
while (true) {
|
||||
int option_index = getopt_long(argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option);
|
||||
int option_index =
|
||||
getopt_long(argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option);
|
||||
|
||||
if (option_index == -1 || option_index == EOF) {
|
||||
break;
|
||||
|
|
@ -381,7 +389,8 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.ld_port = DEFAULT_PORT;
|
||||
}
|
||||
|
||||
if (strstr(argv[0], "check_ldaps") && !result.config.starttls && !result.config.ssl_on_connect) {
|
||||
if (strstr(argv[0], "check_ldaps") && !result.config.starttls &&
|
||||
!result.config.ssl_on_connect) {
|
||||
result.config.starttls = true;
|
||||
}
|
||||
|
||||
|
|
@ -398,7 +407,8 @@ check_ldap_config_wrapper validate_arguments(check_ldap_config_wrapper config_wr
|
|||
}
|
||||
|
||||
if (config_wrapper.config.crit_entries != NULL || config_wrapper.config.warn_entries != NULL) {
|
||||
set_thresholds(&config_wrapper.config.entries_thresholds, config_wrapper.config.warn_entries, config_wrapper.config.crit_entries);
|
||||
set_thresholds(&config_wrapper.config.entries_thresholds,
|
||||
config_wrapper.config.warn_entries, config_wrapper.config.crit_entries);
|
||||
}
|
||||
|
||||
if (config_wrapper.config.ld_passwd == NULL) {
|
||||
|
|
@ -435,11 +445,13 @@ void print_help(void) {
|
|||
printf(" %s\n", "-D [--bind]");
|
||||
printf(" %s\n", _("ldap bind DN (if required)"));
|
||||
printf(" %s\n", "-P [--pass]");
|
||||
printf(" %s\n", _("ldap password (if required, or set the password through environment variable 'LDAP_PASSWORD')"));
|
||||
printf(" %s\n", _("ldap password (if required, or set the password through environment "
|
||||
"variable 'LDAP_PASSWORD')"));
|
||||
printf(" %s\n", "-T [--starttls]");
|
||||
printf(" %s\n", _("use starttls mechanism introduced in protocol version 3"));
|
||||
printf(" %s\n", "-S [--ssl]");
|
||||
printf(" %s %i\n", _("use ldaps (ldap v2 ssl method). this also sets the default port to"), LDAPS_PORT);
|
||||
printf(" %s %i\n", _("use ldaps (ldap v2 ssl method). this also sets the default port to"),
|
||||
LDAPS_PORT);
|
||||
|
||||
#ifdef HAVE_LDAP_SET_OPTION
|
||||
printf(" %s\n", "-2 [--ver2]");
|
||||
|
|
@ -463,9 +475,11 @@ void print_help(void) {
|
|||
printf("\n");
|
||||
printf("%s\n", _("Notes:"));
|
||||
printf(" %s\n", _("If this plugin is called via 'check_ldaps', method 'STARTTLS' will be"));
|
||||
printf(_(" implied (using default port %i) unless --port=636 is specified. In that case\n"), DEFAULT_PORT);
|
||||
printf(_(" implied (using default port %i) unless --port=636 is specified. In that case\n"),
|
||||
DEFAULT_PORT);
|
||||
printf(" %s\n", _("'SSL on connect' will be used no matter how the plugin was called."));
|
||||
printf(" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags"));
|
||||
printf(" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' "
|
||||
"or '--ssl' flags"));
|
||||
printf(" %s\n", _("to define the behaviour explicitly instead."));
|
||||
printf(" %s\n", _("The parameters --warn-entries and --crit-entries are optional."));
|
||||
|
||||
|
|
|
|||
|
|
@ -168,7 +168,8 @@ int main(int argc, char **argv) {
|
|||
mp_subcheck scaled_load_sc1 = mp_subcheck_init();
|
||||
scaled_load_sc1 = mp_set_subcheck_state(scaled_load_sc1, mp_get_pd_status(pd_scaled_load1));
|
||||
mp_add_perfdata_to_subcheck(&scaled_load_sc1, pd_scaled_load1);
|
||||
xasprintf(&scaled_load_sc1.output, "1 Minute: %s", pd_value_to_string(pd_scaled_load1.value));
|
||||
xasprintf(&scaled_load_sc1.output, "1 Minute: %s",
|
||||
pd_value_to_string(pd_scaled_load1.value));
|
||||
mp_add_subcheck_to_subcheck(&scaled_load_sc, scaled_load_sc1);
|
||||
|
||||
mp_perfdata pd_scaled_load5 = perfdata_init();
|
||||
|
|
@ -179,7 +180,8 @@ int main(int argc, char **argv) {
|
|||
mp_subcheck scaled_load_sc5 = mp_subcheck_init();
|
||||
scaled_load_sc5 = mp_set_subcheck_state(scaled_load_sc5, mp_get_pd_status(pd_scaled_load5));
|
||||
mp_add_perfdata_to_subcheck(&scaled_load_sc5, pd_scaled_load5);
|
||||
xasprintf(&scaled_load_sc5.output, "5 Minutes: %s", pd_value_to_string(pd_scaled_load5.value));
|
||||
xasprintf(&scaled_load_sc5.output, "5 Minutes: %s",
|
||||
pd_value_to_string(pd_scaled_load5.value));
|
||||
mp_add_subcheck_to_subcheck(&scaled_load_sc, scaled_load_sc5);
|
||||
|
||||
mp_perfdata pd_scaled_load15 = perfdata_init();
|
||||
|
|
@ -188,9 +190,11 @@ int main(int argc, char **argv) {
|
|||
pd_scaled_load15 = mp_pd_set_thresholds(pd_scaled_load15, config.th_load[2]);
|
||||
|
||||
mp_subcheck scaled_load_sc15 = mp_subcheck_init();
|
||||
scaled_load_sc15 = mp_set_subcheck_state(scaled_load_sc15, mp_get_pd_status(pd_scaled_load15));
|
||||
scaled_load_sc15 =
|
||||
mp_set_subcheck_state(scaled_load_sc15, mp_get_pd_status(pd_scaled_load15));
|
||||
mp_add_perfdata_to_subcheck(&scaled_load_sc15, pd_scaled_load15);
|
||||
xasprintf(&scaled_load_sc15.output, "15 Minutes: %s", pd_value_to_string(pd_scaled_load15.value));
|
||||
xasprintf(&scaled_load_sc15.output, "15 Minutes: %s",
|
||||
pd_value_to_string(pd_scaled_load15.value));
|
||||
mp_add_subcheck_to_subcheck(&scaled_load_sc, scaled_load_sc15);
|
||||
|
||||
mp_add_subcheck_to_check(&overall, scaled_load_sc);
|
||||
|
|
@ -245,11 +249,13 @@ int main(int argc, char **argv) {
|
|||
mp_subcheck top_proc_sc = mp_subcheck_init();
|
||||
top_proc_sc = mp_set_subcheck_state(top_proc_sc, STATE_OK);
|
||||
top_processes_result top_proc = print_top_consuming_processes(config.n_procs_to_show);
|
||||
xasprintf(&top_proc_sc.output, "Top %lu CPU time consuming processes", config.n_procs_to_show);
|
||||
xasprintf(&top_proc_sc.output, "Top %lu CPU time consuming processes",
|
||||
config.n_procs_to_show);
|
||||
|
||||
if (top_proc.errorcode == OK) {
|
||||
for (unsigned long i = 0; i < config.n_procs_to_show; i++) {
|
||||
xasprintf(&top_proc_sc.output, "%s\n%s", top_proc_sc.output, top_proc.top_processes[i]);
|
||||
xasprintf(&top_proc_sc.output, "%s\n%s", top_proc_sc.output,
|
||||
top_proc.top_processes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -417,7 +423,8 @@ void print_help(void) {
|
|||
|
||||
void print_usage(void) {
|
||||
printf("%s\n", _("Usage:"));
|
||||
printf("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n", progname);
|
||||
printf("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15 [-n NUMBER_OF_PROCS]\n",
|
||||
progname);
|
||||
}
|
||||
|
||||
#ifdef PS_USES_PROCPCPU
|
||||
|
|
@ -462,7 +469,8 @@ static top_processes_result print_top_consuming_processes(unsigned long n_procs_
|
|||
#ifdef PS_USES_PROCPCPU
|
||||
qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char *), cmpstringp);
|
||||
#endif /* PS_USES_PROCPCPU */
|
||||
unsigned long lines_to_show = chld_out.lines < (size_t)(n_procs_to_show + 1) ? chld_out.lines : n_procs_to_show + 1;
|
||||
unsigned long lines_to_show =
|
||||
chld_out.lines < (size_t)(n_procs_to_show + 1) ? chld_out.lines : n_procs_to_show + 1;
|
||||
|
||||
result.top_processes = calloc(lines_to_show, sizeof(char *));
|
||||
if (result.top_processes == NULL) {
|
||||
|
|
|
|||
|
|
@ -129,7 +129,8 @@ int main(int argc, char **argv) {
|
|||
time_t current_time;
|
||||
time(¤t_time);
|
||||
if (config.expire_minutes > 0 && (current_time - timestamp) > (config.expire_minutes * 60)) {
|
||||
printf(_("MRTG data has expired (%d minutes old)\n"), (int)((current_time - timestamp) / 60));
|
||||
printf(_("MRTG data has expired (%d minutes old)\n"),
|
||||
(int)((current_time - timestamp) / 60));
|
||||
return STATE_WARNING;
|
||||
}
|
||||
|
||||
|
|
@ -148,20 +149,29 @@ int main(int argc, char **argv) {
|
|||
result = STATE_WARNING;
|
||||
}
|
||||
|
||||
printf("%s. %s = %lu %s|%s\n", (config.use_average) ? _("Avg") : _("Max"), config.label, rate, config.units,
|
||||
perfdata(config.label, (long)rate, config.units, config.value_warning_threshold_set, (long)config.value_warning_threshold,
|
||||
config.value_critical_threshold_set, (long)config.value_critical_threshold, 0, 0, 0, 0));
|
||||
printf("%s. %s = %lu %s|%s\n", (config.use_average) ? _("Avg") : _("Max"), config.label, rate,
|
||||
config.units,
|
||||
perfdata(config.label, (long)rate, config.units, config.value_warning_threshold_set,
|
||||
(long)config.value_warning_threshold, config.value_critical_threshold_set,
|
||||
(long)config.value_critical_threshold, 0, 0, 0, 0));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* process command-line arguments */
|
||||
check_mrtg_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {
|
||||
{"logfile", required_argument, 0, 'F'}, {"expires", required_argument, 0, 'e'}, {"aggregation", required_argument, 0, 'a'},
|
||||
{"variable", required_argument, 0, 'v'}, {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'},
|
||||
{"label", required_argument, 0, 'l'}, {"units", required_argument, 0, 'u'}, {"variable", required_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
||||
static struct option longopts[] = {{"logfile", required_argument, 0, 'F'},
|
||||
{"expires", required_argument, 0, 'e'},
|
||||
{"aggregation", required_argument, 0, 'a'},
|
||||
{"variable", required_argument, 0, 'v'},
|
||||
{"critical", required_argument, 0, 'c'},
|
||||
{"warning", required_argument, 0, 'w'},
|
||||
{"label", required_argument, 0, 'l'},
|
||||
{"units", required_argument, 0, 'u'},
|
||||
{"variable", required_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_mrtg_config_wrapper result = {
|
||||
.errorcode = OK,
|
||||
|
|
@ -242,7 +252,9 @@ check_mrtg_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (is_intpos(argv[option_char])) {
|
||||
result.config.expire_minutes = atoi(argv[option_char++]);
|
||||
} else {
|
||||
die(STATE_UNKNOWN, _("%s is not a valid expiration time\nUse '%s -h' for additional help\n"), argv[option_char], progname);
|
||||
die(STATE_UNKNOWN,
|
||||
_("%s is not a valid expiration time\nUse '%s -h' for additional help\n"),
|
||||
argv[option_char], progname);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,25 +346,32 @@ void print_help(void) {
|
|||
printf(" %s\n", _("\"Bytes Per Second\", \"%% Utilization\")"));
|
||||
|
||||
printf("\n");
|
||||
printf(" %s\n", _("If the value exceeds the <vwl> threshold, a WARNING status is returned. If"));
|
||||
printf(" %s\n",
|
||||
_("If the value exceeds the <vwl> threshold, a WARNING status is returned. If"));
|
||||
printf(" %s\n", _("the value exceeds the <vcl> threshold, a CRITICAL status is returned. If"));
|
||||
printf(" %s\n", _("the data in the log file is older than <expire_minutes> old, a WARNING"));
|
||||
printf(" %s\n", _("status is returned and a warning message is printed."));
|
||||
|
||||
printf("\n");
|
||||
printf(" %s\n", _("This plugin is useful for monitoring MRTG data that does not correspond to"));
|
||||
printf(" %s\n", _("bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth)."));
|
||||
printf(" %s\n", _("It can be used to monitor any kind of data that MRTG is monitoring - errors,"));
|
||||
printf(" %s\n", _("packets/sec, etc. I use MRTG in conjunction with the Novell NLM that allows"));
|
||||
printf(" %s\n",
|
||||
_("This plugin is useful for monitoring MRTG data that does not correspond to"));
|
||||
printf(" %s\n",
|
||||
_("bandwidth usage. (Use the check_mrtgtraf plugin for monitoring bandwidth)."));
|
||||
printf(" %s\n",
|
||||
_("It can be used to monitor any kind of data that MRTG is monitoring - errors,"));
|
||||
printf(" %s\n",
|
||||
_("packets/sec, etc. I use MRTG in conjunction with the Novell NLM that allows"));
|
||||
printf(" %s\n", _("me to track processor utilization, user connections, drive space, etc and"));
|
||||
printf(" %s\n\n", _("this plugin works well for monitoring that kind of data as well."));
|
||||
|
||||
printf("%s\n", _("Notes:"));
|
||||
printf(" %s\n", _("- This plugin only monitors one of the two variables stored in the MRTG log"));
|
||||
printf(" %s\n",
|
||||
_("- This plugin only monitors one of the two variables stored in the MRTG log"));
|
||||
printf(" %s\n", _("file. If you want to monitor both values you will have to define two"));
|
||||
printf(" %s\n", _("commands with different values for the <variable> argument. Of course,"));
|
||||
printf(" %s\n", _("you can always hack the code to make this plugin work for you..."));
|
||||
printf(" %s\n", _("- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from"));
|
||||
printf(" %s\n",
|
||||
_("- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from"));
|
||||
printf(" %s\n", "http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html");
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
|
|||
|
|
@ -122,7 +122,8 @@ int main(int argc, char **argv) {
|
|||
time_t current_time;
|
||||
time(¤t_time);
|
||||
if ((config.expire_minutes > 0) && (current_time - timestamp) > (config.expire_minutes * 60)) {
|
||||
die(STATE_WARNING, _("MRTG data has expired (%d minutes old)\n"), (int)((current_time - timestamp) / 60));
|
||||
die(STATE_WARNING, _("MRTG data has expired (%d minutes old)\n"),
|
||||
(int)((current_time - timestamp) / 60));
|
||||
}
|
||||
|
||||
unsigned long incoming_rate = 0L;
|
||||
|
|
@ -177,21 +178,26 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
int result = STATE_OK;
|
||||
if (incoming_rate > config.incoming_critical_threshold || outgoing_rate > config.outgoing_critical_threshold) {
|
||||
if (incoming_rate > config.incoming_critical_threshold ||
|
||||
outgoing_rate > config.outgoing_critical_threshold) {
|
||||
result = STATE_CRITICAL;
|
||||
} else if (incoming_rate > config.incoming_warning_threshold || outgoing_rate > config.outgoing_warning_threshold) {
|
||||
} else if (incoming_rate > config.incoming_warning_threshold ||
|
||||
outgoing_rate > config.outgoing_warning_threshold) {
|
||||
result = STATE_WARNING;
|
||||
}
|
||||
|
||||
char *error_message;
|
||||
xasprintf(&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"), (config.use_average) ? _("Avg") : _("Max"),
|
||||
adjusted_incoming_rate, incoming_speed_rating, (config.use_average) ? _("Avg") : _("Max"), adjusted_outgoing_rate,
|
||||
outgoing_speed_rating,
|
||||
fperfdata("in", adjusted_incoming_rate, incoming_speed_rating, (int)config.incoming_warning_threshold,
|
||||
config.incoming_warning_threshold, (int)config.incoming_critical_threshold, config.incoming_critical_threshold,
|
||||
xasprintf(&error_message, _("%s. In = %0.1f %s/s, %s. Out = %0.1f %s/s|%s %s\n"),
|
||||
(config.use_average) ? _("Avg") : _("Max"), adjusted_incoming_rate,
|
||||
incoming_speed_rating, (config.use_average) ? _("Avg") : _("Max"),
|
||||
adjusted_outgoing_rate, outgoing_speed_rating,
|
||||
fperfdata("in", adjusted_incoming_rate, incoming_speed_rating,
|
||||
(int)config.incoming_warning_threshold, config.incoming_warning_threshold,
|
||||
(int)config.incoming_critical_threshold, config.incoming_critical_threshold,
|
||||
true, 0, false, 0),
|
||||
fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating, (int)config.outgoing_warning_threshold,
|
||||
config.outgoing_warning_threshold, (int)config.outgoing_critical_threshold, config.outgoing_critical_threshold,
|
||||
fperfdata("out", adjusted_outgoing_rate, outgoing_speed_rating,
|
||||
(int)config.outgoing_warning_threshold, config.outgoing_warning_threshold,
|
||||
(int)config.outgoing_critical_threshold, config.outgoing_critical_threshold,
|
||||
true, 0, false, 0));
|
||||
|
||||
printf(_("Traffic %s - %s\n"), state_text(result), error_message);
|
||||
|
|
@ -249,10 +255,12 @@ check_mrtgtraf_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.use_average = (bool)(strcmp(optarg, "MAX"));
|
||||
break;
|
||||
case 'c': /* warning threshold */
|
||||
sscanf(optarg, "%lu,%lu", &result.config.incoming_critical_threshold, &result.config.outgoing_critical_threshold);
|
||||
sscanf(optarg, "%lu,%lu", &result.config.incoming_critical_threshold,
|
||||
&result.config.outgoing_critical_threshold);
|
||||
break;
|
||||
case 'w': /* critical threshold */
|
||||
sscanf(optarg, "%lu,%lu", &result.config.incoming_warning_threshold, &result.config.outgoing_warning_threshold);
|
||||
sscanf(optarg, "%lu,%lu", &result.config.incoming_warning_threshold,
|
||||
&result.config.outgoing_warning_threshold);
|
||||
break;
|
||||
case 'V': /* version */
|
||||
print_revision(progname, NP_VERSION);
|
||||
|
|
|
|||
|
|
@ -50,15 +50,23 @@ static int verbose = 0;
|
|||
|
||||
#define LENGTH_METRIC_UNIT 6
|
||||
static const char *metric_unit[LENGTH_METRIC_UNIT] = {
|
||||
"Open_files", "Open_tables", "Qcache_free_memory", "Qcache_queries_in_cache", "Threads_connected", "Threads_running"};
|
||||
"Open_files", "Open_tables", "Qcache_free_memory", "Qcache_queries_in_cache",
|
||||
"Threads_connected", "Threads_running"};
|
||||
|
||||
#define LENGTH_METRIC_COUNTER 9
|
||||
static const char *metric_counter[LENGTH_METRIC_COUNTER] = {
|
||||
"Connections", "Qcache_hits", "Qcache_inserts", "Qcache_lowmem_prunes", "Qcache_not_cached", "Queries",
|
||||
"Questions", "Table_locks_waited", "Uptime"};
|
||||
static const char *metric_counter[LENGTH_METRIC_COUNTER] = {"Connections",
|
||||
"Qcache_hits",
|
||||
"Qcache_inserts",
|
||||
"Qcache_lowmem_prunes",
|
||||
"Qcache_not_cached",
|
||||
"Queries",
|
||||
"Questions",
|
||||
"Table_locks_waited",
|
||||
"Uptime"};
|
||||
|
||||
#define MYSQLDUMP_THREADS_QUERY \
|
||||
"SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'"
|
||||
#define MYSQLDUMP_THREADS_QUERY \
|
||||
"SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE " \
|
||||
"'SELECT /*!40001 SQL_NO_CACHE */%'"
|
||||
|
||||
typedef struct {
|
||||
int errorcode;
|
||||
|
|
@ -99,16 +107,19 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (config.ssl) {
|
||||
mysql_ssl_set(&mysql, config.key, config.cert, config.ca_cert, config.ca_dir, config.ciphers);
|
||||
mysql_ssl_set(&mysql, config.key, config.cert, config.ca_cert, config.ca_dir,
|
||||
config.ciphers);
|
||||
}
|
||||
/* establish a connection to the server and error checking */
|
||||
if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db, config.db_port, config.db_socket, 0)) {
|
||||
if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db,
|
||||
config.db_port, config.db_socket, 0)) {
|
||||
/* 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 (config.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), mysql_get_proto_info(&mysql));
|
||||
if (config.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),
|
||||
mysql_get_proto_info(&mysql));
|
||||
mysql_close(&mysql);
|
||||
return STATE_OK;
|
||||
}
|
||||
|
|
@ -157,13 +168,17 @@ int main(int argc, char **argv) {
|
|||
while ((row = mysql_fetch_row(res)) != NULL) {
|
||||
for (int i = 0; i < LENGTH_METRIC_UNIT; i++) {
|
||||
if (strcmp(row[0], metric_unit[i]) == 0) {
|
||||
xasprintf(&perf, "%s%s ", perf, perfdata(metric_unit[i], atol(row[1]), "", false, 0, false, 0, false, 0, false, 0));
|
||||
xasprintf(&perf, "%s%s ", perf,
|
||||
perfdata(metric_unit[i], atol(row[1]), "", false, 0, false, 0, false,
|
||||
0, false, 0));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < LENGTH_METRIC_COUNTER; i++) {
|
||||
if (strcmp(row[0], metric_counter[i]) == 0) {
|
||||
xasprintf(&perf, "%s%s ", perf, perfdata(metric_counter[i], atol(row[1]), "c", false, 0, false, 0, false, 0, false, 0));
|
||||
xasprintf(&perf, "%s%s ", perf,
|
||||
perfdata(metric_counter[i], atol(row[1]), "c", false, 0, false, 0,
|
||||
false, 0, false, 0));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -189,8 +204,8 @@ int main(int argc, char **argv) {
|
|||
unsigned long minor_version = (server_verion_int % 10000) / 100;
|
||||
unsigned long patch_version = (server_verion_int % 100);
|
||||
if (verbose) {
|
||||
printf("Found MariaDB: %s, main version: %lu, minor version: %lu, patch version: %lu\n", server_version, major_version,
|
||||
minor_version, patch_version);
|
||||
printf("Found MariaDB: %s, main version: %lu, minor version: %lu, patch version: %lu\n",
|
||||
server_version, major_version, minor_version, patch_version);
|
||||
}
|
||||
|
||||
if (strstr(server_version, "MariaDB") != NULL) {
|
||||
|
|
@ -292,11 +307,15 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* Save replica status in replica_result */
|
||||
snprintf(replica_result, REPLICA_RESULTSIZE, "Replica IO: %s Replica SQL: %s Seconds Behind Master: %s", row[replica_io_field],
|
||||
row[replica_sql_field], seconds_behind_field != -1 ? row[seconds_behind_field] : "Unknown");
|
||||
snprintf(replica_result, REPLICA_RESULTSIZE,
|
||||
"Replica IO: %s Replica SQL: %s Seconds Behind Master: %s",
|
||||
row[replica_io_field], row[replica_sql_field],
|
||||
seconds_behind_field != -1 ? row[seconds_behind_field] : "Unknown");
|
||||
|
||||
/* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no mysqldump threads running */
|
||||
if (strcmp(row[replica_io_field], "Yes") != 0 || strcmp(row[replica_sql_field], "Yes") != 0) {
|
||||
/* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no
|
||||
* mysqldump threads running */
|
||||
if (strcmp(row[replica_io_field], "Yes") != 0 ||
|
||||
strcmp(row[replica_sql_field], "Yes") != 0) {
|
||||
MYSQL_RES *res_mysqldump;
|
||||
MYSQL_ROW row_mysqldump;
|
||||
unsigned int mysqldump_threads = 0;
|
||||
|
|
@ -325,20 +344,23 @@ int main(int argc, char **argv) {
|
|||
if (seconds_behind_field == -1) {
|
||||
printf("seconds_behind_field not found\n");
|
||||
} else {
|
||||
printf("seconds_behind_field(index %d)=%s\n", seconds_behind_field, row[seconds_behind_field]);
|
||||
printf("seconds_behind_field(index %d)=%s\n", seconds_behind_field,
|
||||
row[seconds_behind_field]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check Seconds Behind against threshold */
|
||||
if ((seconds_behind_field != -1) && (row[seconds_behind_field] != NULL && 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;
|
||||
|
||||
status = get_status(value, config.my_threshold);
|
||||
|
||||
xasprintf(&perf, "%s %s", perf,
|
||||
fperfdata("seconds behind master", value, "s", true, (double)config.warning_time, true,
|
||||
(double)config.critical_time, false, 0, false, 0));
|
||||
fperfdata("seconds behind master", value, "s", true,
|
||||
(double)config.warning_time, true, (double)config.critical_time,
|
||||
false, 0, false, 0));
|
||||
|
||||
if (status == STATE_WARNING) {
|
||||
printf("SLOW_REPLICA %s: %s|%s\n", _("WARNING"), replica_result, perf);
|
||||
|
|
@ -410,7 +432,8 @@ check_mysql_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
int option = 0;
|
||||
while (true) {
|
||||
int option_index = getopt_long(argc, argv, "hlvVnSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option);
|
||||
int option_index =
|
||||
getopt_long(argc, argv, "hlvVnSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option);
|
||||
|
||||
if (option_index == -1 || option_index == EOF) {
|
||||
break;
|
||||
|
|
@ -580,15 +603,17 @@ void print_help(void) {
|
|||
printf(" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!"));
|
||||
printf(" %s\n", _("Your clear-text password could be visible as a process table entry"));
|
||||
printf(" %s\n", "-S, --check-slave");
|
||||
printf(" %s\n",
|
||||
_("Check if the slave thread is running properly. This option is deprecated in favour of check-replica, which does the same"));
|
||||
printf(" %s\n", _("Check if the slave thread is running properly. This option is deprecated "
|
||||
"in favour of check-replica, which does the same"));
|
||||
printf(" %s\n", "--check-replica");
|
||||
printf(" %s\n", _("Check if the replica thread is running properly."));
|
||||
printf(" %s\n", "-w, --warning");
|
||||
printf(" %s\n", _("Exit with WARNING status if replica server is more than INTEGER seconds"));
|
||||
printf(" %s\n",
|
||||
_("Exit with WARNING status if replica server is more than INTEGER seconds"));
|
||||
printf(" %s\n", _("behind master"));
|
||||
printf(" %s\n", "-c, --critical");
|
||||
printf(" %s\n", _("Exit with CRITICAL status if replica server is more then INTEGER seconds"));
|
||||
printf(" %s\n",
|
||||
_("Exit with CRITICAL status if replica server is more then INTEGER seconds"));
|
||||
printf(" %s\n", _("behind master"));
|
||||
printf(" %s\n", "-l, --ssl");
|
||||
printf(" %s\n", _("Use ssl encryption"));
|
||||
|
|
@ -604,7 +629,8 @@ void print_help(void) {
|
|||
printf(" %s\n", _("List of valid SSL ciphers"));
|
||||
|
||||
printf("\n");
|
||||
printf(" %s\n", _("There are no required arguments. By default, the local database is checked"));
|
||||
printf(" %s\n",
|
||||
_("There are no required arguments. By default, the local database is checked"));
|
||||
printf(" %s\n", _("using the default unix socket. You can force TCP on localhost by using an"));
|
||||
printf(" %s\n", _("IP address or FQDN ('localhost' will use the socket as well)."));
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ typedef struct {
|
|||
check_mysql_query_config config;
|
||||
} check_mysql_query_config_wrapper;
|
||||
static check_mysql_query_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
|
||||
static check_mysql_query_config_wrapper validate_arguments(check_mysql_query_config_wrapper /*config_wrapper*/);
|
||||
static check_mysql_query_config_wrapper
|
||||
validate_arguments(check_mysql_query_config_wrapper /*config_wrapper*/);
|
||||
static void print_help(void);
|
||||
void print_usage(void);
|
||||
|
||||
|
|
@ -83,7 +84,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* establish a connection to the server and error checking */
|
||||
if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db, config.db_port, config.db_socket, 0)) {
|
||||
if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db,
|
||||
config.db_port, config.db_socket, 0)) {
|
||||
if (mysql_errno(&mysql) == CR_UNKNOWN_HOST) {
|
||||
die(STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error(&mysql));
|
||||
} else if (mysql_errno(&mysql) == CR_VERSION_ERROR) {
|
||||
|
|
@ -155,8 +157,11 @@ int main(int argc, char **argv) {
|
|||
printf("QUERY %s: ", _("CRITICAL"));
|
||||
}
|
||||
printf(_("'%s' returned %f | %s"), config.sql_query, value,
|
||||
fperfdata("result", value, "", config.my_thresholds->warning, config.my_thresholds->warning ? config.my_thresholds->warning->end : 0,
|
||||
config.my_thresholds->critical, config.my_thresholds->critical ? config.my_thresholds->critical->end : 0, false, 0, false, 0));
|
||||
fperfdata("result", value, "", config.my_thresholds->warning,
|
||||
config.my_thresholds->warning ? config.my_thresholds->warning->end : 0,
|
||||
config.my_thresholds->critical,
|
||||
config.my_thresholds->critical ? config.my_thresholds->critical->end : 0,
|
||||
false, 0, false, 0));
|
||||
printf("\n");
|
||||
|
||||
return status;
|
||||
|
|
@ -164,12 +169,21 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* process command-line arguments */
|
||||
check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {
|
||||
{"hostname", required_argument, 0, 'H'}, {"socket", required_argument, 0, 's'}, {"database", required_argument, 0, 'd'},
|
||||
{"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'}, {"file", required_argument, 0, 'f'},
|
||||
{"group", required_argument, 0, 'g'}, {"port", required_argument, 0, 'P'}, {"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"query", required_argument, 0, 'q'},
|
||||
{"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, {0, 0, 0, 0}};
|
||||
static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
|
||||
{"socket", required_argument, 0, 's'},
|
||||
{"database", required_argument, 0, 'd'},
|
||||
{"username", required_argument, 0, 'u'},
|
||||
{"password", required_argument, 0, 'p'},
|
||||
{"file", required_argument, 0, 'f'},
|
||||
{"group", required_argument, 0, 'g'},
|
||||
{"port", required_argument, 0, 'P'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"query", required_argument, 0, 'q'},
|
||||
{"warning", required_argument, 0, 'w'},
|
||||
{"critical", required_argument, 0, 'c'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
check_mysql_query_config_wrapper result = {
|
||||
.errorcode = OK,
|
||||
|
|
@ -255,7 +269,8 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) {
|
|||
return validate_arguments(result);
|
||||
}
|
||||
|
||||
check_mysql_query_config_wrapper validate_arguments(check_mysql_query_config_wrapper config_wrapper) {
|
||||
check_mysql_query_config_wrapper
|
||||
validate_arguments(check_mysql_query_config_wrapper config_wrapper) {
|
||||
if (config_wrapper.config.sql_query == NULL) {
|
||||
usage("Must specify a SQL query to run");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,8 @@ int main(int argc, char **argv) {
|
|||
xasprintf(&send_buffer, "%s&1", config.req_password);
|
||||
fetch_data(config.server_address, config.server_port, send_buffer);
|
||||
if (config.value_list != NULL && strcmp(recv_buffer, config.value_list) != 0) {
|
||||
xasprintf(&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, config.value_list);
|
||||
xasprintf(&output_message, _("Wrong client version - running: %s, required: %s"),
|
||||
recv_buffer, config.value_list);
|
||||
return_code = STATE_WARNING;
|
||||
} else {
|
||||
xasprintf(&output_message, "%s", recv_buffer);
|
||||
|
|
@ -116,9 +117,12 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* loop until one of the parameters is wrong or not present */
|
||||
int offset = 0;
|
||||
while (lvalue_list[0 + offset] > (unsigned long)0 && lvalue_list[0 + offset] <= (unsigned long)17280 &&
|
||||
lvalue_list[1 + offset] > (unsigned long)0 && lvalue_list[1 + offset] <= (unsigned long)100 &&
|
||||
lvalue_list[2 + offset] > (unsigned long)0 && lvalue_list[2 + offset] <= (unsigned long)100) {
|
||||
while (lvalue_list[0 + offset] > (unsigned long)0 &&
|
||||
lvalue_list[0 + offset] <= (unsigned long)17280 &&
|
||||
lvalue_list[1 + offset] > (unsigned long)0 &&
|
||||
lvalue_list[1 + offset] <= (unsigned long)100 &&
|
||||
lvalue_list[2 + offset] > (unsigned long)0 &&
|
||||
lvalue_list[2 + offset] <= (unsigned long)100) {
|
||||
|
||||
/* Send request and retrieve data */
|
||||
xasprintf(&send_buffer, "%s&2&%lu", config.req_password, lvalue_list[0 + offset]);
|
||||
|
|
@ -133,10 +137,12 @@ int main(int argc, char **argv) {
|
|||
return_code = STATE_WARNING;
|
||||
}
|
||||
|
||||
xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization, lvalue_list[0 + offset]);
|
||||
xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization,
|
||||
lvalue_list[0 + offset]);
|
||||
xasprintf(&temp_string, "%s%s", temp_string, output_message);
|
||||
xasprintf(&perfdata, _(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0 + offset], utilization,
|
||||
lvalue_list[1 + offset], lvalue_list[2 + offset]);
|
||||
xasprintf(&perfdata, _(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"),
|
||||
lvalue_list[0 + offset], utilization, lvalue_list[1 + offset],
|
||||
lvalue_list[2 + offset]);
|
||||
xasprintf(&temp_string_perf, "%s%s", temp_string_perf, perfdata);
|
||||
offset += 3; /* move across the array */
|
||||
}
|
||||
|
|
@ -154,8 +160,10 @@ int main(int argc, char **argv) {
|
|||
if (config.value_list == NULL) {
|
||||
tmp_value_list = "minutes";
|
||||
}
|
||||
if (strncmp(tmp_value_list, "seconds", strlen("seconds") + 1) && strncmp(tmp_value_list, "minutes", strlen("minutes") + 1) &&
|
||||
strncmp(config.value_list, "hours", strlen("hours") + 1) && strncmp(tmp_value_list, "days", strlen("days") + 1)) {
|
||||
if (strncmp(tmp_value_list, "seconds", strlen("seconds") + 1) &&
|
||||
strncmp(tmp_value_list, "minutes", strlen("minutes") + 1) &&
|
||||
strncmp(config.value_list, "hours", strlen("hours") + 1) &&
|
||||
strncmp(tmp_value_list, "days", strlen("days") + 1)) {
|
||||
|
||||
output_message = strdup(_("wrong -l argument"));
|
||||
} else {
|
||||
|
|
@ -175,8 +183,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
/* else uptime in seconds, nothing to do */
|
||||
|
||||
xasprintf(&output_message, _("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays, uphours, upminutes,
|
||||
uptime);
|
||||
xasprintf(&output_message,
|
||||
_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays,
|
||||
uphours, upminutes, uptime);
|
||||
|
||||
if (config.check_critical_value && uptime <= config.critical_value) {
|
||||
return_code = STATE_CRITICAL;
|
||||
|
|
@ -207,20 +216,27 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (total_disk_space > 0 && free_disk_space >= 0) {
|
||||
double percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
|
||||
double percent_used_space =
|
||||
((total_disk_space - free_disk_space) / total_disk_space) * 100;
|
||||
double warning_used_space = ((float)config.warning_value / 100) * total_disk_space;
|
||||
double critical_used_space = ((float)config.critical_value / 100) * total_disk_space;
|
||||
double critical_used_space =
|
||||
((float)config.critical_value / 100) * total_disk_space;
|
||||
|
||||
xasprintf(&temp_string, _("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), config.value_list,
|
||||
total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, percent_used_space,
|
||||
free_disk_space / 1073741824, (free_disk_space / total_disk_space) * 100);
|
||||
xasprintf(&temp_string_perf, _("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), config.value_list,
|
||||
(total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
|
||||
critical_used_space / 1073741824, total_disk_space / 1073741824);
|
||||
xasprintf(
|
||||
&temp_string,
|
||||
_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
|
||||
config.value_list, total_disk_space / 1073741824,
|
||||
(total_disk_space - free_disk_space) / 1073741824, percent_used_space,
|
||||
free_disk_space / 1073741824, (free_disk_space / total_disk_space) * 100);
|
||||
xasprintf(&temp_string_perf, _("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"),
|
||||
config.value_list, (total_disk_space - free_disk_space) / 1073741824,
|
||||
warning_used_space / 1073741824, critical_used_space / 1073741824,
|
||||
total_disk_space / 1073741824);
|
||||
|
||||
if (config.check_critical_value && percent_used_space >= config.critical_value) {
|
||||
return_code = STATE_CRITICAL;
|
||||
} else if (config.check_warning_value && percent_used_space >= config.warning_value) {
|
||||
} else if (config.check_warning_value &&
|
||||
percent_used_space >= config.warning_value) {
|
||||
return_code = STATE_WARNING;
|
||||
} else {
|
||||
return_code = STATE_OK;
|
||||
|
|
@ -239,8 +255,10 @@ int main(int argc, char **argv) {
|
|||
if (config.value_list == NULL) {
|
||||
output_message = strdup(_("No service/process specified"));
|
||||
} else {
|
||||
preparelist(config.value_list); /* replace , between services with & to send the request */
|
||||
xasprintf(&send_buffer, "%s&%u&%s&%s", config.req_password, (config.vars_to_check == CHECK_SERVICESTATE) ? 5 : 6,
|
||||
preparelist(
|
||||
config.value_list); /* replace , between services with & to send the request */
|
||||
xasprintf(&send_buffer, "%s&%u&%s&%s", config.req_password,
|
||||
(config.vars_to_check == CHECK_SERVICESTATE) ? 5 : 6,
|
||||
(config.show_all) ? "ShowAll" : "ShowFail", config.value_list);
|
||||
fetch_data(config.server_address, config.server_port, send_buffer);
|
||||
char *numstr = strtok(recv_buffer, "&");
|
||||
|
|
@ -271,10 +289,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
|
||||
which equals RAM + Pagefiles. */
|
||||
xasprintf(&output_message, _("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"),
|
||||
mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space, (mem_commitLimit - mem_commitByte) / 1048567,
|
||||
(mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
|
||||
xasprintf(&perfdata, _("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567, warning_used_space / 1048567,
|
||||
xasprintf(
|
||||
&output_message,
|
||||
_("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"),
|
||||
mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,
|
||||
(mem_commitLimit - mem_commitByte) / 1048567,
|
||||
(mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
|
||||
xasprintf(&perfdata, _("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"),
|
||||
mem_commitByte / 1048567, warning_used_space / 1048567,
|
||||
critical_used_space / 1048567, mem_commitLimit / 1048567);
|
||||
|
||||
return_code = STATE_OK;
|
||||
|
|
@ -302,16 +324,17 @@ int main(int argc, char **argv) {
|
|||
the counter unit - that is, the dimensions of the counter you're getting. Examples:
|
||||
pages/s, packets transferred, etc.
|
||||
|
||||
4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory,
|
||||
but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise.
|
||||
strange things will happen when you make graphs of your data.
|
||||
4) If you want, you may provide the minimum and maximum values to expect. They aren't
|
||||
mandatory, but once specified they MUST have the same order of magnitude and units of -w and
|
||||
-c; otherwise. strange things will happen when you make graphs of your data.
|
||||
*/
|
||||
|
||||
double counter_value = 0.0;
|
||||
if (config.value_list == NULL) {
|
||||
output_message = strdup(_("No counter specified"));
|
||||
} else {
|
||||
preparelist(config.value_list); /* replace , between services with & to send the request */
|
||||
preparelist(
|
||||
config.value_list); /* replace , between services with & to send the request */
|
||||
bool isPercent = (strchr(config.value_list, '%') != NULL);
|
||||
|
||||
strtok(config.value_list, "&"); /* burn the first parameters */
|
||||
|
|
@ -358,15 +381,18 @@ int main(int argc, char **argv) {
|
|||
if (allRight) {
|
||||
/* Let's format the output string, finally... */
|
||||
if (strstr(description, "%") == NULL) {
|
||||
xasprintf(&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
|
||||
xasprintf(&output_message, "%s = %.2f %s", description, counter_value,
|
||||
counter_unit);
|
||||
} else {
|
||||
/* has formatting, will segv if wrong */
|
||||
xasprintf(&output_message, description, counter_value);
|
||||
}
|
||||
xasprintf(&output_message, "%s |", output_message);
|
||||
xasprintf(&output_message, "%s %s", output_message,
|
||||
fperfdata(description, counter_value, counter_unit, 1, config.warning_value, 1, config.critical_value,
|
||||
(!(isPercent) && (minval != NULL)), fminval, (!(isPercent) && (minval != NULL)), fmaxval));
|
||||
fperfdata(description, counter_value, counter_unit, 1,
|
||||
config.warning_value, 1, config.critical_value,
|
||||
(!(isPercent) && (minval != NULL)), fminval,
|
||||
(!(isPercent) && (minval != NULL)), fmaxval));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +417,8 @@ int main(int argc, char **argv) {
|
|||
if (config.value_list == NULL) {
|
||||
output_message = strdup(_("No counter specified"));
|
||||
} else {
|
||||
preparelist(config.value_list); /* replace , between services with & to send the request */
|
||||
preparelist(
|
||||
config.value_list); /* replace , between services with & to send the request */
|
||||
xasprintf(&send_buffer, "%s&9&%s", config.req_password, config.value_list);
|
||||
fetch_data(config.server_address, config.server_port, send_buffer);
|
||||
unsigned long age_in_minutes = atoi(strtok(recv_buffer, "&"));
|
||||
|
|
@ -724,25 +751,31 @@ void print_help(void) {
|
|||
printf(" %s\n", "\"%%.f %%%% paging file used.\"");
|
||||
printf(" %s\n", "INSTANCES =");
|
||||
printf(" %s\n", _("Check any performance counter object of Windows NT/2000."));
|
||||
printf(" %s\n", _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>"));
|
||||
printf(" %s\n",
|
||||
_("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>"));
|
||||
printf(" %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),"));
|
||||
printf(" %s\n", _("if it is two words, it should be enclosed in quotes"));
|
||||
printf(" %s\n", _("The returned results will be a comma-separated list of instances on "));
|
||||
printf(" %s\n", _(" the selected computer for that object."));
|
||||
printf(" %s\n", _("The purpose of this is to be run from command line to determine what instances"));
|
||||
printf(" %s\n", _(" are available for monitoring without having to log onto the Windows server"));
|
||||
printf(" %s\n",
|
||||
_("The purpose of this is to be run from command line to determine what instances"));
|
||||
printf(" %s\n",
|
||||
_(" are available for monitoring without having to log onto the Windows server"));
|
||||
printf(" %s\n", _(" to run Perfmon directly."));
|
||||
printf(" %s\n", _("It can also be used in scripts that automatically create the monitoring service"));
|
||||
printf(" %s\n",
|
||||
_("It can also be used in scripts that automatically create the monitoring service"));
|
||||
printf(" %s\n", _(" configuration files."));
|
||||
printf(" %s\n", _("Some examples:"));
|
||||
printf(" %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process"));
|
||||
|
||||
printf("%s\n", _("Notes:"));
|
||||
printf(" %s\n", _("- The NSClient service should be running on the server to get any information"));
|
||||
printf(" %s\n",
|
||||
_("- The NSClient service should be running on the server to get any information"));
|
||||
printf(" %s\n", "(http://nsclient.ready2run.nl).");
|
||||
printf(" %s\n", _("- Critical thresholds should be lower than warning thresholds"));
|
||||
printf(" %s\n", _("- Default port 1248 is sometimes in use by other services. The error"));
|
||||
printf(" %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
|
||||
printf(" %s\n",
|
||||
_("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
|
||||
printf(" %s\n", _("One fix for this is to change the port to something else on check_nt "));
|
||||
printf(" %s\n", _("and on the client service it\'s connecting to."));
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -83,9 +83,9 @@ typedef struct {
|
|||
/* bits 1,2 are the leap indicator */
|
||||
#define LI_MASK 0xc0
|
||||
#define LI(x) ((x & LI_MASK) >> 6)
|
||||
#define LI_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 6) & LI_MASK); \
|
||||
#define LI_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 6) & LI_MASK); \
|
||||
} while (0)
|
||||
/* and these are the values of the leap indicator */
|
||||
#define LI_NOWARNING 0x00
|
||||
|
|
@ -95,17 +95,17 @@ typedef struct {
|
|||
/* bits 3,4,5 are the ntp version */
|
||||
#define VN_MASK 0x38
|
||||
#define VN(x) ((x & VN_MASK) >> 3)
|
||||
#define VN_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 3) & VN_MASK); \
|
||||
#define VN_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 3) & VN_MASK); \
|
||||
} while (0)
|
||||
#define VN_RESERVED 0x02
|
||||
/* bits 6,7,8 are the ntp mode */
|
||||
#define MODE_MASK 0x07
|
||||
#define MODE(x) (x & MODE_MASK)
|
||||
#define MODE_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & MODE_MASK); \
|
||||
#define MODE_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & MODE_MASK); \
|
||||
} while (0)
|
||||
/* here are some values */
|
||||
#define MODE_CLIENT 0x03
|
||||
|
|
@ -117,9 +117,9 @@ typedef struct {
|
|||
#define REM_MORE 0x20
|
||||
/* In control message, bits 11 - 15 are opcode */
|
||||
#define OP_MASK 0x1f
|
||||
#define OP_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & OP_MASK); \
|
||||
#define OP_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & OP_MASK); \
|
||||
} while (0)
|
||||
#define OP_READSTAT 0x01
|
||||
#define OP_READVAR 0x02
|
||||
|
|
@ -132,18 +132,19 @@ typedef struct {
|
|||
/* NTP control message header is 12 bytes, plus any data in the data
|
||||
* field, plus null padding to the nearest 32-bit boundary per rfc.
|
||||
*/
|
||||
#define SIZEOF_NTPCM(m) (12 + ntohs(m.count) + ((ntohs(m.count) % 4) ? 4 - (ntohs(m.count) % 4) : 0))
|
||||
#define SIZEOF_NTPCM(m) \
|
||||
(12 + ntohs(m.count) + ((ntohs(m.count) % 4) ? 4 - (ntohs(m.count) % 4) : 0))
|
||||
|
||||
/* finally, a little helper or two for debugging: */
|
||||
#define DBG(x) \
|
||||
do { \
|
||||
if (verbose > 1) { \
|
||||
x; \
|
||||
} \
|
||||
#define DBG(x) \
|
||||
do { \
|
||||
if (verbose > 1) { \
|
||||
x; \
|
||||
} \
|
||||
} while (0);
|
||||
#define PRINTSOCKADDR(x) \
|
||||
do { \
|
||||
printf("%u.%u.%u.%u", (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); \
|
||||
#define PRINTSOCKADDR(x) \
|
||||
do { \
|
||||
printf("%u.%u.%u.%u", (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); \
|
||||
} while (0);
|
||||
|
||||
void print_ntp_control_message(const ntp_control_message *message) {
|
||||
|
|
@ -360,7 +361,8 @@ ntp_request_result ntp_request(const check_ntp_peer_config config) {
|
|||
if (req.op & REM_ERROR) {
|
||||
if (strstr(getvar, "jitter")) {
|
||||
if (verbose) {
|
||||
printf("The command failed. This is usually caused by servers refusing the 'jitter'\nvariable. Restarting with "
|
||||
printf("The command failed. This is usually caused by servers refusing the "
|
||||
"'jitter'\nvariable. Restarting with "
|
||||
"'dispersion'...\n");
|
||||
}
|
||||
getvar = "stratum,offset,dispersion";
|
||||
|
|
@ -404,7 +406,8 @@ ntp_request_result ntp_request(const check_ntp_peer_config config) {
|
|||
if (verbose) {
|
||||
printf("%.10g\n", tmp_offset);
|
||||
}
|
||||
if (result.offset_result == STATE_UNKNOWN || fabs(tmp_offset) < fabs(result.offset)) {
|
||||
if (result.offset_result == STATE_UNKNOWN ||
|
||||
fabs(tmp_offset) < fabs(result.offset)) {
|
||||
result.offset = tmp_offset;
|
||||
result.offset_result = STATE_OK;
|
||||
} else {
|
||||
|
|
@ -416,10 +419,12 @@ ntp_request_result ntp_request(const check_ntp_peer_config config) {
|
|||
if (config.do_jitter) {
|
||||
/* get the jitter */
|
||||
if (verbose) {
|
||||
printf("parsing %s from peer %.2x: ", strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter",
|
||||
printf("parsing %s from peer %.2x: ",
|
||||
strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter",
|
||||
ntohs(peers[i].assoc));
|
||||
}
|
||||
value = np_extract_ntpvar(data, strstr(getvar, "dispersion") != NULL ? "dispersion" : "jitter");
|
||||
value = np_extract_ntpvar(data, strstr(getvar, "dispersion") != NULL ? "dispersion"
|
||||
: "jitter");
|
||||
nptr = NULL;
|
||||
/* Convert the value if we have one */
|
||||
if (value != NULL) {
|
||||
|
|
@ -471,12 +476,15 @@ ntp_request_result ntp_request(const check_ntp_peer_config config) {
|
|||
|
||||
check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {
|
||||
{"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'},
|
||||
{"use-ipv4", no_argument, 0, '4'}, {"use-ipv6", no_argument, 0, '6'}, {"quiet", no_argument, 0, 'q'},
|
||||
{"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, {"swarn", required_argument, 0, 'W'},
|
||||
{"scrit", required_argument, 0, 'C'}, {"jwarn", required_argument, 0, 'j'}, {"jcrit", required_argument, 0, 'k'},
|
||||
{"twarn", required_argument, 0, 'm'}, {"tcrit", required_argument, 0, 'n'}, {"timeout", required_argument, 0, 't'},
|
||||
{"hostname", required_argument, 0, 'H'}, {"port", required_argument, 0, 'p'}, {0, 0, 0, 0}};
|
||||
{"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'},
|
||||
{"verbose", no_argument, 0, 'v'}, {"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'}, {"quiet", no_argument, 0, 'q'},
|
||||
{"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'},
|
||||
{"swarn", required_argument, 0, 'W'}, {"scrit", required_argument, 0, 'C'},
|
||||
{"jwarn", required_argument, 0, 'j'}, {"jcrit", required_argument, 0, 'k'},
|
||||
{"twarn", required_argument, 0, 'm'}, {"tcrit", required_argument, 0, 'n'},
|
||||
{"timeout", required_argument, 0, 't'}, {"hostname", required_argument, 0, 'H'},
|
||||
{"port", required_argument, 0, 'p'}, {0, 0, 0, 0}};
|
||||
|
||||
if (argc < 2) {
|
||||
usage("\n");
|
||||
|
|
@ -489,7 +497,8 @@ check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
while (true) {
|
||||
int option = 0;
|
||||
int option_char = getopt_long(argc, argv, "Vhv46qw:c:W:C:j:k:m:n:t:H:p:", longopts, &option);
|
||||
int option_char =
|
||||
getopt_long(argc, argv, "Vhv46qw:c:W:C:j:k:m:n:t:H:p:", longopts, &option);
|
||||
if (option_char == -1 || option_char == EOF || option_char == 1) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -581,22 +590,24 @@ check_ntp_peer_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
|
||||
char *perfd_offset(double offset, thresholds *offset_thresholds) {
|
||||
return fperfdata("offset", offset, "s", true, offset_thresholds->warning->end, true, offset_thresholds->critical->end, false, 0, false,
|
||||
0);
|
||||
return fperfdata("offset", offset, "s", true, offset_thresholds->warning->end, true,
|
||||
offset_thresholds->critical->end, false, 0, false, 0);
|
||||
}
|
||||
|
||||
char *perfd_jitter(double jitter, bool do_jitter, thresholds *jitter_thresholds) {
|
||||
return fperfdata("jitter", jitter, "", do_jitter, jitter_thresholds->warning->end, do_jitter, jitter_thresholds->critical->end, true, 0,
|
||||
false, 0);
|
||||
return fperfdata("jitter", jitter, "", do_jitter, jitter_thresholds->warning->end, do_jitter,
|
||||
jitter_thresholds->critical->end, true, 0, false, 0);
|
||||
}
|
||||
|
||||
char *perfd_stratum(int stratum, bool do_stratum, thresholds *stratum_thresholds) {
|
||||
return perfdata("stratum", stratum, "", do_stratum, (int)stratum_thresholds->warning->end, do_stratum,
|
||||
(int)stratum_thresholds->critical->end, true, 0, true, 16);
|
||||
return perfdata("stratum", stratum, "", do_stratum, (int)stratum_thresholds->warning->end,
|
||||
do_stratum, (int)stratum_thresholds->critical->end, true, 0, true, 16);
|
||||
}
|
||||
|
||||
char *perfd_truechimers(int num_truechimers, const bool do_truechimers, thresholds *truechimer_thresholds) {
|
||||
return perfdata("truechimers", num_truechimers, "", do_truechimers, (int)truechimer_thresholds->warning->end, do_truechimers,
|
||||
char *perfd_truechimers(int num_truechimers, const bool do_truechimers,
|
||||
thresholds *truechimer_thresholds) {
|
||||
return perfdata("truechimers", num_truechimers, "", do_truechimers,
|
||||
(int)truechimer_thresholds->warning->end, do_truechimers,
|
||||
(int)truechimer_thresholds->critical->end, true, 0, false, 0);
|
||||
}
|
||||
|
||||
|
|
@ -686,9 +697,11 @@ int main(int argc, char *argv[]) {
|
|||
xasprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
|
||||
xasprintf(&perfdata_line, "");
|
||||
} else if (oresult == STATE_WARNING) {
|
||||
xasprintf(&result_line, "%s %s %.10g secs (WARNING)", result_line, _("Offset"), ntp_res.offset);
|
||||
xasprintf(&result_line, "%s %s %.10g secs (WARNING)", result_line, _("Offset"),
|
||||
ntp_res.offset);
|
||||
} else if (oresult == STATE_CRITICAL) {
|
||||
xasprintf(&result_line, "%s %s %.10g secs (CRITICAL)", result_line, _("Offset"), ntp_res.offset);
|
||||
xasprintf(&result_line, "%s %s %.10g secs (CRITICAL)", result_line, _("Offset"),
|
||||
ntp_res.offset);
|
||||
} else {
|
||||
xasprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), ntp_res.offset);
|
||||
}
|
||||
|
|
@ -702,7 +715,8 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
xasprintf(&result_line, "%s, jitter=%f", result_line, ntp_res.jitter);
|
||||
}
|
||||
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(ntp_res.jitter, config.do_jitter, config.jitter_thresholds));
|
||||
xasprintf(&perfdata_line, "%s %s", perfdata_line,
|
||||
perfd_jitter(ntp_res.jitter, config.do_jitter, config.jitter_thresholds));
|
||||
}
|
||||
|
||||
if (config.do_stratum) {
|
||||
|
|
@ -713,19 +727,23 @@ int main(int argc, char *argv[]) {
|
|||
} else {
|
||||
xasprintf(&result_line, "%s, stratum=%li", result_line, ntp_res.stratum);
|
||||
}
|
||||
xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_stratum(ntp_res.stratum, config.do_stratum, config.stratum_thresholds));
|
||||
xasprintf(&perfdata_line, "%s %s", perfdata_line,
|
||||
perfd_stratum(ntp_res.stratum, config.do_stratum, config.stratum_thresholds));
|
||||
}
|
||||
|
||||
if (config.do_truechimers) {
|
||||
if (tresult == STATE_WARNING) {
|
||||
xasprintf(&result_line, "%s, truechimers=%i (WARNING)", result_line, ntp_res.num_truechimers);
|
||||
xasprintf(&result_line, "%s, truechimers=%i (WARNING)", result_line,
|
||||
ntp_res.num_truechimers);
|
||||
} else if (tresult == STATE_CRITICAL) {
|
||||
xasprintf(&result_line, "%s, truechimers=%i (CRITICAL)", result_line, ntp_res.num_truechimers);
|
||||
xasprintf(&result_line, "%s, truechimers=%i (CRITICAL)", result_line,
|
||||
ntp_res.num_truechimers);
|
||||
} else {
|
||||
xasprintf(&result_line, "%s, truechimers=%i", result_line, ntp_res.num_truechimers);
|
||||
}
|
||||
xasprintf(&perfdata_line, "%s %s", perfdata_line,
|
||||
perfd_truechimers(ntp_res.num_truechimers, config.do_truechimers, config.truechimer_thresholds));
|
||||
perfd_truechimers(ntp_res.num_truechimers, config.do_truechimers,
|
||||
config.truechimer_thresholds));
|
||||
}
|
||||
|
||||
printf("%s|%s\n", result_line, perfdata_line);
|
||||
|
|
@ -753,7 +771,8 @@ void print_help(void) {
|
|||
printf(UT_IPv46);
|
||||
printf(UT_HOST_PORT, 'p', "123");
|
||||
printf(" %s\n", "-q, --quiet");
|
||||
printf(" %s\n", _("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized"));
|
||||
printf(" %s\n",
|
||||
_("Returns UNKNOWN instead of CRITICAL or WARNING if server isn't synchronized"));
|
||||
printf(" %s\n", "-w, --warning=THRESHOLD");
|
||||
printf(" %s\n", _("Offset to result in warning status (seconds)"));
|
||||
printf(" %s\n", "-c, --critical=THRESHOLD");
|
||||
|
|
@ -790,7 +809,8 @@ void print_help(void) {
|
|||
printf(" %s\n", _("Simple NTP server check:"));
|
||||
printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1"));
|
||||
printf("\n");
|
||||
printf(" %s\n", _("Check jitter too, avoiding critical notifications if jitter isn't available"));
|
||||
printf(" %s\n",
|
||||
_("Check jitter too, avoiding critical notifications if jitter isn't available"));
|
||||
printf(" %s\n", _("(See Notes above for more details on thresholds formats):"));
|
||||
printf(" %s\n", ("./check_ntp_peer -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200"));
|
||||
printf("\n");
|
||||
|
|
|
|||
|
|
@ -93,9 +93,9 @@ typedef struct {
|
|||
/* bits 1,2 are the leap indicator */
|
||||
#define LI_MASK 0xc0
|
||||
#define LI(x) ((x & LI_MASK) >> 6)
|
||||
#define LI_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 6) & LI_MASK); \
|
||||
#define LI_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 6) & LI_MASK); \
|
||||
} while (0)
|
||||
/* and these are the values of the leap indicator */
|
||||
#define LI_NOWARNING 0x00
|
||||
|
|
@ -105,17 +105,17 @@ typedef struct {
|
|||
/* bits 3,4,5 are the ntp version */
|
||||
#define VN_MASK 0x38
|
||||
#define VN(x) ((x & VN_MASK) >> 3)
|
||||
#define VN_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 3) & VN_MASK); \
|
||||
#define VN_SET(x, y) \
|
||||
do { \
|
||||
x |= ((y << 3) & VN_MASK); \
|
||||
} while (0)
|
||||
#define VN_RESERVED 0x02
|
||||
/* bits 6,7,8 are the ntp mode */
|
||||
#define MODE_MASK 0x07
|
||||
#define MODE(x) (x & MODE_MASK)
|
||||
#define MODE_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & MODE_MASK); \
|
||||
#define MODE_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & MODE_MASK); \
|
||||
} while (0)
|
||||
/* here are some values */
|
||||
#define MODE_CLIENT 0x03
|
||||
|
|
@ -127,9 +127,9 @@ typedef struct {
|
|||
#define REM_MORE 0x20
|
||||
/* In control message, bits 11 - 15 are opcode */
|
||||
#define OP_MASK 0x1f
|
||||
#define OP_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & OP_MASK); \
|
||||
#define OP_SET(x, y) \
|
||||
do { \
|
||||
x |= (y & OP_MASK); \
|
||||
} while (0)
|
||||
#define OP_READSTAT 0x01
|
||||
#define OP_READVAR 0x02
|
||||
|
|
@ -163,32 +163,34 @@ typedef struct {
|
|||
#define NTP32asDOUBLE(x) (ntohs(L16(x)) + ((double)ntohs(R16(x)) / 65536.0))
|
||||
|
||||
/* likewise for a 64-bit ntp fp number */
|
||||
#define NTP64asDOUBLE(n) \
|
||||
(double)(((uint64_t)n) ? (ntohl(L32(n)) - EPOCHDIFF) + (.00000001 * (0.5 + (double)(ntohl(R32(n)) / 42.94967296))) : 0)
|
||||
#define NTP64asDOUBLE(n) \
|
||||
(double)(((uint64_t)n) ? (ntohl(L32(n)) - EPOCHDIFF) + \
|
||||
(.00000001 * (0.5 + (double)(ntohl(R32(n)) / 42.94967296))) \
|
||||
: 0)
|
||||
|
||||
/* convert a struct timeval to a double */
|
||||
#define TVasDOUBLE(x) (double)(x.tv_sec + (0.000001 * x.tv_usec))
|
||||
|
||||
/* convert an ntp 64-bit fp number to a struct timeval */
|
||||
#define NTP64toTV(n, t) \
|
||||
do { \
|
||||
if (!n) \
|
||||
t.tv_sec = t.tv_usec = 0; \
|
||||
else { \
|
||||
t.tv_sec = ntohl(L32(n)) - EPOCHDIFF; \
|
||||
t.tv_usec = (int)(0.5 + (double)(ntohl(R32(n)) / 4294.967296)); \
|
||||
} \
|
||||
#define NTP64toTV(n, t) \
|
||||
do { \
|
||||
if (!n) \
|
||||
t.tv_sec = t.tv_usec = 0; \
|
||||
else { \
|
||||
t.tv_sec = ntohl(L32(n)) - EPOCHDIFF; \
|
||||
t.tv_usec = (int)(0.5 + (double)(ntohl(R32(n)) / 4294.967296)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* convert a struct timeval to an ntp 64-bit fp number */
|
||||
#define TVtoNTP64(t, n) \
|
||||
do { \
|
||||
if (!t.tv_usec && !t.tv_sec) \
|
||||
n = 0x0UL; \
|
||||
else { \
|
||||
L32(n) = htonl(t.tv_sec + EPOCHDIFF); \
|
||||
R32(n) = htonl((uint64_t)((4294.967296 * t.tv_usec) + .5)); \
|
||||
} \
|
||||
#define TVtoNTP64(t, n) \
|
||||
do { \
|
||||
if (!t.tv_usec && !t.tv_sec) \
|
||||
n = 0x0UL; \
|
||||
else { \
|
||||
L32(n) = htonl(t.tv_sec + EPOCHDIFF); \
|
||||
R32(n) = htonl((uint64_t)((4294.967296 * t.tv_usec) + .5)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* NTP control message header is 12 bytes, plus any data in the data
|
||||
|
|
@ -197,15 +199,15 @@ typedef struct {
|
|||
#define SIZEOF_NTPCM(m) (12 + ntohs(m.count) + ((m.count) ? 4 - (ntohs(m.count) % 4) : 0))
|
||||
|
||||
/* finally, a little helper or two for debugging: */
|
||||
#define DBG(x) \
|
||||
do { \
|
||||
if (verbose > 1) { \
|
||||
x; \
|
||||
} \
|
||||
#define DBG(x) \
|
||||
do { \
|
||||
if (verbose > 1) { \
|
||||
x; \
|
||||
} \
|
||||
} while (0);
|
||||
#define PRINTSOCKADDR(x) \
|
||||
do { \
|
||||
printf("%u.%u.%u.%u", (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); \
|
||||
#define PRINTSOCKADDR(x) \
|
||||
do { \
|
||||
printf("%u.%u.%u.%u", (x >> 24) & 0xff, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); \
|
||||
} while (0);
|
||||
|
||||
/* calculate the offset of the local clock */
|
||||
|
|
@ -358,7 +360,8 @@ double offset_request(const char *host, const char *port, mp_state_enum *status,
|
|||
die(STATE_UNKNOWN, "can not allocate socket array");
|
||||
}
|
||||
|
||||
ntp_server_results *servers = (ntp_server_results *)malloc(sizeof(ntp_server_results) * num_hosts);
|
||||
ntp_server_results *servers =
|
||||
(ntp_server_results *)malloc(sizeof(ntp_server_results) * num_hosts);
|
||||
if (servers == NULL) {
|
||||
die(STATE_UNKNOWN, "can not allocate server array");
|
||||
}
|
||||
|
|
@ -585,8 +588,8 @@ check_ntp_time_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
|
||||
char *perfd_offset(double offset, thresholds *offset_thresholds) {
|
||||
return fperfdata("offset", offset, "s", true, offset_thresholds->warning->end, true, offset_thresholds->critical->end, false, 0, false,
|
||||
0);
|
||||
return fperfdata("offset", offset, "s", true, offset_thresholds->warning->end, true,
|
||||
offset_thresholds->critical->end, false, 0, false, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
@ -613,7 +616,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
mp_state_enum offset_result = STATE_OK;
|
||||
mp_state_enum result = STATE_OK;
|
||||
double offset = offset_request(config.server_address, config.port, &offset_result, config.time_offset);
|
||||
double offset =
|
||||
offset_request(config.server_address, config.port, &offset_result, config.time_offset);
|
||||
if (offset_result == STATE_UNKNOWN) {
|
||||
result = ((!config.quiet) ? STATE_UNKNOWN : STATE_CRITICAL);
|
||||
} else {
|
||||
|
|
@ -701,5 +705,6 @@ void print_help(void) {
|
|||
|
||||
void print_usage(void) {
|
||||
printf("%s\n", _("Usage:"));
|
||||
printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose] [-o <time offset>]\n", progname);
|
||||
printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose] [-o <time offset>]\n",
|
||||
progname);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,14 +46,15 @@ const char *email = "devel@monitoring-plugins.org";
|
|||
#define DEFAULT_HOST "127.0.0.1"
|
||||
|
||||
/* return the PSQL server version as a 3-tuple */
|
||||
#define PSQL_SERVER_VERSION3(server_version) \
|
||||
(server_version) / 10000, (server_version) / 100 - (int)((server_version) / 10000) * 100, \
|
||||
#define PSQL_SERVER_VERSION3(server_version) \
|
||||
(server_version) / 10000, (server_version) / 100 - (int)((server_version) / 10000) * 100, \
|
||||
(server_version) - (int)((server_version) / 100) * 100
|
||||
/* return true if the given host is a UNIX domain socket */
|
||||
#define PSQL_IS_UNIX_DOMAIN_SOCKET(host) ((NULL == (host)) || ('\0' == *(host)) || ('/' == *(host)))
|
||||
/* return a 3-tuple identifying a host/port independent of the socket type */
|
||||
#define PSQL_SOCKET3(host, port) \
|
||||
((NULL == (host)) || ('\0' == *(host))) ? DEFAULT_PGSOCKET_DIR : host, PSQL_IS_UNIX_DOMAIN_SOCKET(host) ? "/.s.PGSQL." : ":", port
|
||||
#define PSQL_SOCKET3(host, port) \
|
||||
((NULL == (host)) || ('\0' == *(host))) ? DEFAULT_PGSOCKET_DIR : host, \
|
||||
PSQL_IS_UNIX_DOMAIN_SOCKET(host) ? "/.s.PGSQL." : ":", port
|
||||
|
||||
typedef struct {
|
||||
int errorcode;
|
||||
|
|
@ -63,8 +64,9 @@ static check_pgsql_config_wrapper process_arguments(int /*argc*/, char ** /*argv
|
|||
|
||||
static void print_help(void);
|
||||
static bool is_pg_logname(char * /*username*/);
|
||||
static mp_state_enum do_query(PGconn * /*conn*/, char * /*query*/, const char /*pgqueryname*/[], thresholds * /*qthresholds*/,
|
||||
char * /*query_warning*/, char * /*query_critical*/);
|
||||
static mp_state_enum do_query(PGconn * /*conn*/, char * /*query*/, const char /*pgqueryname*/[],
|
||||
thresholds * /*qthresholds*/, char * /*query_warning*/,
|
||||
char * /*query_critical*/);
|
||||
void print_usage(void);
|
||||
|
||||
static int verbose = 0;
|
||||
|
|
@ -167,7 +169,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (verbose) { /* do not include password (see right below) in output */
|
||||
printf("Connecting to PostgreSQL using conninfo: %s%s\n", conninfo, config.pgpasswd ? " password = <hidden>" : "");
|
||||
printf("Connecting to PostgreSQL using conninfo: %s%s\n", conninfo,
|
||||
config.pgpasswd ? " password = <hidden>" : "");
|
||||
}
|
||||
|
||||
if (config.pgpasswd) {
|
||||
|
|
@ -185,8 +188,8 @@ int main(int argc, char **argv) {
|
|||
--end_timeval.tv_sec;
|
||||
end_timeval.tv_usec += 1000000;
|
||||
}
|
||||
double elapsed_time =
|
||||
(double)(end_timeval.tv_sec - start_timeval.tv_sec) + ((double)(end_timeval.tv_usec - start_timeval.tv_usec) / 1000000.0);
|
||||
double elapsed_time = (double)(end_timeval.tv_sec - start_timeval.tv_sec) +
|
||||
((double)(end_timeval.tv_usec - start_timeval.tv_usec) / 1000000.0);
|
||||
|
||||
if (verbose) {
|
||||
printf("Time elapsed: %f\n", elapsed_time);
|
||||
|
|
@ -218,16 +221,18 @@ int main(int argc, char **argv) {
|
|||
printf("Successfully connected to database %s (user %s) "
|
||||
"at server %s%s%s (server version: %d.%d.%d, "
|
||||
"protocol version: %d, pid: %d)\n",
|
||||
PQdb(conn), PQuser(conn), PSQL_SOCKET3(server_host, PQport(conn)), PSQL_SERVER_VERSION3(server_version),
|
||||
PQprotocolVersion(conn), PQbackendPID(conn));
|
||||
PQdb(conn), PQuser(conn), PSQL_SOCKET3(server_host, PQport(conn)),
|
||||
PSQL_SERVER_VERSION3(server_version), PQprotocolVersion(conn), PQbackendPID(conn));
|
||||
}
|
||||
|
||||
printf(_(" %s - database %s (%f sec.)|%s\n"), state_text(status), config.dbName, elapsed_time,
|
||||
fperfdata("time", elapsed_time, "s", (config.twarn > 0.0), config.twarn, (config.tcrit > 0.0), config.tcrit, true, 0, false, 0));
|
||||
fperfdata("time", elapsed_time, "s", (config.twarn > 0.0), config.twarn,
|
||||
(config.tcrit > 0.0), config.tcrit, true, 0, false, 0));
|
||||
|
||||
mp_state_enum query_status = STATE_UNKNOWN;
|
||||
if (config.pgquery) {
|
||||
query_status = do_query(conn, config.pgquery, config.pgqueryname, config.qthresholds, config.query_warning, config.query_critical);
|
||||
query_status = do_query(conn, config.pgquery, config.pgqueryname, config.qthresholds,
|
||||
config.query_warning, config.query_critical);
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
|
|
@ -265,7 +270,8 @@ check_pgsql_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
while (true) {
|
||||
int option = 0;
|
||||
int option_char = getopt_long(argc, argv, "hVt:c:w:H:P:d:l:p:a:o:q:C:W:v", longopts, &option);
|
||||
int option_char =
|
||||
getopt_long(argc, argv, "hVt:c:w:H:P:d:l:p:a:o:q:C:W:v", longopts, &option);
|
||||
|
||||
if (option_char == EOF) {
|
||||
break;
|
||||
|
|
@ -357,7 +363,8 @@ check_pgsql_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
set_thresholds(&result.config.qthresholds, result.config.query_warning, result.config.query_critical);
|
||||
set_thresholds(&result.config.qthresholds, result.config.query_warning,
|
||||
result.config.query_critical);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -457,29 +464,39 @@ void print_help(void) {
|
|||
|
||||
printf(" %s\n", _("If a query is specified using the -q option, it will be executed after"));
|
||||
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",
|
||||
_("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", _("column in the first row is used as the check result. If a second column is"));
|
||||
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",
|
||||
_("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."));
|
||||
printf(" %s\n\n",
|
||||
_("for details about how to access internal statistics of the database server."));
|
||||
|
||||
printf(" %s\n", _("For a list of available connection parameters which may be used with the -o"));
|
||||
printf(" %s\n", _("command line option, see the documentation for PQconnectdb() in the chapter"));
|
||||
printf(" %s\n",
|
||||
_("For a list of available connection parameters which may be used with the -o"));
|
||||
printf(" %s\n",
|
||||
_("command line option, see the documentation for PQconnectdb() in the chapter"));
|
||||
printf(" %s\n", _("\"libpq - C Library\" of the PostgreSQL manual. For example, this may be"));
|
||||
printf(" %s\n", _("used to specify a service name in pg_service.conf to be used for additional"));
|
||||
printf(" %s\n",
|
||||
_("used to specify a service name in pg_service.conf to be used for additional"));
|
||||
printf(" %s\n", _("connection parameters: -o 'service=<name>' or to specify the SSL mode:"));
|
||||
printf(" %s\n\n", _("-o 'sslmode=require'."));
|
||||
|
||||
printf(" %s\n", _("The plugin will connect to a local postmaster if no host is specified. To"));
|
||||
printf(" %s\n", _("connect to a remote host, be sure that the remote postmaster accepts TCP/IP"));
|
||||
printf(" %s\n",
|
||||
_("connect to a remote host, be sure that the remote postmaster accepts TCP/IP"));
|
||||
printf(" %s\n\n", _("connections (start the postmaster with the -i option)."));
|
||||
|
||||
printf(" %s\n", _("Typically, the monitoring user (unless the --logname option is used) should be"));
|
||||
printf(" %s\n", _("able to connect to the database without a password. The plugin can also send"));
|
||||
printf(" %s\n",
|
||||
_("Typically, the monitoring user (unless the --logname option is used) should be"));
|
||||
printf(" %s\n",
|
||||
_("able to connect to the database without a password. The plugin can also send"));
|
||||
printf(" %s\n", _("a password, but no effort is made to obscure or encrypt the password."));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
@ -492,15 +509,16 @@ void print_usage(void) {
|
|||
"[-q <query>] [-C <critical query range>] [-W <warning query range>]\n");
|
||||
}
|
||||
|
||||
mp_state_enum do_query(PGconn *conn, char *query, const char pgqueryname[], thresholds *qthresholds, char *query_warning,
|
||||
char *query_critical) {
|
||||
mp_state_enum do_query(PGconn *conn, char *query, const char pgqueryname[], thresholds *qthresholds,
|
||||
char *query_warning, char *query_critical) {
|
||||
if (verbose) {
|
||||
printf("Executing SQL query \"%s\".\n", query);
|
||||
}
|
||||
PGresult *res = PQexec(conn, query);
|
||||
|
||||
if (PGRES_TUPLES_OK != PQresultStatus(res)) {
|
||||
printf(_("QUERY %s - %s: %s.\n"), _("CRITICAL"), _("Error with query"), PQerrorMessage(conn));
|
||||
printf(_("QUERY %s - %s: %s.\n"), _("CRITICAL"), _("Error with query"),
|
||||
PQerrorMessage(conn));
|
||||
return STATE_CRITICAL;
|
||||
}
|
||||
|
||||
|
|
@ -548,7 +566,8 @@ mp_state_enum do_query(PGconn *conn, char *query, const char pgqueryname[], thre
|
|||
printf(_("'%s' returned %f"), query, value);
|
||||
}
|
||||
|
||||
printf("|query=%f;%s;%s;;\n", value, query_warning ? query_warning : "", query_critical ? query_critical : "");
|
||||
printf("|query=%f;%s;%s;;\n", value, query_warning ? query_warning : "",
|
||||
query_critical ? query_critical : "");
|
||||
if (PQnfields(res) > 1) {
|
||||
char *extra_info = PQgetvalue(res, 0, 1);
|
||||
if (extra_info != NULL) {
|
||||
|
|
|
|||
|
|
@ -135,7 +135,8 @@ int main(int argc, char **argv) {
|
|||
die(STATE_UNKNOWN, _("CRITICAL - Could not interpret output from ping command\n"));
|
||||
}
|
||||
|
||||
if (pinged.packet_loss >= config.cpl || pinged.round_trip_average >= config.crta || pinged.round_trip_average < 0) {
|
||||
if (pinged.packet_loss >= config.cpl || pinged.round_trip_average >= config.crta ||
|
||||
pinged.round_trip_average < 0) {
|
||||
pinged.state = STATE_CRITICAL;
|
||||
} else if (pinged.packet_loss >= config.wpl || pinged.round_trip_average >= config.wrta) {
|
||||
pinged.state = STATE_WARNING;
|
||||
|
|
@ -151,10 +152,11 @@ int main(int argc, char **argv) {
|
|||
printf("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, config.addresses[i]);
|
||||
}
|
||||
if (pinged.packet_loss == 100) {
|
||||
printf(_("PING %s - %sPacket loss = %d%%"), state_text(pinged.state), warn_text, pinged.packet_loss);
|
||||
printf(_("PING %s - %sPacket loss = %d%%"), state_text(pinged.state), warn_text,
|
||||
pinged.packet_loss);
|
||||
} else {
|
||||
printf(_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"), state_text(pinged.state), warn_text, pinged.packet_loss,
|
||||
pinged.round_trip_average);
|
||||
printf(_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"), state_text(pinged.state),
|
||||
warn_text, pinged.packet_loss, pinged.round_trip_average);
|
||||
}
|
||||
if (config.display_html) {
|
||||
printf("</A>");
|
||||
|
|
@ -162,14 +164,16 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* Print performance data */
|
||||
if (pinged.packet_loss != 100) {
|
||||
printf("|%s", fperfdata("rta", pinged.round_trip_average, "ms", (bool)(config.wrta > 0), config.wrta, (bool)(config.crta > 0),
|
||||
config.crta, true, 0, false, 0));
|
||||
printf("|%s",
|
||||
fperfdata("rta", pinged.round_trip_average, "ms", (bool)(config.wrta > 0),
|
||||
config.wrta, (bool)(config.crta > 0), config.crta, true, 0, false, 0));
|
||||
} else {
|
||||
printf("| rta=U;%f;%f;;", config.wrta, config.crta);
|
||||
}
|
||||
|
||||
printf(" %s\n", perfdata("pl", (long)pinged.packet_loss, "%", (bool)(config.wpl > 0), config.wpl, (bool)(config.cpl > 0),
|
||||
config.cpl, true, 0, false, 0));
|
||||
printf(" %s\n",
|
||||
perfdata("pl", (long)pinged.packet_loss, "%", (bool)(config.wpl > 0), config.wpl,
|
||||
(bool)(config.cpl > 0), config.cpl, true, 0, false, 0));
|
||||
|
||||
if (verbose >= 2) {
|
||||
printf("%f:%d%% %f:%d%%\n", config.wrta, config.wpl, config.crta, config.cpl);
|
||||
|
|
@ -254,7 +258,8 @@ check_ping_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.n_addresses++;
|
||||
if (result.config.n_addresses > max_addr) {
|
||||
max_addr *= 2;
|
||||
result.config.addresses = realloc(result.config.addresses, sizeof(char *) * max_addr);
|
||||
result.config.addresses =
|
||||
realloc(result.config.addresses, sizeof(char *) * max_addr);
|
||||
if (result.config.addresses == NULL) {
|
||||
die(STATE_UNKNOWN, _("Could not realloc() addresses\n"));
|
||||
}
|
||||
|
|
@ -411,13 +416,15 @@ check_ping_config_wrapper validate_arguments(check_ping_config_wrapper config_wr
|
|||
}
|
||||
|
||||
if (config_wrapper.config.wrta > config_wrapper.config.crta) {
|
||||
printf(_("<wrta> (%f) cannot be larger than <crta> (%f)\n"), config_wrapper.config.wrta, config_wrapper.config.crta);
|
||||
printf(_("<wrta> (%f) cannot be larger than <crta> (%f)\n"), config_wrapper.config.wrta,
|
||||
config_wrapper.config.crta);
|
||||
config_wrapper.errorcode = ERROR;
|
||||
return config_wrapper;
|
||||
}
|
||||
|
||||
if (config_wrapper.config.wpl > config_wrapper.config.cpl) {
|
||||
printf(_("<wpl> (%d) cannot be larger than <cpl> (%d)\n"), config_wrapper.config.wpl, config_wrapper.config.cpl);
|
||||
printf(_("<wpl> (%d) cannot be larger than <cpl> (%d)\n"), config_wrapper.config.wpl,
|
||||
config_wrapper.config.cpl);
|
||||
config_wrapper.errorcode = ERROR;
|
||||
return config_wrapper;
|
||||
}
|
||||
|
|
@ -426,7 +433,8 @@ check_ping_config_wrapper validate_arguments(check_ping_config_wrapper config_wr
|
|||
config_wrapper.config.max_packets = DEFAULT_MAX_PACKETS;
|
||||
}
|
||||
|
||||
double max_seconds = (config_wrapper.config.crta / 1000.0 * config_wrapper.config.max_packets) + config_wrapper.config.max_packets;
|
||||
double max_seconds = (config_wrapper.config.crta / 1000.0 * config_wrapper.config.max_packets) +
|
||||
config_wrapper.config.max_packets;
|
||||
if (max_seconds > timeout_interval) {
|
||||
timeout_interval = (unsigned int)max_seconds;
|
||||
}
|
||||
|
|
@ -470,37 +478,70 @@ ping_result run_ping(const char *cmd, const char *addr, double crta) {
|
|||
|
||||
/* get the percent loss statistics */
|
||||
int match = 0;
|
||||
if ((sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) ==
|
||||
1 &&
|
||||
if ((sscanf(
|
||||
buf,
|
||||
"%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n", &result.packet_loss,
|
||||
&match) == 1 &&
|
||||
(sscanf(buf,
|
||||
"%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet "
|
||||
"loss%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n", &result.packet_loss, &match) == 1 &&
|
||||
(sscanf(buf,
|
||||
"%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% packet loss%n", &result.packet_loss, &match) == 1 && match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% loss, time%n", &result.packet_loss, &match) == 1 && match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d received, %d%% loss, time%n", &result.packet_loss, &match) == 1 && match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d received, %d%% packet loss, time%n", &result.packet_loss, &match) == 1 && match) ==
|
||||
1 ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) == 1 &&
|
||||
(sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% packet loss%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n", &result.packet_loss, &match) == 1 &&
|
||||
(sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% loss, time%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d received, %d%% loss, time%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d received, %d%% packet loss, time%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) == 1 ||
|
||||
(sscanf(buf, "%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n",
|
||||
&result.packet_loss, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*[^(](%d%% %*[^)])%n", &result.packet_loss, &match) == 1 && match)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get the round trip average */
|
||||
if ((sscanf(buf, "round-trip min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/mdev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/sdev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/stddev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/std-dev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "round-trip (ms) min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "round-trip (ms) min/avg/max/stddev = %*f/%lf/%*f/%*f%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "rtt min/avg/max/mdev = %*f/%lf/%*f/%*f ms%n", &result.round_trip_average, &match) == 1 && match) ||
|
||||
(sscanf(buf, "%*[^=] = %*fms, %*[^=] = %*fms, %*[^=] = %lfms%n", &result.round_trip_average, &match) == 1 && match)) {
|
||||
if ((sscanf(buf, "round-trip min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average,
|
||||
&match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/mdev = %*f/%lf/%*f/%*f%n",
|
||||
&result.round_trip_average, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/sdev = %*f/%lf/%*f/%*f%n",
|
||||
&result.round_trip_average, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/stddev = %*f/%lf/%*f/%*f%n",
|
||||
&result.round_trip_average, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "round-trip min/avg/max/std-dev = %*f/%lf/%*f/%*f%n",
|
||||
&result.round_trip_average, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "round-trip (ms) min/avg/max = %*f/%lf/%*f%n", &result.round_trip_average,
|
||||
&match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "round-trip (ms) min/avg/max/stddev = %*f/%lf/%*f/%*f%n",
|
||||
&result.round_trip_average, &match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "rtt min/avg/max/mdev = %*f/%lf/%*f/%*f ms%n", &result.round_trip_average,
|
||||
&match) == 1 &&
|
||||
match) ||
|
||||
(sscanf(buf, "%*[^=] = %*fms, %*[^=] = %*fms, %*[^=] = %lfms%n",
|
||||
&result.round_trip_average, &match) == 1 &&
|
||||
match)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
|
@ -513,7 +554,8 @@ ping_result run_ping(const char *cmd, const char *addr, double crta) {
|
|||
/* check stderr, setting at least WARNING if there is output here */
|
||||
/* Add warning into warn_text */
|
||||
while (fgets(buf, MAX_INPUT_BUFFER - 1, child_stderr)) {
|
||||
if (!strstr(buf, "WARNING - no SO_TIMESTAMP support, falling back to SIOCGSTAMP") && !strstr(buf, "Warning: time of day goes back")
|
||||
if (!strstr(buf, "WARNING - no SO_TIMESTAMP support, falling back to SIOCGSTAMP") &&
|
||||
!strstr(buf, "Warning: time of day goes back")
|
||||
|
||||
) {
|
||||
if (verbose >= 3) {
|
||||
|
|
@ -524,7 +566,8 @@ ping_result run_ping(const char *cmd, const char *addr, double crta) {
|
|||
if (warn_text == NULL) {
|
||||
warn_text = strdup(_("System call sent warnings to stderr "));
|
||||
} else {
|
||||
xasprintf(&warn_text, "%s %s", warn_text, _("System call sent warnings to stderr "));
|
||||
xasprintf(&warn_text, "%s %s", warn_text,
|
||||
_("System call sent warnings to stderr "));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -542,7 +585,8 @@ ping_result run_ping(const char *cmd, const char *addr, double crta) {
|
|||
}
|
||||
|
||||
mp_state_enum error_scan(char buf[MAX_INPUT_BUFFER], const char *addr) {
|
||||
if (strstr(buf, "Network is unreachable") || strstr(buf, "Destination Net Unreachable") || strstr(buf, "No route")) {
|
||||
if (strstr(buf, "Network is unreachable") || strstr(buf, "Destination Net Unreachable") ||
|
||||
strstr(buf, "No route")) {
|
||||
die(STATE_CRITICAL, _("CRITICAL - Network Unreachable (%s)\n"), addr);
|
||||
} else if (strstr(buf, "Destination Host Unreachable") || strstr(buf, "Address unreachable")) {
|
||||
die(STATE_CRITICAL, _("CRITICAL - Host Unreachable (%s)\n"), addr);
|
||||
|
|
@ -567,7 +611,8 @@ mp_state_enum error_scan(char buf[MAX_INPUT_BUFFER], const char *addr) {
|
|||
if (strstr(buf, "(DUP!)") || strstr(buf, "DUPLICATES FOUND")) {
|
||||
if (warn_text == NULL) {
|
||||
warn_text = strdup(_(WARN_DUPLICATES));
|
||||
} else if (!strstr(warn_text, _(WARN_DUPLICATES)) && xasprintf(&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1) {
|
||||
} else if (!strstr(warn_text, _(WARN_DUPLICATES)) &&
|
||||
xasprintf(&warn_text, "%s %s", warn_text, _(WARN_DUPLICATES)) == -1) {
|
||||
die(STATE_UNKNOWN, _("Unable to realloc warn_text\n"));
|
||||
}
|
||||
return STATE_WARNING;
|
||||
|
|
@ -613,8 +658,10 @@ void print_help(void) {
|
|||
printf("%s\n", _("percentage of packet loss to trigger an alarm state."));
|
||||
|
||||
printf("\n");
|
||||
printf("%s\n", _("This plugin uses the ping command to probe the specified host for packet loss"));
|
||||
printf("%s\n", _("(percentage) and round trip average (milliseconds). It can produce HTML output."));
|
||||
printf("%s\n",
|
||||
_("This plugin uses the ping command to probe the specified host for packet loss"));
|
||||
printf("%s\n",
|
||||
_("(percentage) and round trip average (milliseconds). It can produce HTML output."));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,8 @@ void print_usage(void);
|
|||
#define EREG_ARGS 1024
|
||||
#define EXCLUDE_PROGS 2048
|
||||
|
||||
#define KTHREAD_PARENT \
|
||||
"kthreadd" /* the parent process of kernel threads: \
|
||||
#define KTHREAD_PARENT \
|
||||
"kthreadd" /* the parent process of kernel threads: \
|
||||
ppid of procs are compared to pid of this proc*/
|
||||
|
||||
static int verbose = 0;
|
||||
|
|
@ -197,14 +197,17 @@ int main(int argc, char **argv) {
|
|||
procseconds = convert_to_seconds(procetime, config.metric);
|
||||
|
||||
if (verbose >= 3) {
|
||||
printf("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", procs, procuid, procvsz,
|
||||
procrss, procpid, procppid, procpcpu, procstat, procetime, procprog, procargs);
|
||||
printf("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s "
|
||||
"prog=%s args=%s\n",
|
||||
procs, procuid, procvsz, procrss, procpid, procppid, procpcpu, procstat,
|
||||
procetime, procprog, procargs);
|
||||
}
|
||||
|
||||
/* Ignore self */
|
||||
int ret = 0;
|
||||
if ((config.usepid && mypid == procpid) ||
|
||||
(((!config.usepid) && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino)) ||
|
||||
(((!config.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");
|
||||
|
|
@ -255,7 +258,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (kthread_ppid == procppid) {
|
||||
if (verbose >= 2) {
|
||||
printf("Ignore kernel thread: pid=%d ppid=%d prog=%s args=%s\n", procpid, procppid, procprog, procargs);
|
||||
printf("Ignore kernel thread: pid=%d ppid=%d prog=%s args=%s\n", procpid,
|
||||
procppid, procprog, procargs);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -267,7 +271,8 @@ int main(int argc, char **argv) {
|
|||
if ((config.options & ARGS) && procargs && (strstr(procargs, config.args) != NULL)) {
|
||||
resultsum |= ARGS;
|
||||
}
|
||||
if ((config.options & EREG_ARGS) && procargs && (regexec(&config.re_args, procargs, (size_t)0, NULL, 0) == 0)) {
|
||||
if ((config.options & EREG_ARGS) && procargs &&
|
||||
(regexec(&config.re_args, procargs, (size_t)0, NULL, 0) == 0)) {
|
||||
resultsum |= EREG_ARGS;
|
||||
}
|
||||
if ((config.options & PROG) && procprog && (strcmp(config.prog, procprog) == 0)) {
|
||||
|
|
@ -298,8 +303,10 @@ int main(int argc, char **argv) {
|
|||
|
||||
procs++;
|
||||
if (verbose >= 2) {
|
||||
printf("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n", procuid, procvsz,
|
||||
procrss, procpid, procppid, procpcpu, procstat, procetime, procprog, procargs);
|
||||
printf("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s "
|
||||
"prog=%s args=%s\n",
|
||||
procuid, procvsz, procrss, procpid, procppid, procpcpu, procstat, procetime,
|
||||
procprog, procargs);
|
||||
}
|
||||
|
||||
mp_state_enum temporary_result = STATE_OK;
|
||||
|
|
@ -318,12 +325,14 @@ int main(int argc, char **argv) {
|
|||
if (config.metric != METRIC_PROCS) {
|
||||
if (temporary_result == STATE_WARNING) {
|
||||
warn++;
|
||||
xasprintf(&config.fails, "%s%s%s", config.fails, (strcmp(config.fails, "") ? ", " : ""), procprog);
|
||||
xasprintf(&config.fails, "%s%s%s", config.fails,
|
||||
(strcmp(config.fails, "") ? ", " : ""), procprog);
|
||||
result = max_state(result, temporary_result);
|
||||
}
|
||||
if (temporary_result == STATE_CRITICAL) {
|
||||
crit++;
|
||||
xasprintf(&config.fails, "%s%s%s", config.fails, (strcmp(config.fails, "") ? ", " : ""), procprog);
|
||||
xasprintf(&config.fails, "%s%s%s", config.fails,
|
||||
(strcmp(config.fails, "") ? ", " : ""), procprog);
|
||||
result = max_state(result, temporary_result);
|
||||
}
|
||||
}
|
||||
|
|
@ -420,7 +429,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
|
||||
while (true) {
|
||||
int option = 0;
|
||||
int option_index = getopt_long(argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T:X:", longopts, &option);
|
||||
int option_index =
|
||||
getopt_long(argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:T:X:", longopts, &option);
|
||||
|
||||
if (option_index == -1 || option_index == EOF) {
|
||||
break;
|
||||
|
|
@ -451,7 +461,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
case 'p': { /* process id */
|
||||
static char tmp[MAX_INPUT_BUFFER];
|
||||
if (sscanf(optarg, "%d%[^0-9]", &result.config.ppid, tmp) == 1) {
|
||||
xasprintf(&result.config.fmt, "%s%sPPID = %d", (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, "%s%sPPID = %d",
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.ppid);
|
||||
result.config.options |= PPID;
|
||||
break;
|
||||
|
|
@ -464,7 +475,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
} else {
|
||||
result.config.statopts = optarg;
|
||||
}
|
||||
xasprintf(&result.config.fmt, _("%s%sSTATE = %s"), (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, _("%s%sSTATE = %s"),
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.statopts);
|
||||
result.config.options |= STAT;
|
||||
break;
|
||||
|
|
@ -488,7 +500,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
|
||||
char *user = pw->pw_name;
|
||||
xasprintf(&result.config.fmt, "%s%sUID = %d (%s)", (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, "%s%sUID = %d (%s)",
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.uid, user);
|
||||
result.config.options |= USER;
|
||||
} break;
|
||||
|
|
@ -499,7 +512,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
} else {
|
||||
result.config.prog = optarg;
|
||||
}
|
||||
xasprintf(&result.config.fmt, _("%s%scommand name '%s'"), (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, _("%s%scommand name '%s'"),
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.prog);
|
||||
result.config.options |= PROG;
|
||||
break;
|
||||
|
|
@ -509,14 +523,17 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
} else {
|
||||
result.config.exclude_progs = optarg;
|
||||
}
|
||||
xasprintf(&result.config.fmt, _("%s%sexclude progs '%s'"), (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, _("%s%sexclude progs '%s'"),
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.exclude_progs);
|
||||
char *tmp_pointer = strtok(result.config.exclude_progs, ",");
|
||||
|
||||
while (tmp_pointer) {
|
||||
result.config.exclude_progs_arr =
|
||||
realloc(result.config.exclude_progs_arr, sizeof(char *) * ++result.config.exclude_progs_counter);
|
||||
result.config.exclude_progs_arr[result.config.exclude_progs_counter - 1] = tmp_pointer;
|
||||
realloc(result.config.exclude_progs_arr,
|
||||
sizeof(char *) * ++result.config.exclude_progs_counter);
|
||||
result.config.exclude_progs_arr[result.config.exclude_progs_counter - 1] =
|
||||
tmp_pointer;
|
||||
tmp_pointer = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
|
|
@ -529,7 +546,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
} else {
|
||||
result.config.args = optarg;
|
||||
}
|
||||
xasprintf(&result.config.fmt, "%s%sargs '%s'", (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, "%s%sargs '%s'",
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.args);
|
||||
result.config.options |= ARGS;
|
||||
break;
|
||||
|
|
@ -539,7 +557,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
if (err != 0) {
|
||||
char errbuf[MAX_INPUT_BUFFER];
|
||||
regerror(err, &result.config.re_args, errbuf, MAX_INPUT_BUFFER);
|
||||
die(STATE_UNKNOWN, "PROCS %s: %s - %s\n", _("UNKNOWN"), _("Could not compile regular expression"), errbuf);
|
||||
die(STATE_UNKNOWN, "PROCS %s: %s - %s\n", _("UNKNOWN"),
|
||||
_("Could not compile regular expression"), errbuf);
|
||||
}
|
||||
/* Strip off any | within the regex optarg */
|
||||
char *temp_string = strdup(optarg);
|
||||
|
|
@ -550,14 +569,16 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
index++;
|
||||
}
|
||||
xasprintf(&result.config.fmt, "%s%sregex args '%s'", (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, "%s%sregex args '%s'",
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), temp_string);
|
||||
result.config.options |= EREG_ARGS;
|
||||
} break;
|
||||
case 'r': { /* RSS */
|
||||
static char tmp[MAX_INPUT_BUFFER];
|
||||
if (sscanf(optarg, "%d%[^0-9]", &result.config.rss, tmp) == 1) {
|
||||
xasprintf(&result.config.fmt, "%s%sRSS >= %d", (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, "%s%sRSS >= %d",
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.rss);
|
||||
result.config.options |= RSS;
|
||||
break;
|
||||
|
|
@ -567,7 +588,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
case 'z': { /* VSZ */
|
||||
static char tmp[MAX_INPUT_BUFFER];
|
||||
if (sscanf(optarg, "%d%[^0-9]", &result.config.vsz, tmp) == 1) {
|
||||
xasprintf(&result.config.fmt, "%s%sVSZ >= %d", (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, "%s%sVSZ >= %d",
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.vsz);
|
||||
result.config.options |= VSZ;
|
||||
break;
|
||||
|
|
@ -578,7 +600,8 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
/* TODO: -P 1.5.5 is accepted */
|
||||
static char tmp[MAX_INPUT_BUFFER];
|
||||
if (sscanf(optarg, "%f%[^0-9.]", &result.config.pcpu, tmp) == 1) {
|
||||
xasprintf(&result.config.fmt, "%s%sPCPU >= %.2f", (result.config.fmt ? result.config.fmt : ""),
|
||||
xasprintf(&result.config.fmt, "%s%sPCPU >= %.2f",
|
||||
(result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.pcpu);
|
||||
result.config.options |= PCPU;
|
||||
break;
|
||||
|
|
@ -633,13 +656,15 @@ check_procs_config_wrapper process_arguments(int argc, char **argv) {
|
|||
}
|
||||
if (result.config.statopts == NULL && argv[index]) {
|
||||
xasprintf(&result.config.statopts, "%s", argv[index++]);
|
||||
xasprintf(&result.config.fmt, _("%s%sSTATE = %s"), (result.config.fmt ? result.config.fmt : ""),
|
||||
(result.config.options ? ", " : ""), result.config.statopts);
|
||||
xasprintf(&result.config.fmt, _("%s%sSTATE = %s"),
|
||||
(result.config.fmt ? result.config.fmt : ""), (result.config.options ? ", " : ""),
|
||||
result.config.statopts);
|
||||
result.config.options |= STAT;
|
||||
}
|
||||
|
||||
/* this will abort in case of invalid ranges */
|
||||
set_thresholds(&result.config.procs_thresholds, result.config.warning_range, result.config.critical_range);
|
||||
set_thresholds(&result.config.procs_thresholds, result.config.warning_range,
|
||||
result.config.critical_range);
|
||||
|
||||
return validate_arguments(result);
|
||||
}
|
||||
|
|
@ -722,13 +747,17 @@ void print_help(void) {
|
|||
printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
|
||||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified"));
|
||||
printf("%s\n", _("metric is outside the required threshold ranges. The metric defaults to number"));
|
||||
printf("%s\n", _("of processes. Search filters can be applied to limit the processes to check."));
|
||||
printf("%s\n",
|
||||
_("Checks all processes and generates WARNING or CRITICAL states if the specified"));
|
||||
printf("%s\n",
|
||||
_("metric is outside the required threshold ranges. The metric defaults to number"));
|
||||
printf("%s\n",
|
||||
_("of processes. Search filters can be applied to limit the processes to check."));
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
printf("%s\n", _("The parent process, check_procs itself and any child process of check_procs (ps)"));
|
||||
printf("%s\n",
|
||||
_("The parent process, check_procs itself and any child process of check_procs (ps)"));
|
||||
printf("%s\n", _("are excluded from any checks to prevent false positives."));
|
||||
|
||||
printf("\n\n");
|
||||
|
|
|
|||
|
|
@ -56,7 +56,8 @@ static check_radius_config_wrapper process_arguments(int /*argc*/, char ** /*arg
|
|||
static void print_help(void);
|
||||
void print_usage(void);
|
||||
|
||||
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
|
||||
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || \
|
||||
defined(HAVE_LIBRADCLI)
|
||||
# define my_rc_conf_str(a) rc_conf_str(rch, a)
|
||||
# if defined(HAVE_LIBRADCLI)
|
||||
# define my_rc_send_server(a, b) rc_send_server(rch, a, b, AUTH)
|
||||
|
|
@ -157,12 +158,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
check_radius_config config = tmp_config.config;
|
||||
|
||||
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
|
||||
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || \
|
||||
defined(HAVE_LIBRADCLI)
|
||||
rc_handle *rch = NULL;
|
||||
#endif
|
||||
|
||||
char *str = strdup("dictionary");
|
||||
if ((config.config_file && my_rc_read_config(config.config_file, &rch)) || my_rc_read_dictionary(my_rc_conf_str(str))) {
|
||||
if ((config.config_file && my_rc_read_config(config.config_file, &rch)) ||
|
||||
my_rc_read_dictionary(my_rc_conf_str(str))) {
|
||||
die(STATE_UNKNOWN, _("Config file error\n"));
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +203,8 @@ int main(int argc, char **argv) {
|
|||
die(STATE_UNKNOWN, _("Invalid NAS-IP-Address\n"));
|
||||
}
|
||||
|
||||
my_rc_buildreq(&data, PW_ACCESS_REQUEST, config.server, config.port, (int)timeout_interval, config.retries);
|
||||
my_rc_buildreq(&data, PW_ACCESS_REQUEST, config.server, config.port, (int)timeout_interval,
|
||||
config.retries);
|
||||
|
||||
#ifdef RC_BUFFER_LEN
|
||||
char msg[RC_BUFFER_LEN];
|
||||
|
|
@ -251,13 +255,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* process command-line arguments */
|
||||
check_radius_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"port", required_argument, 0, 'P'},
|
||||
{"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'},
|
||||
{"nas-id", required_argument, 0, 'n'}, {"nas-ip-address", required_argument, 0, 'N'},
|
||||
{"filename", required_argument, 0, 'F'}, {"expect", required_argument, 0, 'e'},
|
||||
{"retries", required_argument, 0, 'r'}, {"timeout", required_argument, 0, 't'},
|
||||
{"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
||||
static struct option longopts[] = {
|
||||
{"hostname", required_argument, 0, 'H'}, {"port", required_argument, 0, 'P'},
|
||||
{"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'},
|
||||
{"nas-id", required_argument, 0, 'n'}, {"nas-ip-address", required_argument, 0, 'N'},
|
||||
{"filename", required_argument, 0, 'F'}, {"expect", required_argument, 0, 'e'},
|
||||
{"retries", required_argument, 0, 'r'}, {"timeout", required_argument, 0, 't'},
|
||||
{"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
||||
|
||||
check_radius_config_wrapper result = {
|
||||
.errorcode = OK,
|
||||
|
|
@ -397,9 +402,11 @@ void print_help(void) {
|
|||
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"));
|
||||
printf("%s\n",
|
||||
_("password can possibly be determined by careful watching of the command line"));
|
||||
printf("%s\n", _("in a process listing. This risk is exacerbated because the plugin will"));
|
||||
printf("%s\n", _("typically be executed at regular predictable intervals. Please be sure that"));
|
||||
printf("%s\n",
|
||||
_("typically be executed at regular predictable intervals. Please be sure that"));
|
||||
printf("%s\n", _("the password used does not allow access to sensitive system resources."));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
@ -414,7 +421,8 @@ void print_usage(void) {
|
|||
}
|
||||
|
||||
int my_rc_read_config(char *config_file_name, rc_handle **rch) {
|
||||
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || defined(HAVE_LIBRADCLI)
|
||||
#if defined(HAVE_LIBFREERADIUS_CLIENT) || defined(HAVE_LIBRADIUSCLIENT_NG) || \
|
||||
defined(HAVE_LIBRADCLI)
|
||||
*rch = rc_read_config(config_file_name);
|
||||
return (rch == NULL) ? 1 : 0;
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ int main(int argc, char **argv) {
|
|||
/* try to connect to the host at the given port number */
|
||||
int socket;
|
||||
if (my_tcp_connect(config.server_address, config.server_port, &socket) != STATE_OK) {
|
||||
die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), config.server_address, config.server_port);
|
||||
die(STATE_CRITICAL, _("Unable to connect to %s on port %d\n"), config.server_address,
|
||||
config.server_port);
|
||||
}
|
||||
|
||||
/* Part I - Server Check */
|
||||
|
|
@ -166,7 +167,8 @@ int main(int argc, char **argv) {
|
|||
/* Part I - Server Check */
|
||||
|
||||
/* send the DESCRIBE request */
|
||||
sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", config.host_name, config.server_port, config.server_url);
|
||||
sprintf(buffer, "DESCRIBE rtsp://%s:%d%s RTSP/1.0\r\n", config.host_name,
|
||||
config.server_port, config.server_url);
|
||||
|
||||
ssize_t sent_bytes = send(socket, buffer, strlen(buffer), 0);
|
||||
if (sent_bytes == -1) {
|
||||
|
|
@ -200,7 +202,8 @@ int main(int argc, char **argv) {
|
|||
if (config.server_port == PORT) {
|
||||
printf("%s\n", _("Invalid REAL response received from host"));
|
||||
} else {
|
||||
printf(_("Invalid REAL response received from host on port %d\n"), config.server_port);
|
||||
printf(_("Invalid REAL response received from host on port %d\n"),
|
||||
config.server_port);
|
||||
}
|
||||
} else {
|
||||
|
||||
|
|
@ -256,7 +259,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* Put some HTML in here to create a dynamic link */
|
||||
printf(_("REAL %s - %d second response time\n"), state_text(result), (int)(end_time - start_time));
|
||||
printf(_("REAL %s - %d second response time\n"), state_text(result),
|
||||
(int)(end_time - start_time));
|
||||
} else {
|
||||
printf("%s\n", status_line);
|
||||
}
|
||||
|
|
@ -272,12 +276,13 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* process command-line arguments */
|
||||
check_real_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'},
|
||||
{"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'},
|
||||
{"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'},
|
||||
{"warning", required_argument, 0, 'w'}, {"timeout", required_argument, 0, 't'},
|
||||
{"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
||||
static struct option longopts[] = {
|
||||
{"hostname", required_argument, 0, 'H'}, {"IPaddress", required_argument, 0, 'I'},
|
||||
{"expect", required_argument, 0, 'e'}, {"url", required_argument, 0, 'u'},
|
||||
{"port", required_argument, 0, 'p'}, {"critical", required_argument, 0, 'c'},
|
||||
{"warning", required_argument, 0, 'w'}, {"timeout", required_argument, 0, 't'},
|
||||
{"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'}, {0, 0, 0, 0}};
|
||||
|
||||
check_real_config_wrapper result = {
|
||||
.errorcode = OK,
|
||||
|
|
@ -427,7 +432,8 @@ void print_help(void) {
|
|||
printf("%s\n", _("This plugin will attempt to open an RTSP connection with the host."));
|
||||
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",
|
||||
_("but incorrect response messages from the host result in STATE_WARNING return"));
|
||||
printf("%s\n", _("values."));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ typedef struct {
|
|||
} check_smtp_config_wrapper;
|
||||
static check_smtp_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
|
||||
|
||||
int my_recv(check_smtp_config config, void *buf, int num, int socket_descriptor, bool ssl_established) {
|
||||
int my_recv(check_smtp_config config, void *buf, int num, int socket_descriptor,
|
||||
bool ssl_established) {
|
||||
#ifdef HAVE_SSL
|
||||
if ((config.use_starttls || config.use_ssl) && ssl_established) {
|
||||
return np_net_ssl_read(buf, num);
|
||||
|
|
@ -69,7 +70,8 @@ int my_recv(check_smtp_config config, void *buf, int num, int socket_descriptor,
|
|||
#endif
|
||||
}
|
||||
|
||||
int my_send(check_smtp_config config, void *buf, int num, int socket_descriptor, bool ssl_established) {
|
||||
int my_send(check_smtp_config config, void *buf, int num, int socket_descriptor,
|
||||
bool ssl_established) {
|
||||
#ifdef HAVE_SSL
|
||||
if ((config.use_starttls || config.use_ssl) && ssl_established) {
|
||||
|
||||
|
|
@ -83,10 +85,12 @@ int my_send(check_smtp_config config, void *buf, int num, int socket_descriptor,
|
|||
|
||||
static void print_help(void);
|
||||
void print_usage(void);
|
||||
static char *smtp_quit(check_smtp_config /*config*/, char /*buffer*/[MAX_INPUT_BUFFER], int /*socket_descriptor*/,
|
||||
bool /*ssl_established*/);
|
||||
static int recvline(char * /*buf*/, size_t /*bufsize*/, check_smtp_config /*config*/, int /*socket_descriptor*/, bool /*ssl_established*/);
|
||||
static int recvlines(check_smtp_config /*config*/, char * /*buf*/, size_t /*bufsize*/, int /*socket_descriptor*/, bool /*ssl_established*/);
|
||||
static char *smtp_quit(check_smtp_config /*config*/, char /*buffer*/[MAX_INPUT_BUFFER],
|
||||
int /*socket_descriptor*/, bool /*ssl_established*/);
|
||||
static int recvline(char * /*buf*/, size_t /*bufsize*/, check_smtp_config /*config*/,
|
||||
int /*socket_descriptor*/, bool /*ssl_established*/);
|
||||
static int recvlines(check_smtp_config /*config*/, char * /*buf*/, size_t /*bufsize*/,
|
||||
int /*socket_descriptor*/, bool /*ssl_established*/);
|
||||
static int my_close(int /*socket_descriptor*/);
|
||||
|
||||
static int verbose = 0;
|
||||
|
|
@ -158,7 +162,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
int socket_descriptor = 0;
|
||||
/* try to connect to the host at the given port number */
|
||||
mp_state_enum result = my_tcp_connect(config.server_address, config.server_port, &socket_descriptor);
|
||||
mp_state_enum result =
|
||||
my_tcp_connect(config.server_address, config.server_port, &socket_descriptor);
|
||||
|
||||
char *error_msg = "";
|
||||
char buffer[MAX_INPUT_BUFFER];
|
||||
|
|
@ -174,7 +179,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
#ifdef HAVE_SSL
|
||||
if (config.use_ssl) {
|
||||
result = np_net_ssl_init_with_hostname(socket_descriptor, (config.use_sni ? config.server_address : NULL));
|
||||
result = np_net_ssl_init_with_hostname(socket_descriptor,
|
||||
(config.use_sni ? config.server_address : NULL));
|
||||
if (result != STATE_OK) {
|
||||
printf(_("CRITICAL - Cannot create SSL context.\n"));
|
||||
close(socket_descriptor);
|
||||
|
|
@ -223,14 +229,16 @@ int main(int argc, char **argv) {
|
|||
/* send the STARTTLS command */
|
||||
send(socket_descriptor, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0);
|
||||
|
||||
recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established); /* wait for it */
|
||||
recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor,
|
||||
ssl_established); /* wait for it */
|
||||
if (!strstr(buffer, SMTP_EXPECT)) {
|
||||
printf(_("Server does not support STARTTLS\n"));
|
||||
smtp_quit(config, buffer, socket_descriptor, ssl_established);
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
|
||||
result = np_net_ssl_init_with_hostname(socket_descriptor, (config.use_sni ? config.server_address : NULL));
|
||||
result = np_net_ssl_init_with_hostname(socket_descriptor,
|
||||
(config.use_sni ? config.server_address : NULL));
|
||||
if (result != STATE_OK) {
|
||||
printf(_("CRITICAL - Cannot create SSL context.\n"));
|
||||
close(socket_descriptor);
|
||||
|
|
@ -251,7 +259,8 @@ int main(int argc, char **argv) {
|
|||
* reason, some MTAs will not allow an AUTH LOGIN command before
|
||||
* we resent EHLO via TLS.
|
||||
*/
|
||||
if (my_send(config, helocmd, strlen(helocmd), socket_descriptor, ssl_established) <= 0) {
|
||||
if (my_send(config, helocmd, strlen(helocmd), socket_descriptor, ssl_established) <=
|
||||
0) {
|
||||
printf("%s\n", _("SMTP UNKNOWN - Cannot send EHLO command via TLS."));
|
||||
my_close(socket_descriptor);
|
||||
exit(STATE_UNKNOWN);
|
||||
|
|
@ -261,7 +270,8 @@ int main(int argc, char **argv) {
|
|||
printf(_("sent %s"), helocmd);
|
||||
}
|
||||
|
||||
if (recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established) <= 0) {
|
||||
if (recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established) <=
|
||||
0) {
|
||||
printf("%s\n", _("SMTP UNKNOWN - Cannot read EHLO response via TLS."));
|
||||
my_close(socket_descriptor);
|
||||
exit(STATE_UNKNOWN);
|
||||
|
|
@ -273,7 +283,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
# ifdef USE_OPENSSL
|
||||
if (config.check_cert) {
|
||||
result = np_net_ssl_check_cert(config.days_till_exp_warn, config.days_till_exp_crit);
|
||||
result =
|
||||
np_net_ssl_check_cert(config.days_till_exp_warn, config.days_till_exp_crit);
|
||||
smtp_quit(config, buffer, socket_descriptor, ssl_established);
|
||||
my_close(socket_descriptor);
|
||||
exit(result);
|
||||
|
|
@ -296,14 +307,17 @@ int main(int argc, char **argv) {
|
|||
if (config.server_port == SMTP_PORT) {
|
||||
printf(_("Invalid SMTP response received from host: %s\n"), server_response);
|
||||
} else {
|
||||
printf(_("Invalid SMTP response received from host on port %d: %s\n"), config.server_port, server_response);
|
||||
printf(_("Invalid SMTP response received from host on port %d: %s\n"),
|
||||
config.server_port, server_response);
|
||||
}
|
||||
exit(STATE_WARNING);
|
||||
}
|
||||
|
||||
if (config.send_mail_from) {
|
||||
my_send(config, cmd_str, (int)strlen(cmd_str), socket_descriptor, ssl_established);
|
||||
if (recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established) >= 1 && verbose) {
|
||||
if (recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established) >=
|
||||
1 &&
|
||||
verbose) {
|
||||
printf("%s", buffer);
|
||||
}
|
||||
}
|
||||
|
|
@ -312,7 +326,9 @@ int main(int argc, char **argv) {
|
|||
while (counter < config.ncommands) {
|
||||
xasprintf(&cmd_str, "%s%s", config.commands[counter], "\r\n");
|
||||
my_send(config, cmd_str, (int)strlen(cmd_str), socket_descriptor, ssl_established);
|
||||
if (recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established) >= 1 && verbose) {
|
||||
if (recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established) >=
|
||||
1 &&
|
||||
verbose) {
|
||||
printf("%s", buffer);
|
||||
}
|
||||
strip(buffer);
|
||||
|
|
@ -334,7 +350,8 @@ int main(int argc, char **argv) {
|
|||
result = STATE_OK;
|
||||
} else if (excode == REG_NOMATCH) {
|
||||
result = STATE_WARNING;
|
||||
printf(_("SMTP %s - Invalid response '%s' to command '%s'\n"), state_text(result), buffer, config.commands[counter]);
|
||||
printf(_("SMTP %s - Invalid response '%s' to command '%s'\n"),
|
||||
state_text(result), buffer, config.commands[counter]);
|
||||
} else {
|
||||
regerror(excode, &preg, errbuf, MAX_INPUT_BUFFER);
|
||||
printf(_("Execute Error: %s\n"), errbuf);
|
||||
|
|
@ -361,12 +378,14 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
/* send AUTH LOGIN */
|
||||
my_send(config, SMTP_AUTH_LOGIN, strlen(SMTP_AUTH_LOGIN), socket_descriptor, ssl_established);
|
||||
my_send(config, SMTP_AUTH_LOGIN, strlen(SMTP_AUTH_LOGIN), socket_descriptor,
|
||||
ssl_established);
|
||||
if (verbose) {
|
||||
printf(_("sent %s\n"), "AUTH LOGIN");
|
||||
}
|
||||
|
||||
if ((ret = recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established)) <= 0) {
|
||||
if ((ret = recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor,
|
||||
ssl_established)) <= 0) {
|
||||
xasprintf(&error_msg, _("recv() failed after AUTH LOGIN, "));
|
||||
result = STATE_WARNING;
|
||||
break;
|
||||
|
|
@ -389,7 +408,8 @@ int main(int argc, char **argv) {
|
|||
printf(_("sent %s\n"), abuf);
|
||||
}
|
||||
|
||||
if ((ret = recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established)) <= 0) {
|
||||
if ((ret = recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor,
|
||||
ssl_established)) <= 0) {
|
||||
result = STATE_CRITICAL;
|
||||
xasprintf(&error_msg, _("recv() failed after sending authuser, "));
|
||||
break;
|
||||
|
|
@ -409,7 +429,8 @@ int main(int argc, char **argv) {
|
|||
if (verbose) {
|
||||
printf(_("sent %s\n"), abuf);
|
||||
}
|
||||
if ((ret = recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor, ssl_established)) <= 0) {
|
||||
if ((ret = recvlines(config, buffer, MAX_INPUT_BUFFER, socket_descriptor,
|
||||
ssl_established)) <= 0) {
|
||||
result = STATE_CRITICAL;
|
||||
xasprintf(&error_msg, _("recv() failed after sending authpass, "));
|
||||
break;
|
||||
|
|
@ -451,10 +472,10 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
printf(_("SMTP %s - %s%.3f sec. response time%s%s|%s\n"), state_text(result), error_msg, elapsed_time, verbose ? ", " : "",
|
||||
verbose ? buffer : "",
|
||||
fperfdata("time", elapsed_time, "s", config.check_warning_time, config.warning_time, config.check_critical_time,
|
||||
config.critical_time, true, 0, false, 0));
|
||||
printf(_("SMTP %s - %s%.3f sec. response time%s%s|%s\n"), state_text(result), error_msg,
|
||||
elapsed_time, verbose ? ", " : "", verbose ? buffer : "",
|
||||
fperfdata("time", elapsed_time, "s", config.check_warning_time, config.warning_time,
|
||||
config.check_critical_time, config.critical_time, true, 0, false, 0));
|
||||
|
||||
exit(result);
|
||||
}
|
||||
|
|
@ -519,7 +540,8 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
|
|||
bool implicit_tls = false;
|
||||
int server_port_option = 0;
|
||||
while (true) {
|
||||
int opt_index = getopt_long(argc, argv, "+hVv46Lrt:p:f:e:c:w:H:C:R:sSD:F:A:U:P:q", longopts, &option);
|
||||
int opt_index =
|
||||
getopt_long(argc, argv, "+hVv46Lrt:p:f:e:c:w:H:C:R:sSD:F:A:U:P:q", longopts, &option);
|
||||
|
||||
if (opt_index == -1 || opt_index == EOF) {
|
||||
break;
|
||||
|
|
@ -546,7 +568,8 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
case 'f': /* from argument */
|
||||
result.config.from_arg = optarg + strspn(optarg, "<");
|
||||
result.config.from_arg = strndup(result.config.from_arg, strcspn(result.config.from_arg, ">"));
|
||||
result.config.from_arg =
|
||||
strndup(result.config.from_arg, strcspn(result.config.from_arg, ">"));
|
||||
result.config.send_mail_from = true;
|
||||
break;
|
||||
case 'A':
|
||||
|
|
@ -565,9 +588,11 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
|
|||
case 'C': /* commands */
|
||||
if (result.config.ncommands >= command_size) {
|
||||
command_size += 8;
|
||||
result.config.commands = realloc(result.config.commands, sizeof(char *) * command_size);
|
||||
result.config.commands =
|
||||
realloc(result.config.commands, sizeof(char *) * command_size);
|
||||
if (result.config.commands == NULL) {
|
||||
die(STATE_UNKNOWN, _("Could not realloc() units [%d]\n"), result.config.ncommands);
|
||||
die(STATE_UNKNOWN, _("Could not realloc() units [%d]\n"),
|
||||
result.config.ncommands);
|
||||
}
|
||||
}
|
||||
result.config.commands[result.config.ncommands] = (char *)malloc(sizeof(char) * 255);
|
||||
|
|
@ -577,9 +602,11 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
|
|||
case 'R': /* server responses */
|
||||
if (result.config.nresponses >= response_size) {
|
||||
response_size += 8;
|
||||
result.config.responses = realloc(result.config.responses, sizeof(char *) * response_size);
|
||||
result.config.responses =
|
||||
realloc(result.config.responses, sizeof(char *) * response_size);
|
||||
if (result.config.responses == NULL) {
|
||||
die(STATE_UNKNOWN, _("Could not realloc() units [%d]\n"), result.config.nresponses);
|
||||
die(STATE_UNKNOWN, _("Could not realloc() units [%d]\n"),
|
||||
result.config.nresponses);
|
||||
}
|
||||
}
|
||||
result.config.responses[result.config.nresponses] = (char *)malloc(sizeof(char) * 255);
|
||||
|
|
@ -718,8 +745,10 @@ check_smtp_config_wrapper process_arguments(int argc, char **argv) {
|
|||
return result;
|
||||
}
|
||||
|
||||
char *smtp_quit(check_smtp_config config, char buffer[MAX_INPUT_BUFFER], int socket_descriptor, bool ssl_established) {
|
||||
int sent_bytes = my_send(config, SMTP_QUIT, strlen(SMTP_QUIT), socket_descriptor, ssl_established);
|
||||
char *smtp_quit(check_smtp_config config, char buffer[MAX_INPUT_BUFFER], int socket_descriptor,
|
||||
bool ssl_established) {
|
||||
int sent_bytes =
|
||||
my_send(config, SMTP_QUIT, strlen(SMTP_QUIT), socket_descriptor, ssl_established);
|
||||
if (sent_bytes < 0) {
|
||||
if (config.ignore_send_quit_failure) {
|
||||
if (verbose) {
|
||||
|
|
@ -759,7 +788,8 @@ char *smtp_quit(check_smtp_config config, char buffer[MAX_INPUT_BUFFER], int soc
|
|||
* function which buffers the data, move that to netutils.c and change
|
||||
* check_smtp and other plugins to use that. Also, remove (\r)\n.
|
||||
*/
|
||||
int recvline(char *buf, size_t bufsize, check_smtp_config config, int socket_descriptor, bool ssl_established) {
|
||||
int recvline(char *buf, size_t bufsize, check_smtp_config config, int socket_descriptor,
|
||||
bool ssl_established) {
|
||||
int result;
|
||||
int counter;
|
||||
|
||||
|
|
@ -789,13 +819,16 @@ int recvline(char *buf, size_t bufsize, check_smtp_config config, int socket_des
|
|||
*
|
||||
* TODO: Move this to netutils.c. Also, remove \r and possibly the final \n.
|
||||
*/
|
||||
int recvlines(check_smtp_config config, char *buf, size_t bufsize, int socket_descriptor, bool ssl_established) {
|
||||
int recvlines(check_smtp_config config, char *buf, size_t bufsize, int socket_descriptor,
|
||||
bool ssl_established) {
|
||||
int result;
|
||||
int counter;
|
||||
|
||||
for (counter = 0; /* forever */; counter += result) {
|
||||
if (!((result = recvline(buf + counter, bufsize - counter, config, socket_descriptor, ssl_established)) > 3 &&
|
||||
isdigit((int)buf[counter]) && isdigit((int)buf[counter + 1]) && isdigit((int)buf[counter + 2]) && buf[counter + 3] == '-')) {
|
||||
if (!((result = recvline(buf + counter, bufsize - counter, config, socket_descriptor,
|
||||
ssl_established)) > 3 &&
|
||||
isdigit((int)buf[counter]) && isdigit((int)buf[counter + 1]) &&
|
||||
isdigit((int)buf[counter + 2]) && buf[counter + 3] == '-')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -835,13 +868,15 @@ void print_help(void) {
|
|||
printf(UT_IPv46);
|
||||
|
||||
printf(" %s\n", "-e, --expect=STRING");
|
||||
printf(_(" String to expect in first line of server response (default: '%s')\n"), SMTP_EXPECT);
|
||||
printf(_(" String to expect in first line of server response (default: '%s')\n"),
|
||||
SMTP_EXPECT);
|
||||
printf(" %s\n", "-C, --command=STRING");
|
||||
printf(" %s\n", _("SMTP command (may be used repeatedly)"));
|
||||
printf(" %s\n", "-R, --response=STRING");
|
||||
printf(" %s\n", _("Expected response to command (may be used repeatedly)"));
|
||||
printf(" %s\n", "-f, --from=STRING");
|
||||
printf(" %s\n", _("FROM-address to include in MAIL command, required by Exchange 2000")), printf(" %s\n", "-F, --fqdn=STRING");
|
||||
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."));
|
||||
|
|
@ -885,7 +920,9 @@ void print_help(void) {
|
|||
|
||||
void 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("%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]] [-r] [--sni] [-v] \n");
|
||||
printf("[-F fqdn] [-S] [-L] [-D warn days cert expire[,crit days cert expire]] [-r] [--sni] "
|
||||
"[-v] \n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,7 +172,8 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (config.warn_is_set) {
|
||||
if ((config.warn.is_percentage && (percent_used >= (100 - (double)config.warn.value))) || config.warn.value >= data.metrics.free) {
|
||||
if ((config.warn.is_percentage && (percent_used >= (100 - (double)config.warn.value))) ||
|
||||
config.warn.value >= data.metrics.free) {
|
||||
sc1 = mp_set_subcheck_state(sc1, STATE_WARNING);
|
||||
}
|
||||
}
|
||||
|
|
@ -182,13 +183,14 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (config.crit_is_set) {
|
||||
if ((config.crit.is_percentage && (percent_used >= (100 - (double)config.crit.value))) || config.crit.value >= data.metrics.free) {
|
||||
if ((config.crit.is_percentage && (percent_used >= (100 - (double)config.crit.value))) ||
|
||||
config.crit.value >= data.metrics.free) {
|
||||
sc1 = mp_set_subcheck_state(sc1, STATE_CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
xasprintf(&sc1.output, _("%g%% free (%lluMiB out of %lluMiB)"), (100 - percent_used), data.metrics.free >> 20,
|
||||
data.metrics.total >> 20);
|
||||
xasprintf(&sc1.output, _("%g%% free (%lluMiB out of %lluMiB)"), (100 - percent_used),
|
||||
data.metrics.free >> 20, data.metrics.total >> 20);
|
||||
|
||||
overall.summary = "Swap";
|
||||
mp_add_subcheck_to_check(&overall, sc1);
|
||||
|
|
@ -201,7 +203,9 @@ int check_swap(float free_swap_mb, float total_swap_mb, swap_config config) {
|
|||
return config.no_swap_state;
|
||||
}
|
||||
|
||||
uint64_t free_swap = (uint64_t)(free_swap_mb * (1024 * 1024)); /* Convert back to bytes as warn and crit specified in bytes */
|
||||
uint64_t free_swap =
|
||||
(uint64_t)(free_swap_mb *
|
||||
(1024 * 1024)); /* Convert back to bytes as warn and crit specified in bytes */
|
||||
|
||||
if (!config.crit.is_percentage && config.crit.value >= free_swap) {
|
||||
return STATE_CRITICAL;
|
||||
|
|
@ -210,13 +214,16 @@ int check_swap(float free_swap_mb, float total_swap_mb, swap_config config) {
|
|||
return STATE_WARNING;
|
||||
}
|
||||
|
||||
uint64_t usage_percentage = (uint64_t)((total_swap_mb - free_swap_mb) / total_swap_mb) * HUNDRED_PERCENT;
|
||||
uint64_t usage_percentage =
|
||||
(uint64_t)((total_swap_mb - free_swap_mb) / total_swap_mb) * HUNDRED_PERCENT;
|
||||
|
||||
if (config.crit.is_percentage && config.crit.value != 0 && usage_percentage >= (HUNDRED_PERCENT - config.crit.value)) {
|
||||
if (config.crit.is_percentage && config.crit.value != 0 &&
|
||||
usage_percentage >= (HUNDRED_PERCENT - config.crit.value)) {
|
||||
return STATE_CRITICAL;
|
||||
}
|
||||
|
||||
if (config.warn.is_percentage && config.warn.value != 0 && usage_percentage >= (HUNDRED_PERCENT - config.warn.value)) {
|
||||
if (config.warn.is_percentage && config.warn.value != 0 &&
|
||||
usage_percentage >= (HUNDRED_PERCENT - config.warn.value)) {
|
||||
return STATE_WARNING;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ swap_config swap_config_init(void);
|
|||
|
||||
swap_result get_swap_data(swap_config config);
|
||||
swap_result getSwapFromProcMeminfo(char path_to_proc_meminfo[]);
|
||||
swap_result getSwapFromSwapCommand(swap_config config, const char swap_command[], const char swap_format[]);
|
||||
swap_result getSwapFromSwapCommand(swap_config config, const char swap_command[],
|
||||
const char swap_format[]);
|
||||
swap_result getSwapFromSwapctl_BSD(swap_config config);
|
||||
swap_result getSwapFromSwap_SRV4(swap_config config);
|
||||
|
|
|
|||
|
|
@ -95,12 +95,14 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) {
|
|||
* 123 123" which exists on NetBSD (at least),
|
||||
* The unit should be Bytes
|
||||
*/
|
||||
if (sscanf(input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lu %lu %lu", &swap_total, &swap_used, &swap_free) == 3) {
|
||||
if (sscanf(input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lu %lu %lu", &swap_total, &swap_used,
|
||||
&swap_free) == 3) {
|
||||
found_total = true;
|
||||
found_free = true;
|
||||
// Set error
|
||||
result.errorcode = STATE_OK;
|
||||
// Break out of fgets here, since both scanf expressions might match (NetBSD for example)
|
||||
// Break out of fgets here, since both scanf expressions might match (NetBSD for
|
||||
// example)
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +151,8 @@ swap_result getSwapFromProcMeminfo(char proc_meminfo[]) {
|
|||
return result;
|
||||
}
|
||||
|
||||
swap_result getSwapFromSwapCommand(swap_config config, const char swap_command[], const char swap_format[]) {
|
||||
swap_result getSwapFromSwapCommand(swap_config config, const char swap_command[],
|
||||
const char swap_format[]) {
|
||||
swap_result result = {0};
|
||||
|
||||
char *temp_buffer;
|
||||
|
|
@ -212,7 +215,8 @@ swap_result getSwapFromSwapCommand(swap_config config, const char swap_command[]
|
|||
used_swap_mb = total_swap_mb - free_swap_mb;
|
||||
|
||||
if (verbose >= 3) {
|
||||
printf(_("total=%.0f, used=%.0f, free=%.0f\n"), total_swap_mb, used_swap_mb, free_swap_mb);
|
||||
printf(_("total=%.0f, used=%.0f, free=%.0f\n"), total_swap_mb, used_swap_mb,
|
||||
free_swap_mb);
|
||||
}
|
||||
} else {
|
||||
while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process)) {
|
||||
|
|
@ -398,7 +402,8 @@ swap_result getSwapFromSwap_SRV4(swap_config config) {
|
|||
}
|
||||
|
||||
/* initialize swap table + entries */
|
||||
swaptbl_t *tbl = (swaptbl_t *)malloc(sizeof(swaptbl_t) + (sizeof(swapent_t) * (unsigned long)nswaps));
|
||||
swaptbl_t *tbl =
|
||||
(swaptbl_t *)malloc(sizeof(swaptbl_t) + (sizeof(swapent_t) * (unsigned long)nswaps));
|
||||
|
||||
if (tbl == NULL) {
|
||||
die(STATE_UNKNOWN, _("malloc() failed!\n"));
|
||||
|
|
@ -433,7 +438,8 @@ swap_result getSwapFromSwap_SRV4(swap_config config) {
|
|||
dskused_mb = (dsktotal_mb - dskfree_mb);
|
||||
|
||||
if (verbose >= 3) {
|
||||
printf("dsktotal_mb=%.0f dskfree_mb=%.0f dskused_mb=%.0f\n", dsktotal_mb, dskfree_mb, dskused_mb);
|
||||
printf("dsktotal_mb=%.0f dskfree_mb=%.0f dskused_mb=%.0f\n", dsktotal_mb, dskfree_mb,
|
||||
dskused_mb);
|
||||
}
|
||||
|
||||
if (config.allswaps && dsktotal_mb > 0) {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ typedef struct {
|
|||
int errorcode;
|
||||
check_tcp_config config;
|
||||
} check_tcp_config_wrapper;
|
||||
static check_tcp_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/, check_tcp_config /*config*/);
|
||||
static check_tcp_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/,
|
||||
check_tcp_config /*config*/);
|
||||
void print_help(const char *service);
|
||||
void print_usage(void);
|
||||
|
||||
|
|
@ -137,7 +138,8 @@ int main(int argc, char **argv) {
|
|||
config.server_expect[0] = "220";
|
||||
config.quit = "QUIT\r\n";
|
||||
config.server_port = DEFAULT_FTP_PORT;
|
||||
} else if (!strncmp(config.service, "POP", strlen("POP")) || !strncmp(config.service, "POP3", strlen("POP3"))) {
|
||||
} else if (!strncmp(config.service, "POP", strlen("POP")) ||
|
||||
!strncmp(config.service, "POP3", strlen("POP3"))) {
|
||||
config.server_expect[0] = "+OK";
|
||||
config.quit = "QUIT\r\n";
|
||||
config.server_port = DEFAULT_POP_PORT;
|
||||
|
|
@ -167,7 +169,8 @@ int main(int argc, char **argv) {
|
|||
config.use_tls = true;
|
||||
config.server_port = DEFAULT_SSMTP_PORT;
|
||||
} else if (!strncmp(config.service, "JABBER", strlen("JABBER"))) {
|
||||
config.send = "<stream:stream to=\'host\' xmlns=\'jabber:client\' xmlns:stream=\'http://etherx.jabber.org/streams\'>\n";
|
||||
config.send = "<stream:stream to=\'host\' xmlns=\'jabber:client\' "
|
||||
"xmlns:stream=\'http://etherx.jabber.org/streams\'>\n";
|
||||
config.server_expect[0] = "<?xml version=\'1.0\'";
|
||||
config.quit = "</stream:stream>\n";
|
||||
config.hide_output = true;
|
||||
|
|
@ -246,46 +249,58 @@ int main(int argc, char **argv) {
|
|||
mp_subcheck inital_connect_result = mp_subcheck_init();
|
||||
|
||||
// Try initial connection
|
||||
if (np_net_connect(config.server_address, config.server_port, &socket_descriptor, config.protocol) == STATE_CRITICAL) {
|
||||
if (np_net_connect(config.server_address, config.server_port, &socket_descriptor,
|
||||
config.protocol) == STATE_CRITICAL) {
|
||||
// Early exit here, we got connection refused
|
||||
inital_connect_result = mp_set_subcheck_state(inital_connect_result, config.econn_refuse_state);
|
||||
xasprintf(&inital_connect_result.output, "Connection to %s on port %i was REFUSED", config.server_address, config.server_port);
|
||||
inital_connect_result =
|
||||
mp_set_subcheck_state(inital_connect_result, config.econn_refuse_state);
|
||||
xasprintf(&inital_connect_result.output, "Connection to %s on port %i was REFUSED",
|
||||
config.server_address, config.server_port);
|
||||
mp_add_subcheck_to_check(&overall, inital_connect_result);
|
||||
mp_exit(overall);
|
||||
} else {
|
||||
inital_connect_result = mp_set_subcheck_state(inital_connect_result, STATE_OK);
|
||||
xasprintf(&inital_connect_result.output, "Connection to %s on port %i was a SUCCESS", config.server_address, config.server_port);
|
||||
xasprintf(&inital_connect_result.output, "Connection to %s on port %i was a SUCCESS",
|
||||
config.server_address, config.server_port);
|
||||
mp_add_subcheck_to_check(&overall, inital_connect_result);
|
||||
}
|
||||
|
||||
#ifdef HAVE_SSL
|
||||
if (config.use_tls) {
|
||||
mp_subcheck tls_connection_result = mp_subcheck_init();
|
||||
mp_state_enum result = np_net_ssl_init_with_hostname(socket_descriptor, (config.sni_specified ? config.sni : NULL));
|
||||
mp_state_enum result = np_net_ssl_init_with_hostname(
|
||||
socket_descriptor, (config.sni_specified ? config.sni : NULL));
|
||||
tls_connection_result = mp_set_subcheck_default_state(tls_connection_result, result);
|
||||
|
||||
if (result == STATE_OK) {
|
||||
xasprintf(&tls_connection_result.output, "TLS connection succeeded");
|
||||
|
||||
if (config.check_cert) {
|
||||
result = np_net_ssl_check_cert(config.days_till_exp_warn, config.days_till_exp_crit);
|
||||
result =
|
||||
np_net_ssl_check_cert(config.days_till_exp_warn, config.days_till_exp_crit);
|
||||
|
||||
mp_subcheck tls_certificate_lifetime_result = mp_subcheck_init();
|
||||
tls_certificate_lifetime_result = mp_set_subcheck_state(tls_certificate_lifetime_result, result);
|
||||
tls_certificate_lifetime_result =
|
||||
mp_set_subcheck_state(tls_certificate_lifetime_result, result);
|
||||
|
||||
if (result == STATE_OK) {
|
||||
xasprintf(&tls_certificate_lifetime_result.output, "Certificate lifetime is within thresholds");
|
||||
xasprintf(&tls_certificate_lifetime_result.output,
|
||||
"Certificate lifetime is within thresholds");
|
||||
} else if (result == STATE_WARNING) {
|
||||
xasprintf(&tls_certificate_lifetime_result.output, "Certificate lifetime is violating warning threshold (%i)",
|
||||
xasprintf(&tls_certificate_lifetime_result.output,
|
||||
"Certificate lifetime is violating warning threshold (%i)",
|
||||
config.days_till_exp_warn);
|
||||
} else if (result == STATE_CRITICAL) {
|
||||
xasprintf(&tls_certificate_lifetime_result.output, "Certificate lifetime is violating critical threshold (%i)",
|
||||
xasprintf(&tls_certificate_lifetime_result.output,
|
||||
"Certificate lifetime is violating critical threshold (%i)",
|
||||
config.days_till_exp_crit);
|
||||
} else {
|
||||
xasprintf(&tls_certificate_lifetime_result.output, "Certificate lifetime is somehow unknown");
|
||||
xasprintf(&tls_certificate_lifetime_result.output,
|
||||
"Certificate lifetime is somehow unknown");
|
||||
}
|
||||
|
||||
mp_add_subcheck_to_subcheck(&tls_connection_result, tls_certificate_lifetime_result);
|
||||
mp_add_subcheck_to_subcheck(&tls_connection_result,
|
||||
tls_certificate_lifetime_result);
|
||||
}
|
||||
|
||||
mp_add_subcheck_to_check(&overall, tls_connection_result);
|
||||
|
|
@ -336,7 +351,8 @@ int main(int argc, char **argv) {
|
|||
char buffer[MAXBUF];
|
||||
|
||||
/* watch for the expect string */
|
||||
while ((received = my_recv(socket_descriptor, buffer, sizeof(buffer), config.use_tls)) > 0) {
|
||||
while ((received = my_recv(socket_descriptor, buffer, sizeof(buffer), config.use_tls)) >
|
||||
0) {
|
||||
received_buffer = realloc(received_buffer, len + received + 1);
|
||||
|
||||
if (received_buffer == NULL) {
|
||||
|
|
@ -352,7 +368,8 @@ int main(int argc, char **argv) {
|
|||
break;
|
||||
}
|
||||
|
||||
if ((match = np_expect_match(received_buffer, config.server_expect, config.server_expect_count, config.match_flags)) !=
|
||||
if ((match = np_expect_match(received_buffer, config.server_expect,
|
||||
config.server_expect_count, config.match_flags)) !=
|
||||
NP_MATCH_RETRY) {
|
||||
break;
|
||||
}
|
||||
|
|
@ -385,7 +402,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* print raw output if we're debugging */
|
||||
if (verbosity > 0) {
|
||||
printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n", (int)len + 1, received_buffer);
|
||||
printf("received %d bytes from host\n#-raw-recv-------#\n%s\n#-raw-recv-------#\n",
|
||||
(int)len + 1, received_buffer);
|
||||
}
|
||||
/* strip whitespace from end of output */
|
||||
while (--len > 0 && isspace(received_buffer[len])) {
|
||||
|
|
@ -415,7 +433,9 @@ int main(int argc, char **argv) {
|
|||
time_pd.uom = "s";
|
||||
|
||||
if (config.critical_time_set && elapsed_time > config.critical_time) {
|
||||
xasprintf(&elapsed_time_result.output, "Connection time %fs exceeded critical threshold (%f)", elapsed_time, config.critical_time);
|
||||
xasprintf(&elapsed_time_result.output,
|
||||
"Connection time %fs exceeded critical threshold (%f)", elapsed_time,
|
||||
config.critical_time);
|
||||
|
||||
elapsed_time_result = mp_set_subcheck_state(elapsed_time_result, STATE_CRITICAL);
|
||||
time_pd.crit_present = true;
|
||||
|
|
@ -426,7 +446,9 @@ int main(int argc, char **argv) {
|
|||
|
||||
time_pd.crit = crit_val;
|
||||
} else if (config.warning_time_set && elapsed_time > config.warning_time) {
|
||||
xasprintf(&elapsed_time_result.output, "Connection time %fs exceeded warning threshold (%f)", elapsed_time, config.critical_time);
|
||||
xasprintf(&elapsed_time_result.output,
|
||||
"Connection time %fs exceeded warning threshold (%f)", elapsed_time,
|
||||
config.critical_time);
|
||||
|
||||
elapsed_time_result = mp_set_subcheck_state(elapsed_time_result, STATE_WARNING);
|
||||
time_pd.warn_present = true;
|
||||
|
|
@ -437,7 +459,8 @@ int main(int argc, char **argv) {
|
|||
time_pd.warn = warn_val;
|
||||
} else {
|
||||
elapsed_time_result = mp_set_subcheck_state(elapsed_time_result, STATE_OK);
|
||||
xasprintf(&elapsed_time_result.output, "Connection time %fs is within thresholds", elapsed_time);
|
||||
xasprintf(&elapsed_time_result.output, "Connection time %fs is within thresholds",
|
||||
elapsed_time);
|
||||
}
|
||||
|
||||
mp_add_perfdata_to_subcheck(&elapsed_time_result, time_pd);
|
||||
|
|
@ -445,7 +468,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* did we get the response we hoped? */
|
||||
if (match == NP_MATCH_FAILURE) {
|
||||
expected_data_result = mp_set_subcheck_state(expected_data_result, config.expect_mismatch_state);
|
||||
expected_data_result =
|
||||
mp_set_subcheck_state(expected_data_result, config.expect_mismatch_state);
|
||||
xasprintf(&expected_data_result.output, "Answer failed to match expectation");
|
||||
mp_add_subcheck_to_check(&overall, expected_data_result);
|
||||
} else if (match == NP_MATCH_SUCCESS) {
|
||||
|
|
@ -467,34 +491,35 @@ static check_tcp_config_wrapper process_arguments(int argc, char **argv, check_t
|
|||
output_format_index,
|
||||
};
|
||||
|
||||
static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
|
||||
{"critical", required_argument, 0, 'c'},
|
||||
{"warning", required_argument, 0, 'w'},
|
||||
{"critical-codes", required_argument, 0, 'C'},
|
||||
{"warning-codes", required_argument, 0, 'W'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"protocol", required_argument, 0, 'P'}, /* FIXME: Unhandled */
|
||||
{"port", required_argument, 0, 'p'},
|
||||
{"escape", no_argument, 0, 'E'},
|
||||
{"all", no_argument, 0, 'A'},
|
||||
{"send", required_argument, 0, 's'},
|
||||
{"expect", required_argument, 0, 'e'},
|
||||
{"maxbytes", required_argument, 0, 'm'},
|
||||
{"quit", required_argument, 0, 'q'},
|
||||
{"jail", no_argument, 0, 'j'},
|
||||
{"delay", required_argument, 0, 'd'},
|
||||
{"refuse", required_argument, 0, 'r'},
|
||||
{"mismatch", required_argument, 0, 'M'},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"ssl", no_argument, 0, 'S'},
|
||||
{"sni", required_argument, 0, SNI_OPTION},
|
||||
{"certificate", required_argument, 0, 'D'},
|
||||
{"output-format", required_argument, 0, output_format_index},
|
||||
{0, 0, 0, 0}};
|
||||
static struct option longopts[] = {
|
||||
{"hostname", required_argument, 0, 'H'},
|
||||
{"critical", required_argument, 0, 'c'},
|
||||
{"warning", required_argument, 0, 'w'},
|
||||
{"critical-codes", required_argument, 0, 'C'},
|
||||
{"warning-codes", required_argument, 0, 'W'},
|
||||
{"timeout", required_argument, 0, 't'},
|
||||
{"protocol", required_argument, 0, 'P'}, /* FIXME: Unhandled */
|
||||
{"port", required_argument, 0, 'p'},
|
||||
{"escape", no_argument, 0, 'E'},
|
||||
{"all", no_argument, 0, 'A'},
|
||||
{"send", required_argument, 0, 's'},
|
||||
{"expect", required_argument, 0, 'e'},
|
||||
{"maxbytes", required_argument, 0, 'm'},
|
||||
{"quit", required_argument, 0, 'q'},
|
||||
{"jail", no_argument, 0, 'j'},
|
||||
{"delay", required_argument, 0, 'd'},
|
||||
{"refuse", required_argument, 0, 'r'},
|
||||
{"mismatch", required_argument, 0, 'M'},
|
||||
{"use-ipv4", no_argument, 0, '4'},
|
||||
{"use-ipv6", no_argument, 0, '6'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"ssl", no_argument, 0, 'S'},
|
||||
{"sni", required_argument, 0, SNI_OPTION},
|
||||
{"certificate", required_argument, 0, 'D'},
|
||||
{"output-format", required_argument, 0, output_format_index},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
if (argc < 2) {
|
||||
usage4(_("No arguments found"));
|
||||
|
|
@ -522,7 +547,8 @@ static check_tcp_config_wrapper process_arguments(int argc, char **argv, check_t
|
|||
|
||||
while (true) {
|
||||
int option = 0;
|
||||
int option_index = getopt_long(argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:", longopts, &option);
|
||||
int option_index =
|
||||
getopt_long(argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:", longopts, &option);
|
||||
|
||||
if (option_index == -1 || option_index == EOF || option_index == 1) {
|
||||
break;
|
||||
|
|
@ -595,7 +621,8 @@ static check_tcp_config_wrapper process_arguments(int argc, char **argv, check_t
|
|||
if (config.server_expect_count == 0) {
|
||||
config.server_expect = malloc(sizeof(char *) * (++config.server_expect_count));
|
||||
} else {
|
||||
config.server_expect = realloc(config.server_expect, sizeof(char *) * (++config.server_expect_count));
|
||||
config.server_expect =
|
||||
realloc(config.server_expect, sizeof(char *) * (++config.server_expect_count));
|
||||
}
|
||||
|
||||
if (config.server_expect == NULL) {
|
||||
|
|
@ -718,8 +745,8 @@ static check_tcp_config_wrapper process_arguments(int argc, char **argv, check_t
|
|||
if (config.server_address == NULL) {
|
||||
usage4(_("You must provide a server address"));
|
||||
} else if (config.server_address[0] != '/' && !is_host(config.server_address)) {
|
||||
die(STATE_CRITICAL, "%s %s - %s: %s\n", config.service, state_text(STATE_CRITICAL), _("Invalid hostname, address or socket"),
|
||||
config.server_address);
|
||||
die(STATE_CRITICAL, "%s %s - %s: %s\n", config.service, state_text(STATE_CRITICAL),
|
||||
_("Invalid hostname, address or socket"), config.server_address);
|
||||
}
|
||||
|
||||
check_tcp_config_wrapper result = {
|
||||
|
|
@ -735,7 +762,8 @@ void print_help(const char *service) {
|
|||
printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
|
||||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf(_("This plugin tests %s connections with the specified host (or unix socket).\n\n"), service);
|
||||
printf(_("This plugin tests %s connections with the specified host (or unix socket).\n\n"),
|
||||
service);
|
||||
|
||||
print_usage();
|
||||
|
||||
|
|
@ -747,7 +775,8 @@ void print_help(const char *service) {
|
|||
printf(UT_IPv46);
|
||||
|
||||
printf(" %s\n", "-E, --escape");
|
||||
printf(" %s\n", _("Can use \\n, \\r, \\t or \\\\ in send or quit string. Must come before send or quit option"));
|
||||
printf(" %s\n", _("Can use \\n, \\r, \\t or \\\\ in send or quit string. Must come before "
|
||||
"send or quit option"));
|
||||
printf(" %s\n", _("Default: nothing added to send, \\r\\n added to end of quit"));
|
||||
printf(" %s\n", "-s, --send=STRING");
|
||||
printf(" %s\n", _("String to send to the server"));
|
||||
|
|
@ -760,7 +789,8 @@ void print_help(const char *service) {
|
|||
printf(" %s\n", "-r, --refuse=ok|warn|crit");
|
||||
printf(" %s\n", _("Accept TCP refusals with states ok, warn, crit (default: crit)"));
|
||||
printf(" %s\n", "-M, --mismatch=ok|warn|crit");
|
||||
printf(" %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
|
||||
printf(" %s\n",
|
||||
_("Accept expected string mismatches with states ok, warn, crit (default: warn)"));
|
||||
printf(" %s\n", "-j, --jail");
|
||||
printf(" %s\n", _("Hide output from TCP socket"));
|
||||
printf(" %s\n", "-m, --maxbytes=INTEGER");
|
||||
|
|
@ -790,7 +820,8 @@ void print_help(const char *service) {
|
|||
|
||||
void print_usage(void) {
|
||||
printf("%s\n", _("Usage:"));
|
||||
printf("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n", progname);
|
||||
printf("%s -H host -p port [-w <warning time>] [-c <critical time>] [-s <send string>]\n",
|
||||
progname);
|
||||
printf("[-e <expect string>] [-q <quit string>][-m <maximum bytes>] [-d <delay>]\n");
|
||||
printf("[-t <timeout seconds>] [-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n");
|
||||
printf("[-D <warn days cert expire>[,<crit days cert expire>]] [-S <use SSL>] [-E]\n");
|
||||
|
|
|
|||
|
|
@ -87,7 +87,8 @@ int main(int argc, char **argv) {
|
|||
} else {
|
||||
result = STATE_UNKNOWN;
|
||||
}
|
||||
die(result, _("TIME UNKNOWN - could not connect to server %s, port %d\n"), config.server_address, config.server_port);
|
||||
die(result, _("TIME UNKNOWN - could not connect to server %s, port %d\n"),
|
||||
config.server_address, config.server_port);
|
||||
}
|
||||
|
||||
if (config.use_udp) {
|
||||
|
|
@ -99,7 +100,8 @@ int main(int argc, char **argv) {
|
|||
} else {
|
||||
result = STATE_UNKNOWN;
|
||||
}
|
||||
die(result, _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"), config.server_address, config.server_port);
|
||||
die(result, _("TIME UNKNOWN - could not send UDP request to server %s, port %d\n"),
|
||||
config.server_address, config.server_port);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +125,8 @@ int main(int argc, char **argv) {
|
|||
} else {
|
||||
result = STATE_UNKNOWN;
|
||||
}
|
||||
die(result, _("TIME UNKNOWN - no data received from server %s, port %d\n"), config.server_address, config.server_port);
|
||||
die(result, _("TIME UNKNOWN - no data received from server %s, port %d\n"),
|
||||
config.server_address, config.server_port);
|
||||
}
|
||||
|
||||
result = STATE_OK;
|
||||
|
|
@ -137,7 +140,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (result != STATE_OK) {
|
||||
die(result, _("TIME %s - %d second response time|%s\n"), state_text(result), (int)conntime,
|
||||
perfdata("time", (long)conntime, "s", config.check_warning_time, (long)config.warning_time, config.check_critical_time,
|
||||
perfdata("time", (long)conntime, "s", config.check_warning_time,
|
||||
(long)config.warning_time, config.check_critical_time,
|
||||
(long)config.critical_time, true, 0, false, 0));
|
||||
}
|
||||
|
||||
|
|
@ -157,10 +161,11 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
printf(_("TIME %s - %lu second time difference|%s %s\n"), state_text(result), diff_time,
|
||||
perfdata("time", (long)conntime, "s", config.check_warning_time, (long)config.warning_time, config.check_critical_time,
|
||||
perfdata("time", (long)conntime, "s", config.check_warning_time,
|
||||
(long)config.warning_time, config.check_critical_time,
|
||||
(long)config.critical_time, true, 0, false, 0),
|
||||
perfdata("offset", diff_time, "s", config.check_warning_diff, config.warning_diff, config.check_critical_diff,
|
||||
config.critical_diff, true, 0, false, 0));
|
||||
perfdata("offset", diff_time, "s", config.check_warning_diff, config.warning_diff,
|
||||
config.check_critical_diff, config.critical_diff, true, 0, false, 0));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +235,8 @@ check_time_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.warning_diff = strtoul(optarg, NULL, 10);
|
||||
result.config.check_warning_diff = true;
|
||||
} else if (strspn(optarg, "0123456789:,") > 0) {
|
||||
if (sscanf(optarg, "%lu%*[:,]%d", &result.config.warning_diff, &result.config.warning_time) == 2) {
|
||||
if (sscanf(optarg, "%lu%*[:,]%d", &result.config.warning_diff,
|
||||
&result.config.warning_time) == 2) {
|
||||
result.config.check_warning_diff = true;
|
||||
result.config.check_warning_time = true;
|
||||
} else {
|
||||
|
|
@ -245,7 +251,8 @@ check_time_config_wrapper process_arguments(int argc, char **argv) {
|
|||
result.config.critical_diff = strtoul(optarg, NULL, 10);
|
||||
result.config.check_critical_diff = true;
|
||||
} else if (strspn(optarg, "0123456789:,") > 0) {
|
||||
if (sscanf(optarg, "%lu%*[:,]%d", &result.config.critical_diff, &result.config.critical_time) == 2) {
|
||||
if (sscanf(optarg, "%lu%*[:,]%d", &result.config.critical_diff,
|
||||
&result.config.critical_time) == 2) {
|
||||
result.config.check_critical_diff = true;
|
||||
result.config.check_critical_time = true;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,8 @@ int main(int argc, char **argv) {
|
|||
if (ups_status_flags & UPSSTATUS_OFF) {
|
||||
xasprintf(&ups_status, "Off");
|
||||
result = STATE_CRITICAL;
|
||||
} else if ((ups_status_flags & (UPSSTATUS_OB | UPSSTATUS_LB)) == (UPSSTATUS_OB | UPSSTATUS_LB)) {
|
||||
} else if ((ups_status_flags & (UPSSTATUS_OB | UPSSTATUS_LB)) ==
|
||||
(UPSSTATUS_OB | UPSSTATUS_LB)) {
|
||||
xasprintf(&ups_status, _("On Battery, Low Battery"));
|
||||
result = STATE_CRITICAL;
|
||||
} else {
|
||||
|
|
@ -192,11 +193,14 @@ int main(int argc, char **argv) {
|
|||
result = max_state(result, STATE_WARNING);
|
||||
}
|
||||
xasprintf(&performance_data, "%s",
|
||||
perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", config.check_warn, (long)(1000 * config.warning_value),
|
||||
config.check_crit, (long)(1000 * config.critical_value), true, 0, false, 0));
|
||||
perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV",
|
||||
config.check_warn, (long)(1000 * config.warning_value),
|
||||
config.check_crit, (long)(1000 * config.critical_value), true, 0,
|
||||
false, 0));
|
||||
} else {
|
||||
xasprintf(&performance_data, "%s",
|
||||
perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", false, 0, false, 0, true, 0, false, 0));
|
||||
perfdata("voltage", (long)(1000 * ups_utility_voltage), "mV", false, 0, false,
|
||||
0, true, 0, false, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -220,11 +224,13 @@ int main(int argc, char **argv) {
|
|||
result = max_state(result, STATE_WARNING);
|
||||
}
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("battery", (long)ups_battery_percent, "%", config.check_warn, (long)(config.warning_value),
|
||||
config.check_crit, (long)(config.critical_value), true, 0, true, 100));
|
||||
perfdata("battery", (long)ups_battery_percent, "%", config.check_warn,
|
||||
(long)(config.warning_value), config.check_crit,
|
||||
(long)(config.critical_value), true, 0, true, 100));
|
||||
} else {
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("battery", (long)ups_battery_percent, "%", false, 0, false, 0, true, 0, true, 100));
|
||||
perfdata("battery", (long)ups_battery_percent, "%", false, 0, false, 0, true,
|
||||
0, true, 100));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -248,11 +254,13 @@ int main(int argc, char **argv) {
|
|||
result = max_state(result, STATE_WARNING);
|
||||
}
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("load", (long)ups_load_percent, "%", config.check_warn, (long)(config.warning_value), config.check_crit,
|
||||
perfdata("load", (long)ups_load_percent, "%", config.check_warn,
|
||||
(long)(config.warning_value), config.check_crit,
|
||||
(long)(config.critical_value), true, 0, true, 100));
|
||||
} else {
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("load", (long)ups_load_percent, "%", false, 0, false, 0, true, 0, true, 100));
|
||||
perfdata("load", (long)ups_load_percent, "%", false, 0, false, 0, true, 0,
|
||||
true, 100));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -285,11 +293,13 @@ int main(int argc, char **argv) {
|
|||
result = max_state(result, STATE_WARNING);
|
||||
}
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("temp", (long)ups_temperature, tunits, config.check_warn, (long)(config.warning_value), config.check_crit,
|
||||
perfdata("temp", (long)ups_temperature, tunits, config.check_warn,
|
||||
(long)(config.warning_value), config.check_crit,
|
||||
(long)(config.critical_value), true, 0, false, 0));
|
||||
} else {
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("temp", (long)ups_temperature, tunits, false, 0, false, 0, true, 0, false, 0));
|
||||
perfdata("temp", (long)ups_temperature, tunits, false, 0, false, 0, true, 0,
|
||||
false, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -312,11 +322,13 @@ int main(int argc, char **argv) {
|
|||
result = max_state(result, STATE_WARNING);
|
||||
}
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("realpower", (long)ups_realpower, "W", config.check_warn, (long)(config.warning_value), config.check_crit,
|
||||
perfdata("realpower", (long)ups_realpower, "W", config.check_warn,
|
||||
(long)(config.warning_value), config.check_crit,
|
||||
(long)(config.critical_value), true, 0, false, 0));
|
||||
} else {
|
||||
xasprintf(&performance_data, "%s %s", performance_data,
|
||||
perfdata("realpower", (long)ups_realpower, "W", false, 0, false, 0, true, 0, false, 0));
|
||||
perfdata("realpower", (long)ups_realpower, "W", false, 0, false, 0, true, 0,
|
||||
false, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -401,7 +413,8 @@ int get_ups_variable(const char *varname, char *buf, const check_ups_config conf
|
|||
|
||||
/* create the command string to send to the UPS daemon */
|
||||
/* Add LOGOUT to avoid read failure logs */
|
||||
int res = snprintf(send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", config.ups_name, varname);
|
||||
int res = snprintf(send_buffer, sizeof(send_buffer), "GET VAR %s %s\nLOGOUT\n", config.ups_name,
|
||||
varname);
|
||||
if ((res > 0) && ((size_t)res >= sizeof(send_buffer))) {
|
||||
printf("%s\n", _("UPS name to long for buffer"));
|
||||
return ERROR;
|
||||
|
|
@ -410,7 +423,8 @@ int get_ups_variable(const char *varname, char *buf, const check_ups_config conf
|
|||
char temp_buffer[MAX_INPUT_BUFFER];
|
||||
|
||||
/* send the command to the daemon and get a response back */
|
||||
if (process_tcp_request(config.server_address, config.server_port, send_buffer, temp_buffer, sizeof(temp_buffer)) != STATE_OK) {
|
||||
if (process_tcp_request(config.server_address, config.server_port, send_buffer, temp_buffer,
|
||||
sizeof(temp_buffer)) != STATE_OK) {
|
||||
printf("%s\n", _("Invalid response received from host"));
|
||||
return ERROR;
|
||||
}
|
||||
|
|
@ -630,7 +644,8 @@ void print_help(void) {
|
|||
printf(" %s\n", "-T, --temperature");
|
||||
printf(" %s\n", _("Output of temperatures in Celsius"));
|
||||
printf(" %s\n", "-v, --variable=STRING");
|
||||
printf(" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT, LOADPCT or REALPOWER");
|
||||
printf(" %s %s\n", _("Valid values for STRING are"),
|
||||
"LINE, TEMP, BATTPCT, LOADPCT or REALPOWER");
|
||||
|
||||
printf(UT_WARN_CRIT);
|
||||
|
||||
|
|
|
|||
|
|
@ -52,4 +52,3 @@ check_ups_config check_ups_config_init(void) {
|
|||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,10 +128,14 @@ int main(int argc, char **argv) {
|
|||
|
||||
switch (tmp_status) {
|
||||
case STATE_WARNING:
|
||||
xasprintf(&sc_users.output, "%d users currently logged in. This violates the warning threshold", user_wrapper.users);
|
||||
xasprintf(&sc_users.output,
|
||||
"%d users currently logged in. This violates the warning threshold",
|
||||
user_wrapper.users);
|
||||
break;
|
||||
case STATE_CRITICAL:
|
||||
xasprintf(&sc_users.output, "%d users currently logged in. This violates the critical threshold", user_wrapper.users);
|
||||
xasprintf(&sc_users.output,
|
||||
"%d users currently logged in. This violates the critical threshold",
|
||||
user_wrapper.users);
|
||||
break;
|
||||
default:
|
||||
xasprintf(&sc_users.output, "%d users currently logged in", user_wrapper.users);
|
||||
|
|
@ -218,7 +222,7 @@ check_users_config_wrapper process_arguments(int argc, char **argv) {
|
|||
printf("Warning threshold missing\n");
|
||||
print_usage();
|
||||
exit(STATE_UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
if (tmp.error == MP_PARSING_SUCCES) {
|
||||
result.config.thresholds.warning = tmp.range;
|
||||
|
|
@ -254,7 +258,8 @@ void print_help(void) {
|
|||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("This plugin checks the number of users currently logged in on the local"));
|
||||
printf("%s\n", _("system and generates an error if the number exceeds the thresholds specified."));
|
||||
printf("%s\n",
|
||||
_("system and generates an error if the number exceeds the thresholds specified."));
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
|
|
@ -264,9 +269,11 @@ void print_help(void) {
|
|||
printf(UT_EXTRA_OPTS);
|
||||
|
||||
printf(" %s\n", "-w, --warning=RANGE_EXPRESSION");
|
||||
printf(" %s\n", _("Set WARNING status if number of logged in users violates RANGE_EXPRESSION"));
|
||||
printf(" %s\n",
|
||||
_("Set WARNING status if number of logged in users violates RANGE_EXPRESSION"));
|
||||
printf(" %s\n", "-c, --critical=RANGE_EXPRESSION");
|
||||
printf(" %s\n", _("Set CRITICAL status if number of logged in users violates RANGE_EXPRESSION"));
|
||||
printf(" %s\n",
|
||||
_("Set CRITICAL status if number of logged in users violates RANGE_EXPRESSION"));
|
||||
printf(UT_OUTPUT_FORMAT);
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ get_num_of_users_wrapper get_num_of_users_windows() {
|
|||
LPTSTR username;
|
||||
DWORD size;
|
||||
|
||||
if (!WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, wtsinfo[index].SessionId, WTSUserName, &username, &size)) {
|
||||
if (!WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, wtsinfo[index].SessionId,
|
||||
WTSUserName, &username, &size)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -150,7 +151,8 @@ get_num_of_users_wrapper get_num_of_users_who_command() {
|
|||
|
||||
/* check STDERR */
|
||||
if (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) {
|
||||
// if this fails, something broke and the result can not be relied upon or so is the theorie here
|
||||
// if this fails, something broke and the result can not be relied upon or so is the theorie
|
||||
// here
|
||||
result.errorcode = STDERR_COULD_NOT_BE_READ;
|
||||
}
|
||||
(void)fclose(child_stderr);
|
||||
|
|
|
|||
175
plugins/common.h
175
plugins/common.h
|
|
@ -1,32 +1,32 @@
|
|||
/*****************************************************************************
|
||||
*
|
||||
* Monitoring Plugins common include file
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
|
||||
* Copyright (c) 2003-2007 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* This file contains common include files and defines used in many of
|
||||
* the plugins.
|
||||
*
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
*
|
||||
* Monitoring Plugins common include file
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
|
||||
* Copyright (c) 2003-2007 Monitoring Plugins Development Team
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
* This file contains common include files and defines used in many of
|
||||
* the plugins.
|
||||
*
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef _COMMON_H_
|
||||
#define _COMMON_H_
|
||||
|
|
@ -35,77 +35,78 @@
|
|||
#include "../lib/monitoringplug.h"
|
||||
|
||||
#ifdef HAVE_FEATURES_H
|
||||
#include <features.h>
|
||||
# include <features.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h> /* obligatory includes */
|
||||
#include <stdio.h> /* obligatory includes */
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* This block provides uintmax_t - should be reported to coreutils that this should be added to fsuage.h */
|
||||
/* This block provides uintmax_t - should be reported to coreutils that this should be added to
|
||||
* fsuage.h */
|
||||
#if HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
#if HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#ifndef UINTMAX_MAX
|
||||
# define UINTMAX_MAX ((uintmax_t) -1)
|
||||
# define UINTMAX_MAX ((uintmax_t) - 1)
|
||||
#endif
|
||||
|
||||
#include <limits.h> /* This is assumed true, because coreutils assume it too */
|
||||
#include <limits.h> /* This is assumed true, because coreutils assume it too */
|
||||
|
||||
#ifdef HAVE_MATH_H
|
||||
#include <math.h>
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
#ifdef _AIX
|
||||
#ifdef HAVE_MP_H
|
||||
#include <mp.h>
|
||||
#endif
|
||||
# ifdef HAVE_MP_H
|
||||
# include <mp.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRINGS_H
|
||||
#include <strings.h>
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* GET_NUMBER_OF_CPUS is a macro to return
|
||||
/* GET_NUMBER_OF_CPUS is a macro to return
|
||||
number of CPUs, if we can get that data.
|
||||
Use configure.in to test for various OS ways of
|
||||
getting that data
|
||||
Will return -1 if cannot get data
|
||||
*/
|
||||
#if defined(HAVE_SYSCONF__SC_NPROCESSORS_ONLN)
|
||||
# define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_ONLN)
|
||||
#elif defined (HAVE_SYSCONF__SC_NPROCESSORS_CONF)
|
||||
# define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
|
||||
# define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_ONLN)
|
||||
#elif defined(HAVE_SYSCONF__SC_NPROCESSORS_CONF)
|
||||
# define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
|
||||
#else
|
||||
# define GET_NUMBER_OF_CPUS() -1
|
||||
# define GET_NUMBER_OF_CPUS() -1
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
# include <signal.h>
|
||||
#endif
|
||||
|
||||
/* GNU Libraries */
|
||||
|
|
@ -115,7 +116,7 @@
|
|||
#include <locale.h>
|
||||
|
||||
#ifdef HAVE_SYS_POLL_H
|
||||
# include "sys/poll.h"
|
||||
# include "sys/poll.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -125,42 +126,42 @@
|
|||
*/
|
||||
|
||||
#ifndef HAVE_STRTOL
|
||||
# define strtol(a,b,c) atol((a))
|
||||
# define strtol(a, b, c) atol((a))
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRTOUL
|
||||
# define strtoul(a,b,c) (unsigned long)atol((a))
|
||||
# define strtoul(a, b, c) (unsigned long)atol((a))
|
||||
#endif
|
||||
|
||||
/* SSL implementations */
|
||||
#ifdef HAVE_GNUTLS_OPENSSL_H
|
||||
# include <gnutls/openssl.h>
|
||||
# include <gnutls/openssl.h>
|
||||
#else
|
||||
# define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */
|
||||
# ifdef HAVE_SSL_H
|
||||
# include <rsa.h>
|
||||
# include <crypto.h>
|
||||
# include <x509.h>
|
||||
# include <pem.h>
|
||||
# include <ssl.h>
|
||||
# include <err.h>
|
||||
# else
|
||||
# ifdef HAVE_OPENSSL_SSL_H
|
||||
# include <openssl/rsa.h>
|
||||
# include <openssl/crypto.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/pem.h>
|
||||
# include <openssl/ssl.h>
|
||||
# include <openssl/err.h>
|
||||
# endif
|
||||
# endif
|
||||
# define OPENSSL_LOAD_CONF /* See the OPENSSL_config(3) man page. */
|
||||
# ifdef HAVE_SSL_H
|
||||
# include <rsa.h>
|
||||
# include <crypto.h>
|
||||
# include <x509.h>
|
||||
# include <pem.h>
|
||||
# include <ssl.h>
|
||||
# include <err.h>
|
||||
# else
|
||||
# ifdef HAVE_OPENSSL_SSL_H
|
||||
# include <openssl/rsa.h>
|
||||
# include <openssl/crypto.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/pem.h>
|
||||
# include <openssl/ssl.h>
|
||||
# include <openssl/err.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* openssl 1.1 does not set OPENSSL_NO_SSL2 by default but ships without ssl2 */
|
||||
#ifdef OPENSSL_VERSION_NUMBER
|
||||
# if OPENSSL_VERSION_NUMBER >= 0x10100000
|
||||
# define OPENSSL_NO_SSL2
|
||||
# endif
|
||||
# if OPENSSL_VERSION_NUMBER >= 0x10100000
|
||||
# define OPENSSL_NO_SSL2
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
@ -171,7 +172,7 @@
|
|||
|
||||
/* MariaDB 10.2 client does not set MYSQL_PORT */
|
||||
#ifndef MYSQL_PORT
|
||||
# define MYSQL_PORT 3306
|
||||
# define MYSQL_PORT 3306
|
||||
#endif
|
||||
|
||||
enum {
|
||||
|
|
@ -180,9 +181,9 @@ enum {
|
|||
};
|
||||
|
||||
enum {
|
||||
DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
|
||||
MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
|
||||
MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
|
||||
DEFAULT_SOCKET_TIMEOUT = 10, /* timeout after 10 seconds */
|
||||
MAX_INPUT_BUFFER = 8192, /* max size of most buffers we use */
|
||||
MAX_HOST_ADDRESS_LENGTH = 256 /* max size of a host address */
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
@ -191,17 +192,17 @@ enum {
|
|||
*
|
||||
*/
|
||||
#include "../gl/gettext.h"
|
||||
#define _(String) gettext (String)
|
||||
#if ! ENABLE_NLS
|
||||
# undef textdomain
|
||||
# define textdomain(Domainname) /* empty */
|
||||
# undef bindtextdomain
|
||||
# define bindtextdomain(Domainname, Dirname) /* empty */
|
||||
#define _(String) gettext(String)
|
||||
#if !ENABLE_NLS
|
||||
# undef textdomain
|
||||
# define textdomain(Domainname) /* empty */
|
||||
# undef bindtextdomain
|
||||
# define bindtextdomain(Domainname, Dirname) /* empty */
|
||||
#endif
|
||||
|
||||
/* For non-GNU compilers to ignore __attribute__ */
|
||||
#ifndef __GNUC__
|
||||
# define __attribute__(x) /* do nothing */
|
||||
# define __attribute__(x) /* do nothing */
|
||||
#endif
|
||||
|
||||
#endif /* _COMMON_H_ */
|
||||
|
|
|
|||
|
|
@ -105,7 +105,8 @@ int main(int argc, char **argv) {
|
|||
*sub = '\0';
|
||||
sub += strlen(state_text(result));
|
||||
/* then put everything back together */
|
||||
xasprintf(&chld_out.line[i], "%s%s%s", chld_out.line[i], state_text(config.state[result]), sub);
|
||||
xasprintf(&chld_out.line[i], "%s%s%s", chld_out.line[i],
|
||||
state_text(config.state[result]), sub);
|
||||
}
|
||||
}
|
||||
printf("%s\n", chld_out.line[i]);
|
||||
|
|
@ -120,11 +121,12 @@ int main(int argc, char **argv) {
|
|||
|
||||
/* process command-line arguments */
|
||||
static negate_config_wrapper process_arguments(int argc, char **argv) {
|
||||
static struct option longopts[] = {{"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'},
|
||||
{"timeout", required_argument, 0, 't'}, {"timeout-result", required_argument, 0, 'T'},
|
||||
{"ok", required_argument, 0, 'o'}, {"warning", required_argument, 0, 'w'},
|
||||
{"critical", required_argument, 0, 'c'}, {"unknown", required_argument, 0, 'u'},
|
||||
{"substitute", no_argument, 0, 's'}, {0, 0, 0, 0}};
|
||||
static struct option longopts[] = {
|
||||
{"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'},
|
||||
{"timeout", required_argument, 0, 't'}, {"timeout-result", required_argument, 0, 'T'},
|
||||
{"ok", required_argument, 0, 'o'}, {"warning", required_argument, 0, 'w'},
|
||||
{"critical", required_argument, 0, 'c'}, {"unknown", required_argument, 0, 'u'},
|
||||
{"substitute", no_argument, 0, 's'}, {0, 0, 0, 0}};
|
||||
|
||||
negate_config_wrapper result = {
|
||||
.errorcode = OK,
|
||||
|
|
@ -159,31 +161,36 @@ static negate_config_wrapper process_arguments(int argc, char **argv) {
|
|||
break;
|
||||
case 'T': /* Result to return on timeouts */
|
||||
if ((timeout_state = mp_translate_state(optarg)) == ERROR) {
|
||||
usage4(_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
usage4(_("Timeout result must be a valid state name (OK, WARNING, CRITICAL, "
|
||||
"UNKNOWN) or integer (0-3)."));
|
||||
}
|
||||
break;
|
||||
case 'o': /* replacement for OK */
|
||||
if ((result.config.state[STATE_OK] = mp_translate_state(optarg)) == ERROR) {
|
||||
usage4(_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
usage4(_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or "
|
||||
"integer (0-3)."));
|
||||
}
|
||||
permute = false;
|
||||
break;
|
||||
|
||||
case 'w': /* replacement for WARNING */
|
||||
if ((result.config.state[STATE_WARNING] = mp_translate_state(optarg)) == ERROR) {
|
||||
usage4(_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
usage4(_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or "
|
||||
"integer (0-3)."));
|
||||
}
|
||||
permute = false;
|
||||
break;
|
||||
case 'c': /* replacement for CRITICAL */
|
||||
if ((result.config.state[STATE_CRITICAL] = mp_translate_state(optarg)) == ERROR) {
|
||||
usage4(_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
usage4(_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or "
|
||||
"integer (0-3)."));
|
||||
}
|
||||
permute = false;
|
||||
break;
|
||||
case 'u': /* replacement for UNKNOWN */
|
||||
if ((result.config.state[STATE_UNKNOWN] = mp_translate_state(optarg)) == ERROR) {
|
||||
usage4(_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
|
||||
usage4(_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or "
|
||||
"integer (0-3)."));
|
||||
}
|
||||
permute = false;
|
||||
break;
|
||||
|
|
@ -208,7 +215,8 @@ negate_config_wrapper validate_arguments(negate_config_wrapper config_wrapper) {
|
|||
usage4(_("Could not parse arguments"));
|
||||
}
|
||||
|
||||
if (strncmp(config_wrapper.config.command_line[0], "/", 1) != 0 && strncmp(config_wrapper.config.command_line[0], "./", 2) != 0) {
|
||||
if (strncmp(config_wrapper.config.command_line[0], "/", 1) != 0 &&
|
||||
strncmp(config_wrapper.config.command_line[0], "./", 2) != 0) {
|
||||
usage4(_("Require path to command"));
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +228,8 @@ void print_help(void) {
|
|||
|
||||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("Negates only the return code of a plugin (returns OK for CRITICAL and vice-versa) by default."));
|
||||
printf("%s\n", _("Negates only the return code of a plugin (returns OK for CRITICAL and "
|
||||
"vice-versa) by default."));
|
||||
printf("%s\n", _("Additional switches can be used to control:\n"));
|
||||
printf("\t - which state becomes what\n");
|
||||
printf("\t - changing the plugin output text to match the return code");
|
||||
|
|
@ -250,17 +259,20 @@ void print_help(void) {
|
|||
printf("%s\n", _("Examples:"));
|
||||
printf(" %s\n", "negate /usr/local/nagios/libexec/check_ping -H host");
|
||||
printf(" %s\n", _("Run check_ping and invert result. Must use full path to plugin"));
|
||||
printf(" %s\n", "negate -w OK -c UNKNOWN /usr/local/nagios/libexec/check_procs -a 'vi negate.c'");
|
||||
printf(" %s\n",
|
||||
"negate -w OK -c UNKNOWN /usr/local/nagios/libexec/check_procs -a 'vi negate.c'");
|
||||
printf(" %s\n", _("This will return OK instead of WARNING and UNKNOWN instead of CRITICAL"));
|
||||
printf("\n");
|
||||
printf("%s\n", _("Notes:"));
|
||||
printf(" %s\n", _("This plugin is a wrapper to take the output of another plugin and invert it."));
|
||||
printf(" %s\n",
|
||||
_("This plugin is a wrapper to take the output of another plugin and invert it."));
|
||||
printf(" %s\n", _("The full path of the plugin must be provided."));
|
||||
printf(" %s\n", _("If the wrapped plugin returns OK, the wrapper will return CRITICAL."));
|
||||
printf(" %s\n", _("If the wrapped plugin returns CRITICAL, the wrapper will return OK."));
|
||||
printf(" %s\n", _("Otherwise, the output state of the wrapped plugin is unchanged."));
|
||||
printf("\n");
|
||||
printf(" %s\n", _("Using timeout-result, it is possible to override the timeout behaviour or a"));
|
||||
printf(" %s\n",
|
||||
_("Using timeout-result, it is possible to override the timeout behaviour or a"));
|
||||
printf(" %s\n", _("plugin by setting the negate timeout a bit lower."));
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,8 @@ void socket_timeout_alarm_handler(int sig) {
|
|||
/* connects to a host on a specified tcp port, sends a string, and gets a
|
||||
response. loops on select-recv until timeout or eof to get all of a
|
||||
multi-packet answer */
|
||||
int process_tcp_request2(const char *server_address, int server_port, const char *send_buffer, char *recv_buffer, int recv_size) {
|
||||
int process_tcp_request2(const char *server_address, int server_port, const char *send_buffer,
|
||||
char *recv_buffer, int recv_size) {
|
||||
|
||||
int result;
|
||||
int send_result;
|
||||
|
|
@ -104,7 +105,8 @@ int process_tcp_request2(const char *server_address, int server_port, const char
|
|||
}
|
||||
break;
|
||||
} else { /* it has */
|
||||
recv_result = recv(sd, recv_buffer + recv_length, (size_t)recv_size - recv_length - 1, 0);
|
||||
recv_result =
|
||||
recv(sd, recv_buffer + recv_length, (size_t)recv_size - recv_length - 1, 0);
|
||||
if (recv_result == -1) {
|
||||
/* recv failed, bail out */
|
||||
strcpy(recv_buffer + recv_length, "");
|
||||
|
|
@ -133,7 +135,8 @@ int process_tcp_request2(const char *server_address, int server_port, const char
|
|||
|
||||
/* connects to a host on a specified port, sends a string, and gets a
|
||||
response */
|
||||
int process_request(const char *server_address, int server_port, int proto, const char *send_buffer, char *recv_buffer, int recv_size) {
|
||||
int process_request(const char *server_address, int server_port, int proto, const char *send_buffer,
|
||||
char *recv_buffer, int recv_size) {
|
||||
int result;
|
||||
int sd;
|
||||
|
||||
|
|
@ -253,7 +256,8 @@ int np_net_connect(const char *host_name, int port, int *sd, int proto) {
|
|||
if (is_socket) {
|
||||
// printf("connect to file socket %s: %s\n", host_name, strerror(errno));
|
||||
} else {
|
||||
// printf("connect to address %s and port %d: %s\n", host_name, port, strerror(errno));
|
||||
// printf("connect to address %s and port %d: %s\n", host_name, port,
|
||||
// strerror(errno));
|
||||
}
|
||||
return STATE_CRITICAL;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -50,59 +50,61 @@
|
|||
# define ALIGNED(n) __attribute__((aligned(n)))
|
||||
#endif
|
||||
|
||||
#define IS_PRINTABLE_ASCII(c) ((unsigned char)(c)-040u < 0137u)
|
||||
#define IS_PRINTABLE_ASCII(c) ((unsigned char)(c) - 040u < 0137u)
|
||||
|
||||
#define CHECK_EOF() \
|
||||
if (buf == buf_end) { \
|
||||
*ret = -2; \
|
||||
return NULL; \
|
||||
#define CHECK_EOF() \
|
||||
if (buf == buf_end) { \
|
||||
*ret = -2; \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define EXPECT_CHAR_NO_CHECK(ch) \
|
||||
if (*buf++ != ch) { \
|
||||
*ret = -1; \
|
||||
return NULL; \
|
||||
#define EXPECT_CHAR_NO_CHECK(ch) \
|
||||
if (*buf++ != ch) { \
|
||||
*ret = -1; \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define EXPECT_CHAR(ch) \
|
||||
CHECK_EOF(); \
|
||||
#define EXPECT_CHAR(ch) \
|
||||
CHECK_EOF(); \
|
||||
EXPECT_CHAR_NO_CHECK(ch);
|
||||
|
||||
#define ADVANCE_TOKEN(tok, toklen) \
|
||||
do { \
|
||||
const char *tok_start = buf; \
|
||||
static const char ALIGNED(16) ranges2[16] = "\000\040\177\177"; \
|
||||
int found2; \
|
||||
buf = findchar_fast(buf, buf_end, ranges2, 4, &found2); \
|
||||
if (!found2) { \
|
||||
CHECK_EOF(); \
|
||||
} \
|
||||
while (1) { \
|
||||
if (*buf == ' ') { \
|
||||
break; \
|
||||
} else if (unlikely(!IS_PRINTABLE_ASCII(*buf))) { \
|
||||
if ((unsigned char)*buf < '\040' || *buf == '\177') { \
|
||||
*ret = -1; \
|
||||
return NULL; \
|
||||
} \
|
||||
} \
|
||||
++buf; \
|
||||
CHECK_EOF(); \
|
||||
} \
|
||||
tok = tok_start; \
|
||||
toklen = buf - tok_start; \
|
||||
#define ADVANCE_TOKEN(tok, toklen) \
|
||||
do { \
|
||||
const char *tok_start = buf; \
|
||||
static const char ALIGNED(16) ranges2[16] = "\000\040\177\177"; \
|
||||
int found2; \
|
||||
buf = findchar_fast(buf, buf_end, ranges2, 4, &found2); \
|
||||
if (!found2) { \
|
||||
CHECK_EOF(); \
|
||||
} \
|
||||
while (1) { \
|
||||
if (*buf == ' ') { \
|
||||
break; \
|
||||
} else if (unlikely(!IS_PRINTABLE_ASCII(*buf))) { \
|
||||
if ((unsigned char)*buf < '\040' || *buf == '\177') { \
|
||||
*ret = -1; \
|
||||
return NULL; \
|
||||
} \
|
||||
} \
|
||||
++buf; \
|
||||
CHECK_EOF(); \
|
||||
} \
|
||||
tok = tok_start; \
|
||||
toklen = buf - tok_start; \
|
||||
} while (0)
|
||||
|
||||
static const char *token_char_map = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\1\0\1\1\1\1\1\0\0\1\1\0\1\1\0\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0"
|
||||
"\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\1\1"
|
||||
"\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\1\0\1\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
static const char *token_char_map =
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\1\0\1\1\1\1\1\0\0\1\1\0\1\1\0\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0"
|
||||
"\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\1\1"
|
||||
"\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\1\0\1\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||
|
||||
static const char *findchar_fast(const char *buf, const char *buf_end, const char *ranges, size_t ranges_size, int *found) {
|
||||
static const char *findchar_fast(const char *buf, const char *buf_end, const char *ranges,
|
||||
size_t ranges_size, int *found) {
|
||||
*found = 0;
|
||||
#if __SSE4_2__
|
||||
if (likely(buf_end - buf >= 16)) {
|
||||
|
|
@ -111,7 +113,8 @@ static const char *findchar_fast(const char *buf, const char *buf_end, const cha
|
|||
size_t left = (buf_end - buf) & ~15;
|
||||
do {
|
||||
__m128i b16 = _mm_loadu_si128((const __m128i *)buf);
|
||||
int r = _mm_cmpestri(ranges16, ranges_size, b16, 16, _SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES | _SIDD_UBYTE_OPS);
|
||||
int r = _mm_cmpestri(ranges16, ranges_size, b16, 16,
|
||||
_SIDD_LEAST_SIGNIFICANT | _SIDD_CMP_RANGES | _SIDD_UBYTE_OPS);
|
||||
if (unlikely(r != 16)) {
|
||||
buf += r;
|
||||
*found = 1;
|
||||
|
|
@ -130,25 +133,29 @@ static const char *findchar_fast(const char *buf, const char *buf_end, const cha
|
|||
return buf;
|
||||
}
|
||||
|
||||
static const char *get_token_to_eol(const char *buf, const char *buf_end, const char **token, size_t *token_len, int *ret) {
|
||||
static const char *get_token_to_eol(const char *buf, const char *buf_end, const char **token,
|
||||
size_t *token_len, int *ret) {
|
||||
const char *token_start = buf;
|
||||
|
||||
#ifdef __SSE4_2__
|
||||
static const char ALIGNED(16) ranges1[16] = "\0\010" /* allow HT */
|
||||
"\012\037" /* allow SP and up to but not including DEL */
|
||||
"\177\177"; /* allow chars w. MSB set */
|
||||
static const char ALIGNED(16) ranges1[16] =
|
||||
"\0\010" /* allow HT */
|
||||
"\012\037" /* allow SP and up to but not including DEL */
|
||||
"\177\177"; /* allow chars w. MSB set */
|
||||
int found;
|
||||
buf = findchar_fast(buf, buf_end, ranges1, 6, &found);
|
||||
if (found)
|
||||
if (found) {
|
||||
goto FOUND_CTL;
|
||||
}
|
||||
#else
|
||||
/* find non-printable char within the next 8 bytes, this is the hottest code; manually inlined */
|
||||
/* find non-printable char within the next 8 bytes, this is the hottest code; manually inlined
|
||||
*/
|
||||
while (likely(buf_end - buf >= 8)) {
|
||||
# define DOIT() \
|
||||
do { \
|
||||
if (unlikely(!IS_PRINTABLE_ASCII(*buf))) \
|
||||
goto NonPrintable; \
|
||||
++buf; \
|
||||
# define DOIT() \
|
||||
do { \
|
||||
if (unlikely(!IS_PRINTABLE_ASCII(*buf))) \
|
||||
goto NonPrintable; \
|
||||
++buf; \
|
||||
} while (0)
|
||||
DOIT();
|
||||
DOIT();
|
||||
|
|
@ -161,7 +168,8 @@ static const char *get_token_to_eol(const char *buf, const char *buf_end, const
|
|||
# undef DOIT
|
||||
continue;
|
||||
NonPrintable:
|
||||
if ((likely((unsigned char)*buf < '\040') && likely(*buf != '\011')) || unlikely(*buf == '\177')) {
|
||||
if ((likely((unsigned char)*buf < '\040') && likely(*buf != '\011')) ||
|
||||
unlikely(*buf == '\177')) {
|
||||
goto FOUND_CTL;
|
||||
}
|
||||
++buf;
|
||||
|
|
@ -170,7 +178,8 @@ static const char *get_token_to_eol(const char *buf, const char *buf_end, const
|
|||
for (;; ++buf) {
|
||||
CHECK_EOF();
|
||||
if (unlikely(!IS_PRINTABLE_ASCII(*buf))) {
|
||||
if ((likely((unsigned char)*buf < '\040') && likely(*buf != '\011')) || unlikely(*buf == '\177')) {
|
||||
if ((likely((unsigned char)*buf < '\040') && likely(*buf != '\011')) ||
|
||||
unlikely(*buf == '\177')) {
|
||||
goto FOUND_CTL;
|
||||
}
|
||||
}
|
||||
|
|
@ -219,27 +228,28 @@ static const char *is_complete(const char *buf, const char *buf_end, size_t last
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#define PARSE_INT(valp_, mul_) \
|
||||
if (*buf < '0' || '9' < *buf) { \
|
||||
buf++; \
|
||||
*ret = -1; \
|
||||
return NULL; \
|
||||
} \
|
||||
#define PARSE_INT(valp_, mul_) \
|
||||
if (*buf < '0' || '9' < *buf) { \
|
||||
buf++; \
|
||||
*ret = -1; \
|
||||
return NULL; \
|
||||
} \
|
||||
*(valp_) = (mul_) * (*buf++ - '0');
|
||||
|
||||
#define PARSE_INT_3(valp_) \
|
||||
do { \
|
||||
int res_ = 0; \
|
||||
PARSE_INT(&res_, 100) \
|
||||
*valp_ = res_; \
|
||||
PARSE_INT(&res_, 10) \
|
||||
*valp_ += res_; \
|
||||
PARSE_INT(&res_, 1) \
|
||||
*valp_ += res_; \
|
||||
#define PARSE_INT_3(valp_) \
|
||||
do { \
|
||||
int res_ = 0; \
|
||||
PARSE_INT(&res_, 100) \
|
||||
*valp_ = res_; \
|
||||
PARSE_INT(&res_, 10) \
|
||||
*valp_ += res_; \
|
||||
PARSE_INT(&res_, 1) \
|
||||
*valp_ += res_; \
|
||||
} while (0)
|
||||
|
||||
/* returned pointer is always within [buf, buf_end), or null */
|
||||
static const char *parse_http_version(const char *buf, const char *buf_end, int *major_version, int *minor_version, int *ret) {
|
||||
static const char *parse_http_version(const char *buf, const char *buf_end, int *major_version,
|
||||
int *minor_version, int *ret) {
|
||||
/* we want at least [HTTP/1.<two chars>] to try to parse */
|
||||
if (buf_end - buf < 9) {
|
||||
*ret = -2;
|
||||
|
|
@ -260,8 +270,8 @@ static const char *parse_http_version(const char *buf, const char *buf_end, int
|
|||
return buf;
|
||||
}
|
||||
|
||||
static const char *parse_headers(const char *buf, const char *buf_end, struct phr_header *headers, size_t *num_headers, size_t max_headers,
|
||||
int *ret) {
|
||||
static const char *parse_headers(const char *buf, const char *buf_end, struct phr_header *headers,
|
||||
size_t *num_headers, size_t max_headers, int *ret) {
|
||||
for (;; ++*num_headers) {
|
||||
CHECK_EOF();
|
||||
if (*buf == '\015') {
|
||||
|
|
@ -337,9 +347,10 @@ static const char *parse_headers(const char *buf, const char *buf_end, struct ph
|
|||
return buf;
|
||||
}
|
||||
|
||||
static const char *parse_request(const char *buf, const char *buf_end, const char **method, size_t *method_len, const char **path,
|
||||
size_t *path_len, int *major_version, int *minor_version, struct phr_header *headers, size_t *num_headers,
|
||||
size_t max_headers, int *ret) {
|
||||
static const char *parse_request(const char *buf, const char *buf_end, const char **method,
|
||||
size_t *method_len, const char **path, size_t *path_len,
|
||||
int *major_version, int *minor_version, struct phr_header *headers,
|
||||
size_t *num_headers, size_t max_headers, int *ret) {
|
||||
/* skip first empty line (some clients add CRLF after POST content) */
|
||||
CHECK_EOF();
|
||||
if (*buf == '\015') {
|
||||
|
|
@ -378,8 +389,9 @@ static const char *parse_request(const char *buf, const char *buf_end, const cha
|
|||
return parse_headers(buf, buf_end, headers, num_headers, max_headers, ret);
|
||||
}
|
||||
|
||||
int phr_parse_request(const char *buf_start, size_t len, const char **method, size_t *method_len, const char **path, size_t *path_len,
|
||||
int *major_version, int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len) {
|
||||
int phr_parse_request(const char *buf_start, size_t len, const char **method, size_t *method_len,
|
||||
const char **path, size_t *path_len, int *major_version, int *minor_version,
|
||||
struct phr_header *headers, size_t *num_headers, size_t last_len) {
|
||||
const char *buf = buf_start, *buf_end = buf_start + len;
|
||||
size_t max_headers = *num_headers;
|
||||
int r;
|
||||
|
|
@ -398,17 +410,18 @@ int phr_parse_request(const char *buf_start, size_t len, const char **method, si
|
|||
return r;
|
||||
}
|
||||
|
||||
if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len, major_version, minor_version, headers, num_headers,
|
||||
max_headers, &r)) == NULL) {
|
||||
if ((buf = parse_request(buf, buf_end, method, method_len, path, path_len, major_version,
|
||||
minor_version, headers, num_headers, max_headers, &r)) == NULL) {
|
||||
return r;
|
||||
}
|
||||
|
||||
return (int)(buf - buf_start);
|
||||
}
|
||||
|
||||
static const char *parse_response(const char *buf, const char *buf_end, int *major_version, int *minor_version, int *status,
|
||||
const char **msg, size_t *msg_len, struct phr_header *headers, size_t *num_headers, size_t max_headers,
|
||||
int *ret) {
|
||||
static const char *parse_response(const char *buf, const char *buf_end, int *major_version,
|
||||
int *minor_version, int *status, const char **msg,
|
||||
size_t *msg_len, struct phr_header *headers, size_t *num_headers,
|
||||
size_t max_headers, int *ret) {
|
||||
/* parse "HTTP/1.x" */
|
||||
if ((buf = parse_http_version(buf, buf_end, major_version, minor_version, ret)) == NULL) {
|
||||
return NULL;
|
||||
|
|
@ -421,7 +434,8 @@ static const char *parse_response(const char *buf, const char *buf_end, int *maj
|
|||
do {
|
||||
++buf;
|
||||
} while (*buf == ' ');
|
||||
/* parse status code, we want at least [:digit:][:digit:][:digit:]<other char> to try to parse */
|
||||
/* parse status code, we want at least [:digit:][:digit:][:digit:]<other char> to try to parse
|
||||
*/
|
||||
if (buf_end - buf < 4) {
|
||||
*ret = -2;
|
||||
return NULL;
|
||||
|
|
@ -449,8 +463,9 @@ static const char *parse_response(const char *buf, const char *buf_end, int *maj
|
|||
return parse_headers(buf, buf_end, headers, num_headers, max_headers, ret);
|
||||
}
|
||||
|
||||
int phr_parse_response(const char *buf_start, size_t len, int *major_version, int *minor_version, int *status, const char **msg,
|
||||
size_t *msg_len, struct phr_header *headers, size_t *num_headers, size_t last_len) {
|
||||
int phr_parse_response(const char *buf_start, size_t len, int *major_version, int *minor_version,
|
||||
int *status, const char **msg, size_t *msg_len, struct phr_header *headers,
|
||||
size_t *num_headers, size_t last_len) {
|
||||
const char *buf = buf_start, *buf_end = buf + len;
|
||||
size_t max_headers = *num_headers;
|
||||
int r;
|
||||
|
|
@ -468,15 +483,16 @@ int phr_parse_response(const char *buf_start, size_t len, int *major_version, in
|
|||
return r;
|
||||
}
|
||||
|
||||
if ((buf = parse_response(buf, buf_end, major_version, minor_version, status, msg, msg_len, headers, num_headers, max_headers, &r)) ==
|
||||
NULL) {
|
||||
if ((buf = parse_response(buf, buf_end, major_version, minor_version, status, msg, msg_len,
|
||||
headers, num_headers, max_headers, &r)) == NULL) {
|
||||
return r;
|
||||
}
|
||||
|
||||
return (int)(buf - buf_start);
|
||||
}
|
||||
|
||||
int phr_parse_headers(const char *buf_start, size_t len, struct phr_header *headers, size_t *num_headers, size_t last_len) {
|
||||
int phr_parse_headers(const char *buf_start, size_t len, struct phr_header *headers,
|
||||
size_t *num_headers, size_t last_len) {
|
||||
const char *buf = buf_start, *buf_end = buf + len;
|
||||
size_t max_headers = *num_headers;
|
||||
int r;
|
||||
|
|
@ -526,8 +542,9 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
case CHUNKED_IN_CHUNK_SIZE:
|
||||
for (;; ++src) {
|
||||
int v;
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
}
|
||||
if ((v = decode_hex(buf[src])) == -1) {
|
||||
if (decoder->_hex_count == 0) {
|
||||
ret = -1;
|
||||
|
|
@ -548,10 +565,12 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
case CHUNKED_IN_CHUNK_EXT:
|
||||
/* RFC 7230 A.2 "Line folding in chunk extensions is disallowed" */
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] == '\012')
|
||||
}
|
||||
if (buf[src] == '\012') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
++src;
|
||||
if (decoder->bytes_left_in_chunk == 0) {
|
||||
|
|
@ -567,15 +586,17 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
case CHUNKED_IN_CHUNK_DATA: {
|
||||
size_t avail = bufsz - src;
|
||||
if (avail < decoder->bytes_left_in_chunk) {
|
||||
if (dst != src)
|
||||
if (dst != src) {
|
||||
memmove(buf + dst, buf + src, avail);
|
||||
}
|
||||
src += avail;
|
||||
dst += avail;
|
||||
decoder->bytes_left_in_chunk -= avail;
|
||||
goto Exit;
|
||||
}
|
||||
if (dst != src)
|
||||
if (dst != src) {
|
||||
memmove(buf + dst, buf + src, decoder->bytes_left_in_chunk);
|
||||
}
|
||||
src += decoder->bytes_left_in_chunk;
|
||||
dst += decoder->bytes_left_in_chunk;
|
||||
decoder->bytes_left_in_chunk = 0;
|
||||
|
|
@ -584,10 +605,12 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
/* fallthru */
|
||||
case CHUNKED_IN_CHUNK_CRLF:
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] != '\015')
|
||||
}
|
||||
if (buf[src] != '\015') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (buf[src] != '\012') {
|
||||
ret = -1;
|
||||
|
|
@ -598,21 +621,26 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
break;
|
||||
case CHUNKED_IN_TRAILERS_LINE_HEAD:
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] != '\015')
|
||||
}
|
||||
if (buf[src] != '\015') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (buf[src++] == '\012')
|
||||
if (buf[src++] == '\012') {
|
||||
goto Complete;
|
||||
}
|
||||
decoder->_state = CHUNKED_IN_TRAILERS_LINE_MIDDLE;
|
||||
/* fallthru */
|
||||
case CHUNKED_IN_TRAILERS_LINE_MIDDLE:
|
||||
for (;; ++src) {
|
||||
if (src == bufsz)
|
||||
if (src == bufsz) {
|
||||
goto Exit;
|
||||
if (buf[src] == '\012')
|
||||
}
|
||||
if (buf[src] == '\012') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
++src;
|
||||
decoder->_state = CHUNKED_IN_TRAILERS_LINE_HEAD;
|
||||
|
|
@ -625,13 +653,16 @@ ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_
|
|||
Complete:
|
||||
ret = bufsz - src;
|
||||
Exit:
|
||||
if (dst != src)
|
||||
if (dst != src) {
|
||||
memmove(buf + dst, buf + src, bufsz - src);
|
||||
}
|
||||
*_bufsz = dst;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int phr_decode_chunked_is_in_data(struct phr_chunked_decoder *decoder) { return decoder->_state == CHUNKED_IN_CHUNK_DATA; }
|
||||
int phr_decode_chunked_is_in_data(struct phr_chunked_decoder *decoder) {
|
||||
return decoder->_state == CHUNKED_IN_CHUNK_DATA;
|
||||
}
|
||||
|
||||
#undef CHECK_EOF
|
||||
#undef EXPECT_CHAR
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define ssize_t intptr_t
|
||||
# define ssize_t intptr_t
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -40,30 +40,33 @@ extern "C" {
|
|||
/* contains name and value of a header (name == NULL if is a continuing line
|
||||
* of a multiline header */
|
||||
struct phr_header {
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *value;
|
||||
size_t value_len;
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *value;
|
||||
size_t value_len;
|
||||
};
|
||||
|
||||
/* returns number of bytes consumed if successful, -2 if request is partial,
|
||||
* -1 if failed */
|
||||
int phr_parse_request(const char *buf, size_t len, const char **method, size_t *method_len, const char **path, size_t *path_len,
|
||||
int *major_version, int *minor_version, struct phr_header *headers, size_t *num_headers, size_t last_len);
|
||||
int phr_parse_request(const char *buf, size_t len, const char **method, size_t *method_len,
|
||||
const char **path, size_t *path_len, int *major_version, int *minor_version,
|
||||
struct phr_header *headers, size_t *num_headers, size_t last_len);
|
||||
|
||||
/* ditto */
|
||||
int phr_parse_response(const char *_buf, size_t len, int *major_version, int *minor_version, int *status, const char **msg, size_t *msg_len,
|
||||
struct phr_header *headers, size_t *num_headers, size_t last_len);
|
||||
int phr_parse_response(const char *_buf, size_t len, int *major_version, int *minor_version,
|
||||
int *status, const char **msg, size_t *msg_len, struct phr_header *headers,
|
||||
size_t *num_headers, size_t last_len);
|
||||
|
||||
/* ditto */
|
||||
int phr_parse_headers(const char *buf, size_t len, struct phr_header *headers, size_t *num_headers, size_t last_len);
|
||||
int phr_parse_headers(const char *buf, size_t len, struct phr_header *headers, size_t *num_headers,
|
||||
size_t last_len);
|
||||
|
||||
/* should be zero-filled before start */
|
||||
struct phr_chunked_decoder {
|
||||
size_t bytes_left_in_chunk; /* number of bytes left in current chunk */
|
||||
char consume_trailer; /* if trailing headers should be consumed */
|
||||
char _hex_count;
|
||||
char _state;
|
||||
size_t bytes_left_in_chunk; /* number of bytes left in current chunk */
|
||||
char consume_trailer; /* if trailing headers should be consumed */
|
||||
char _hex_count;
|
||||
char _state;
|
||||
};
|
||||
|
||||
/* the function rewrites the buffer given as (buf, bufsz) removing the chunked-
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ void popen_timeout_alarm_handler(int /*signo*/);
|
|||
#endif
|
||||
|
||||
#ifndef WIFEXITED
|
||||
# define WIFEXITED(stat_val) (((stat_val)&255) == 0)
|
||||
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
||||
#endif
|
||||
|
||||
/* 4.3BSD Reno <signal.h> doesn't define SIG_ERR */
|
||||
|
|
@ -96,24 +96,28 @@ FILE *spopen(const char *cmdstring) {
|
|||
env[1] = NULL;
|
||||
|
||||
/* if no command was passed, return with no error */
|
||||
if (cmdstring == NULL)
|
||||
if (cmdstring == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
char *cmd = NULL;
|
||||
/* make copy of command string so strtok() doesn't silently modify it */
|
||||
/* (the calling program may want to access it later) */
|
||||
cmd = malloc(strlen(cmdstring) + 1);
|
||||
if (cmd == NULL)
|
||||
if (cmd == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
strcpy(cmd, cmdstring);
|
||||
|
||||
/* This is not a shell, so we don't handle "???" */
|
||||
if (strstr(cmdstring, "\""))
|
||||
if (strstr(cmdstring, "\"")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* allow single quotes, but only if non-whitesapce doesn't occur on both sides */
|
||||
if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''"))
|
||||
if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''")) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int argc;
|
||||
char **argv = NULL;
|
||||
|
|
@ -140,15 +144,17 @@ FILE *spopen(const char *cmdstring) {
|
|||
|
||||
if (strstr(str, "'") == str) { /* handle SIMPLE quoted strings */
|
||||
str++;
|
||||
if (!strstr(str, "'"))
|
||||
if (!strstr(str, "'")) {
|
||||
return NULL; /* balanced? */
|
||||
}
|
||||
cmd = 1 + strstr(str, "'");
|
||||
str[strcspn(str, "'")] = 0;
|
||||
} else if (strcspn(str, "'") < strcspn(str, " \t\r\n")) {
|
||||
/* handle --option='foo bar' strings */
|
||||
char *tmp = str + strcspn(str, "'") + 1;
|
||||
if (!strstr(tmp, "'"))
|
||||
if (!strstr(tmp, "'")) {
|
||||
return NULL; /* balanced? */
|
||||
}
|
||||
tmp += strcspn(tmp, "'") + 1;
|
||||
*tmp = 0;
|
||||
cmd = tmp + 1;
|
||||
|
|
@ -161,8 +167,9 @@ FILE *spopen(const char *cmdstring) {
|
|||
}
|
||||
}
|
||||
|
||||
if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n"))
|
||||
if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n")) {
|
||||
cmd = NULL;
|
||||
}
|
||||
|
||||
argv[i++] = str;
|
||||
}
|
||||
|
|
@ -171,22 +178,26 @@ FILE *spopen(const char *cmdstring) {
|
|||
long maxfd = mp_open_max();
|
||||
|
||||
if (childpid == NULL) { /* first time through */
|
||||
if ((childpid = calloc((size_t)maxfd, sizeof(pid_t))) == NULL)
|
||||
if ((childpid = calloc((size_t)maxfd, sizeof(pid_t))) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (child_stderr_array == NULL) { /* first time through */
|
||||
if ((child_stderr_array = calloc((size_t)maxfd, sizeof(int))) == NULL)
|
||||
if ((child_stderr_array = calloc((size_t)maxfd, sizeof(int))) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
||||
int pfd[2];
|
||||
if (pipe(pfd) < 0)
|
||||
if (pipe(pfd) < 0) {
|
||||
return (NULL); /* errno set by pipe() */
|
||||
}
|
||||
|
||||
int pfderr[2];
|
||||
if (pipe(pfderr) < 0)
|
||||
if (pipe(pfderr) < 0) {
|
||||
return (NULL); /* errno set by pipe() */
|
||||
}
|
||||
|
||||
#ifdef REDHAT_SPOPEN_ERROR
|
||||
if (signal(SIGCHLD, popen_sigchld_handler) == SIG_ERR) {
|
||||
|
|
@ -195,8 +206,9 @@ FILE *spopen(const char *cmdstring) {
|
|||
#endif
|
||||
|
||||
pid_t pid;
|
||||
if ((pid = fork()) < 0)
|
||||
if ((pid = fork()) < 0) {
|
||||
return (NULL); /* errno set by fork() */
|
||||
}
|
||||
|
||||
if (pid == 0) { /* child */
|
||||
close(pfd[0]);
|
||||
|
|
@ -210,17 +222,20 @@ FILE *spopen(const char *cmdstring) {
|
|||
close(pfderr[1]);
|
||||
}
|
||||
/* close all descriptors in childpid[] */
|
||||
for (i = 0; i < maxfd; i++)
|
||||
if (childpid[i] > 0)
|
||||
for (i = 0; i < maxfd; i++) {
|
||||
if (childpid[i] > 0) {
|
||||
close(i);
|
||||
}
|
||||
}
|
||||
|
||||
execve(argv[0], argv, env);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
close(pfd[1]); /* parent */
|
||||
if ((child_process = fdopen(pfd[0], "r")) == NULL)
|
||||
if ((child_process = fdopen(pfd[0], "r")) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
close(pfderr[1]);
|
||||
|
||||
childpid[fileno(child_process)] = pid; /* remember child pid for this fd */
|
||||
|
|
@ -229,17 +244,20 @@ FILE *spopen(const char *cmdstring) {
|
|||
}
|
||||
|
||||
int spclose(FILE *fp) {
|
||||
if (childpid == NULL)
|
||||
if (childpid == NULL) {
|
||||
return (1); /* popen() has never been called */
|
||||
}
|
||||
|
||||
pid_t pid;
|
||||
int fd = fileno(fp);
|
||||
if ((pid = childpid[fd]) == 0)
|
||||
if ((pid = childpid[fd]) == 0) {
|
||||
return (1); /* fp wasn't opened by popen() */
|
||||
}
|
||||
|
||||
childpid[fd] = 0;
|
||||
if (fclose(fp) == EOF)
|
||||
if (fclose(fp) == EOF) {
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef REDHAT_SPOPEN_ERROR
|
||||
while (!childtermd)
|
||||
|
|
@ -247,20 +265,24 @@ int spclose(FILE *fp) {
|
|||
#endif
|
||||
|
||||
int status;
|
||||
while (waitpid(pid, &status, 0) < 0)
|
||||
if (errno != EINTR)
|
||||
while (waitpid(pid, &status, 0) < 0) {
|
||||
if (errno != EINTR) {
|
||||
return (1); /* error other than EINTR from waitpid() */
|
||||
}
|
||||
}
|
||||
|
||||
if (WIFEXITED(status))
|
||||
if (WIFEXITED(status)) {
|
||||
return (WEXITSTATUS(status)); /* return child's termination status */
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef REDHAT_SPOPEN_ERROR
|
||||
void popen_sigchld_handler(int signo) {
|
||||
if (signo == SIGCHLD)
|
||||
if (signo == SIGCHLD) {
|
||||
childtermd = 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
/******************************************************************************
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
FILE *spopen (const char *);
|
||||
int spclose (FILE *);
|
||||
void popen_timeout_alarm_handler (int);
|
||||
FILE *spopen(const char *);
|
||||
int spclose(FILE *);
|
||||
void popen_timeout_alarm_handler(int);
|
||||
|
||||
pid_t *childpid=NULL;
|
||||
int *child_stderr_array=NULL;
|
||||
FILE *child_process=NULL;
|
||||
FILE *child_stderr=NULL;
|
||||
pid_t *childpid = NULL;
|
||||
int *child_stderr_array = NULL;
|
||||
FILE *child_process = NULL;
|
||||
FILE *child_stderr = NULL;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
#endif
|
||||
|
||||
#ifndef WIFEXITED
|
||||
# define WIFEXITED(stat_val) (((stat_val)&255) == 0)
|
||||
# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
|
||||
#endif
|
||||
|
||||
/* 4.3BSD Reno <signal.h> doesn't define SIG_ERR */
|
||||
|
|
@ -87,8 +87,9 @@ extern void die(int, const char *, ...) __attribute__((__noreturn__, __format__(
|
|||
* through this api and thus achieve async-safeness throughout the api */
|
||||
void np_runcmd_init(void) {
|
||||
long maxfd = mp_open_max();
|
||||
if (!np_pids)
|
||||
if (!np_pids) {
|
||||
np_pids = calloc(maxfd, sizeof(pid_t));
|
||||
}
|
||||
}
|
||||
|
||||
/* Start running a command */
|
||||
|
|
@ -106,8 +107,9 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) {
|
|||
|
||||
int i = 0;
|
||||
|
||||
if (!np_pids)
|
||||
if (!np_pids) {
|
||||
NP_RUNCMD_INIT;
|
||||
}
|
||||
|
||||
env[0] = strdup("LC_ALL=C");
|
||||
env[1] = NULL;
|
||||
|
|
@ -115,18 +117,21 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) {
|
|||
/* make copy of command string so strtok() doesn't silently modify it */
|
||||
/* (the calling program may want to access it later) */
|
||||
cmdlen = strlen(cmdstring);
|
||||
if ((cmd = malloc(cmdlen + 1)) == NULL)
|
||||
if ((cmd = malloc(cmdlen + 1)) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(cmd, cmdstring, cmdlen);
|
||||
cmd[cmdlen] = '\0';
|
||||
|
||||
/* This is not a shell, so we don't handle "???" */
|
||||
if (strstr(cmdstring, "\""))
|
||||
if (strstr(cmdstring, "\"")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* allow single quotes, but only if non-whitesapce doesn't occur on both sides */
|
||||
if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''"))
|
||||
if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''")) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* each arg must be whitespace-separated, so args can be a maximum
|
||||
* of (len / 2) + 1. We add 1 extra to the mix for NULL termination */
|
||||
|
|
@ -145,8 +150,9 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) {
|
|||
|
||||
if (strstr(str, "'") == str) { /* handle SIMPLE quoted strings */
|
||||
str++;
|
||||
if (!strstr(str, "'"))
|
||||
if (!strstr(str, "'")) {
|
||||
return -1; /* balanced? */
|
||||
}
|
||||
cmd = 1 + strstr(str, "'");
|
||||
str[strcspn(str, "'")] = 0;
|
||||
} else {
|
||||
|
|
@ -158,14 +164,16 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) {
|
|||
}
|
||||
}
|
||||
|
||||
if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n"))
|
||||
if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n")) {
|
||||
cmd = NULL;
|
||||
}
|
||||
|
||||
argv[i++] = str;
|
||||
}
|
||||
|
||||
if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0)
|
||||
if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0) {
|
||||
return -1; /* errno set by the failing function */
|
||||
}
|
||||
|
||||
/* child runs exceve() and _exit. */
|
||||
if (pid == 0) {
|
||||
|
|
@ -190,9 +198,11 @@ static int np_runcmd_open(const char *cmdstring, int *pfd, int *pfderr) {
|
|||
* 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)
|
||||
for (i = 0; i < maxfd; i++) {
|
||||
if (np_pids[i] > 0) {
|
||||
close(i);
|
||||
}
|
||||
}
|
||||
|
||||
execve(argv[0], argv, env);
|
||||
_exit(STATE_UNKNOWN);
|
||||
|
|
@ -215,17 +225,21 @@ static int np_runcmd_close(int fd) {
|
|||
|
||||
/* 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)
|
||||
if (fd < 0 || fd > maxfd || !np_pids || (pid = np_pids[fd]) == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
np_pids[fd] = 0;
|
||||
if (close(fd) == -1)
|
||||
if (close(fd) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* EINTR is ok (sort of), everything else is bad */
|
||||
while (waitpid(pid, &status, 0) < 0)
|
||||
if (errno != EINTR)
|
||||
while (waitpid(pid, &status, 0) < 0) {
|
||||
if (errno != EINTR) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* return child's termination status */
|
||||
return (WIFEXITED(status)) ? WEXITSTATUS(status) : -1;
|
||||
|
|
@ -233,15 +247,18 @@ static int np_runcmd_close(int fd) {
|
|||
|
||||
void runcmd_timeout_alarm_handler(int signo) {
|
||||
|
||||
if (signo == SIGALRM)
|
||||
if (signo == SIGALRM) {
|
||||
puts(_("CRITICAL - Plugin timed out while executing system call"));
|
||||
}
|
||||
|
||||
long maxfd = mp_open_max();
|
||||
if (np_pids)
|
||||
if (np_pids) {
|
||||
for (long int i = 0; i < maxfd; i++) {
|
||||
if (np_pids[i] != 0)
|
||||
if (np_pids[i] != 0) {
|
||||
kill(np_pids[i], SIGKILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exit(STATE_CRITICAL);
|
||||
}
|
||||
|
|
@ -270,15 +287,17 @@ static int np_fetch_output(int fd, output *op, int flags) {
|
|||
|
||||
/* some plugins may want to keep output unbroken, and some commands
|
||||
* will yield no output, so return here for those */
|
||||
if (flags & RUNCMD_NO_ARRAYS || !op->buf || !op->buflen)
|
||||
if (flags & RUNCMD_NO_ARRAYS || !op->buf || !op->buflen) {
|
||||
return op->buflen;
|
||||
}
|
||||
|
||||
/* and some may want both */
|
||||
if (flags & RUNCMD_NO_ASSOC) {
|
||||
buf = malloc(op->buflen);
|
||||
memcpy(buf, op->buf, op->buflen);
|
||||
} else
|
||||
} else {
|
||||
buf = op->buf;
|
||||
}
|
||||
|
||||
op->line = NULL;
|
||||
op->lens = NULL;
|
||||
|
|
@ -299,8 +318,9 @@ static int np_fetch_output(int fd, output *op, int flags) {
|
|||
op->line[lineno] = &buf[i];
|
||||
|
||||
/* hop to next newline or end of buffer */
|
||||
while (buf[i] != '\n' && i < op->buflen)
|
||||
while (buf[i] != '\n' && i < op->buflen) {
|
||||
i++;
|
||||
}
|
||||
buf[i] = '\0';
|
||||
|
||||
/* calculate the string length using pointer difference */
|
||||
|
|
@ -317,18 +337,23 @@ int np_runcmd(const char *cmd, output *out, output *err, int flags) {
|
|||
int fd, pfd_out[2], pfd_err[2];
|
||||
|
||||
/* initialize the structs */
|
||||
if (out)
|
||||
if (out) {
|
||||
memset(out, 0, sizeof(output));
|
||||
if (err)
|
||||
}
|
||||
if (err) {
|
||||
memset(err, 0, sizeof(output));
|
||||
}
|
||||
|
||||
if ((fd = np_runcmd_open(cmd, pfd_out, pfd_err)) == -1)
|
||||
if ((fd = np_runcmd_open(cmd, pfd_out, pfd_err)) == -1) {
|
||||
die(STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd);
|
||||
}
|
||||
|
||||
if (out)
|
||||
if (out) {
|
||||
out->lines = np_fetch_output(pfd_out[0], out, flags);
|
||||
if (err)
|
||||
}
|
||||
if (err) {
|
||||
err->lines = np_fetch_output(pfd_err[0], err, flags);
|
||||
}
|
||||
|
||||
return np_runcmd_close(fd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
/****************************************************************************
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2005 Monitoring Plugins Development Team
|
||||
* Author: Andreas Ericsson <ae@op5.se>
|
||||
*
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
*
|
||||
* License: GPL
|
||||
* Copyright (c) 2005 Monitoring Plugins Development Team
|
||||
* Author: Andreas Ericsson <ae@op5.se>
|
||||
*
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef NAGIOSPLUG_RUNCMD_H
|
||||
#define NAGIOSPLUG_RUNCMD_H
|
||||
|
|
@ -29,8 +29,7 @@
|
|||
|
||||
/** prototypes **/
|
||||
int np_runcmd(const char *, output *, output *, int);
|
||||
void runcmd_timeout_alarm_handler(int)
|
||||
__attribute__((__noreturn__));
|
||||
void runcmd_timeout_alarm_handler(int) __attribute__((__noreturn__));
|
||||
|
||||
/* only multi-threaded plugins need to bother with this */
|
||||
void np_runcmd_init(void);
|
||||
|
|
@ -38,6 +37,6 @@ void np_runcmd_init(void);
|
|||
|
||||
/* possible flags for np_runcmd()'s fourth argument */
|
||||
#define RUNCMD_NO_ARRAYS 0x01 /* don't populate arrays at all */
|
||||
#define RUNCMD_NO_ASSOC 0x02 /* output.line won't point to buf */
|
||||
#define RUNCMD_NO_ASSOC 0x02 /* output.line won't point to buf */
|
||||
|
||||
#endif /* NAGIOSPLUG_RUNCMD_H */
|
||||
|
|
|
|||
|
|
@ -437,16 +437,14 @@ mp_subcheck mp_net_ssl_check_certificate(X509 *certificate, int days_till_exp_wa
|
|||
xasprintf(&sc_cert.output, _("Certificate '%s' expired on %s"), commonName, timestamp);
|
||||
sc_cert = mp_set_subcheck_state(sc_cert, STATE_CRITICAL);
|
||||
} else if (days_left == 0) {
|
||||
xasprintf(&sc_cert.output, _("Certificate '%s' just expired (%s)"), commonName,
|
||||
timestamp);
|
||||
xasprintf(&sc_cert.output, _("Certificate '%s' just expired (%s)"), commonName, timestamp);
|
||||
if (days_left > days_till_exp_crit) {
|
||||
sc_cert = mp_set_subcheck_state(sc_cert, STATE_WARNING);
|
||||
} else {
|
||||
sc_cert = mp_set_subcheck_state(sc_cert, STATE_CRITICAL);
|
||||
}
|
||||
} else {
|
||||
xasprintf(&sc_cert.output, _("Certificate '%s' will expire on %s"), commonName,
|
||||
timestamp);
|
||||
xasprintf(&sc_cert.output, _("Certificate '%s' will expire on %s"), commonName, timestamp);
|
||||
sc_cert = mp_set_subcheck_state(sc_cert, STATE_OK);
|
||||
}
|
||||
X509_free(certificate);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
#include "../../tap/tap.h"
|
||||
#include "regex.h"
|
||||
|
||||
void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc);
|
||||
void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags,
|
||||
int expect, char *desc);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
plan_tests(35);
|
||||
|
|
@ -70,16 +71,26 @@ int main(int argc, char **argv) {
|
|||
|
||||
int cflags = REG_NOSUB | REG_EXTENDED;
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/"), cflags, 3, strdup("a"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3, strdup("regex on dev names:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0, strdup("regex on non existent dev/path:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0, strdup("regi on non existent dev/path:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3, strdup("partial devname regex match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1, strdup("partial devname regex match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1, strdup("partial devname regi match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1, strdup("partial pathname regex match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1, strdup("partial pathname regi match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2, strdup("grouped regex pathname match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2, strdup("grouped regi pathname match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/dev"), cflags, 3,
|
||||
strdup("regex on dev names:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/foo"), cflags, 0,
|
||||
strdup("regex on non existent dev/path:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/Foo"), cflags | REG_ICASE, 0,
|
||||
strdup("regi on non existent dev/path:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("/c.t0"), cflags, 3,
|
||||
strdup("partial devname regex match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("c0t0"), cflags, 1,
|
||||
strdup("partial devname regex match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("C0t0"), cflags | REG_ICASE, 1,
|
||||
strdup("partial devname regi match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("home"), cflags, 1,
|
||||
strdup("partial pathname regex match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("hOme"), cflags | REG_ICASE, 1,
|
||||
strdup("partial pathname regi match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("(/home)|(/var)"), cflags, 2,
|
||||
strdup("grouped regex pathname match:"));
|
||||
np_test_mount_entry_regex(dummy_mount_list, strdup("(/homE)|(/Var)"), cflags | REG_ICASE, 2,
|
||||
strdup("grouped regi pathname match:"));
|
||||
|
||||
filesystem_list test_paths = filesystem_list_init();
|
||||
mp_int_fs_list_append(&test_paths, "/home/groups");
|
||||
|
|
@ -94,15 +105,18 @@ int main(int argc, char **argv) {
|
|||
struct mount_entry *temp_me;
|
||||
temp_me = p->best_match;
|
||||
if (!strcmp(p->name, "/home/groups")) {
|
||||
ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home");
|
||||
ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"),
|
||||
"/home/groups got right best match: /home");
|
||||
} else if (!strcmp(p->name, "/var")) {
|
||||
ok(temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var");
|
||||
} else if (!strcmp(p->name, "/tmp")) {
|
||||
ok(temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /");
|
||||
} else if (!strcmp(p->name, "/home/tonvoon")) {
|
||||
ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home");
|
||||
ok(temp_me && !strcmp(temp_me->me_mountdir, "/home"),
|
||||
"/home/tonvoon got right best match: /home");
|
||||
} else if (!strcmp(p->name, "/dev/c2t0d0s0")) {
|
||||
ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0");
|
||||
ok(temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"),
|
||||
"/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +194,8 @@ int main(int argc, char **argv) {
|
|||
return exit_status();
|
||||
}
|
||||
|
||||
void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags, int expect, char *desc) {
|
||||
void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regstr, int cflags,
|
||||
int expect, char *desc) {
|
||||
regex_t regex;
|
||||
if (regcomp(®ex, regstr, cflags) == 0) {
|
||||
int matches = 0;
|
||||
|
|
@ -189,7 +204,8 @@ void np_test_mount_entry_regex(struct mount_entry *dummy_mount_list, char *regst
|
|||
matches++;
|
||||
}
|
||||
}
|
||||
ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect, matches);
|
||||
ok(matches == expect, "%s '%s' matched %i/3 entries. ok: %i/3", desc, regstr, expect,
|
||||
matches);
|
||||
|
||||
} else {
|
||||
ok(false, "regex '%s' not compilable", regstr);
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@
|
|||
int verbose = 0;
|
||||
|
||||
void print_usage(void) {}
|
||||
void print_help(swap_config config) {
|
||||
(void) config;
|
||||
}
|
||||
void print_help(swap_config config) { (void)config; }
|
||||
|
||||
const char *progname = "test_check_swap";
|
||||
|
||||
|
|
|
|||
|
|
@ -53,8 +53,10 @@ int main(int argc, char **argv) {
|
|||
|
||||
int c;
|
||||
int option = 0;
|
||||
static struct option longopts[] = {
|
||||
{"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"url", required_argument, 0, 'u'}, {0, 0, 0, 0}};
|
||||
static struct option longopts[] = {{"help", no_argument, 0, 'h'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"url", required_argument, 0, 'u'},
|
||||
{0, 0, 0, 0}};
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
|
|
@ -69,8 +71,9 @@ int main(int argc, char **argv) {
|
|||
while (1) {
|
||||
c = getopt_long(argc, argv, "+hVu:", longopts, &option);
|
||||
|
||||
if (c == -1 || c == EOF)
|
||||
if (c == -1 || c == EOF) {
|
||||
break;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'h': /* help */
|
||||
|
|
@ -90,8 +93,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
}
|
||||
|
||||
if (url == NULL)
|
||||
if (url == NULL) {
|
||||
url = strdup(argv[optind++]);
|
||||
}
|
||||
|
||||
cmd = strdup(argv[optind++]);
|
||||
for (c = optind; c < argc; c++) {
|
||||
|
|
@ -118,27 +122,32 @@ int main(int argc, char **argv) {
|
|||
strcat(tstr, buf);
|
||||
}
|
||||
|
||||
if (!found)
|
||||
die(STATE_UNKNOWN, _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"), argv[0], cmd);
|
||||
if (!found) {
|
||||
die(STATE_UNKNOWN, _("%s UNKNOWN - No data received from host\nCMD: %s</A>\n"), argv[0],
|
||||
cmd);
|
||||
}
|
||||
|
||||
/* chop the newline character */
|
||||
if ((nstr = strchr(tstr, NEWLINE_CHARACTER)) != NULL)
|
||||
if ((nstr = strchr(tstr, NEWLINE_CHARACTER)) != NULL) {
|
||||
*nstr = '\0';
|
||||
}
|
||||
|
||||
/* tokenize the string for Perfdata if there is some */
|
||||
nstr = strtok(tstr, PERF_CHARACTER);
|
||||
printf("%s", nstr);
|
||||
printf("</A>");
|
||||
nstr = strtok(NULL, PERF_CHARACTER);
|
||||
if (nstr != NULL)
|
||||
if (nstr != NULL) {
|
||||
printf(" | %s", nstr);
|
||||
}
|
||||
|
||||
/* close the pipe */
|
||||
result = spclose(child_process);
|
||||
|
||||
/* WARNING if output found on stderr */
|
||||
if (fgets(buf, MAX_INPUT_BUFFER - 1, child_stderr))
|
||||
if (fgets(buf, MAX_INPUT_BUFFER - 1, child_stderr)) {
|
||||
result = max_state(result, STATE_WARNING);
|
||||
}
|
||||
|
||||
/* close stderr */
|
||||
(void)fclose(child_stderr);
|
||||
|
|
@ -153,8 +162,10 @@ void print_help(void) {
|
|||
printf(COPYRIGHT, copyright, email);
|
||||
|
||||
printf("%s\n", _("This plugin wraps the text output of another command (plugin) in HTML <A>"));
|
||||
printf("%s\n", _("tags, thus displaying the child plugin's output as a clickable link in compatible"));
|
||||
printf("%s\n", _("monitoring status screen. This plugin returns the status of the invoked plugin."));
|
||||
printf("%s\n",
|
||||
_("tags, thus displaying the child plugin's output as a clickable link in compatible"));
|
||||
printf("%s\n",
|
||||
_("monitoring status screen. This plugin returns the status of the invoked plugin."));
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
|
|
@ -164,7 +175,8 @@ void print_help(void) {
|
|||
|
||||
printf("\n");
|
||||
printf("%s\n", _("Examples:"));
|
||||
printf("%s\n", _("Pay close attention to quoting to ensure that the shell passes the expected"));
|
||||
printf("%s\n",
|
||||
_("Pay close attention to quoting to ensure that the shell passes the expected"));
|
||||
printf("%s\n\n", _("data to the plugin. For example, in:"));
|
||||
printf(" %s\n\n", _("urlize http://example.com/ check_http -H example.com -r 'two words'"));
|
||||
printf(" %s\n", _("the shell will remove the single quotes and urlize will see:"));
|
||||
|
|
|
|||
|
|
@ -285,7 +285,8 @@ double delta_time(struct timeval tv) {
|
|||
struct timeval now;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
return ((double)(now.tv_sec - tv.tv_sec) + (double)(now.tv_usec - tv.tv_usec) / (double)1000000);
|
||||
return ((double)(now.tv_sec - tv.tv_sec) +
|
||||
(double)(now.tv_usec - tv.tv_usec) / (double)1000000);
|
||||
}
|
||||
|
||||
long deltime(struct timeval tv) {
|
||||
|
|
@ -507,8 +508,8 @@ int xasprintf(char **strp, const char *fmt, ...) {
|
|||
*
|
||||
******************************************************************************/
|
||||
|
||||
char *perfdata(const char *label, long int val, const char *uom, bool warnp, long int warn, bool critp, long int crit, bool minp,
|
||||
long int minv, bool maxp, long int maxv) {
|
||||
char *perfdata(const char *label, long int val, const char *uom, bool warnp, long int warn,
|
||||
bool critp, long int crit, bool minp, long int minv, bool maxp, long int maxv) {
|
||||
char *data = NULL;
|
||||
|
||||
if (strpbrk(label, "'= ")) {
|
||||
|
|
@ -542,10 +543,11 @@ char *perfdata(const char *label, long int val, const char *uom, bool warnp, lon
|
|||
return data;
|
||||
}
|
||||
|
||||
char *perfdata_uint64(const char *label, uint64_t val, const char *uom, bool warnp, /* Warning present */
|
||||
uint64_t warn, bool critp, /* Critical present */
|
||||
uint64_t crit, bool minp, /* Minimum present */
|
||||
uint64_t minv, bool maxp, /* Maximum present */
|
||||
char *perfdata_uint64(const char *label, uint64_t val, const char *uom,
|
||||
bool warnp, /* Warning present */
|
||||
uint64_t warn, bool critp, /* Critical present */
|
||||
uint64_t crit, bool minp, /* Minimum present */
|
||||
uint64_t minv, bool maxp, /* Maximum present */
|
||||
uint64_t maxv) {
|
||||
char *data = NULL;
|
||||
|
||||
|
|
@ -580,10 +582,11 @@ char *perfdata_uint64(const char *label, uint64_t val, const char *uom, bool war
|
|||
return data;
|
||||
}
|
||||
|
||||
char *perfdata_int64(const char *label, int64_t val, const char *uom, bool warnp, /* Warning present */
|
||||
int64_t warn, bool critp, /* Critical present */
|
||||
int64_t crit, bool minp, /* Minimum present */
|
||||
int64_t minv, bool maxp, /* Maximum present */
|
||||
char *perfdata_int64(const char *label, int64_t val, const char *uom,
|
||||
bool warnp, /* Warning present */
|
||||
int64_t warn, bool critp, /* Critical present */
|
||||
int64_t crit, bool minp, /* Minimum present */
|
||||
int64_t minv, bool maxp, /* Maximum present */
|
||||
int64_t maxv) {
|
||||
char *data = NULL;
|
||||
|
||||
|
|
@ -618,8 +621,8 @@ char *perfdata_int64(const char *label, int64_t val, const char *uom, bool warnp
|
|||
return data;
|
||||
}
|
||||
|
||||
char *fperfdata(const char *label, double val, const char *uom, bool warnp, double warn, bool critp, double crit, bool minp, double minv,
|
||||
bool maxp, double maxv) {
|
||||
char *fperfdata(const char *label, double val, const char *uom, bool warnp, double warn, bool critp,
|
||||
double crit, bool minp, double minv, bool maxp, double maxv) {
|
||||
char *data = NULL;
|
||||
|
||||
if (strpbrk(label, "'= ")) {
|
||||
|
|
@ -655,7 +658,8 @@ char *fperfdata(const char *label, double val, const char *uom, bool warnp, doub
|
|||
return data;
|
||||
}
|
||||
|
||||
char *sperfdata(const char *label, double val, const char *uom, char *warn, char *crit, bool minp, double minv, bool maxp, double maxv) {
|
||||
char *sperfdata(const char *label, double val, const char *uom, char *warn, char *crit, bool minp,
|
||||
double minv, bool maxp, double maxv) {
|
||||
char *data = NULL;
|
||||
if (strpbrk(label, "'= ")) {
|
||||
xasprintf(&data, "'%s'=", label);
|
||||
|
|
@ -690,7 +694,8 @@ char *sperfdata(const char *label, double val, const char *uom, char *warn, char
|
|||
return data;
|
||||
}
|
||||
|
||||
char *sperfdata_int(const char *label, int val, const char *uom, char *warn, char *crit, bool minp, int minv, bool maxp, int maxv) {
|
||||
char *sperfdata_int(const char *label, int val, const char *uom, char *warn, char *crit, bool minp,
|
||||
int minv, bool maxp, int maxv) {
|
||||
char *data = NULL;
|
||||
if (strpbrk(label, "'= ")) {
|
||||
xasprintf(&data, "'%s'=", label);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ char *strnl(char *);
|
|||
char *strpcpy(char *, const char *, const char *);
|
||||
char *strpcat(char *, const char *, const char *);
|
||||
int xvasprintf(char **strp, const char *fmt, va_list ap);
|
||||
int xasprintf(char **strp, const char *fmt, ...)__attribute__ ((format (printf, 2, 3)));
|
||||
int xasprintf(char **strp, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
|
||||
void usage(const char *) __attribute__((noreturn));
|
||||
void usage2(const char *, const char *) __attribute__((noreturn));
|
||||
|
|
@ -88,13 +88,17 @@ void usage_va(const char *fmt, ...) __attribute__((noreturn));
|
|||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
char *perfdata(const char *, long int, const char *, bool, long int, bool, long int, bool, long int, bool, long int);
|
||||
char *perfdata(const char *, long int, const char *, bool, long int, bool, long int, bool, long int,
|
||||
bool, long int);
|
||||
|
||||
char *perfdata_uint64(const char *, uint64_t, const char *, bool, uint64_t, bool, uint64_t, bool, uint64_t, bool, uint64_t);
|
||||
char *perfdata_uint64(const char *, uint64_t, const char *, bool, uint64_t, bool, uint64_t, bool,
|
||||
uint64_t, bool, uint64_t);
|
||||
|
||||
char *perfdata_int64(const char *, int64_t, const char *, bool, int64_t, bool, int64_t, bool, int64_t, bool, int64_t);
|
||||
char *perfdata_int64(const char *, int64_t, const char *, bool, int64_t, bool, int64_t, bool,
|
||||
int64_t, bool, int64_t);
|
||||
|
||||
char *fperfdata(const char *, double, const char *, bool, double, bool, double, bool, double, bool, double);
|
||||
char *fperfdata(const char *, double, const char *, bool, double, bool, double, bool, double, bool,
|
||||
double);
|
||||
|
||||
char *sperfdata(const char *, double, const char *, char *, char *, bool, double, bool, double);
|
||||
|
||||
|
|
@ -104,21 +108,22 @@ char *sperfdata_int(const char *, int, const char *, char *, char *, bool, int,
|
|||
most will or should. Therefore, for consistency, these very common
|
||||
options should have only these meanings throughout the overall suite */
|
||||
|
||||
#define STD_LONG_OPTS \
|
||||
{"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, \
|
||||
{"timeout", required_argument, 0, 't'}, {"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, \
|
||||
#define STD_LONG_OPTS \
|
||||
{"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, \
|
||||
{"help", no_argument, 0, 'h'}, {"timeout", required_argument, 0, 't'}, \
|
||||
{"critical", required_argument, 0, 'c'}, {"warning", required_argument, 0, 'w'}, \
|
||||
{"hostname", required_argument, 0, 'H'}
|
||||
|
||||
#define COPYRIGHT \
|
||||
#define COPYRIGHT \
|
||||
"Copyright (c) %s Monitoring Plugins Development Team\n\
|
||||
\t<%s>\n\n"
|
||||
|
||||
#define UT_HLP_VRS \
|
||||
#define UT_HLP_VRS \
|
||||
_("\
|
||||
%s (-h | --help) for detailed help\n\
|
||||
%s (-V | --version) for version information\n")
|
||||
|
||||
#define UT_HELP_VRSN \
|
||||
#define UT_HELP_VRSN \
|
||||
_("\
|
||||
\nOptions:\n\
|
||||
-h, --help\n\
|
||||
|
|
@ -126,52 +131,52 @@ char *sperfdata_int(const char *, int, const char *, char *, char *, bool, int,
|
|||
-V, --version\n\
|
||||
Print version information\n")
|
||||
|
||||
#define UT_HOST_PORT \
|
||||
#define UT_HOST_PORT \
|
||||
_("\
|
||||
-H, --hostname=ADDRESS\n\
|
||||
Host name, IP Address, or unix socket (must be an absolute path)\n\
|
||||
-%c, --port=INTEGER\n\
|
||||
Port number (default: %s)\n")
|
||||
|
||||
#define UT_IPv46 \
|
||||
#define UT_IPv46 \
|
||||
_("\
|
||||
-4, --use-ipv4\n\
|
||||
Use IPv4 connection\n\
|
||||
-6, --use-ipv6\n\
|
||||
Use IPv6 connection\n")
|
||||
|
||||
#define UT_VERBOSE \
|
||||
#define UT_VERBOSE \
|
||||
_("\
|
||||
-v, --verbose\n\
|
||||
Show details for command-line debugging (output may be truncated by\n\
|
||||
the monitoring system)\n")
|
||||
|
||||
#define UT_WARN_CRIT \
|
||||
#define UT_WARN_CRIT \
|
||||
_("\
|
||||
-w, --warning=DOUBLE\n\
|
||||
Response time to result in warning status (seconds)\n\
|
||||
-c, --critical=DOUBLE\n\
|
||||
Response time to result in critical status (seconds)\n")
|
||||
|
||||
#define UT_WARN_CRIT_RANGE \
|
||||
#define UT_WARN_CRIT_RANGE \
|
||||
_("\
|
||||
-w, --warning=RANGE\n\
|
||||
Warning range (format: start:end). Alert if outside this range\n\
|
||||
-c, --critical=RANGE\n\
|
||||
Critical range\n")
|
||||
|
||||
#define UT_CONN_TIMEOUT \
|
||||
#define UT_CONN_TIMEOUT \
|
||||
_("\
|
||||
-t, --timeout=INTEGER\n\
|
||||
Seconds before connection times out (default: %d)\n")
|
||||
|
||||
#define UT_PLUG_TIMEOUT \
|
||||
#define UT_PLUG_TIMEOUT \
|
||||
_("\
|
||||
-t, --timeout=INTEGER\n\
|
||||
Seconds before plugin times out (default: %d)\n")
|
||||
|
||||
#ifdef NP_EXTRA_OPTS
|
||||
# define UT_EXTRA_OPTS \
|
||||
# define UT_EXTRA_OPTS \
|
||||
_("\
|
||||
--extra-opts=[section][@file]\n\
|
||||
Read options from an ini file. See\n\
|
||||
|
|
@ -181,25 +186,25 @@ char *sperfdata_int(const char *, int, const char *, char *, char *, bool, int,
|
|||
# define UT_EXTRA_OPTS " \b"
|
||||
#endif
|
||||
|
||||
#define UT_THRESHOLDS_NOTES \
|
||||
#define UT_THRESHOLDS_NOTES \
|
||||
_("\
|
||||
See:\n\
|
||||
https://www.monitoring-plugins.org/doc/guidelines.html#THRESHOLDFORMAT\n\
|
||||
for THRESHOLD format and examples.\n")
|
||||
|
||||
#define UT_SUPPORT \
|
||||
#define UT_SUPPORT \
|
||||
_("\n\
|
||||
Send email to help@monitoring-plugins.org if you have questions regarding\n\
|
||||
use of this software. To submit patches or suggest improvements, send email\n\
|
||||
to devel@monitoring-plugins.org\n\n")
|
||||
|
||||
#define UT_NOWARRANTY \
|
||||
#define UT_NOWARRANTY \
|
||||
_("\n\
|
||||
The Monitoring Plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\n\
|
||||
copies of the plugins under the terms of the GNU General Public License.\n\
|
||||
For more information about these matters, see the file named COPYING.\n")
|
||||
|
||||
#define UT_OUTPUT_FORMAT \
|
||||
#define UT_OUTPUT_FORMAT \
|
||||
_("\
|
||||
--output-format=OUTPUT_FORMAT\n\
|
||||
Select output format. Valid values: \"multi-line\", \"mp-test-json\"\n")
|
||||
|
|
|
|||
25
tap/tap.c
25
tap/tap.c
|
|
@ -65,7 +65,8 @@ static void _cleanup(void);
|
|||
* test_name -- the name of the test, may be NULL
|
||||
* test_comment -- a comment to print afterwards, may be NULL
|
||||
*/
|
||||
unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line, char *test_name, ...) {
|
||||
unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line, char *test_name,
|
||||
...) {
|
||||
va_list ap;
|
||||
char *local_test_name = NULL;
|
||||
char *c;
|
||||
|
|
@ -95,7 +96,9 @@ unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line
|
|||
}
|
||||
|
||||
if (name_is_digits) {
|
||||
diag(" You named your test '%s'. You shouldn't use numbers for your test names.", local_test_name);
|
||||
diag(
|
||||
" You named your test '%s'. You shouldn't use numbers for your test names.",
|
||||
local_test_name);
|
||||
diag(" Very confusing.");
|
||||
}
|
||||
}
|
||||
|
|
@ -116,8 +119,9 @@ unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line
|
|||
if (local_test_name != NULL) {
|
||||
flockfile(stdout);
|
||||
for (c = local_test_name; *c != '\0'; c++) {
|
||||
if (*c == '#')
|
||||
if (*c == '#') {
|
||||
fputc('\\', stdout);
|
||||
}
|
||||
fputc((int)*c, stdout);
|
||||
}
|
||||
funlockfile(stdout);
|
||||
|
|
@ -135,14 +139,16 @@ unsigned int _gen_result(int ok, const char *func, char *file, unsigned int line
|
|||
the test failed. */
|
||||
if (todo) {
|
||||
printf(" # TODO %s", todo_msg ? todo_msg : todo_msg_fixed);
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
failures--;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
diag(" Failed %stest (%s:%s() at line %d)", todo ? "(TODO) " : "", file, func, line);
|
||||
}
|
||||
|
||||
free(local_test_name);
|
||||
|
||||
|
|
@ -212,8 +218,9 @@ int plan_skip_all(char *reason) {
|
|||
|
||||
printf("1..0");
|
||||
|
||||
if (reason != NULL)
|
||||
if (reason != NULL) {
|
||||
printf(" # Skip %s", reason);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
|
@ -294,7 +301,8 @@ int skip(unsigned int n, char *fmt, ...) {
|
|||
|
||||
while (n-- > 0) {
|
||||
test_count++;
|
||||
printf("ok %d # skip %s\n", test_count, skip_msg != NULL ? skip_msg : "libtap():malloc() failed");
|
||||
printf("ok %d # skip %s\n", test_count,
|
||||
skip_msg != NULL ? skip_msg : "libtap():malloc() failed");
|
||||
}
|
||||
|
||||
free(skip_msg);
|
||||
|
|
@ -396,8 +404,9 @@ void _cleanup(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (failures)
|
||||
if (failures) {
|
||||
diag("Looks like you failed %d tests of %d.", failures, test_count);
|
||||
}
|
||||
|
||||
UNLOCK;
|
||||
}
|
||||
|
|
|
|||
43
tap/tap.h
43
tap/tap.h
|
|
@ -28,45 +28,50 @@
|
|||
and requires the caller to add the final comma if they've omitted
|
||||
the optional arguments */
|
||||
#ifdef __GNUC__
|
||||
# define ok(e, test, ...) \
|
||||
((e) ? _gen_result(1, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__) \
|
||||
# define ok(e, test, ...) \
|
||||
((e) ? _gen_result(1, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__) \
|
||||
: _gen_result(0, __func__, __FILE__, __LINE__, test, ##__VA_ARGS__))
|
||||
|
||||
# define ok1(e) ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
|
||||
# define ok1(e) \
|
||||
((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) \
|
||||
: _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
|
||||
|
||||
# define pass(test, ...) ok(1, test, ##__VA_ARGS__);
|
||||
# define fail(test, ...) ok(0, test, ##__VA_ARGS__);
|
||||
|
||||
# define skip_start(test, n, fmt, ...) \
|
||||
do { \
|
||||
if ((test)) { \
|
||||
skip(n, fmt, ##__VA_ARGS__); \
|
||||
continue; \
|
||||
# define skip_start(test, n, fmt, ...) \
|
||||
do { \
|
||||
if ((test)) { \
|
||||
skip(n, fmt, ##__VA_ARGS__); \
|
||||
continue; \
|
||||
}
|
||||
#else /* __GNUC__ */
|
||||
/* The original tap.h used to test if __STDC_VERSION__ >= 199901L here. This
|
||||
* doesn't seem to work on HP-UX even though the code compile fine. I'm not
|
||||
* sure how to add an exception here for HP-UX so I just removed the check
|
||||
* for now */
|
||||
# define ok(e, ...) \
|
||||
((e) ? _gen_result(1, __func__, __FILE__, __LINE__, __VA_ARGS__) : _gen_result(0, __func__, __FILE__, __LINE__, __VA_ARGS__))
|
||||
# define ok(e, ...) \
|
||||
((e) ? _gen_result(1, __func__, __FILE__, __LINE__, __VA_ARGS__) \
|
||||
: _gen_result(0, __func__, __FILE__, __LINE__, __VA_ARGS__))
|
||||
|
||||
# define ok1(e) ((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
|
||||
# define ok1(e) \
|
||||
((e) ? _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) \
|
||||
: _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
|
||||
|
||||
# define pass(...) ok(1, __VA_ARGS__);
|
||||
# define fail(...) ok(0, __VA_ARGS__);
|
||||
|
||||
# define skip_start(test, n, ...) \
|
||||
do { \
|
||||
if ((test)) { \
|
||||
skip(n, __VA_ARGS__); \
|
||||
continue; \
|
||||
# define skip_start(test, n, ...) \
|
||||
do { \
|
||||
if ((test)) { \
|
||||
skip(n, __VA_ARGS__); \
|
||||
continue; \
|
||||
}
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
#define skip_end \
|
||||
} \
|
||||
while (0) \
|
||||
#define skip_end \
|
||||
} \
|
||||
while (0) \
|
||||
;
|
||||
|
||||
unsigned int _gen_result(int, const char *, char *, unsigned int, char *, ...);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
/*
|
||||
/*
|
||||
*
|
||||
* MINI_EPN.C - Mini Embedded Perl Nagios
|
||||
* Contributed by Stanley Hopcroft
|
||||
* Modified by Douglas Warner
|
||||
* Last Modified: 05/02/2002
|
||||
*
|
||||
* This is a sample mini embedded Perl interpreter (hacked out checks.c and
|
||||
* perlembed) for use in testing Perl plugins.
|
||||
* This is a sample mini embedded Perl interpreter (hacked out checks.c and
|
||||
* perlembed) for use in testing Perl plugins.
|
||||
*
|
||||
* It can be compiled with the following command (see 'man perlembed' for
|
||||
* It can be compiled with the following command (see 'man perlembed' for
|
||||
* more info):
|
||||
*
|
||||
* gcc -omini_epn mini_epn.c `perl -MExtUtils::Embed -e ccopts -e ldopts`
|
||||
|
|
@ -21,7 +21,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <EXTERN.h>
|
||||
#include <perl.h>
|
||||
#include <fcntl.h>
|
||||
|
|
@ -30,7 +29,7 @@
|
|||
/* include PERL xs_init code for module and C library support */
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define is_cplusplus
|
||||
# define is_cplusplus
|
||||
#endif
|
||||
|
||||
#ifdef is_cplusplus
|
||||
|
|
@ -42,22 +41,20 @@ extern "C" {
|
|||
|
||||
#ifdef is_cplusplus
|
||||
}
|
||||
# ifndef EXTERN_C
|
||||
# define EXTERN_C extern "C"
|
||||
# endif
|
||||
# ifndef EXTERN_C
|
||||
# define EXTERN_C extern "C"
|
||||
# endif
|
||||
#else
|
||||
# ifndef EXTERN_C
|
||||
# define EXTERN_C extern
|
||||
# endif
|
||||
# ifndef EXTERN_C
|
||||
# define EXTERN_C extern
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
EXTERN_C void xs_init _((void));
|
||||
|
||||
EXTERN_C void boot_DynaLoader _((CV* cv));
|
||||
EXTERN_C void boot_DynaLoader _((CV * cv));
|
||||
|
||||
EXTERN_C void xs_init(void)
|
||||
{
|
||||
EXTERN_C void xs_init(void) {
|
||||
char *file = __FILE__;
|
||||
dXSUB_SYS;
|
||||
|
||||
|
|
@ -65,85 +62,80 @@ EXTERN_C void xs_init(void)
|
|||
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
|
||||
}
|
||||
|
||||
|
||||
static PerlInterpreter *perl = NULL;
|
||||
|
||||
|
||||
int main(int argc, char **argv, char **env)
|
||||
{
|
||||
char *embedding[] = { "", "p1.pl" };
|
||||
int main(int argc, char **argv, char **env) {
|
||||
char *embedding[] = {"", "p1.pl"};
|
||||
char plugin_output[1024];
|
||||
char buffer[512];
|
||||
char tmpfname[32];
|
||||
char fname[32];
|
||||
char *args[] = {"","0", "", "", NULL };
|
||||
char *args[] = {"", "0", "", "", NULL};
|
||||
FILE *fp;
|
||||
|
||||
const int command_line_size = 160;
|
||||
char command_line[command_line_size];
|
||||
char *ap ;
|
||||
char *ap;
|
||||
int exitstatus;
|
||||
int pclose_result;
|
||||
#ifdef THREADEDPERL
|
||||
dTHX;
|
||||
#endif
|
||||
dSP;
|
||||
dSP;
|
||||
|
||||
if ((perl=perl_alloc())==NULL) {
|
||||
snprintf(buffer,sizeof(buffer),"Error: Could not allocate memory for embedded Perl interpreter!\n");
|
||||
buffer[sizeof(buffer)-1]='\x0';
|
||||
if ((perl = perl_alloc()) == NULL) {
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"Error: Could not allocate memory for embedded Perl interpreter!\n");
|
||||
buffer[sizeof(buffer) - 1] = '\x0';
|
||||
printf("%s\n", buffer);
|
||||
exit(1);
|
||||
}
|
||||
perl_construct(perl);
|
||||
exitstatus=perl_parse(perl,xs_init,2,embedding,NULL);
|
||||
exitstatus = perl_parse(perl, xs_init, 2, embedding, NULL);
|
||||
if (!exitstatus) {
|
||||
|
||||
exitstatus=perl_run(perl);
|
||||
exitstatus = perl_run(perl);
|
||||
|
||||
while(printf("Enter file name: ") && fgets(command_line, command_line_size, stdin)) {
|
||||
while (printf("Enter file name: ") && fgets(command_line, command_line_size, stdin)) {
|
||||
|
||||
/* call the subroutine, passing it the filename as an argument */
|
||||
|
||||
command_line[strlen(command_line) -1] = '\0';
|
||||
command_line[strlen(command_line) - 1] = '\0';
|
||||
|
||||
strncpy(fname,command_line,strcspn(command_line," "));
|
||||
fname[strcspn(command_line," ")] = '\x0';
|
||||
args[0] = fname ;
|
||||
args[3] = command_line + strlen(fname) + 1 ;
|
||||
strncpy(fname, command_line, strcspn(command_line, " "));
|
||||
fname[strcspn(command_line, " ")] = '\x0';
|
||||
args[0] = fname;
|
||||
args[3] = command_line + strlen(fname) + 1;
|
||||
|
||||
/* generate a temporary filename to which stdout can be redirected. */
|
||||
sprintf(tmpfname,"/tmp/embedded%d",getpid());
|
||||
sprintf(tmpfname, "/tmp/embedded%d", getpid());
|
||||
args[2] = tmpfname;
|
||||
|
||||
/* call our perl interpreter to compile and optionally cache the command */
|
||||
perl_call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args);
|
||||
|
||||
perl_call_argv("Embed::Persistent::run_package", G_DISCARD | G_EVAL, args);
|
||||
|
||||
|
||||
/* check return status */
|
||||
if(SvTRUE(ERRSV)){
|
||||
pclose_result=-2;
|
||||
printf("embedded perl ran %s with error %s\n",fname,SvPV(ERRSV,PL_na));
|
||||
if (SvTRUE(ERRSV)) {
|
||||
pclose_result = -2;
|
||||
printf("embedded perl ran %s with error %s\n", fname, SvPV(ERRSV, PL_na));
|
||||
}
|
||||
|
||||
|
||||
/* read back stdout from script */
|
||||
fp=fopen(tmpfname, "r");
|
||||
|
||||
fp = fopen(tmpfname, "r");
|
||||
|
||||
/* default return string in case nothing was returned */
|
||||
strcpy(plugin_output,"(No output!)");
|
||||
|
||||
fgets(plugin_output,sizeof(plugin_output)-1,fp);
|
||||
plugin_output[sizeof(plugin_output)-1]='\x0';
|
||||
strcpy(plugin_output, "(No output!)");
|
||||
|
||||
fgets(plugin_output, sizeof(plugin_output) - 1, fp);
|
||||
plugin_output[sizeof(plugin_output) - 1] = '\x0';
|
||||
fclose(fp);
|
||||
unlink(tmpfname);
|
||||
printf("embedded perl plugin output was %d,%s\n",pclose_result, plugin_output);
|
||||
|
||||
unlink(tmpfname);
|
||||
printf("embedded perl plugin output was %d,%s\n", pclose_result, plugin_output);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
PL_perl_destruct_level = 0;
|
||||
perl_destruct(perl);
|
||||
perl_free(perl);
|
||||
|
|
|
|||
Loading…
Reference in a new issue