From 802e46f8ea36c344f112d7e1dd8d64d17a4cc939 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Mon, 15 Sep 2025 12:59:37 +0200 Subject: Run clang-format again --- plugins/check_by_ssh.c | 108 +++-- plugins/check_cluster.c | 26 +- plugins/check_dbi.c | 108 +++-- plugins/check_dig.c | 18 +- plugins/check_disk.c | 288 +++++++----- plugins/check_disk.d/utils_disk.c | 35 +- plugins/check_disk.d/utils_disk.h | 9 +- plugins/check_dns.c | 133 ++++-- plugins/check_dummy.c | 15 +- plugins/check_fping.c | 58 ++- plugins/check_fping.d/config.h | 1 - plugins/check_game.c | 68 +-- plugins/check_hpjd.c | 14 +- plugins/check_ldap.c | 50 ++- plugins/check_load.c | 24 +- plugins/check_mrtg.c | 53 ++- plugins/check_mrtgtraf.c | 32 +- plugins/check_mysql.c | 88 ++-- plugins/check_mysql_query.c | 37 +- plugins/check_nt.c | 115 +++-- plugins/check_ntp.c | 756 +++++++++++++++++--------------- plugins/check_ntp_peer.c | 118 ++--- plugins/check_ntp_time.c | 91 ++-- plugins/check_pgsql.c | 77 ++-- plugins/check_ping.c | 125 ++++-- plugins/check_procs.c | 93 ++-- plugins/check_radius.c | 36 +- plugins/check_real.c | 28 +- plugins/check_smtp.c | 119 +++-- plugins/check_swap.c | 23 +- plugins/check_swap.d/check_swap.h | 3 +- plugins/check_swap.d/swap.c | 18 +- plugins/check_tcp.c | 147 ++++--- plugins/check_time.c | 25 +- plugins/check_ups.c | 47 +- plugins/check_ups.d/config.h | 1 - plugins/check_users.c | 19 +- plugins/check_users.d/users.c | 6 +- plugins/common.h | 175 ++++---- plugins/negate.c | 44 +- plugins/netutils.c | 12 +- plugins/picohttpparser/picohttpparser.c | 243 +++++----- plugins/picohttpparser/picohttpparser.h | 31 +- plugins/popen.c | 68 ++- plugins/popen.h | 20 +- plugins/runcmd.c | 77 ++-- plugins/runcmd.h | 47 +- plugins/sslutils.c | 6 +- plugins/tests/test_check_disk.c | 48 +- plugins/tests/test_check_swap.c | 4 +- plugins/urlize.c | 36 +- plugins/utils.c | 35 +- plugins/utils.h | 51 ++- 53 files changed, 2349 insertions(+), 1560 deletions(-) (limited to 'plugins') diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index 2bc38d49..74b7a46f 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c @@ -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"); diff --git a/plugins/check_cluster.c b/plugins/check_cluster.c index 9b695499..373520ee 100644 --- a/plugins/check_cluster.c +++ b/plugins/check_cluster.c @@ -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); diff --git a/plugins/check_dbi.c b/plugins/check_dbi.c index 9efcd1cb..468ded31 100644 --- a/plugins/check_dbi.c +++ b/plugins/check_dbi.c @@ -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 : "", query_time); + printf(", '%s' returned '%s' in %fs", config.dbi_query, + query_val_str ? query_val_str : "", 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 ] [-r|-R ]\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; diff --git a/plugins/check_dig.c b/plugins/check_dig.c index d0903be2..c27e5f13 100644 --- a/plugins/check_dig.c +++ b/plugins/check_dig.c @@ -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")); diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 515ddff0..d42b5486 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -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 "); 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); } diff --git a/plugins/check_disk.d/utils_disk.c b/plugins/check_disk.d/utils_disk.c index eec1282b..0b89018d 100644 --- a/plugins/check_disk.d/utils_disk.c +++ b/plugins/check_disk.d/utils_disk.c @@ -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! diff --git a/plugins/check_disk.d/utils_disk.h b/plugins/check_disk.d/utils_disk.h index 6831d1fd..c96d4296 100644 --- a/plugins/check_disk.d/utils_disk.h +++ b/plugins/check_disk.d/utils_disk.h @@ -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 *); diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 95f33083..56f91dae 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -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 \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); } diff --git a/plugins/check_dummy.c b/plugins/check_dummy.c index 19f6c046..602d5868 100644 --- a/plugins/check_dummy.c +++ b/plugins/check_dummy.c @@ -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 \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 argument with optional text")); diff --git a/plugins/check_fping.c b/plugins/check_fping.c index 8018e06d..6160c2cb 100644 --- a/plugins/check_fping.c +++ b/plugins/check_fping.c @@ -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 \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 ,%% where is the round trip average travel time (ms)")); + printf(" %s\n", + _("THRESHOLD is ,%% where is the round trip average travel time (ms)")); printf(" %s\n", _("which triggers a WARNING or CRITICAL state, and 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 -w limit -c limit [-b size] [-n number] [-T number] [-i number]\n", progname); + printf(" %s -w limit -c limit [-b size] [-n number] [-T number] [-i number]\n", + progname); } diff --git a/plugins/check_fping.d/config.h b/plugins/check_fping.d/config.h index d95e9ded..d3e50565 100644 --- a/plugins/check_fping.d/config.h +++ b/plugins/check_fping.d/config.h @@ -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 diff --git a/plugins/check_game.c b/plugins/check_game.c index c0193b03..974a7253 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c @@ -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] " + printf(" %s [-hvV] [-P port] [-t timeout] [-g game_field] [-m map_field] [-p ping_field] [-G " + "game-time] [-H hostname] " "\n", progname); } diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 62417fd6..9907abc5 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c @@ -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); } } diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 597644bd..77a33304 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c @@ -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.")); diff --git a/plugins/check_load.c b/plugins/check_load.c index 2925bff3..f7a6f7fd 100644 --- a/plugins/check_load.c +++ b/plugins/check_load.c @@ -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) { diff --git a/plugins/check_mrtg.c b/plugins/check_mrtg.c index 5bd276dc..4a17049a 100644 --- a/plugins/check_mrtg.c +++ b/plugins/check_mrtg.c @@ -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 threshold, a WARNING status is returned. If")); + printf(" %s\n", + _("If the value exceeds the threshold, a WARNING status is returned. If")); printf(" %s\n", _("the value exceeds the threshold, a CRITICAL status is returned. If")); printf(" %s\n", _("the data in the log file is older than 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 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); diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index 8c7cf8aa..10ce936f 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c @@ -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); diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index ca3422b5..3d7ec4cd 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -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"}; - -#define MYSQLDUMP_THREADS_QUERY \ - "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'" +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 */%'" 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"); - - /* 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) { + 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) { 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).")); diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 5e04a94b..c7e84deb 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -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"); } diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 7dd23e5c..35ca92cd 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c @@ -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; - - 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); + 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); 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 -p -v INSTANCES -l ")); + printf(" %s\n", + _("Syntax: check_nt -H -p -v INSTANCES -l ")); printf(" %s\n", _(" 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.")); diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index d33f8786..b22cc3c1 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c @@ -1,34 +1,34 @@ /***************************************************************************** -* -* Monitoring check_ntp plugin -* -* License: GPL -* Copyright (c) 2006 Sean Finney -* Copyright (c) 2006-2024 Monitoring Plugins Development Team -* -* Description: -* -* This file contains the check_ntp plugin -* -* This plugin to check ntp servers independent of any commandline -* programs or external libraries. -* -* -* 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 . -* -* -*****************************************************************************/ + * + * Monitoring check_ntp plugin + * + * License: GPL + * Copyright (c) 2006 Sean Finney + * Copyright (c) 2006-2024 Monitoring Plugins Development Team + * + * Description: + * + * This file contains the check_ntp plugin + * + * This plugin to check ntp servers independent of any commandline + * programs or external libraries. + * + * + * 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 . + * + * + *****************************************************************************/ const char *progname = "check_ntp"; const char *copyright = "2006-2024"; @@ -38,24 +38,24 @@ const char *email = "devel@monitoring-plugins.org"; #include "netutils.h" #include "utils.h" -static char *server_address=NULL; -static int verbose=0; +static char *server_address = NULL; +static int verbose = 0; static bool do_offset = false; -static char *owarn="60"; -static char *ocrit="120"; +static char *owarn = "60"; +static char *ocrit = "120"; static bool do_jitter = false; -static char *jwarn="5000"; -static char *jcrit="10000"; +static char *jwarn = "5000"; +static char *jcrit = "10000"; -static int process_arguments (int /*argc*/, char ** /*argv*/); +static int process_arguments(int /*argc*/, char ** /*argv*/); static thresholds *offset_thresholds = NULL; static thresholds *jitter_thresholds = NULL; -static void print_help (void); -void print_usage (void); +static void print_help(void); +void print_usage(void); /* number of times to perform each request to get a good average. */ #ifndef AVG_NUM -#define AVG_NUM 4 +# define AVG_NUM 4 #endif /* max size of control message data */ @@ -63,17 +63,17 @@ void print_usage (void); /* this structure holds everything in an ntp request/response as per rfc1305 */ typedef struct { - uint8_t flags; /* byte with leapindicator,vers,mode. see macros */ - uint8_t stratum; /* clock stratum */ - int8_t poll; /* polling interval */ - int8_t precision; /* precision of the local clock */ - int32_t rtdelay; /* total rt delay, as a fixed point num. see macros */ - uint32_t rtdisp; /* like above, but for max err to primary src */ - uint32_t refid; /* ref clock identifier */ - uint64_t refts; /* reference timestamp. local time local clock */ - uint64_t origts; /* time at which request departed client */ - uint64_t rxts; /* time at which request arrived at server */ - uint64_t txts; /* time at which request departed server */ + uint8_t flags; /* byte with leapindicator,vers,mode. see macros */ + uint8_t stratum; /* clock stratum */ + int8_t poll; /* polling interval */ + int8_t precision; /* precision of the local clock */ + int32_t rtdelay; /* total rt delay, as a fixed point num. see macros */ + uint32_t rtdisp; /* like above, but for max err to primary src */ + uint32_t refid; /* ref clock identifier */ + uint64_t refts; /* reference timestamp. local time local clock */ + uint64_t origts; /* time at which request departed client */ + uint64_t rxts; /* time at which request arrived at server */ + uint64_t txts; /* time at which request departed server */ } ntp_message; /* this structure holds data about results from querying offset from a peer */ @@ -84,20 +84,20 @@ typedef struct { double rtdelay; /* converted from the ntp_message */ double rtdisp; /* converted from the ntp_message */ double offset[AVG_NUM]; /* offsets from each response */ - uint8_t flags; /* byte with leapindicator,vers,mode. see macros */ + uint8_t flags; /* byte with leapindicator,vers,mode. see macros */ } ntp_server_results; /* this structure holds everything in an ntp control message as per rfc1305 */ typedef struct { - uint8_t flags; /* byte with leapindicator,vers,mode. see macros */ - uint8_t op; /* R,E,M bits and Opcode */ - uint16_t seq; /* Packet sequence */ - uint16_t status; /* Clock status */ - uint16_t assoc; /* Association */ - uint16_t offset; /* Similar to TCP sequence # */ - uint16_t count; /* # bytes of data */ + uint8_t flags; /* byte with leapindicator,vers,mode. see macros */ + uint8_t op; /* R,E,M bits and Opcode */ + uint16_t seq; /* Packet sequence */ + uint16_t status; /* Clock status */ + uint16_t assoc; /* Association */ + uint16_t offset; /* Similar to TCP sequence # */ + uint16_t count; /* # bytes of data */ char data[MAX_CM_SIZE]; /* ASCII data of the request */ - /* NB: not necessarily NULL terminated! */ + /* NB: not necessarily NULL terminated! */ } ntp_control_message; /* this is an association/status-word pair found in control packet responses */ @@ -108,38 +108,50 @@ 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); }while(0) +#define LI(x) ((x & LI_MASK) >> 6) +#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 -#define LI_EXTRASEC 0x01 +#define LI_NOWARNING 0x00 +#define LI_EXTRASEC 0x01 #define LI_MISSINGSEC 0x02 -#define LI_ALARM 0x03 +#define LI_ALARM 0x03 /* 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); }while(0) +#define VN(x) ((x & VN_MASK) >> 3) +#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); }while(0) +#define MODE(x) (x & MODE_MASK) +#define MODE_SET(x, y) \ + do { \ + x |= (y & MODE_MASK); \ + } while (0) /* here are some values */ -#define MODE_CLIENT 0x03 +#define MODE_CLIENT 0x03 #define MODE_CONTROLMSG 0x06 /* In control message, bits 8-10 are R,E,M bits */ -#define REM_MASK 0xe0 -#define REM_RESP 0x80 +#define REM_MASK 0xe0 +#define REM_RESP 0x80 #define REM_ERROR 0x40 -#define REM_MORE 0x20 +#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); }while(0) +#define OP_SET(x, y) \ + do { \ + x |= (y & OP_MASK); \ + } while (0) #define OP_READSTAT 0x01 #define OP_READVAR 0x02 /* In peer status bytes, bits 6,7,8 determine clock selection status */ -#define PEER_SEL(x) ((ntohs(x)>>8)&0x07) -#define PEER_INCLUDED 0x04 +#define PEER_SEL(x) ((ntohs(x) >> 8) & 0x07) +#define PEER_INCLUDED 0x04 #define PEER_SYNCSOURCE 0x06 /** @@ -153,82 +165,92 @@ typedef struct { /* macros to access the left/right 16 bits of a 32-bit ntp "fixed point" number. note that these can be used as lvalues too */ -#define L16(x) (((uint16_t*)&x)[0]) -#define R16(x) (((uint16_t*)&x)[1]) +#define L16(x) (((uint16_t *)&x)[0]) +#define R16(x) (((uint16_t *)&x)[1]) /* macros to access the left/right 32 bits of a 64-bit ntp "fixed point" number. these too can be used as lvalues */ -#define L32(x) (((uint32_t*)&x)[0]) -#define R32(x) (((uint32_t*)&x)[1]) +#define L32(x) (((uint32_t *)&x)[0]) +#define R32(x) (((uint32_t *)&x)[1]) /* ntp wants seconds since 1/1/00, epoch is 1/1/70. this is the difference */ #define EPOCHDIFF 0x83aa7e80UL /* extract a 32-bit ntp fixed point number into a double */ -#define NTP32asDOUBLE(x) (ntohs(L16(x)) + (double)ntohs(R16(x))/65536.0) +#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)) +#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)); \ - } \ - }while(0) +#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)); \ - } \ - } while(0) +#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 * 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; }}while(0); -#define PRINTSOCKADDR(x) \ - do{ \ - printf("%u.%u.%u.%u", (x>>24)&0xff, (x>>16)&0xff, (x>>8)&0xff, x&0xff);\ - }while(0); +#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); \ + } while (0); /* calculate the offset of the local clock */ -static inline double calc_offset(const ntp_message *m, const struct timeval *t){ +static inline double calc_offset(const ntp_message *m, const struct timeval *t) { double client_tx, peer_rx, peer_tx, client_rx; client_tx = NTP64asDOUBLE(m->origts); peer_rx = NTP64asDOUBLE(m->rxts); peer_tx = NTP64asDOUBLE(m->txts); - client_rx=TVasDOUBLE((*t)); - return (.5*((peer_tx-client_rx)+(peer_rx-client_tx))); + client_rx = TVasDOUBLE((*t)); + return (.5 * ((peer_tx - client_rx) + (peer_rx - client_tx))); } /* print out a ntp packet in human readable/debuggable format */ -void print_ntp_message(const ntp_message *p){ +void print_ntp_message(const ntp_message *p) { struct timeval ref, orig, rx, tx; - NTP64toTV(p->refts,ref); - NTP64toTV(p->origts,orig); - NTP64toTV(p->rxts,rx); - NTP64toTV(p->txts,tx); + NTP64toTV(p->refts, ref); + NTP64toTV(p->origts, orig); + NTP64toTV(p->rxts, rx); + NTP64toTV(p->txts, tx); printf("packet contents:\n"); printf("\tflags: 0x%.2x\n", p->flags); - printf("\t li=%d (0x%.2x)\n", LI(p->flags), p->flags&LI_MASK); - printf("\t vn=%d (0x%.2x)\n", VN(p->flags), p->flags&VN_MASK); - printf("\t mode=%d (0x%.2x)\n", MODE(p->flags), p->flags&MODE_MASK); + printf("\t li=%d (0x%.2x)\n", LI(p->flags), p->flags & LI_MASK); + printf("\t vn=%d (0x%.2x)\n", VN(p->flags), p->flags & VN_MASK); + printf("\t mode=%d (0x%.2x)\n", MODE(p->flags), p->flags & MODE_MASK); printf("\tstratum = %d\n", p->stratum); printf("\tpoll = %g\n", pow(2, p->poll)); printf("\tprecision = %g\n", pow(2, p->precision)); @@ -241,32 +263,31 @@ void print_ntp_message(const ntp_message *p){ printf("\ttxts = %-.16g\n", NTP64asDOUBLE(p->txts)); } -void print_ntp_control_message(const ntp_control_message *p){ - int i=0, numpeers=0; - const ntp_assoc_status_pair *peer=NULL; +void print_ntp_control_message(const ntp_control_message *p) { + int i = 0, numpeers = 0; + const ntp_assoc_status_pair *peer = NULL; printf("control packet contents:\n"); printf("\tflags: 0x%.2x , 0x%.2x\n", p->flags, p->op); - printf("\t li=%d (0x%.2x)\n", LI(p->flags), p->flags&LI_MASK); - printf("\t vn=%d (0x%.2x)\n", VN(p->flags), p->flags&VN_MASK); - printf("\t mode=%d (0x%.2x)\n", MODE(p->flags), p->flags&MODE_MASK); - printf("\t response=%d (0x%.2x)\n", (p->op&REM_RESP)>0, p->op&REM_RESP); - printf("\t more=%d (0x%.2x)\n", (p->op&REM_MORE)>0, p->op&REM_MORE); - printf("\t error=%d (0x%.2x)\n", (p->op&REM_ERROR)>0, p->op&REM_ERROR); - printf("\t op=%d (0x%.2x)\n", p->op&OP_MASK, p->op&OP_MASK); + printf("\t li=%d (0x%.2x)\n", LI(p->flags), p->flags & LI_MASK); + printf("\t vn=%d (0x%.2x)\n", VN(p->flags), p->flags & VN_MASK); + printf("\t mode=%d (0x%.2x)\n", MODE(p->flags), p->flags & MODE_MASK); + printf("\t response=%d (0x%.2x)\n", (p->op & REM_RESP) > 0, p->op & REM_RESP); + printf("\t more=%d (0x%.2x)\n", (p->op & REM_MORE) > 0, p->op & REM_MORE); + printf("\t error=%d (0x%.2x)\n", (p->op & REM_ERROR) > 0, p->op & REM_ERROR); + printf("\t op=%d (0x%.2x)\n", p->op & OP_MASK, p->op & OP_MASK); printf("\tsequence: %d (0x%.2x)\n", ntohs(p->seq), ntohs(p->seq)); printf("\tstatus: %d (0x%.2x)\n", ntohs(p->status), ntohs(p->status)); printf("\tassoc: %d (0x%.2x)\n", ntohs(p->assoc), ntohs(p->assoc)); printf("\toffset: %d (0x%.2x)\n", ntohs(p->offset), ntohs(p->offset)); printf("\tcount: %d (0x%.2x)\n", ntohs(p->count), ntohs(p->count)); - numpeers=ntohs(p->count)/(sizeof(ntp_assoc_status_pair)); - if(p->op&REM_RESP && p->op&OP_READSTAT){ - peer=(ntp_assoc_status_pair*)p->data; - for(i=0;i= PEER_INCLUDED){ - if(PEER_SEL(peer[i].status) >= PEER_SYNCSOURCE){ + numpeers = ntohs(p->count) / (sizeof(ntp_assoc_status_pair)); + if (p->op & REM_RESP && p->op & OP_READSTAT) { + peer = (ntp_assoc_status_pair *)p->data; + for (i = 0; i < numpeers; i++) { + printf("\tpeer id %.2x status %.2x", ntohs(peer[i].assoc), ntohs(peer[i].status)); + if (PEER_SEL(peer[i].status) >= PEER_INCLUDED) { + if (PEER_SEL(peer[i].status) >= PEER_SYNCSOURCE) { printf(" <-- current sync source"); } else { printf(" <-- current sync candidate"); @@ -277,41 +298,45 @@ void print_ntp_control_message(const ntp_control_message *p){ } } -void setup_request(ntp_message *p){ +void setup_request(ntp_message *p) { struct timeval t; memset(p, 0, sizeof(ntp_message)); LI_SET(p->flags, LI_ALARM); VN_SET(p->flags, 4); MODE_SET(p->flags, MODE_CLIENT); - p->poll=4; - p->precision=(int8_t)0xfa; - L16(p->rtdelay)=htons(1); - L16(p->rtdisp)=htons(1); + p->poll = 4; + p->precision = (int8_t)0xfa; + L16(p->rtdelay) = htons(1); + L16(p->rtdisp) = htons(1); gettimeofday(&t, NULL); - TVtoNTP64(t,p->txts); + TVtoNTP64(t, p->txts); } /* select the "best" server from a list of servers, and return its index. * this is done by filtering servers based on stratum, dispersion, and * finally round-trip delay. */ -int best_offset_server(const ntp_server_results *slist, int nservers){ - int cserver=0, best_server=-1; +int best_offset_server(const ntp_server_results *slist, int nservers) { + int cserver = 0, best_server = -1; /* for each server */ - for(cserver=0; cserver= 0) { + if (best_server >= 0) { DBG(printf("best server selected: peer %d\n", best_server)); return best_server; } else { @@ -354,16 +379,16 @@ int best_offset_server(const ntp_server_results *slist, int nservers){ * we don't waste time sitting around waiting for single packets. * - we also "manually" handle resolving host names and connecting, because * we have to do it in a way that our lazy macros don't handle currently :( */ -double offset_request(const char *host, int *status){ - int i=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; - int servers_completed=0, one_read=0, servers_readable=0, best_index=-1; - time_t now_time=0, start_ts=0; - ntp_message *req=NULL; - double avg_offset=0.; +double offset_request(const char *host, int *status) { + int i = 0, ga_result = 0, num_hosts = 0, *socklist = NULL, respnum = 0; + int servers_completed = 0, one_read = 0, servers_readable = 0, best_index = -1; + time_t now_time = 0, start_ts = 0; + ntp_message *req = NULL; + double avg_offset = 0.; struct timeval recv_time; - struct addrinfo *ai=NULL, *ai_tmp=NULL, hints; - struct pollfd *ufds=NULL; - ntp_server_results *servers=NULL; + struct addrinfo *ai = NULL, *ai_tmp = NULL, hints; + struct pollfd *ufds = NULL; + ntp_server_results *servers = NULL; /* setup hints to only return results from getaddrinfo that we'd like */ memset(&hints, 0, sizeof(struct addrinfo)); @@ -373,97 +398,112 @@ double offset_request(const char *host, int *status){ /* fill in ai with the list of hosts resolved by the host name */ ga_result = getaddrinfo(host, "123", &hints, &ai); - if(ga_result!=0){ - die(STATE_UNKNOWN, "error getting address for %s: %s\n", - host, gai_strerror(ga_result)); + if (ga_result != 0) { + die(STATE_UNKNOWN, "error getting address for %s: %s\n", host, gai_strerror(ga_result)); } /* count the number of returned hosts, and allocate stuff accordingly */ - for(ai_tmp=ai; ai_tmp!=NULL; ai_tmp=ai_tmp->ai_next){ num_hosts++; } - req=(ntp_message*)malloc(sizeof(ntp_message)*num_hosts); - if(req==NULL) die(STATE_UNKNOWN, "can not allocate ntp message array"); - socklist=(int*)malloc(sizeof(int)*num_hosts); - if(socklist==NULL) die(STATE_UNKNOWN, "can not allocate socket array"); - ufds=(struct pollfd*)malloc(sizeof(struct pollfd)*num_hosts); - if(ufds==NULL) die(STATE_UNKNOWN, "can not allocate socket array"); - servers=(ntp_server_results*)malloc(sizeof(ntp_server_results)*num_hosts); - if(servers==NULL) die(STATE_UNKNOWN, "can not allocate server array"); - memset(servers, 0, sizeof(ntp_server_results)*num_hosts); + for (ai_tmp = ai; ai_tmp != NULL; ai_tmp = ai_tmp->ai_next) { + num_hosts++; + } + req = (ntp_message *)malloc(sizeof(ntp_message) * num_hosts); + if (req == NULL) { + die(STATE_UNKNOWN, "can not allocate ntp message array"); + } + socklist = (int *)malloc(sizeof(int) * num_hosts); + if (socklist == NULL) { + die(STATE_UNKNOWN, "can not allocate socket array"); + } + ufds = (struct pollfd *)malloc(sizeof(struct pollfd) * num_hosts); + if (ufds == NULL) { + die(STATE_UNKNOWN, "can not allocate socket array"); + } + servers = (ntp_server_results *)malloc(sizeof(ntp_server_results) * num_hosts); + if (servers == NULL) { + die(STATE_UNKNOWN, "can not allocate server array"); + } + memset(servers, 0, sizeof(ntp_server_results) * num_hosts); DBG(printf("Found %d peers to check\n", num_hosts)); /* setup each socket for writing, and the corresponding struct pollfd */ - ai_tmp=ai; - for(i=0;ai_tmp;i++){ - socklist[i]=socket(ai_tmp->ai_family, SOCK_DGRAM, IPPROTO_UDP); - if(socklist[i] == -1) { + ai_tmp = ai; + for (i = 0; ai_tmp; i++) { + socklist[i] = socket(ai_tmp->ai_family, SOCK_DGRAM, IPPROTO_UDP); + if (socklist[i] == -1) { perror(NULL); die(STATE_UNKNOWN, "can not create new socket"); } - if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){ + if (connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)) { /* don't die here, because it is enough if there is one server answering in time. This also would break for dual ipv4/6 stacked ntp servers when the client only supports on of them. */ DBG(printf("can't create socket connection on peer %i: %s\n", i, strerror(errno))); } else { - ufds[i].fd=socklist[i]; - ufds[i].events=POLLIN; - ufds[i].revents=0; + ufds[i].fd = socklist[i]; + ufds[i].events = POLLIN; + ufds[i].revents = 0; } ai_tmp = ai_tmp->ai_next; } /* now do AVG_NUM checks to each host. we stop before timeout/2 seconds * have passed in order to ensure post-processing and jitter time. */ - now_time=start_ts=time(NULL); - while(servers_completedflags, LI_NOWARNING); VN_SET(p->flags, VN_RESERVED); @@ -512,16 +553,16 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){ } /* XXX handle responses with the error bit set */ -double jitter_request(int *status){ - int conn=-1, i, npeers=0, num_candidates=0; +double jitter_request(int *status) { + int conn = -1, i, npeers = 0, num_candidates = 0; bool syncsource_found = false; - int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; - int peers_size=0, peer_offset=0; - ntp_assoc_status_pair *peers=NULL; + int run = 0, min_peer_sel = PEER_INCLUDED, num_selected = 0, num_valid = 0; + int peers_size = 0, peer_offset = 0; + ntp_assoc_status_pair *peers = NULL; ntp_control_message req; const char *getvar = "jitter"; double rval = 0.0, jitter = -1.0; - char *startofvalue=NULL, *nptr=NULL; + char *startofvalue = NULL, *nptr = NULL; void *tmp; /* Long-winded explanation: @@ -542,54 +583,62 @@ double jitter_request(int *status){ /* keep sending requests until the server stops setting the * REM_MORE bit, though usually this is only 1 packet. */ - do{ + do { setup_control_request(&req, OP_READSTAT, 1); DBG(printf("sending READSTAT request")); write(conn, &req, SIZEOF_NTPCM(req)); DBG(print_ntp_control_message(&req)); /* Attempt to read the largest size packet possible */ - req.count=htons(MAX_CM_SIZE); + req.count = htons(MAX_CM_SIZE); DBG(printf("receiving READSTAT response")) read(conn, &req, SIZEOF_NTPCM(req)); DBG(print_ntp_control_message(&req)); /* Each peer identifier is 4 bytes in the data section, which - * we represent as a ntp_assoc_status_pair datatype. - */ - peers_size+=ntohs(req.count); - if((tmp=realloc(peers, peers_size)) == NULL) + * we represent as a ntp_assoc_status_pair datatype. + */ + peers_size += ntohs(req.count); + if ((tmp = realloc(peers, peers_size)) == NULL) { free(peers), die(STATE_UNKNOWN, "can not (re)allocate 'peers' buffer\n"); - peers=tmp; - memcpy((void*)((ptrdiff_t)peers+peer_offset), (void*)req.data, ntohs(req.count)); - npeers=peers_size/sizeof(ntp_assoc_status_pair); - peer_offset+=ntohs(req.count); - } while(req.op&REM_MORE); + } + peers = tmp; + memcpy((void *)((ptrdiff_t)peers + peer_offset), (void *)req.data, ntohs(req.count)); + npeers = peers_size / sizeof(ntp_assoc_status_pair); + peer_offset += ntohs(req.count); + } while (req.op & REM_MORE); /* first, let's find out if we have a sync source, or if there are * at least some candidates. in the case of the latter we'll issue * a warning but go ahead with the check on them. */ - for (i = 0; i < npeers; i++){ - if (PEER_SEL(peers[i].status) >= PEER_INCLUDED){ + for (i = 0; i < npeers; i++) { + if (PEER_SEL(peers[i].status) >= PEER_INCLUDED) { num_candidates++; - if(PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE){ + if (PEER_SEL(peers[i].status) >= PEER_SYNCSOURCE) { syncsource_found = true; - min_peer_sel=PEER_SYNCSOURCE; + min_peer_sel = PEER_SYNCSOURCE; } } } - if(verbose) printf("%d candidate peers available\n", num_candidates); - if(verbose && syncsource_found) printf("synchronization source found\n"); - if(! syncsource_found){ + if (verbose) { + printf("%d candidate peers available\n", num_candidates); + } + if (verbose && syncsource_found) { + printf("synchronization source found\n"); + } + if (!syncsource_found) { *status = STATE_UNKNOWN; - if(verbose) printf("warning: no synchronization source found\n"); + if (verbose) { + printf("warning: no synchronization source found\n"); + } } - - for (run=0; run= min_peer_sel){ - char jitter_data[MAX_CM_SIZE+1]; + if (PEER_SEL(peers[i].status) >= min_peer_sel) { + char jitter_data[MAX_CM_SIZE + 1]; size_t jitter_data_count; num_selected++; @@ -602,7 +651,7 @@ double jitter_request(int *status){ */ /* Older servers doesn't know what jitter is, so if we get an * error on the first pass we redo it with "dispersion" */ - strncpy(req.data, getvar, MAX_CM_SIZE-1); + strncpy(req.data, getvar, MAX_CM_SIZE - 1); req.count = htons(strlen(getvar)); DBG(printf("sending READVAR request...\n")); write(conn, &req, SIZEOF_NTPCM(req)); @@ -613,8 +662,11 @@ double jitter_request(int *status){ read(conn, &req, SIZEOF_NTPCM(req)); DBG(print_ntp_control_message(&req)); - if(req.op&REM_ERROR && strstr(getvar, "jitter")) { - if(verbose) printf("The 'jitter' command failed (old ntp server?)\nRestarting with 'dispersion'...\n"); + if (req.op & REM_ERROR && strstr(getvar, "jitter")) { + if (verbose) { + printf("The 'jitter' command failed (old ntp server?)\nRestarting with " + "'dispersion'...\n"); + } getvar = "dispersion"; num_selected--; i--; @@ -622,32 +674,33 @@ double jitter_request(int *status){ } /* get to the float value */ - if(verbose) { + if (verbose) { printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc)); } - if((jitter_data_count = ntohs(req.count)) >= sizeof(jitter_data)){ - die(STATE_UNKNOWN, - _("jitter response too large (%lu bytes)\n"), - (unsigned long)jitter_data_count); + if ((jitter_data_count = ntohs(req.count)) >= sizeof(jitter_data)) { + die(STATE_UNKNOWN, _("jitter response too large (%lu bytes)\n"), + (unsigned long)jitter_data_count); } memcpy(jitter_data, req.data, jitter_data_count); jitter_data[jitter_data_count] = '\0'; startofvalue = strchr(jitter_data, '='); - if(startofvalue != NULL) { + if (startofvalue != NULL) { startofvalue++; jitter = strtod(startofvalue, &nptr); } - if(startofvalue == NULL || startofvalue==nptr){ + if (startofvalue == NULL || startofvalue == nptr) { printf("warning: unable to read server jitter response.\n"); *status = STATE_UNKNOWN; } else { - if(verbose) printf("%g\n", jitter); + if (verbose) { + printf("%g\n", jitter); + } num_valid++; rval += jitter; } } } - if(verbose){ + if (verbose) { printf("jitter parsed from %d/%d peers\n", num_valid, num_selected); } } @@ -655,37 +708,33 @@ double jitter_request(int *status){ rval = num_valid ? rval / num_valid : -1.0; close(conn); - if(peers!=NULL) free(peers); + if (peers != NULL) { + free(peers); + } /* If we return -1.0, it means no synchronization source was found */ return rval; } -int process_arguments(int argc, char **argv){ +int process_arguments(int argc, char **argv) { int c; - int option=0; + int option = 0; 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'}, - {"warning", required_argument, 0, 'w'}, - {"critical", required_argument, 0, 'c'}, - {"jwarn", required_argument, 0, 'j'}, - {"jcrit", required_argument, 0, 'k'}, - {"timeout", required_argument, 0, 't'}, - {"hostname", required_argument, 0, 'H'}, - {0, 0, 0, 0} - }; - - - if (argc < 2) - usage ("\n"); + {"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'}, {"warning", required_argument, 0, 'w'}, + {"critical", required_argument, 0, 'c'}, {"jwarn", required_argument, 0, 'j'}, + {"jcrit", required_argument, 0, 'k'}, {"timeout", required_argument, 0, 't'}, + {"hostname", required_argument, 0, 'H'}, {0, 0, 0, 0}}; + + if (argc < 2) { + usage("\n"); + } while (1) { - c = getopt_long (argc, argv, "Vhv46w:c:j:k:t:H:", longopts, &option); - if (c == -1 || c == EOF || c == 1) + c = getopt_long(argc, argv, "Vhv46w:c:j:k:t:H:", longopts, &option); + if (c == -1 || c == EOF || c == 1) { break; + } switch (c) { case 'h': @@ -716,12 +765,13 @@ int process_arguments(int argc, char **argv){ jcrit = optarg; break; case 'H': - if(!is_host(optarg)) + if (!is_host(optarg)) { usage2(_("Invalid hostname/address"), optarg); + } server_address = strdup(optarg); break; case 't': - socket_timeout=atoi(optarg); + socket_timeout = atoi(optarg); break; case '4': address_family = AF_INET; @@ -730,64 +780,59 @@ int process_arguments(int argc, char **argv){ #ifdef USE_IPV6 address_family = AF_INET6; #else - usage4 (_("IPv6 support not available")); + usage4(_("IPv6 support not available")); #endif break; case '?': /* print short usage statement if args not parsable */ - usage5 (); + usage5(); break; } } - if(server_address == NULL){ + if (server_address == NULL) { usage4(_("Hostname was not supplied")); } return 0; } -char *perfd_offset (double offset) -{ - return fperfdata ("offset", offset, "s", - true, offset_thresholds->warning->end, - true, offset_thresholds->critical->end, - false, 0, false, 0); +char *perfd_offset(double offset) { + return fperfdata("offset", offset, "s", true, offset_thresholds->warning->end, true, + offset_thresholds->critical->end, false, 0, false, 0); } -char *perfd_jitter (double jitter) -{ - return fperfdata ("jitter", jitter, "s", - do_jitter, jitter_thresholds->warning->end, - do_jitter, jitter_thresholds->critical->end, - true, 0, false, 0); +char *perfd_jitter(double jitter) { + return fperfdata("jitter", jitter, "s", do_jitter, jitter_thresholds->warning->end, do_jitter, + jitter_thresholds->critical->end, true, 0, false, 0); } -int main(int argc, char *argv[]){ +int main(int argc, char *argv[]) { int result, offset_result, jitter_result; - double offset=0, jitter=0; + double offset = 0, jitter = 0; char *result_line, *perfdata_line; - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); result = offset_result = jitter_result = STATE_OK; /* Parse extra opts if any */ - argv=np_extra_opts (&argc, argv, progname); + argv = np_extra_opts(&argc, argv, progname); - if (process_arguments (argc, argv) == ERROR) - usage4 (_("Could not parse arguments")); + if (process_arguments(argc, argv) == ERROR) { + usage4(_("Could not parse arguments")); + } set_thresholds(&offset_thresholds, owarn, ocrit); set_thresholds(&jitter_thresholds, jwarn, jcrit); /* initialize alarm signal handling */ - signal (SIGALRM, socket_timeout_alarm_handler); + signal(SIGALRM, socket_timeout_alarm_handler); /* set socket timeout */ - alarm (socket_timeout); + alarm(socket_timeout); offset = offset_request(server_address, &offset_result); /* check_ntp used to always return CRITICAL if offset_result == STATE_UNKNOWN. @@ -803,31 +848,32 @@ int main(int argc, char *argv[]){ * servers recognize. Trying to check the jitter on OpenNTPD * (for example) will result in an error */ - if(do_jitter){ - jitter=jitter_request(&jitter_result); + if (do_jitter) { + jitter = jitter_request(&jitter_result); result = max_state_alt(result, get_status(jitter, jitter_thresholds)); /* -1 indicates that we couldn't calculate the jitter * Only overrides STATE_OK from the offset */ - if(jitter == -1.0 && result == STATE_OK) + if (jitter == -1.0 && result == STATE_OK) { result = STATE_UNKNOWN; + } } result = max_state_alt(result, jitter_result); switch (result) { - case STATE_CRITICAL : - xasprintf(&result_line, _("NTP CRITICAL:")); - break; - case STATE_WARNING : - xasprintf(&result_line, _("NTP WARNING:")); - break; - case STATE_OK : - xasprintf(&result_line, _("NTP OK:")); - break; - default : - xasprintf(&result_line, _("NTP UNKNOWN:")); - break; + case STATE_CRITICAL: + xasprintf(&result_line, _("NTP CRITICAL:")); + break; + case STATE_WARNING: + xasprintf(&result_line, _("NTP WARNING:")); + break; + case STATE_OK: + xasprintf(&result_line, _("NTP OK:")); + break; + default: + xasprintf(&result_line, _("NTP UNKNOWN:")); + break; } - if(offset_result == STATE_UNKNOWN){ + if (offset_result == STATE_UNKNOWN) { xasprintf(&result_line, "%s %s", result_line, _("Offset unknown")); xasprintf(&perfdata_line, ""); } else { @@ -836,41 +882,41 @@ int main(int argc, char *argv[]){ } if (do_jitter) { xasprintf(&result_line, "%s, jitter=%f", result_line, jitter); - xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); + xasprintf(&perfdata_line, "%s %s", perfdata_line, perfd_jitter(jitter)); } printf("%s|%s\n", result_line, perfdata_line); - if(server_address!=NULL) free(server_address); + if (server_address != NULL) { + free(server_address); + } return result; } - - -void print_help(void){ +void print_help(void) { print_revision(progname, NP_VERSION); - printf ("Copyright (c) 2006 Sean Finney\n"); - printf (COPYRIGHT, copyright, email); + printf("Copyright (c) 2006 Sean Finney\n"); + printf(COPYRIGHT, copyright, email); - printf ("%s\n", _("This plugin checks the selected ntp server")); + printf("%s\n", _("This plugin checks the selected ntp server")); - printf ("\n\n"); + printf("\n\n"); print_usage(); - printf (UT_HELP_VRSN); - printf (UT_EXTRA_OPTS); - printf (UT_HOST_PORT, 'p', "123"); - printf (UT_IPv46); - printf (" %s\n", "-w, --warning=THRESHOLD"); - printf (" %s\n", _("Offset to result in warning status (seconds)")); - printf (" %s\n", "-c, --critical=THRESHOLD"); - printf (" %s\n", _("Offset to result in critical status (seconds)")); - printf (" %s\n", "-j, --jwarn=THRESHOLD"); - printf (" %s\n", _("Warning threshold for jitter")); - printf (" %s\n", "-k, --jcrit=THRESHOLD"); - printf (" %s\n", _("Critical threshold for jitter")); - printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); - printf (UT_VERBOSE); + printf(UT_HELP_VRSN); + printf(UT_EXTRA_OPTS); + printf(UT_HOST_PORT, 'p', "123"); + printf(UT_IPv46); + printf(" %s\n", "-w, --warning=THRESHOLD"); + printf(" %s\n", _("Offset to result in warning status (seconds)")); + printf(" %s\n", "-c, --critical=THRESHOLD"); + printf(" %s\n", _("Offset to result in critical status (seconds)")); + printf(" %s\n", "-j, --jwarn=THRESHOLD"); + printf(" %s\n", _("Warning threshold for jitter")); + printf(" %s\n", "-k, --jcrit=THRESHOLD"); + printf(" %s\n", _("Critical threshold for jitter")); + printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); + printf(UT_VERBOSE); printf("\n"); printf("%s\n", _("Notes:")); @@ -881,21 +927,21 @@ void print_help(void){ printf(" %s\n", _("Normal offset check:")); printf(" %s\n", ("./check_ntp -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 -H ntpserv -w 0.5 -c 1 -j -1:100 -k -1:200")); - printf (UT_SUPPORT); + printf(UT_SUPPORT); - printf ("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); - printf ("%s\n\n", _("check_ntp_time instead.")); + printf("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); + printf("%s\n\n", _("check_ntp_time instead.")); } -void -print_usage(void) -{ - printf ("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); - printf ("%s\n\n", _("check_ntp_time instead.")); - printf ("%s\n", _("Usage:")); - printf(" %s -H [-w ] [-c ] [-j ] [-k ] [-4|-6] [-v verbose]\n", progname); +void print_usage(void) { + printf("%s\n", _("WARNING: check_ntp is deprecated. Please use check_ntp_peer or")); + printf("%s\n\n", _("check_ntp_time instead.")); + printf("%s\n", _("Usage:")); + printf(" %s -H [-w ] [-c ] [-j ] [-k ] [-4|-6] [-v verbose]\n", + progname); } diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index 5c4ff386..24d1c9b5 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c @@ -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"); diff --git a/plugins/check_ntp_time.c b/plugins/check_ntp_time.c index 31162883..ad69b804 100644 --- a/plugins/check_ntp_time.c +++ b/plugins/check_ntp_time.c @@ -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 [-4|-6] [-w ] [-c ] [-v verbose] [-o