From f2900e0ccf18f321857e4072681ad9c10a0cb67f Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 13 Mar 2025 15:36:36 +0100
Subject: check_load: clang-format
---
plugins/check_load.c | 330 +++++++++++++++++++++++++--------------------------
1 file changed, 162 insertions(+), 168 deletions(-)
(limited to 'plugins/check_load.c')
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 1431d130..e3a45f58 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -1,32 +1,32 @@
/*****************************************************************************
-*
-* Monitoring check_load plugin
-*
-* License: GPL
-* Copyright (c) 1999-2007 Monitoring Plugins Development Team
-*
-* Description:
-*
-* This file contains the check_load plugin
-*
-* This plugin tests the current system load average.
-*
-*
-* 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_load plugin
+ *
+ * License: GPL
+ * Copyright (c) 1999-2007 Monitoring Plugins Development Team
+ *
+ * Description:
+ *
+ * This file contains the check_load plugin
+ *
+ * This plugin tests the current system load average.
+ *
+ *
+ * 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_load";
const char *copyright = "1999-2022";
@@ -40,127 +40,129 @@ const char *email = "devel@monitoring-plugins.org";
#include
#ifdef HAVE_SYS_LOADAVG_H
-#include
+# include
#endif
/* needed for compilation under NetBSD, as suggested by Andy Doran */
#ifndef LOADAVG_1MIN
-#define LOADAVG_1MIN 0
-#define LOADAVG_5MIN 1
-#define LOADAVG_15MIN 2
+# define LOADAVG_1MIN 0
+# define LOADAVG_5MIN 1
+# define LOADAVG_15MIN 2
#endif /* !defined LOADAVG_1MIN */
-
-static int process_arguments (int argc, char **argv);
-static int validate_arguments (void);
-void print_help (void);
-void print_usage (void);
+static int process_arguments(int argc, char **argv);
+static int validate_arguments(void);
+void print_help(void);
+void print_usage(void);
static int print_top_consuming_processes();
static int n_procs_to_show = 0;
/* strictly for pretty-print usage in loops */
-static const int nums[3] = { 1, 5, 15 };
+static const int nums[3] = {1, 5, 15};
/* provide some fairly sane defaults */
-double wload[3] = { 0.0, 0.0, 0.0 };
-double cload[3] = { 0.0, 0.0, 0.0 };
-#define la1 la[0]
-#define la5 la[1]
+double wload[3] = {0.0, 0.0, 0.0};
+double cload[3] = {0.0, 0.0, 0.0};
+#define la1 la[0]
+#define la5 la[1]
#define la15 la[2]
char *status_line;
bool take_into_account_cpus = false;
-static void
-get_threshold(char *arg, double *th)
-{
+static void get_threshold(char *arg, double *th) {
size_t i, n;
int valid = 0;
char *str = arg, *p;
n = strlen(arg);
- for(i = 0; i < 3; i++) {
+ for (i = 0; i < 3; i++) {
th[i] = strtod(str, &p);
- if(p == str) break;
+ if (p == str) {
+ break;
+ }
valid = 1;
str = p + 1;
- if(n <= (size_t)(str - arg)) break;
+ if (n <= (size_t)(str - arg)) {
+ break;
+ }
}
/* empty argument or non-floatish, so warn about it and die */
- if(!i && !valid) usage (_("Warning threshold must be float or float triplet!\n"));
+ if (!i && !valid) {
+ usage(_("Warning threshold must be float or float triplet!\n"));
+ }
- if(i != 2) {
+ if (i != 2) {
/* one or more numbers were given, so fill array with last
* we got (most likely to NOT produce the least expected result) */
- for(n = i; n < 3; n++) th[n] = th[i];
+ for (n = i; n < 3; n++) {
+ th[n] = th[i];
+ }
}
}
-
-int
-main (int argc, char **argv)
-{
+int main(int argc, char **argv) {
int result = -1;
int i;
long numcpus;
- double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about uninitialized arrays */
+ double la[3] = {0.0, 0.0, 0.0}; /* NetBSD complains about uninitialized arrays */
#ifndef HAVE_GETLOADAVG
char input_buffer[MAX_INPUT_BUFFER];
#endif
- setlocale (LC_ALL, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
setlocale(LC_NUMERIC, "POSIX");
/* 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"));
+ }
#ifdef HAVE_GETLOADAVG
- result = getloadavg (la, 3);
- if (result != 3)
+ result = getloadavg(la, 3);
+ if (result != 3) {
return STATE_UNKNOWN;
+ }
#else
- child_process = spopen (PATH_TO_UPTIME);
+ child_process = spopen(PATH_TO_UPTIME);
if (child_process == NULL) {
- printf (_("Error opening %s\n"), PATH_TO_UPTIME);
+ printf(_("Error opening %s\n"), PATH_TO_UPTIME);
return STATE_UNKNOWN;
}
- child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
+ child_stderr = fdopen(child_stderr_array[fileno(child_process)], "r");
if (child_stderr == NULL) {
- printf (_("Could not open stderr for %s\n"), PATH_TO_UPTIME);
+ printf(_("Could not open stderr for %s\n"), PATH_TO_UPTIME);
}
- fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process);
- if(strstr(input_buffer, "load average:")) {
- sscanf (input_buffer, "%*[^l]load average: %lf, %lf, %lf", &la1, &la5, &la15);
- }
- else if(strstr(input_buffer, "load averages:")) {
- sscanf (input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15);
- }
- else {
- printf (_("could not parse load from uptime %s: %d\n"), PATH_TO_UPTIME, result);
+ fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process);
+ if (strstr(input_buffer, "load average:")) {
+ sscanf(input_buffer, "%*[^l]load average: %lf, %lf, %lf", &la1, &la5, &la15);
+ } else if (strstr(input_buffer, "load averages:")) {
+ sscanf(input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15);
+ } else {
+ printf(_("could not parse load from uptime %s: %d\n"), PATH_TO_UPTIME, result);
return STATE_UNKNOWN;
- }
+ }
- result = spclose (child_process);
+ result = spclose(child_process);
if (result) {
- printf (_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME);
+ printf(_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME);
return STATE_UNKNOWN;
}
#endif
if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) {
#ifdef HAVE_GETLOADAVG
- printf (_("Error in getloadavg()\n"));
+ printf(_("Error in getloadavg()\n"));
#else
- printf (_("Error processing %s\n"), PATH_TO_UPTIME);
+ printf(_("Error processing %s\n"), PATH_TO_UPTIME);
#endif
return STATE_UNKNOWN;
}
@@ -171,8 +173,7 @@ main (int argc, char **argv)
xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15);
xasprintf(&status_line, ("total %s"), status_line);
-
- double scaled_la[3] = { 0.0, 0.0, 0.0 };
+ double scaled_la[3] = {0.0, 0.0, 0.0};
bool is_using_scaled_load_values = false;
if (take_into_account_cpus == true && (numcpus = GET_NUMBER_OF_CPUS()) > 0) {
@@ -187,24 +188,26 @@ main (int argc, char **argv)
xasprintf(&status_line, "scaled %s - %s", tmp, status_line);
}
- for(i = 0; i < 3; i++) {
+ for (i = 0; i < 3; i++) {
if (is_using_scaled_load_values) {
- if(scaled_la[i] > cload[i]) {
+ if (scaled_la[i] > cload[i]) {
result = STATE_CRITICAL;
break;
+ } else if (scaled_la[i] > wload[i]) {
+ result = STATE_WARNING;
}
- else if(scaled_la[i] > wload[i]) result = STATE_WARNING;
} else {
- if(la[i] > cload[i]) {
+ if (la[i] > cload[i]) {
result = STATE_CRITICAL;
break;
+ } else if (la[i] > wload[i]) {
+ result = STATE_WARNING;
}
- else if(la[i] > wload[i]) result = STATE_WARNING;
}
}
printf("LOAD %s - %s|", state_text(result), status_line);
- for(i = 0; i < 3; i++) {
+ for (i = 0; i < 3; i++) {
if (is_using_scaled_load_values) {
printf("load%d=%.3f;;;0; ", nums[i], la[i]);
printf("scaled_load%d=%.3f;%.3f;%.3f;0; ", nums[i], scaled_la[i], wload[i], cload[i]);
@@ -220,32 +223,29 @@ main (int argc, char **argv)
return result;
}
-
/* process command-line arguments */
-static int
-process_arguments (int argc, char **argv)
-{
+static int process_arguments(int argc, char **argv) {
int c = 0;
int option = 0;
- static struct option longopts[] = {
- {"warning", required_argument, 0, 'w'},
- {"critical", required_argument, 0, 'c'},
- {"percpu", no_argument, 0, 'r'},
- {"version", no_argument, 0, 'V'},
- {"help", no_argument, 0, 'h'},
- {"procs-to-show", required_argument, 0, 'n'},
- {0, 0, 0, 0}
- };
-
- if (argc < 2)
+ static struct option longopts[] = {{"warning", required_argument, 0, 'w'},
+ {"critical", required_argument, 0, 'c'},
+ {"percpu", no_argument, 0, 'r'},
+ {"version", no_argument, 0, 'V'},
+ {"help", no_argument, 0, 'h'},
+ {"procs-to-show", required_argument, 0, 'n'},
+ {0, 0, 0, 0}};
+
+ if (argc < 2) {
return ERROR;
+ }
while (1) {
- c = getopt_long (argc, argv, "Vhrc:w:n:", longopts, &option);
+ c = getopt_long(argc, argv, "Vhrc:w:n:", longopts, &option);
- if (c == -1 || c == EOF)
+ if (c == -1 || c == EOF) {
break;
+ }
switch (c) {
case 'w': /* warning time threshold */
@@ -257,94 +257,89 @@ process_arguments (int argc, char **argv)
case 'r': /* Divide load average by number of CPUs */
take_into_account_cpus = true;
break;
- case 'V': /* version */
- print_revision (progname, NP_VERSION);
- exit (STATE_UNKNOWN);
- case 'h': /* help */
- print_help ();
- exit (STATE_UNKNOWN);
+ case 'V': /* version */
+ print_revision(progname, NP_VERSION);
+ exit(STATE_UNKNOWN);
+ case 'h': /* help */
+ print_help();
+ exit(STATE_UNKNOWN);
case 'n':
n_procs_to_show = atoi(optarg);
break;
- case '?': /* help */
- usage5 ();
+ case '?': /* help */
+ usage5();
}
}
c = optind;
- if (c == argc)
- return validate_arguments ();
+ if (c == argc) {
+ return validate_arguments();
+ }
/* handle the case if both arguments are missing,
* but not if only one is given without -c or -w flag */
- if(c - argc == 2) {
+ if (c - argc == 2) {
get_threshold(argv[c++], wload);
get_threshold(argv[c++], cload);
- }
- else if(c - argc == 1) {
+ } else if (c - argc == 1) {
get_threshold(argv[c++], cload);
}
- return validate_arguments ();
+ return validate_arguments();
}
-
-static int
-validate_arguments (void)
-{
+static int validate_arguments(void) {
int i = 0;
/* match cload first, as it will give the most friendly error message
* if user hasn't given the -c switch properly */
- for(i = 0; i < 3; i++) {
- if(cload[i] < 0)
- die (STATE_UNKNOWN, _("Critical threshold for %d-minute load average is not specified\n"), nums[i]);
- if(wload[i] < 0)
- die (STATE_UNKNOWN, _("Warning threshold for %d-minute load average is not specified\n"), nums[i]);
- if(wload[i] > cload[i])
- die (STATE_UNKNOWN, _("Parameter inconsistency: %d-minute \"warning load\" is greater than \"critical load\"\n"), nums[i]);
+ for (i = 0; i < 3; i++) {
+ if (cload[i] < 0) {
+ die(STATE_UNKNOWN, _("Critical threshold for %d-minute load average is not specified\n"), nums[i]);
+ }
+ if (wload[i] < 0) {
+ die(STATE_UNKNOWN, _("Warning threshold for %d-minute load average is not specified\n"), nums[i]);
+ }
+ if (wload[i] > cload[i]) {
+ die(STATE_UNKNOWN, _("Parameter inconsistency: %d-minute \"warning load\" is greater than \"critical load\"\n"), nums[i]);
+ }
}
return OK;
}
+void print_help(void) {
+ print_revision(progname, NP_VERSION);
-void
-print_help (void)
-{
- print_revision (progname, NP_VERSION);
-
- printf ("Copyright (c) 1999 Felipe Gustavo de Almeida \n");
- printf (COPYRIGHT, copyright, email);
+ printf("Copyright (c) 1999 Felipe Gustavo de Almeida \n");
+ printf(COPYRIGHT, copyright, email);
- printf (_("This plugin tests the current system load average."));
+ printf(_("This plugin tests the current system load average."));
- printf ("\n\n");
+ printf("\n\n");
- print_usage ();
+ print_usage();
- printf (UT_HELP_VRSN);
- printf (UT_EXTRA_OPTS);
+ printf(UT_HELP_VRSN);
+ printf(UT_EXTRA_OPTS);
- printf (" %s\n", "-w, --warning=WLOAD1,WLOAD5,WLOAD15");
- printf (" %s\n", _("Exit with WARNING status if load average exceeds WLOADn"));
- printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15");
- printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn"));
- printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\""));
- printf (" %s\n", "-r, --percpu");
- printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)"));
- printf (" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS");
- printf (" %s\n", _("Number of processes to show when printing the top consuming processes."));
- printf (" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0"));
+ printf(" %s\n", "-w, --warning=WLOAD1,WLOAD5,WLOAD15");
+ printf(" %s\n", _("Exit with WARNING status if load average exceeds WLOADn"));
+ printf(" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15");
+ printf(" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn"));
+ printf(" %s\n", _("the load average format is the same used by \"uptime\" and \"w\""));
+ printf(" %s\n", "-r, --percpu");
+ printf(" %s\n", _("Divide the load averages by the number of CPUs (when possible)"));
+ printf(" %s\n", "-n, --procs-to-show=NUMBER_OF_PROCS");
+ printf(" %s\n", _("Number of processes to show when printing the top consuming processes."));
+ printf(" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0"));
- printf (UT_SUPPORT);
+ printf(UT_SUPPORT);
}
-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);
+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);
}
#ifdef PS_USES_PROCPCPU
@@ -356,14 +351,14 @@ int cmpstringp(const void *p1, const void *p2) {
int procrss = 0;
float procpcpu = 0;
char procstat[8];
-#ifdef PS_USES_PROCETIME
+# ifdef PS_USES_PROCETIME
char procetime[MAX_INPUT_BUFFER];
-#endif /* PS_USES_PROCETIME */
+# endif /* PS_USES_PROCETIME */
char procprog[MAX_INPUT_BUFFER];
int pos;
- sscanf (* (char * const *) p1, PS_FORMAT, PS_VARLIST);
+ sscanf(*(char *const *)p1, PS_FORMAT, PS_VARLIST);
float procpcpu1 = procpcpu;
- sscanf (* (char * const *) p2, PS_FORMAT, PS_VARLIST);
+ sscanf(*(char *const *)p2, PS_FORMAT, PS_VARLIST);
return procpcpu1 < procpcpu;
}
#endif /* PS_USES_PROCPCPU */
@@ -371,7 +366,7 @@ int cmpstringp(const void *p1, const void *p2) {
static int print_top_consuming_processes() {
int i = 0;
struct output chld_out, chld_err;
- if(np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0) != 0){
+ if (np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0) != 0) {
fprintf(stderr, _("'%s' exited with non-zero status.\n"), PS_COMMAND);
return STATE_UNKNOWN;
}
@@ -380,10 +375,9 @@ static int print_top_consuming_processes() {
return STATE_UNKNOWN;
}
#ifdef PS_USES_PROCPCPU
- qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char*), cmpstringp);
+ qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char *), cmpstringp);
#endif /* PS_USES_PROCPCPU */
- int lines_to_show = chld_out.lines < (size_t)(n_procs_to_show + 1)
- ? (int)chld_out.lines : n_procs_to_show + 1;
+ int lines_to_show = chld_out.lines < (size_t)(n_procs_to_show + 1) ? (int)chld_out.lines : n_procs_to_show + 1;
for (i = 0; i < lines_to_show; i += 1) {
printf("%s\n", chld_out.line[i]);
}
--
cgit v1.2.3-74-g34f1
From 08a475a14fff2d0eee2e49f4765cb286cac8d2e2 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 13 Mar 2025 23:41:12 +0100
Subject: Refactor check_load + new ouput
---
plugins/Makefile.am | 1 +
plugins/check_load.c | 420 ++++++++++++++++++++++++------------------
plugins/check_load.d/config.h | 30 +++
3 files changed, 274 insertions(+), 177 deletions(-)
create mode 100644 plugins/check_load.d/config.h
(limited to 'plugins/check_load.c')
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 30ca63d1..f395e594 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -56,6 +56,7 @@ EXTRA_DIST = t \
check_game.d \
check_radius.d \
check_time.d \
+ check_load.d \
check_nagios.d \
check_dbi.d \
check_tcp.d \
diff --git a/plugins/check_load.c b/plugins/check_load.c
index e3a45f58..57be8c69 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -28,6 +28,9 @@
*
*****************************************************************************/
+#include "output.h"
+#include "perfdata.h"
+#include "thresholds.h"
const char *progname = "check_load";
const char *copyright = "1999-2022";
const char *email = "devel@monitoring-plugins.org";
@@ -36,6 +39,10 @@ const char *email = "devel@monitoring-plugins.org";
#include "./runcmd.h"
#include "./utils.h"
#include "./popen.h"
+#include "states.h"
+#include "check_load.d/config.h"
+
+#include "../gl/stdlib.h"
#include
@@ -50,70 +57,68 @@ const char *email = "devel@monitoring-plugins.org";
# define LOADAVG_15MIN 2
#endif /* !defined LOADAVG_1MIN */
-static int process_arguments(int argc, char **argv);
-static int validate_arguments(void);
+typedef struct {
+ int errorcode;
+ check_load_config config;
+} check_load_config_wrapper;
+static check_load_config_wrapper process_arguments(int argc, char **argv);
+static check_load_config_wrapper validate_arguments(check_load_config_wrapper /*config_wrapper*/);
+
void print_help(void);
void print_usage(void);
-static int print_top_consuming_processes();
-
-static int n_procs_to_show = 0;
-
-/* strictly for pretty-print usage in loops */
-static const int nums[3] = {1, 5, 15};
-
-/* provide some fairly sane defaults */
-double wload[3] = {0.0, 0.0, 0.0};
-double cload[3] = {0.0, 0.0, 0.0};
-#define la1 la[0]
-#define la5 la[1]
-#define la15 la[2]
-
-char *status_line;
-bool take_into_account_cpus = false;
-
-static void get_threshold(char *arg, double *th) {
- size_t i, n;
- int valid = 0;
- char *str = arg, *p;
-
- n = strlen(arg);
- for (i = 0; i < 3; i++) {
- th[i] = strtod(str, &p);
- if (p == str) {
+typedef struct {
+ int errorcode;
+ char **top_processes;
+} top_processes_result;
+static top_processes_result print_top_consuming_processes(int /*n_procs_to_show*/);
+
+typedef struct {
+ mp_range load[3];
+} parsed_thresholds;
+static parsed_thresholds get_threshold(char *arg) {
+ size_t index;
+ char *str = arg;
+ char *tmp_pointer;
+ bool valid = false;
+
+ parsed_thresholds result = {
+ .load[0] = mp_range_init(),
+ .load[1] = mp_range_init(),
+ .load[2] = mp_range_init(),
+ };
+
+ size_t arg_length = strlen(arg);
+ for (index = 0; index < 3; index++) {
+ double tmp = strtod(str, &tmp_pointer);
+ if (tmp_pointer == str) {
break;
}
- valid = 1;
- str = p + 1;
- if (n <= (size_t)(str - arg)) {
+ result.load[index] = mp_range_set_end(result.load[index], mp_create_pd_value(tmp));
+
+ valid = true;
+ str = tmp_pointer + 1;
+ if (arg_length <= (size_t)(str - arg)) {
break;
}
}
/* empty argument or non-floatish, so warn about it and die */
- if (!i && !valid) {
+ if (!index && !valid) {
usage(_("Warning threshold must be float or float triplet!\n"));
}
- if (i != 2) {
+ if (index != 2) {
/* one or more numbers were given, so fill array with last
* we got (most likely to NOT produce the least expected result) */
- for (n = i; n < 3; n++) {
- th[n] = th[i];
+ for (size_t tmp_index = index; tmp_index < 3; tmp_index++) {
+ result.load[tmp_index] = result.load[index];
}
}
+ return result;
}
int main(int argc, char **argv) {
- int result = -1;
- int i;
- long numcpus;
-
- double la[3] = {0.0, 0.0, 0.0}; /* NetBSD complains about uninitialized arrays */
-#ifndef HAVE_GETLOADAVG
- char input_buffer[MAX_INPUT_BUFFER];
-#endif
-
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -122,112 +127,138 @@ int main(int argc, char **argv) {
/* Parse extra opts if any */
argv = np_extra_opts(&argc, argv, progname);
- if (process_arguments(argc, argv) == ERROR) {
+ check_load_config_wrapper tmp_config = process_arguments(argc, argv);
+ if (tmp_config.errorcode == ERROR) {
usage4(_("Could not parse arguments"));
}
-#ifdef HAVE_GETLOADAVG
- result = getloadavg(la, 3);
- if (result != 3) {
- return STATE_UNKNOWN;
- }
-#else
- child_process = spopen(PATH_TO_UPTIME);
- if (child_process == NULL) {
- printf(_("Error opening %s\n"), PATH_TO_UPTIME);
- return STATE_UNKNOWN;
- }
- child_stderr = fdopen(child_stderr_array[fileno(child_process)], "r");
- if (child_stderr == NULL) {
- printf(_("Could not open stderr for %s\n"), PATH_TO_UPTIME);
- }
- fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process);
- if (strstr(input_buffer, "load average:")) {
- sscanf(input_buffer, "%*[^l]load average: %lf, %lf, %lf", &la1, &la5, &la15);
- } else if (strstr(input_buffer, "load averages:")) {
- sscanf(input_buffer, "%*[^l]load averages: %lf, %lf, %lf", &la1, &la5, &la15);
- } else {
- printf(_("could not parse load from uptime %s: %d\n"), PATH_TO_UPTIME, result);
- return STATE_UNKNOWN;
- }
+ const check_load_config config = tmp_config.config;
- result = spclose(child_process);
- if (result) {
- printf(_("Error code %d returned in %s\n"), result, PATH_TO_UPTIME);
- return STATE_UNKNOWN;
- }
-#endif
+ double load_values[3] = {0, 0, 0};
- if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) {
-#ifdef HAVE_GETLOADAVG
- printf(_("Error in getloadavg()\n"));
-#else
- printf(_("Error processing %s\n"), PATH_TO_UPTIME);
-#endif
- return STATE_UNKNOWN;
+ int error = getloadavg(load_values, 3);
+ if (error != 3) {
+ die(STATE_UNKNOWN, _("Failed to retrieve load values"));
}
- /* we got this far, so assume OK until we've measured */
- result = STATE_OK;
-
- xasprintf(&status_line, _("load average: %.2f, %.2f, %.2f"), la1, la5, la15);
- xasprintf(&status_line, ("total %s"), status_line);
+ mp_check overall = mp_check_init();
+ if (config.output_format_set) {
+ mp_set_format(config.output_format);
+ }
- double scaled_la[3] = {0.0, 0.0, 0.0};
bool is_using_scaled_load_values = false;
-
- if (take_into_account_cpus == true && (numcpus = GET_NUMBER_OF_CPUS()) > 0) {
+ long numcpus;
+ if (config.take_into_account_cpus && ((numcpus = GET_NUMBER_OF_CPUS()) > 0)) {
is_using_scaled_load_values = true;
- scaled_la[0] = la[0] / numcpus;
- scaled_la[1] = la[1] / numcpus;
- scaled_la[2] = la[2] / numcpus;
+ double scaled_la[3] = {0.0, 0.0, 0.0};
+ scaled_la[0] = load_values[0] / numcpus;
+ scaled_la[1] = load_values[1] / numcpus;
+ scaled_la[2] = load_values[2] / numcpus;
+
+ mp_subcheck scaled_load_sc = mp_subcheck_init();
+ scaled_load_sc = mp_set_subcheck_default_state(scaled_load_sc, STATE_OK);
+ scaled_load_sc.output = "Scaled Load (divided by number of CPUs";
+
+ mp_perfdata pd_scaled_load1 = perfdata_init();
+ pd_scaled_load1.label = "scaled_load1";
+ pd_scaled_load1 = mp_set_pd_value(pd_scaled_load1, scaled_la[0]);
+ pd_scaled_load1 = mp_pd_set_thresholds(pd_scaled_load1, config.th_load[0]);
+
+ 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));
+ mp_add_subcheck_to_subcheck(&scaled_load_sc, scaled_load_sc1);
+
+ mp_perfdata pd_scaled_load5 = perfdata_init();
+ pd_scaled_load5.label = "scaled_load5";
+ pd_scaled_load5 = mp_set_pd_value(pd_scaled_load5, scaled_la[1]);
+ pd_scaled_load5 = mp_pd_set_thresholds(pd_scaled_load5, config.th_load[1]);
+
+ 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));
+ mp_add_subcheck_to_subcheck(&scaled_load_sc, scaled_load_sc5);
+
+ mp_perfdata pd_scaled_load15 = perfdata_init();
+ pd_scaled_load15.label = "scaled_load15";
+ pd_scaled_load15 = mp_set_pd_value(pd_scaled_load15, scaled_la[2]);
+ 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));
+ 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));
+ mp_add_subcheck_to_subcheck(&scaled_load_sc, scaled_load_sc15);
+
+ mp_add_subcheck_to_check(&overall, scaled_load_sc);
+ }
+
+ mp_subcheck load_sc = mp_subcheck_init();
+ load_sc = mp_set_subcheck_default_state(load_sc, STATE_OK);
+ load_sc.output = "Total Load";
- char *tmp = NULL;
- xasprintf(&tmp, _("load average: %.2f, %.2f, %.2f"), scaled_la[0], scaled_la[1], scaled_la[2]);
- xasprintf(&status_line, "scaled %s - %s", tmp, status_line);
+ mp_perfdata pd_load1 = perfdata_init();
+ pd_load1.label = "load1";
+ pd_load1 = mp_set_pd_value(pd_load1, load_values[0]);
+ if (!is_using_scaled_load_values) {
+ pd_load1 = mp_pd_set_thresholds(pd_load1, config.th_load[0]);
}
- for (i = 0; i < 3; i++) {
- if (is_using_scaled_load_values) {
- if (scaled_la[i] > cload[i]) {
- result = STATE_CRITICAL;
- break;
- } else if (scaled_la[i] > wload[i]) {
- result = STATE_WARNING;
- }
- } else {
- if (la[i] > cload[i]) {
- result = STATE_CRITICAL;
- break;
- } else if (la[i] > wload[i]) {
- result = STATE_WARNING;
- }
- }
+ mp_subcheck load_sc1 = mp_subcheck_init();
+ load_sc1 = mp_set_subcheck_state(load_sc1, mp_get_pd_status(pd_load1));
+ mp_add_perfdata_to_subcheck(&load_sc1, pd_load1);
+ xasprintf(&load_sc1.output, "1 Minute: %s", pd_value_to_string(pd_load1.value));
+ mp_add_subcheck_to_subcheck(&load_sc, load_sc1);
+
+ mp_perfdata pd_load5 = perfdata_init();
+ pd_load5.label = "load5";
+ pd_load5 = mp_set_pd_value(pd_load5, load_values[1]);
+ if (!is_using_scaled_load_values) {
+ pd_load5 = mp_pd_set_thresholds(pd_load5, config.th_load[1]);
}
- printf("LOAD %s - %s|", state_text(result), status_line);
- for (i = 0; i < 3; i++) {
- if (is_using_scaled_load_values) {
- printf("load%d=%.3f;;;0; ", nums[i], la[i]);
- printf("scaled_load%d=%.3f;%.3f;%.3f;0; ", nums[i], scaled_la[i], wload[i], cload[i]);
- } else {
- printf("load%d=%.3f;%.3f;%.3f;0; ", nums[i], la[i], wload[i], cload[i]);
- }
+ mp_subcheck load_sc5 = mp_subcheck_init();
+ load_sc5 = mp_set_subcheck_state(load_sc5, mp_get_pd_status(pd_load5));
+ mp_add_perfdata_to_subcheck(&load_sc5, pd_load5);
+ xasprintf(&load_sc5.output, "5 Minutes: %s", pd_value_to_string(pd_load5.value));
+ mp_add_subcheck_to_subcheck(&load_sc, load_sc5);
+
+ mp_perfdata pd_load15 = perfdata_init();
+ pd_load15.label = "load15";
+ pd_load15 = mp_set_pd_value(pd_load15, load_values[2]);
+ if (!is_using_scaled_load_values) {
+ pd_load15 = mp_pd_set_thresholds(pd_load15, config.th_load[2]);
}
- putchar('\n');
- if (n_procs_to_show > 0) {
- print_top_consuming_processes();
+ mp_subcheck load_sc15 = mp_subcheck_init();
+ load_sc15 = mp_set_subcheck_state(load_sc15, mp_get_pd_status(pd_load15));
+ mp_add_perfdata_to_subcheck(&load_sc15, pd_load15);
+ xasprintf(&load_sc15.output, "15 Minutes: %s", pd_value_to_string(pd_load15.value));
+ mp_add_subcheck_to_subcheck(&load_sc, load_sc15);
+
+ mp_add_subcheck_to_check(&overall, load_sc);
+
+ if (config.n_procs_to_show > 0) {
+ 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);
+ top_proc_sc.output = "";
+
+ if (top_proc.errorcode == OK) {
+ for (int 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]);
+ }
+ }
}
- return result;
+
+ mp_exit(overall);
}
/* process command-line arguments */
-static int process_arguments(int argc, char **argv) {
- int c = 0;
-
- int option = 0;
+static check_load_config_wrapper process_arguments(int argc, char **argv) {
static struct option longopts[] = {{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"percpu", no_argument, 0, 'r'},
@@ -236,26 +267,45 @@ static int process_arguments(int argc, char **argv) {
{"procs-to-show", required_argument, 0, 'n'},
{0, 0, 0, 0}};
+ check_load_config_wrapper result = {
+ .errorcode = OK,
+ .config = check_load_config_init(),
+ };
+
if (argc < 2) {
- return ERROR;
+ result.errorcode = ERROR;
+ return result;
}
- while (1) {
- c = getopt_long(argc, argv, "Vhrc:w:n:", longopts, &option);
+ while (true) {
+ int option = 0;
+ int option_index = getopt_long(argc, argv, "Vhrc:w:n:", longopts, &option);
- if (c == -1 || c == EOF) {
+ if (option_index == -1 || option_index == EOF) {
break;
}
- switch (c) {
- case 'w': /* warning time threshold */
- get_threshold(optarg, wload);
- break;
- case 'c': /* critical time threshold */
- get_threshold(optarg, cload);
- break;
+ switch (option_index) {
+ case 'w': /* warning time threshold */ {
+ parsed_thresholds warning_range = get_threshold(optarg);
+ result.config.th_load[0].warning = warning_range.load[0];
+ result.config.th_load[0].warning_is_set = true;
+ result.config.th_load[1].warning = warning_range.load[1];
+ result.config.th_load[1].warning_is_set = true;
+ result.config.th_load[2].warning = warning_range.load[2];
+ result.config.th_load[2].warning_is_set = true;
+ } break;
+ case 'c': /* critical time threshold */ {
+ parsed_thresholds critical_range = get_threshold(optarg);
+ result.config.th_load[0].critical = critical_range.load[0];
+ result.config.th_load[0].critical_is_set = true;
+ result.config.th_load[1].critical = critical_range.load[1];
+ result.config.th_load[1].critical_is_set = true;
+ result.config.th_load[2].critical = critical_range.load[2];
+ result.config.th_load[2].critical_is_set = true;
+ } break;
case 'r': /* Divide load average by number of CPUs */
- take_into_account_cpus = true;
+ result.config.take_into_account_cpus = true;
break;
case 'V': /* version */
print_revision(progname, NP_VERSION);
@@ -264,49 +314,49 @@ static int process_arguments(int argc, char **argv) {
print_help();
exit(STATE_UNKNOWN);
case 'n':
- n_procs_to_show = atoi(optarg);
+ result.config.n_procs_to_show = atoi(optarg);
break;
case '?': /* help */
usage5();
}
}
- c = optind;
- if (c == argc) {
- return validate_arguments();
+ int index = optind;
+ if (index == argc) {
+ return validate_arguments(result);
}
/* handle the case if both arguments are missing,
* but not if only one is given without -c or -w flag */
- if (c - argc == 2) {
- get_threshold(argv[c++], wload);
- get_threshold(argv[c++], cload);
- } else if (c - argc == 1) {
- get_threshold(argv[c++], cload);
+ if (index - argc == 2) {
+ parsed_thresholds warning_range = get_threshold(argv[index++]);
+ result.config.th_load[0].warning = warning_range.load[0];
+ result.config.th_load[0].warning_is_set = true;
+ result.config.th_load[1].warning = warning_range.load[1];
+ result.config.th_load[1].warning_is_set = true;
+ result.config.th_load[2].warning = warning_range.load[2];
+ result.config.th_load[2].warning_is_set = true;
+ parsed_thresholds critical_range = get_threshold(argv[index++]);
+ result.config.th_load[0].critical = critical_range.load[0];
+ result.config.th_load[0].critical_is_set = true;
+ result.config.th_load[1].critical = critical_range.load[1];
+ result.config.th_load[1].critical_is_set = true;
+ result.config.th_load[2].critical = critical_range.load[2];
+ result.config.th_load[2].critical_is_set = true;
+ } else if (index - argc == 1) {
+ parsed_thresholds critical_range = get_threshold(argv[index++]);
+ result.config.th_load[0].critical = critical_range.load[0];
+ result.config.th_load[0].critical_is_set = true;
+ result.config.th_load[1].critical = critical_range.load[1];
+ result.config.th_load[1].critical_is_set = true;
+ result.config.th_load[2].critical = critical_range.load[2];
+ result.config.th_load[2].critical_is_set = true;
}
- return validate_arguments();
+ return validate_arguments(result);
}
-static int validate_arguments(void) {
- int i = 0;
-
- /* match cload first, as it will give the most friendly error message
- * if user hasn't given the -c switch properly */
- for (i = 0; i < 3; i++) {
- if (cload[i] < 0) {
- die(STATE_UNKNOWN, _("Critical threshold for %d-minute load average is not specified\n"), nums[i]);
- }
- if (wload[i] < 0) {
- die(STATE_UNKNOWN, _("Warning threshold for %d-minute load average is not specified\n"), nums[i]);
- }
- if (wload[i] > cload[i]) {
- die(STATE_UNKNOWN, _("Parameter inconsistency: %d-minute \"warning load\" is greater than \"critical load\"\n"), nums[i]);
- }
- }
-
- return OK;
-}
+static check_load_config_wrapper validate_arguments(check_load_config_wrapper config_wrapper) { return config_wrapper; }
void print_help(void) {
print_revision(progname, NP_VERSION);
@@ -363,23 +413,39 @@ int cmpstringp(const void *p1, const void *p2) {
}
#endif /* PS_USES_PROCPCPU */
-static int print_top_consuming_processes() {
- int i = 0;
- struct output chld_out, chld_err;
+static top_processes_result print_top_consuming_processes(int n_procs_to_show) {
+ top_processes_result result = {
+ .errorcode = OK,
+ };
+ struct output chld_out;
+ struct output chld_err;
if (np_runcmd(PS_COMMAND, &chld_out, &chld_err, 0) != 0) {
fprintf(stderr, _("'%s' exited with non-zero status.\n"), PS_COMMAND);
- return STATE_UNKNOWN;
+ result.errorcode = ERROR;
+ return result;
}
+
if (chld_out.lines < 2) {
fprintf(stderr, _("some error occurred getting procs list.\n"));
- return STATE_UNKNOWN;
+ result.errorcode = ERROR;
+ return result;
}
+
#ifdef PS_USES_PROCPCPU
qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char *), cmpstringp);
#endif /* PS_USES_PROCPCPU */
int lines_to_show = chld_out.lines < (size_t)(n_procs_to_show + 1) ? (int)chld_out.lines : n_procs_to_show + 1;
- for (i = 0; i < lines_to_show; i += 1) {
- printf("%s\n", chld_out.line[i]);
+
+ result.top_processes = calloc(lines_to_show, sizeof(char *));
+ if (result.top_processes == NULL) {
+ // Failed allocation
+ result.errorcode = ERROR;
+ return result;
}
- return OK;
+
+ for (int i = 0; i < lines_to_show; i += 1) {
+ xasprintf(&result.top_processes[i], "%s", chld_out.line[i]);
+ }
+
+ return result;
}
diff --git a/plugins/check_load.d/config.h b/plugins/check_load.d/config.h
new file mode 100644
index 00000000..d399c19c
--- /dev/null
+++ b/plugins/check_load.d/config.h
@@ -0,0 +1,30 @@
+#pragma once
+
+#include "output.h"
+#include "thresholds.h"
+typedef struct {
+ mp_thresholds th_load[3];
+
+ bool take_into_account_cpus;
+ int n_procs_to_show;
+
+ mp_output_format output_format;
+ bool output_format_set;
+} check_load_config;
+
+check_load_config check_load_config_init() {
+ check_load_config tmp = {
+ .th_load =
+ {
+ mp_thresholds_init(),
+ mp_thresholds_init(),
+ mp_thresholds_init(),
+ },
+
+ .take_into_account_cpus = false,
+ .n_procs_to_show = 0,
+
+ .output_format_set = false,
+ };
+ return tmp;
+}
--
cgit v1.2.3-74-g34f1
From fedff97c96ec7f7866fa15bd38b9a349cf260cad Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Thu, 13 Mar 2025 23:51:51 +0100
Subject: improved includes and some comments
---
plugins/check_load.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
(limited to 'plugins/check_load.c')
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 57be8c69..5d3e6237 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -28,28 +28,24 @@
*
*****************************************************************************/
-#include "output.h"
-#include "perfdata.h"
-#include "thresholds.h"
const char *progname = "check_load";
const char *copyright = "1999-2022";
const char *email = "devel@monitoring-plugins.org";
#include "./common.h"
+#include
#include "./runcmd.h"
#include "./utils.h"
#include "./popen.h"
-#include "states.h"
+#include "../lib/states.h"
+#include "../lib/output.h"
+#include "../lib/perfdata.h"
+#include "../lib/thresholds.h"
#include "check_load.d/config.h"
+// getloadavg comes from gnulib
#include "../gl/stdlib.h"
-#include
-
-#ifdef HAVE_SYS_LOADAVG_H
-# include
-#endif
-
/* needed for compilation under NetBSD, as suggested by Andy Doran */
#ifndef LOADAVG_1MIN
# define LOADAVG_1MIN 0
@@ -136,6 +132,7 @@ int main(int argc, char **argv) {
double load_values[3] = {0, 0, 0};
+ // this should be getloadavg from gnulib, should work everywhere™
int error = getloadavg(load_values, 3);
if (error != 3) {
die(STATE_UNKNOWN, _("Failed to retrieve load values"));
--
cgit v1.2.3-74-g34f1
From 5eaeadbb3a50e254fb465bf22c6022de9ecbab2d Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Fri, 14 Mar 2025 00:04:02 +0100
Subject: check_load: Actually allow output format configuring
---
plugins/check_load.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'plugins/check_load.c')
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 5d3e6237..bf3c89d8 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -256,12 +256,18 @@ int main(int argc, char **argv) {
/* process command-line arguments */
static check_load_config_wrapper process_arguments(int argc, char **argv) {
+
+ enum {
+ output_format_index = CHAR_MAX + 1,
+ };
+
static struct option longopts[] = {{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"percpu", no_argument, 0, 'r'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{"procs-to-show", required_argument, 0, 'n'},
+ {"output-format", required_argument, 0, output_format_index},
{0, 0, 0, 0}};
check_load_config_wrapper result = {
@@ -283,6 +289,18 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
}
switch (option_index) {
+ case output_format_index: {
+ parsed_output_format parser = mp_parse_output_format(optarg);
+ if (!parser.parsing_success) {
+ // TODO List all available formats here, maybe add anothoer usage function
+ printf("Invalid output format: %s\n", optarg);
+ exit(STATE_UNKNOWN);
+ }
+
+ result.config.output_format_set = true;
+ result.config.output_format = parser.output_format;
+ break;
+ }
case 'w': /* warning time threshold */ {
parsed_thresholds warning_range = get_threshold(optarg);
result.config.th_load[0].warning = warning_range.load[0];
@@ -381,6 +399,7 @@ void print_help(void) {
printf(" %s\n", _("Number of processes to show when printing the top consuming processes."));
printf(" %s\n", _("NUMBER_OF_PROCS=0 disables this feature. Default value is 0"));
+ printf(UT_OUTPUT_FORMAT);
printf(UT_SUPPORT);
}
--
cgit v1.2.3-74-g34f1
From 4ef8af0d9a2acb2e199b613af2d85af86fed24b2 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 6 Jul 2025 21:46:54 +0200
Subject: check_load: remove useless code and do some formatting
---
plugins/check_load.c | 36 +++++++++++++++++++++++-------------
1 file changed, 23 insertions(+), 13 deletions(-)
(limited to 'plugins/check_load.c')
diff --git a/plugins/check_load.c b/plugins/check_load.c
index bf3c89d8..f7e80fdb 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -58,7 +58,6 @@ typedef struct {
check_load_config config;
} check_load_config_wrapper;
static check_load_config_wrapper process_arguments(int argc, char **argv);
-static check_load_config_wrapper validate_arguments(check_load_config_wrapper /*config_wrapper*/);
void print_help(void);
void print_usage(void);
@@ -78,9 +77,12 @@ static parsed_thresholds get_threshold(char *arg) {
bool valid = false;
parsed_thresholds result = {
- .load[0] = mp_range_init(),
- .load[1] = mp_range_init(),
- .load[2] = mp_range_init(),
+ .load =
+ {
+ mp_range_init(),
+ mp_range_init(),
+ mp_range_init(),
+ },
};
size_t arg_length = strlen(arg);
@@ -148,10 +150,11 @@ int main(int argc, char **argv) {
if (config.take_into_account_cpus && ((numcpus = GET_NUMBER_OF_CPUS()) > 0)) {
is_using_scaled_load_values = true;
- double scaled_la[3] = {0.0, 0.0, 0.0};
- scaled_la[0] = load_values[0] / numcpus;
- scaled_la[1] = load_values[1] / numcpus;
- scaled_la[2] = load_values[2] / numcpus;
+ double scaled_la[3] = {
+ load_values[0] / numcpus,
+ load_values[1] / numcpus,
+ load_values[2] / numcpus,
+ };
mp_subcheck scaled_load_sc = mp_subcheck_init();
scaled_load_sc = mp_set_subcheck_default_state(scaled_load_sc, STATE_OK);
@@ -292,7 +295,6 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
case output_format_index: {
parsed_output_format parser = mp_parse_output_format(optarg);
if (!parser.parsing_success) {
- // TODO List all available formats here, maybe add anothoer usage function
printf("Invalid output format: %s\n", optarg);
exit(STATE_UNKNOWN);
}
@@ -305,8 +307,10 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
parsed_thresholds warning_range = get_threshold(optarg);
result.config.th_load[0].warning = warning_range.load[0];
result.config.th_load[0].warning_is_set = true;
+
result.config.th_load[1].warning = warning_range.load[1];
result.config.th_load[1].warning_is_set = true;
+
result.config.th_load[2].warning = warning_range.load[2];
result.config.th_load[2].warning_is_set = true;
} break;
@@ -314,8 +318,10 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
parsed_thresholds critical_range = get_threshold(optarg);
result.config.th_load[0].critical = critical_range.load[0];
result.config.th_load[0].critical_is_set = true;
+
result.config.th_load[1].critical = critical_range.load[1];
result.config.th_load[1].critical_is_set = true;
+
result.config.th_load[2].critical = critical_range.load[2];
result.config.th_load[2].critical_is_set = true;
} break;
@@ -338,7 +344,7 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
int index = optind;
if (index == argc) {
- return validate_arguments(result);
+ return result;
}
/* handle the case if both arguments are missing,
@@ -347,32 +353,36 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
parsed_thresholds warning_range = get_threshold(argv[index++]);
result.config.th_load[0].warning = warning_range.load[0];
result.config.th_load[0].warning_is_set = true;
+
result.config.th_load[1].warning = warning_range.load[1];
result.config.th_load[1].warning_is_set = true;
+
result.config.th_load[2].warning = warning_range.load[2];
result.config.th_load[2].warning_is_set = true;
parsed_thresholds critical_range = get_threshold(argv[index++]);
result.config.th_load[0].critical = critical_range.load[0];
result.config.th_load[0].critical_is_set = true;
+
result.config.th_load[1].critical = critical_range.load[1];
result.config.th_load[1].critical_is_set = true;
+
result.config.th_load[2].critical = critical_range.load[2];
result.config.th_load[2].critical_is_set = true;
} else if (index - argc == 1) {
parsed_thresholds critical_range = get_threshold(argv[index++]);
result.config.th_load[0].critical = critical_range.load[0];
result.config.th_load[0].critical_is_set = true;
+
result.config.th_load[1].critical = critical_range.load[1];
result.config.th_load[1].critical_is_set = true;
+
result.config.th_load[2].critical = critical_range.load[2];
result.config.th_load[2].critical_is_set = true;
}
- return validate_arguments(result);
+ return result;
}
-static check_load_config_wrapper validate_arguments(check_load_config_wrapper config_wrapper) { return config_wrapper; }
-
void print_help(void) {
print_revision(progname, NP_VERSION);
--
cgit v1.2.3-74-g34f1
From b002a6870b6ef9333d3234cec58b8c2fc1acfeec Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 6 Jul 2025 21:58:55 +0200
Subject: check_load: Add top x functionality to output
---
plugins/check_load.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
(limited to 'plugins/check_load.c')
diff --git a/plugins/check_load.c b/plugins/check_load.c
index f7e80fdb..78daa945 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -245,13 +245,15 @@ 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);
- top_proc_sc.output = "";
+ xasprintf(&top_proc_sc.output, "Top %lu CPU time consuming processes", config.n_procs_to_show);
if (top_proc.errorcode == OK) {
for (int 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]);
}
}
+
+ mp_add_subcheck_to_check(&overall, top_proc_sc);
}
mp_exit(overall);
--
cgit v1.2.3-74-g34f1
From 351b104894fd52e634d60d79f573be682a2da8d4 Mon Sep 17 00:00:00 2001
From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>
Date: Sun, 6 Jul 2025 21:59:12 +0200
Subject: check_load some number type fixes
---
plugins/check_load.c | 12 ++++++------
plugins/check_load.d/config.h | 2 +-
2 files changed, 7 insertions(+), 7 deletions(-)
(limited to 'plugins/check_load.c')
diff --git a/plugins/check_load.c b/plugins/check_load.c
index 78daa945..2925bff3 100644
--- a/plugins/check_load.c
+++ b/plugins/check_load.c
@@ -65,7 +65,7 @@ typedef struct {
int errorcode;
char **top_processes;
} top_processes_result;
-static top_processes_result print_top_consuming_processes(int /*n_procs_to_show*/);
+static top_processes_result print_top_consuming_processes(unsigned long n_procs_to_show);
typedef struct {
mp_range load[3];
@@ -248,7 +248,7 @@ int main(int argc, char **argv) {
xasprintf(&top_proc_sc.output, "Top %lu CPU time consuming processes", config.n_procs_to_show);
if (top_proc.errorcode == OK) {
- for (int i = 0; i < config.n_procs_to_show; i++) {
+ 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]);
}
}
@@ -337,7 +337,7 @@ static check_load_config_wrapper process_arguments(int argc, char **argv) {
print_help();
exit(STATE_UNKNOWN);
case 'n':
- result.config.n_procs_to_show = atoi(optarg);
+ result.config.n_procs_to_show = (unsigned long)atol(optarg);
break;
case '?': /* help */
usage5();
@@ -441,7 +441,7 @@ int cmpstringp(const void *p1, const void *p2) {
}
#endif /* PS_USES_PROCPCPU */
-static top_processes_result print_top_consuming_processes(int n_procs_to_show) {
+static top_processes_result print_top_consuming_processes(unsigned long n_procs_to_show) {
top_processes_result result = {
.errorcode = OK,
};
@@ -462,7 +462,7 @@ static top_processes_result print_top_consuming_processes(int n_procs_to_show) {
#ifdef PS_USES_PROCPCPU
qsort(chld_out.line + 1, chld_out.lines - 1, sizeof(char *), cmpstringp);
#endif /* PS_USES_PROCPCPU */
- int lines_to_show = chld_out.lines < (size_t)(n_procs_to_show + 1) ? (int)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) {
@@ -471,7 +471,7 @@ static top_processes_result print_top_consuming_processes(int n_procs_to_show) {
return result;
}
- for (int i = 0; i < lines_to_show; i += 1) {
+ for (unsigned long i = 0; i < lines_to_show; i += 1) {
xasprintf(&result.top_processes[i], "%s", chld_out.line[i]);
}
diff --git a/plugins/check_load.d/config.h b/plugins/check_load.d/config.h
index d399c19c..fd735455 100644
--- a/plugins/check_load.d/config.h
+++ b/plugins/check_load.d/config.h
@@ -6,7 +6,7 @@ typedef struct {
mp_thresholds th_load[3];
bool take_into_account_cpus;
- int n_procs_to_show;
+ unsigned long n_procs_to_show;
mp_output_format output_format;
bool output_format_set;
--
cgit v1.2.3-74-g34f1
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
---
lib/extra_opts.c | 28 +-
lib/maxfd.c | 5 +-
lib/output.c | 11 +-
lib/parse_ini.c | 112 +++--
lib/tests/test_base64.c | 271 +++++++-----
lib/tests/test_cmd.c | 27 +-
lib/tests/test_generic_output.c | 6 +-
lib/tests/test_ini1.c | 51 ++-
lib/tests/test_opts1.c | 34 +-
lib/tests/test_opts2.c | 69 +--
lib/tests/test_tcp.c | 23 +-
lib/utils_base.c | 4 +-
lib/utils_cmd.c | 95 ++--
lib/utils_tcp.c | 25 +-
lib/utils_tcp.h | 3 +-
plugins-root/check_dhcp.c | 258 +++++++----
plugins-root/check_icmp.d/config.h | 2 +-
plugins-root/pst3.c | 441 +++++++++----------
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 ++-
tap/tap.c | 25 +-
tap/tap.h | 43 +-
tools/mini_epn.c | 96 ++--
74 files changed, 3290 insertions(+), 2248 deletions(-)
(limited to 'plugins/check_load.c')
diff --git a/lib/extra_opts.c b/lib/extra_opts.c
index 88787336..857b34b4 100644
--- a/lib/extra_opts.c
+++ b/lib/extra_opts.c
@@ -27,12 +27,13 @@
/* FIXME: copied from utils.h; we should move a bunch of libs! */
bool is_option2(char *str) {
- if (!str)
+ if (!str) {
return false;
- else if (strspn(str, "-") == 1 || strspn(str, "-") == 2)
+ } else if (strspn(str, "-") == 1 || strspn(str, "-") == 2) {
return true;
- else
+ } else {
return false;
+ }
}
/* this is the externally visible function used by plugins */
@@ -56,8 +57,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
/* It is a single argument with value */
argptr = argv[i] + 13;
/* Delete the extra opts argument */
- for (j = i; j < *argc; j++)
+ for (j = i; j < *argc; j++) {
argv[j] = argv[j + 1];
+ }
i--;
*argc -= 1;
} else if (strcmp(argv[i], "--extra-opts") == 0) {
@@ -65,8 +67,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
/* It is a argument with separate value */
argptr = argv[i + 1];
/* Delete the extra-opts argument/value */
- for (j = i; j < *argc - 1; j++)
+ for (j = i; j < *argc - 1; j++) {
argv[j] = argv[j + 2];
+ }
i -= 2;
*argc -= 2;
ea_num--;
@@ -74,8 +77,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
/* It has no value */
optfound = 1;
/* Delete the extra opts argument */
- for (j = i; j < *argc; j++)
+ for (j = i; j < *argc; j++) {
argv[j] = argv[j + 1];
+ }
i--;
*argc -= 1;
}
@@ -94,16 +98,18 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
/* append the list to extra_args */
if (extra_args == NULL) {
extra_args = ea1;
- while ((ea1 = ea1->next))
+ while ((ea1 = ea1->next)) {
ea_num++;
+ }
} else {
ea_tmp = extra_args;
while (ea_tmp->next) {
ea_tmp = ea_tmp->next;
}
ea_tmp->next = ea1;
- while ((ea1 = ea1->next))
+ while ((ea1 = ea1->next)) {
ea_num++;
+ }
}
ea1 = ea_tmp = NULL;
}
@@ -116,8 +122,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
/* done processing arguments. now create a new argv array... */
argv_new = (char **)malloc((ea_num + 1) * sizeof(char **));
- if (argv_new == NULL)
+ if (argv_new == NULL) {
die(STATE_UNKNOWN, _("malloc() failed!\n"));
+ }
/* starting with program name */
argv_new[0] = argv[0];
@@ -130,8 +137,9 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) {
free(ea1);
}
/* finally the rest of the argv array */
- for (i = 1; i < *argc; i++)
+ for (i = 1; i < *argc; i++) {
argv_new[argc_new++] = argv[i];
+ }
*argc = argc_new;
/* and terminate. */
argv_new[argc_new] = NULL;
diff --git a/lib/maxfd.c b/lib/maxfd.c
index ca5b6e54..9b58d8e3 100644
--- a/lib/maxfd.c
+++ b/lib/maxfd.c
@@ -31,10 +31,11 @@ long mp_open_max(void) {
#ifdef _SC_OPEN_MAX
errno = 0;
if ((maxfd = sysconf(_SC_OPEN_MAX)) < 0) {
- if (errno == 0)
+ if (errno == 0) {
maxfd = DEFAULT_MAXFD; /* it's indeterminate */
- else
+ } else {
die(STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n"));
+ }
}
#elif defined(OPEN_MAX)
return OPEN_MAX
diff --git a/lib/output.c b/lib/output.c
index 34ff7dab..f283969f 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -377,7 +377,9 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
while (tmp_string != NULL) {
*tmp_string = '\0';
- asprintf(&intermediate_string, "%s%s\n%s", intermediate_string,check.output, generate_indentation_string(indentation+1)); // one more indentation to make it look better
+ asprintf(&intermediate_string, "%s%s\n%s", intermediate_string, check.output,
+ generate_indentation_string(
+ indentation + 1)); // one more indentation to make it look better
if (*(tmp_string + 1) != '\0') {
check.output = tmp_string + 1;
@@ -394,13 +396,14 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
// add the rest (if any)
if (have_residual_chars) {
char *tmp = check.output;
- xasprintf(&check.output, "%s\n%s%s", intermediate_string, generate_indentation_string(indentation+1), tmp);
+ xasprintf(&check.output, "%s\n%s%s", intermediate_string,
+ generate_indentation_string(indentation + 1), tmp);
} else {
check.output = intermediate_string;
}
}
- asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation), state_text(mp_compute_subcheck_state(check)),
- check.output);
+ asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation),
+ state_text(mp_compute_subcheck_state(check)), check.output);
subchecks = check.subchecks;
diff --git a/lib/parse_ini.c b/lib/parse_ini.c
index 1289aae2..4c3c1b93 100644
--- a/lib/parse_ini.c
+++ b/lib/parse_ini.c
@@ -40,19 +40,22 @@ typedef struct {
char *stanza;
} np_ini_info;
-static char *default_ini_file_names[] = {"monitoring-plugins.ini", "plugins.ini", "nagios-plugins.ini", NULL};
+static char *default_ini_file_names[] = {"monitoring-plugins.ini", "plugins.ini",
+ "nagios-plugins.ini", NULL};
static char *default_ini_path_names[] = {
- "/usr/local/etc/monitoring-plugins/monitoring-plugins.ini", "/usr/local/etc/monitoring-plugins.ini",
- "/etc/monitoring-plugins/monitoring-plugins.ini", "/etc/monitoring-plugins.ini",
+ "/usr/local/etc/monitoring-plugins/monitoring-plugins.ini",
+ "/usr/local/etc/monitoring-plugins.ini", "/etc/monitoring-plugins/monitoring-plugins.ini",
+ "/etc/monitoring-plugins.ini",
/* deprecated path names (for backward compatibility): */
- "/etc/nagios/plugins.ini", "/usr/local/nagios/etc/plugins.ini", "/usr/local/etc/nagios/plugins.ini", "/etc/opt/nagios/plugins.ini",
- "/etc/nagios-plugins.ini", "/usr/local/etc/nagios-plugins.ini", "/etc/opt/nagios-plugins.ini", NULL};
+ "/etc/nagios/plugins.ini", "/usr/local/nagios/etc/plugins.ini",
+ "/usr/local/etc/nagios/plugins.ini", "/etc/opt/nagios/plugins.ini", "/etc/nagios-plugins.ini",
+ "/usr/local/etc/nagios-plugins.ini", "/etc/opt/nagios-plugins.ini", NULL};
/* eat all characters from a FILE pointer until n is encountered */
-#define GOBBLE_TO(f, c, n) \
- do { \
- (c) = fgetc((f)); \
+#define GOBBLE_TO(f, c, n) \
+ do { \
+ (c) = fgetc((f)); \
} while ((c) != EOF && (c) != (n))
/* internal function that returns the constructed defaults options */
@@ -87,8 +90,9 @@ static void parse_locator(const char *locator, const char *def_stanza, np_ini_in
i->stanza = strdup(def_stanza);
}
- if (i->stanza == NULL)
+ if (i->stanza == NULL) {
die(STATE_UNKNOWN, _("malloc() failed!\n"));
+ }
/* check whether there's an @file part */
if (stanza_len == locator_len) {
@@ -99,8 +103,9 @@ static void parse_locator(const char *locator, const char *def_stanza, np_ini_in
i->file_string_on_heap = true;
}
- if (i->file == NULL || i->file[0] == '\0')
+ if (i->file == NULL || i->file[0] == '\0') {
die(STATE_UNKNOWN, _("Cannot find config file in any standard location.\n"));
+ }
}
/*
@@ -112,26 +117,31 @@ np_arg_list *np_get_defaults(const char *locator, const char *default_section) {
np_ini_info i;
int is_suid_plugin = mp_suid();
- if (is_suid_plugin && idpriv_temp_drop() == -1)
+ if (is_suid_plugin && idpriv_temp_drop() == -1) {
die(STATE_UNKNOWN, _("Cannot drop privileges: %s\n"), strerror(errno));
+ }
parse_locator(locator, default_section, &i);
inifile = strcmp(i.file, "-") == 0 ? stdin : fopen(i.file, "r");
- if (inifile == NULL)
+ if (inifile == NULL) {
die(STATE_UNKNOWN, _("Can't read config file: %s\n"), strerror(errno));
- if (!read_defaults(inifile, i.stanza, &defaults))
+ }
+ if (!read_defaults(inifile, i.stanza, &defaults)) {
die(STATE_UNKNOWN, _("Invalid section '%s' in config file '%s'\n"), i.stanza, i.file);
+ }
if (i.file_string_on_heap) {
free(i.file);
}
- if (inifile != stdin)
+ if (inifile != stdin) {
fclose(inifile);
+ }
free(i.stanza);
- if (is_suid_plugin && idpriv_temp_restore() == -1)
+ if (is_suid_plugin && idpriv_temp_restore() == -1) {
die(STATE_UNKNOWN, _("Cannot restore privileges: %s\n"), strerror(errno));
+ }
return defaults;
}
@@ -158,8 +168,9 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) {
/* our little stanza-parsing state machine */
while ((c = fgetc(f)) != EOF) {
/* gobble up leading whitespace */
- if (isspace(c))
+ if (isspace(c)) {
continue;
+ }
switch (c) {
/* globble up comment lines */
case ';':
@@ -172,9 +183,11 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) {
for (i = 0; i < stanza_len; i++) {
c = fgetc(f);
/* strip leading whitespace */
- if (i == 0)
- for (; isspace(c); c = fgetc(f))
+ if (i == 0) {
+ for (; isspace(c); c = fgetc(f)) {
continue;
+ }
+ }
/* nope, read to the end of the line */
if (c != stanza[i]) {
GOBBLE_TO(f, c, '\n');
@@ -185,10 +198,12 @@ static int read_defaults(FILE *f, const char *stanza, np_arg_list **opts) {
if (i == stanza_len) {
c = fgetc(f);
/* strip trailing whitespace */
- for (; isspace(c); c = fgetc(f))
+ for (; isspace(c); c = fgetc(f)) {
continue;
- if (c == ']')
+ }
+ if (c == ']') {
stanzastate = RIGHTSTANZA;
+ }
}
break;
/* otherwise, we're in the body of a stanza or a parse error */
@@ -239,12 +254,13 @@ static int add_option(FILE *f, np_arg_list **optlst) {
if (linebuf == NULL || read_pos + read_sz >= linebuf_sz) {
linebuf_sz = linebuf_sz > 0 ? linebuf_sz << 1 : read_sz;
linebuf = realloc(linebuf, linebuf_sz);
- if (linebuf == NULL)
+ if (linebuf == NULL) {
die(STATE_UNKNOWN, _("malloc() failed!\n"));
+ }
}
- if (fgets(&linebuf[read_pos], (int)read_sz, f) == NULL)
+ if (fgets(&linebuf[read_pos], (int)read_sz, f) == NULL) {
done_reading = 1;
- else {
+ } else {
read_pos = strlen(linebuf);
if (linebuf[read_pos - 1] == '\n') {
linebuf[--read_pos] = '\0';
@@ -256,38 +272,46 @@ static int add_option(FILE *f, np_arg_list **optlst) {
/* all that to read one line, isn't C fun? :) now comes the parsing :/ */
/* skip leading whitespace */
- for (optptr = linebuf; optptr < lineend && isspace(*optptr); optptr++)
+ for (optptr = linebuf; optptr < lineend && isspace(*optptr); optptr++) {
continue;
+ }
/* continue to '=' or EOL, watching for spaces that might precede it */
for (eqptr = optptr; eqptr < lineend && *eqptr != '='; eqptr++) {
- if (isspace(*eqptr) && optend == NULL)
+ if (isspace(*eqptr) && optend == NULL) {
optend = eqptr;
- else
+ } else {
optend = NULL;
+ }
}
- if (optend == NULL)
+ if (optend == NULL) {
optend = eqptr;
+ }
--optend;
/* ^[[:space:]]*=foo is a syntax error */
- if (optptr == eqptr)
+ if (optptr == eqptr) {
die(STATE_UNKNOWN, "%s\n", _("Config file error"));
+ }
/* continue from '=' to start of value or EOL */
- for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); valptr++)
+ for (valptr = eqptr + 1; valptr < lineend && isspace(*valptr); valptr++) {
continue;
+ }
/* continue to the end of value */
- for (valend = valptr; valend < lineend; valend++)
+ for (valend = valptr; valend < lineend; valend++) {
continue;
+ }
--valend;
/* finally trim off trailing spaces */
- for (; isspace(*valend); valend--)
+ for (; isspace(*valend); valend--) {
continue;
+ }
/* calculate the length of "--foo" */
opt_len = (size_t)(1 + optend - optptr);
/* 1-character params needs only one dash */
- if (opt_len == 1)
+ if (opt_len == 1) {
cfg_len = 1 + (opt_len);
- else
+ } else {
cfg_len = 2 + (opt_len);
+ }
/* if valptrarg[read_pos] = '\0';
/* ...and put that to the end of the list */
- if (*optlst == NULL)
+ if (*optlst == NULL) {
*optlst = optnew;
- else {
- while (opttmp->next != NULL)
+ } else {
+ while (opttmp->next != NULL) {
opttmp = opttmp->next;
+ }
opttmp->next = optnew;
}
@@ -344,7 +370,8 @@ static int add_option(FILE *f, np_arg_list **optlst) {
static char *default_file(void) {
char *ini_file;
- if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL || (ini_file = default_file_in_path()) != NULL) {
+ if ((ini_file = getenv("MP_CONFIG_FILE")) != NULL ||
+ (ini_file = default_file_in_path()) != NULL) {
return ini_file;
}
@@ -360,16 +387,19 @@ static char *default_file_in_path(void) {
char *config_path, **file;
char *dir, *ini_file, *tokens;
- if ((config_path = getenv("NAGIOS_CONFIG_PATH")) == NULL)
+ if ((config_path = getenv("NAGIOS_CONFIG_PATH")) == NULL) {
return NULL;
+ }
/* shall we spit out a warning that NAGIOS_CONFIG_PATH is deprecated? */
- if ((tokens = strdup(config_path)) == NULL)
+ if ((tokens = strdup(config_path)) == NULL) {
die(STATE_UNKNOWN, "%s\n", _("Insufficient Memory"));
+ }
for (dir = strtok(tokens, ":"); dir != NULL; dir = strtok(NULL, ":")) {
for (file = default_ini_file_names; *file != NULL; file++) {
- if ((asprintf(&ini_file, "%s/%s", dir, *file)) < 0)
+ if ((asprintf(&ini_file, "%s/%s", dir, *file)) < 0) {
die(STATE_UNKNOWN, "%s\n", _("Insufficient Memory"));
+ }
if (access(ini_file, F_OK) == 0) {
free(tokens);
return ini_file;
diff --git a/lib/tests/test_base64.c b/lib/tests/test_base64.c
index 94cb5aa9..798244da 100644
--- a/lib/tests/test_base64.c
+++ b/lib/tests/test_base64.c
@@ -180,117 +180,168 @@ int main(int argc, char **argv) {
#endif
char random[1024] = {
- 0x0b, 0x30, 0x44, 0x62, 0x7c, 0x22, 0x1f, 0x0d, 0x05, 0x67, 0x2c, 0x2a, 0x39, 0x21, 0x46, 0x08, 0x50, 0x66, 0x34, 0x37, 0x0b, 0x45,
- 0x4b, 0x38, 0x32, 0x06, 0x7a, 0x3e, 0x7f, 0x0c, 0x40, 0x18, 0x6b, 0x2d, 0x60, 0x4c, 0x60, 0x0c, 0x23, 0x43, 0x3b, 0x3e, 0x1b, 0x16,
- 0x04, 0x46, 0x58, 0x3f, 0x40, 0x6a, 0x11, 0x05, 0x63, 0x71, 0x14, 0x35, 0x47, 0x79, 0x13, 0x6f, 0x6b, 0x27, 0x18, 0x5b, 0x48, 0x27,
- 0x3e, 0x6f, 0x15, 0x33, 0x4f, 0x3e, 0x5e, 0x51, 0x73, 0x68, 0x25, 0x0f, 0x06, 0x5b, 0x7c, 0x72, 0x75, 0x3e, 0x3f, 0x1b, 0x5c, 0x6d,
- 0x6a, 0x39, 0x7c, 0x63, 0x63, 0x60, 0x6c, 0x7a, 0x33, 0x76, 0x52, 0x13, 0x25, 0x33, 0x7d, 0x65, 0x23, 0x27, 0x11, 0x06, 0x06, 0x47,
- 0x71, 0x1e, 0x14, 0x74, 0x63, 0x70, 0x2d, 0x15, 0x27, 0x18, 0x51, 0x06, 0x05, 0x33, 0x11, 0x2c, 0x6b, 0x00, 0x2d, 0x77, 0x20, 0x48,
- 0x0d, 0x73, 0x51, 0x45, 0x25, 0x7f, 0x7f, 0x35, 0x26, 0x2e, 0x26, 0x53, 0x24, 0x68, 0x1e, 0x0e, 0x58, 0x3a, 0x59, 0x50, 0x56, 0x37,
- 0x5f, 0x66, 0x01, 0x4c, 0x5a, 0x64, 0x32, 0x50, 0x7b, 0x6a, 0x20, 0x72, 0x2b, 0x1d, 0x7e, 0x43, 0x7b, 0x61, 0x42, 0x0b, 0x61, 0x73,
- 0x24, 0x79, 0x3a, 0x6b, 0x4a, 0x79, 0x6e, 0x09, 0x0f, 0x27, 0x2d, 0x0c, 0x5e, 0x32, 0x4b, 0x0d, 0x79, 0x46, 0x39, 0x21, 0x0a, 0x26,
- 0x5f, 0x3a, 0x00, 0x26, 0x3f, 0x13, 0x2e, 0x7e, 0x50, 0x2b, 0x67, 0x46, 0x72, 0x3f, 0x3b, 0x01, 0x46, 0x1b, 0x0b, 0x35, 0x49, 0x39,
- 0x19, 0x70, 0x3d, 0x02, 0x41, 0x0e, 0x38, 0x05, 0x76, 0x65, 0x4f, 0x31, 0x6c, 0x5e, 0x17, 0x04, 0x15, 0x36, 0x26, 0x64, 0x34, 0x14,
- 0x17, 0x7c, 0x0e, 0x0b, 0x5b, 0x55, 0x53, 0x6b, 0x00, 0x42, 0x41, 0x4f, 0x02, 0x5c, 0x13, 0x0a, 0x2c, 0x2c, 0x3e, 0x10, 0x14, 0x33,
- 0x45, 0x7c, 0x7a, 0x5a, 0x31, 0x61, 0x39, 0x08, 0x22, 0x6a, 0x1e, 0x0f, 0x6f, 0x1b, 0x6c, 0x13, 0x5e, 0x79, 0x20, 0x79, 0x50, 0x62,
- 0x06, 0x2c, 0x76, 0x17, 0x04, 0x2b, 0x2a, 0x75, 0x1f, 0x0c, 0x37, 0x4e, 0x0f, 0x7b, 0x2d, 0x34, 0x75, 0x60, 0x31, 0x74, 0x2e, 0x0a,
- 0x4a, 0x11, 0x6c, 0x49, 0x25, 0x01, 0x3a, 0x3d, 0x22, 0x1e, 0x6d, 0x18, 0x51, 0x78, 0x2d, 0x62, 0x31, 0x4c, 0x50, 0x40, 0x17, 0x4b,
- 0x6f, 0x22, 0x00, 0x7f, 0x61, 0x2a, 0x34, 0x3e, 0x00, 0x5f, 0x2f, 0x5f, 0x2f, 0x14, 0x2a, 0x55, 0x27, 0x1f, 0x46, 0x1f, 0x12, 0x46,
- 0x5e, 0x1e, 0x0c, 0x7c, 0x38, 0x01, 0x61, 0x64, 0x76, 0x22, 0x6e, 0x08, 0x20, 0x38, 0x4f, 0x73, 0x72, 0x55, 0x12, 0x42, 0x19, 0x50,
- 0x61, 0x43, 0x77, 0x7d, 0x41, 0x2e, 0x35, 0x4f, 0x3d, 0x31, 0x28, 0x58, 0x67, 0x1b, 0x03, 0x51, 0x20, 0x32, 0x1c, 0x08, 0x6e, 0x37,
- 0x75, 0x37, 0x44, 0x4f, 0x68, 0x19, 0x07, 0x64, 0x14, 0x28, 0x25, 0x2b, 0x69, 0x35, 0x18, 0x27, 0x26, 0x14, 0x13, 0x70, 0x42, 0x19,
- 0x12, 0x75, 0x3e, 0x02, 0x5d, 0x7c, 0x13, 0x1f, 0x16, 0x53, 0x3b, 0x74, 0x48, 0x3c, 0x5e, 0x39, 0x6c, 0x1c, 0x1c, 0x74, 0x39, 0x1f,
- 0x00, 0x1b, 0x06, 0x0a, 0x68, 0x3b, 0x52, 0x4f, 0x1e, 0x6e, 0x3c, 0x35, 0x0c, 0x38, 0x0e, 0x0b, 0x3b, 0x1a, 0x76, 0x23, 0x29, 0x53,
- 0x1e, 0x5f, 0x41, 0x0c, 0x4b, 0x0a, 0x65, 0x28, 0x78, 0x67, 0x48, 0x59, 0x26, 0x6d, 0x31, 0x76, 0x23, 0x70, 0x61, 0x64, 0x3b, 0x38,
- 0x79, 0x66, 0x74, 0x53, 0x2c, 0x64, 0x64, 0x54, 0x03, 0x54, 0x65, 0x44, 0x4c, 0x18, 0x4f, 0x48, 0x20, 0x4f, 0x72, 0x10, 0x3f, 0x0c,
- 0x52, 0x2d, 0x03, 0x14, 0x03, 0x51, 0x42, 0x10, 0x77, 0x6a, 0x34, 0x06, 0x32, 0x03, 0x72, 0x14, 0x7c, 0x08, 0x5d, 0x52, 0x1a, 0x62,
- 0x7c, 0x3e, 0x30, 0x7e, 0x5f, 0x7f, 0x54, 0x0f, 0x44, 0x49, 0x5d, 0x5e, 0x10, 0x6a, 0x06, 0x2b, 0x06, 0x53, 0x10, 0x39, 0x37, 0x32,
- 0x4a, 0x4e, 0x3d, 0x2b, 0x65, 0x38, 0x39, 0x07, 0x72, 0x54, 0x64, 0x4d, 0x56, 0x6a, 0x03, 0x22, 0x70, 0x7b, 0x5f, 0x60, 0x0b, 0x2a,
- 0x0b, 0x6b, 0x10, 0x64, 0x14, 0x05, 0x22, 0x00, 0x73, 0x40, 0x23, 0x5b, 0x51, 0x1f, 0x2b, 0x1a, 0x5d, 0x69, 0x7a, 0x46, 0x0c, 0x5f,
- 0x32, 0x4b, 0x4a, 0x28, 0x52, 0x79, 0x5b, 0x12, 0x42, 0x18, 0x00, 0x5d, 0x27, 0x31, 0x53, 0x3c, 0x4c, 0x36, 0x4e, 0x38, 0x3f, 0x72,
- 0x03, 0x71, 0x02, 0x5b, 0x36, 0x59, 0x7f, 0x75, 0x6e, 0x08, 0x54, 0x0d, 0x34, 0x1c, 0x34, 0x57, 0x5d, 0x69, 0x48, 0x00, 0x3b, 0x05,
- 0x07, 0x6e, 0x27, 0x65, 0x6e, 0x40, 0x3d, 0x3a, 0x4f, 0x72, 0x5d, 0x39, 0x16, 0x0f, 0x63, 0x12, 0x12, 0x15, 0x3a, 0x70, 0x0d, 0x57,
- 0x18, 0x0d, 0x5e, 0x3d, 0x22, 0x68, 0x68, 0x7c, 0x6d, 0x4f, 0x0c, 0x7b, 0x09, 0x2d, 0x4a, 0x73, 0x20, 0x47, 0x07, 0x57, 0x75, 0x5d,
- 0x53, 0x70, 0x34, 0x21, 0x40, 0x57, 0x51, 0x5e, 0x49, 0x44, 0x00, 0x54, 0x27, 0x04, 0x68, 0x7e, 0x59, 0x56, 0x58, 0x74, 0x14, 0x3c,
- 0x16, 0x33, 0x41, 0x16, 0x4b, 0x2f, 0x49, 0x37, 0x0a, 0x54, 0x08, 0x08, 0x1f, 0x39, 0x67, 0x76, 0x28, 0x28, 0x07, 0x1d, 0x61, 0x47,
- 0x51, 0x4d, 0x75, 0x26, 0x52, 0x47, 0x47, 0x0c, 0x57, 0x58, 0x74, 0x3e, 0x62, 0x6c, 0x58, 0x3a, 0x44, 0x1e, 0x16, 0x2e, 0x21, 0x1c,
- 0x73, 0x45, 0x67, 0x74, 0x4f, 0x33, 0x66, 0x0e, 0x74, 0x66, 0x26, 0x1f, 0x2e, 0x38, 0x44, 0x40, 0x7e, 0x2a, 0x50, 0x52, 0x5e, 0x43,
- 0x01, 0x7a, 0x38, 0x49, 0x3c, 0x55, 0x4d, 0x5a, 0x44, 0x08, 0x26, 0x59, 0x4d, 0x45, 0x0b, 0x48, 0x0a, 0x33, 0x5e, 0x4a, 0x4d, 0x75,
- 0x16, 0x17, 0x63, 0x46, 0x01, 0x2a, 0x55, 0x7b, 0x0f, 0x02, 0x73, 0x6a, 0x4b, 0x7f, 0x75, 0x65, 0x3c, 0x4c, 0x33, 0x39, 0x6c, 0x74,
- 0x05, 0x60, 0x0f, 0x7f, 0x2d, 0x41, 0x4d, 0x4d, 0x46, 0x71, 0x09, 0x6f, 0x4f, 0x60, 0x15, 0x0f, 0x46, 0x73, 0x63, 0x4c, 0x5e, 0x74,
- 0x30, 0x0d, 0x28, 0x43, 0x08, 0x72, 0x32, 0x04, 0x2e, 0x31, 0x29, 0x27, 0x44, 0x6d, 0x13, 0x17, 0x48, 0x0f, 0x49, 0x52, 0x10, 0x13,
- 0x7f, 0x17, 0x16, 0x62, 0x79, 0x35, 0x78, 0x3e, 0x01, 0x7c, 0x2e, 0x0f, 0x76, 0x3e, 0x5e, 0x53, 0x6c, 0x5b, 0x5f, 0x7c, 0x19, 0x41,
- 0x02, 0x2f, 0x17, 0x64, 0x41, 0x75, 0x10, 0x04, 0x47, 0x7c, 0x3d, 0x4b, 0x52, 0x00, 0x10, 0x5d, 0x51, 0x4e, 0x7a, 0x27, 0x25, 0x55,
- 0x40, 0x12, 0x35, 0x60, 0x05, 0x1b, 0x34, 0x2d, 0x04, 0x7a, 0x6a, 0x69, 0x02, 0x79, 0x03, 0x3a, 0x2f, 0x06, 0x0a, 0x79, 0x7b, 0x12,
- 0x5d, 0x7c, 0x52, 0x29, 0x47, 0x58, 0x12, 0x73, 0x3f, 0x27, 0x56, 0x05, 0x0c, 0x48, 0x32, 0x58, 0x6b, 0x57, 0x5c, 0x03, 0x64, 0x56,
- 0x11, 0x52, 0x7a, 0x30, 0x36, 0x29, 0x17, 0x3b, 0x68, 0x7a, 0x7c, 0x05, 0x6b, 0x6b, 0x13, 0x6a, 0x24, 0x5c, 0x68, 0x42, 0x18, 0x32,
- 0x03, 0x73, 0x6e, 0x04, 0x21, 0x2e, 0x01, 0x04, 0x63, 0x7d, 0x44, 0x41, 0x12, 0x31, 0x0b, 0x15, 0x1f, 0x70, 0x00, 0x2e, 0x66, 0x14,
- 0x3c, 0x7f, 0x2b, 0x00, 0x1f, 0x0c, 0x28, 0x59, 0x0a, 0x16, 0x49, 0x5a, 0x5c, 0x64, 0x65, 0x4b, 0x11, 0x29, 0x15, 0x36, 0x5a, 0x65,
- 0x19, 0x4f, 0x60, 0x23, 0x3a, 0x3a, 0x13, 0x25, 0x02, 0x78, 0x4c, 0x54};
+ 0x0b, 0x30, 0x44, 0x62, 0x7c, 0x22, 0x1f, 0x0d, 0x05, 0x67, 0x2c, 0x2a, 0x39, 0x21, 0x46,
+ 0x08, 0x50, 0x66, 0x34, 0x37, 0x0b, 0x45, 0x4b, 0x38, 0x32, 0x06, 0x7a, 0x3e, 0x7f, 0x0c,
+ 0x40, 0x18, 0x6b, 0x2d, 0x60, 0x4c, 0x60, 0x0c, 0x23, 0x43, 0x3b, 0x3e, 0x1b, 0x16, 0x04,
+ 0x46, 0x58, 0x3f, 0x40, 0x6a, 0x11, 0x05, 0x63, 0x71, 0x14, 0x35, 0x47, 0x79, 0x13, 0x6f,
+ 0x6b, 0x27, 0x18, 0x5b, 0x48, 0x27, 0x3e, 0x6f, 0x15, 0x33, 0x4f, 0x3e, 0x5e, 0x51, 0x73,
+ 0x68, 0x25, 0x0f, 0x06, 0x5b, 0x7c, 0x72, 0x75, 0x3e, 0x3f, 0x1b, 0x5c, 0x6d, 0x6a, 0x39,
+ 0x7c, 0x63, 0x63, 0x60, 0x6c, 0x7a, 0x33, 0x76, 0x52, 0x13, 0x25, 0x33, 0x7d, 0x65, 0x23,
+ 0x27, 0x11, 0x06, 0x06, 0x47, 0x71, 0x1e, 0x14, 0x74, 0x63, 0x70, 0x2d, 0x15, 0x27, 0x18,
+ 0x51, 0x06, 0x05, 0x33, 0x11, 0x2c, 0x6b, 0x00, 0x2d, 0x77, 0x20, 0x48, 0x0d, 0x73, 0x51,
+ 0x45, 0x25, 0x7f, 0x7f, 0x35, 0x26, 0x2e, 0x26, 0x53, 0x24, 0x68, 0x1e, 0x0e, 0x58, 0x3a,
+ 0x59, 0x50, 0x56, 0x37, 0x5f, 0x66, 0x01, 0x4c, 0x5a, 0x64, 0x32, 0x50, 0x7b, 0x6a, 0x20,
+ 0x72, 0x2b, 0x1d, 0x7e, 0x43, 0x7b, 0x61, 0x42, 0x0b, 0x61, 0x73, 0x24, 0x79, 0x3a, 0x6b,
+ 0x4a, 0x79, 0x6e, 0x09, 0x0f, 0x27, 0x2d, 0x0c, 0x5e, 0x32, 0x4b, 0x0d, 0x79, 0x46, 0x39,
+ 0x21, 0x0a, 0x26, 0x5f, 0x3a, 0x00, 0x26, 0x3f, 0x13, 0x2e, 0x7e, 0x50, 0x2b, 0x67, 0x46,
+ 0x72, 0x3f, 0x3b, 0x01, 0x46, 0x1b, 0x0b, 0x35, 0x49, 0x39, 0x19, 0x70, 0x3d, 0x02, 0x41,
+ 0x0e, 0x38, 0x05, 0x76, 0x65, 0x4f, 0x31, 0x6c, 0x5e, 0x17, 0x04, 0x15, 0x36, 0x26, 0x64,
+ 0x34, 0x14, 0x17, 0x7c, 0x0e, 0x0b, 0x5b, 0x55, 0x53, 0x6b, 0x00, 0x42, 0x41, 0x4f, 0x02,
+ 0x5c, 0x13, 0x0a, 0x2c, 0x2c, 0x3e, 0x10, 0x14, 0x33, 0x45, 0x7c, 0x7a, 0x5a, 0x31, 0x61,
+ 0x39, 0x08, 0x22, 0x6a, 0x1e, 0x0f, 0x6f, 0x1b, 0x6c, 0x13, 0x5e, 0x79, 0x20, 0x79, 0x50,
+ 0x62, 0x06, 0x2c, 0x76, 0x17, 0x04, 0x2b, 0x2a, 0x75, 0x1f, 0x0c, 0x37, 0x4e, 0x0f, 0x7b,
+ 0x2d, 0x34, 0x75, 0x60, 0x31, 0x74, 0x2e, 0x0a, 0x4a, 0x11, 0x6c, 0x49, 0x25, 0x01, 0x3a,
+ 0x3d, 0x22, 0x1e, 0x6d, 0x18, 0x51, 0x78, 0x2d, 0x62, 0x31, 0x4c, 0x50, 0x40, 0x17, 0x4b,
+ 0x6f, 0x22, 0x00, 0x7f, 0x61, 0x2a, 0x34, 0x3e, 0x00, 0x5f, 0x2f, 0x5f, 0x2f, 0x14, 0x2a,
+ 0x55, 0x27, 0x1f, 0x46, 0x1f, 0x12, 0x46, 0x5e, 0x1e, 0x0c, 0x7c, 0x38, 0x01, 0x61, 0x64,
+ 0x76, 0x22, 0x6e, 0x08, 0x20, 0x38, 0x4f, 0x73, 0x72, 0x55, 0x12, 0x42, 0x19, 0x50, 0x61,
+ 0x43, 0x77, 0x7d, 0x41, 0x2e, 0x35, 0x4f, 0x3d, 0x31, 0x28, 0x58, 0x67, 0x1b, 0x03, 0x51,
+ 0x20, 0x32, 0x1c, 0x08, 0x6e, 0x37, 0x75, 0x37, 0x44, 0x4f, 0x68, 0x19, 0x07, 0x64, 0x14,
+ 0x28, 0x25, 0x2b, 0x69, 0x35, 0x18, 0x27, 0x26, 0x14, 0x13, 0x70, 0x42, 0x19, 0x12, 0x75,
+ 0x3e, 0x02, 0x5d, 0x7c, 0x13, 0x1f, 0x16, 0x53, 0x3b, 0x74, 0x48, 0x3c, 0x5e, 0x39, 0x6c,
+ 0x1c, 0x1c, 0x74, 0x39, 0x1f, 0x00, 0x1b, 0x06, 0x0a, 0x68, 0x3b, 0x52, 0x4f, 0x1e, 0x6e,
+ 0x3c, 0x35, 0x0c, 0x38, 0x0e, 0x0b, 0x3b, 0x1a, 0x76, 0x23, 0x29, 0x53, 0x1e, 0x5f, 0x41,
+ 0x0c, 0x4b, 0x0a, 0x65, 0x28, 0x78, 0x67, 0x48, 0x59, 0x26, 0x6d, 0x31, 0x76, 0x23, 0x70,
+ 0x61, 0x64, 0x3b, 0x38, 0x79, 0x66, 0x74, 0x53, 0x2c, 0x64, 0x64, 0x54, 0x03, 0x54, 0x65,
+ 0x44, 0x4c, 0x18, 0x4f, 0x48, 0x20, 0x4f, 0x72, 0x10, 0x3f, 0x0c, 0x52, 0x2d, 0x03, 0x14,
+ 0x03, 0x51, 0x42, 0x10, 0x77, 0x6a, 0x34, 0x06, 0x32, 0x03, 0x72, 0x14, 0x7c, 0x08, 0x5d,
+ 0x52, 0x1a, 0x62, 0x7c, 0x3e, 0x30, 0x7e, 0x5f, 0x7f, 0x54, 0x0f, 0x44, 0x49, 0x5d, 0x5e,
+ 0x10, 0x6a, 0x06, 0x2b, 0x06, 0x53, 0x10, 0x39, 0x37, 0x32, 0x4a, 0x4e, 0x3d, 0x2b, 0x65,
+ 0x38, 0x39, 0x07, 0x72, 0x54, 0x64, 0x4d, 0x56, 0x6a, 0x03, 0x22, 0x70, 0x7b, 0x5f, 0x60,
+ 0x0b, 0x2a, 0x0b, 0x6b, 0x10, 0x64, 0x14, 0x05, 0x22, 0x00, 0x73, 0x40, 0x23, 0x5b, 0x51,
+ 0x1f, 0x2b, 0x1a, 0x5d, 0x69, 0x7a, 0x46, 0x0c, 0x5f, 0x32, 0x4b, 0x4a, 0x28, 0x52, 0x79,
+ 0x5b, 0x12, 0x42, 0x18, 0x00, 0x5d, 0x27, 0x31, 0x53, 0x3c, 0x4c, 0x36, 0x4e, 0x38, 0x3f,
+ 0x72, 0x03, 0x71, 0x02, 0x5b, 0x36, 0x59, 0x7f, 0x75, 0x6e, 0x08, 0x54, 0x0d, 0x34, 0x1c,
+ 0x34, 0x57, 0x5d, 0x69, 0x48, 0x00, 0x3b, 0x05, 0x07, 0x6e, 0x27, 0x65, 0x6e, 0x40, 0x3d,
+ 0x3a, 0x4f, 0x72, 0x5d, 0x39, 0x16, 0x0f, 0x63, 0x12, 0x12, 0x15, 0x3a, 0x70, 0x0d, 0x57,
+ 0x18, 0x0d, 0x5e, 0x3d, 0x22, 0x68, 0x68, 0x7c, 0x6d, 0x4f, 0x0c, 0x7b, 0x09, 0x2d, 0x4a,
+ 0x73, 0x20, 0x47, 0x07, 0x57, 0x75, 0x5d, 0x53, 0x70, 0x34, 0x21, 0x40, 0x57, 0x51, 0x5e,
+ 0x49, 0x44, 0x00, 0x54, 0x27, 0x04, 0x68, 0x7e, 0x59, 0x56, 0x58, 0x74, 0x14, 0x3c, 0x16,
+ 0x33, 0x41, 0x16, 0x4b, 0x2f, 0x49, 0x37, 0x0a, 0x54, 0x08, 0x08, 0x1f, 0x39, 0x67, 0x76,
+ 0x28, 0x28, 0x07, 0x1d, 0x61, 0x47, 0x51, 0x4d, 0x75, 0x26, 0x52, 0x47, 0x47, 0x0c, 0x57,
+ 0x58, 0x74, 0x3e, 0x62, 0x6c, 0x58, 0x3a, 0x44, 0x1e, 0x16, 0x2e, 0x21, 0x1c, 0x73, 0x45,
+ 0x67, 0x74, 0x4f, 0x33, 0x66, 0x0e, 0x74, 0x66, 0x26, 0x1f, 0x2e, 0x38, 0x44, 0x40, 0x7e,
+ 0x2a, 0x50, 0x52, 0x5e, 0x43, 0x01, 0x7a, 0x38, 0x49, 0x3c, 0x55, 0x4d, 0x5a, 0x44, 0x08,
+ 0x26, 0x59, 0x4d, 0x45, 0x0b, 0x48, 0x0a, 0x33, 0x5e, 0x4a, 0x4d, 0x75, 0x16, 0x17, 0x63,
+ 0x46, 0x01, 0x2a, 0x55, 0x7b, 0x0f, 0x02, 0x73, 0x6a, 0x4b, 0x7f, 0x75, 0x65, 0x3c, 0x4c,
+ 0x33, 0x39, 0x6c, 0x74, 0x05, 0x60, 0x0f, 0x7f, 0x2d, 0x41, 0x4d, 0x4d, 0x46, 0x71, 0x09,
+ 0x6f, 0x4f, 0x60, 0x15, 0x0f, 0x46, 0x73, 0x63, 0x4c, 0x5e, 0x74, 0x30, 0x0d, 0x28, 0x43,
+ 0x08, 0x72, 0x32, 0x04, 0x2e, 0x31, 0x29, 0x27, 0x44, 0x6d, 0x13, 0x17, 0x48, 0x0f, 0x49,
+ 0x52, 0x10, 0x13, 0x7f, 0x17, 0x16, 0x62, 0x79, 0x35, 0x78, 0x3e, 0x01, 0x7c, 0x2e, 0x0f,
+ 0x76, 0x3e, 0x5e, 0x53, 0x6c, 0x5b, 0x5f, 0x7c, 0x19, 0x41, 0x02, 0x2f, 0x17, 0x64, 0x41,
+ 0x75, 0x10, 0x04, 0x47, 0x7c, 0x3d, 0x4b, 0x52, 0x00, 0x10, 0x5d, 0x51, 0x4e, 0x7a, 0x27,
+ 0x25, 0x55, 0x40, 0x12, 0x35, 0x60, 0x05, 0x1b, 0x34, 0x2d, 0x04, 0x7a, 0x6a, 0x69, 0x02,
+ 0x79, 0x03, 0x3a, 0x2f, 0x06, 0x0a, 0x79, 0x7b, 0x12, 0x5d, 0x7c, 0x52, 0x29, 0x47, 0x58,
+ 0x12, 0x73, 0x3f, 0x27, 0x56, 0x05, 0x0c, 0x48, 0x32, 0x58, 0x6b, 0x57, 0x5c, 0x03, 0x64,
+ 0x56, 0x11, 0x52, 0x7a, 0x30, 0x36, 0x29, 0x17, 0x3b, 0x68, 0x7a, 0x7c, 0x05, 0x6b, 0x6b,
+ 0x13, 0x6a, 0x24, 0x5c, 0x68, 0x42, 0x18, 0x32, 0x03, 0x73, 0x6e, 0x04, 0x21, 0x2e, 0x01,
+ 0x04, 0x63, 0x7d, 0x44, 0x41, 0x12, 0x31, 0x0b, 0x15, 0x1f, 0x70, 0x00, 0x2e, 0x66, 0x14,
+ 0x3c, 0x7f, 0x2b, 0x00, 0x1f, 0x0c, 0x28, 0x59, 0x0a, 0x16, 0x49, 0x5a, 0x5c, 0x64, 0x65,
+ 0x4b, 0x11, 0x29, 0x15, 0x36, 0x5a, 0x65, 0x19, 0x4f, 0x60, 0x23, 0x3a, 0x3a, 0x13, 0x25,
+ 0x02, 0x78, 0x4c, 0x54};
char b64_known[1369] = {
- 0x43, 0x7a, 0x42, 0x45, 0x59, 0x6e, 0x77, 0x69, 0x48, 0x77, 0x30, 0x46, 0x5a, 0x79, 0x77, 0x71, 0x4f, 0x53, 0x46, 0x47, 0x43, 0x46,
- 0x42, 0x6d, 0x4e, 0x44, 0x63, 0x4c, 0x52, 0x55, 0x73, 0x34, 0x4d, 0x67, 0x5a, 0x36, 0x50, 0x6e, 0x38, 0x4d, 0x51, 0x42, 0x68, 0x72,
- 0x4c, 0x57, 0x42, 0x4d, 0x59, 0x41, 0x77, 0x6a, 0x51, 0x7a, 0x73, 0x2b, 0x47, 0x78, 0x59, 0x45, 0x52, 0x6c, 0x67, 0x2f, 0x51, 0x47,
- 0x6f, 0x52, 0x42, 0x57, 0x4e, 0x78, 0x46, 0x44, 0x56, 0x48, 0x65, 0x52, 0x4e, 0x76, 0x61, 0x79, 0x63, 0x59, 0x57, 0x30, 0x67, 0x6e,
- 0x50, 0x6d, 0x38, 0x56, 0x4d, 0x30, 0x38, 0x2b, 0x58, 0x6c, 0x46, 0x7a, 0x61, 0x43, 0x55, 0x50, 0x42, 0x6c, 0x74, 0x38, 0x63, 0x6e,
- 0x55, 0x2b, 0x50, 0x78, 0x74, 0x63, 0x62, 0x57, 0x6f, 0x35, 0x66, 0x47, 0x4e, 0x6a, 0x59, 0x47, 0x78, 0x36, 0x4d, 0x33, 0x5a, 0x53,
- 0x45, 0x79, 0x55, 0x7a, 0x66, 0x57, 0x55, 0x6a, 0x4a, 0x78, 0x45, 0x47, 0x42, 0x6b, 0x64, 0x78, 0x48, 0x68, 0x52, 0x30, 0x59, 0x33,
- 0x41, 0x74, 0x46, 0x53, 0x63, 0x59, 0x55, 0x51, 0x59, 0x46, 0x4d, 0x78, 0x45, 0x73, 0x61, 0x77, 0x41, 0x74, 0x64, 0x79, 0x42, 0x49,
- 0x44, 0x58, 0x4e, 0x52, 0x52, 0x53, 0x56, 0x2f, 0x66, 0x7a, 0x55, 0x6d, 0x4c, 0x69, 0x5a, 0x54, 0x4a, 0x47, 0x67, 0x65, 0x44, 0x6c,
- 0x67, 0x36, 0x57, 0x56, 0x42, 0x57, 0x4e, 0x31, 0x39, 0x6d, 0x41, 0x55, 0x78, 0x61, 0x5a, 0x44, 0x4a, 0x51, 0x65, 0x32, 0x6f, 0x67,
- 0x63, 0x69, 0x73, 0x64, 0x66, 0x6b, 0x4e, 0x37, 0x59, 0x55, 0x49, 0x4c, 0x59, 0x58, 0x4d, 0x6b, 0x65, 0x54, 0x70, 0x72, 0x53, 0x6e,
- 0x6c, 0x75, 0x43, 0x51, 0x38, 0x6e, 0x4c, 0x51, 0x78, 0x65, 0x4d, 0x6b, 0x73, 0x4e, 0x65, 0x55, 0x59, 0x35, 0x49, 0x51, 0x6f, 0x6d,
- 0x58, 0x7a, 0x6f, 0x41, 0x4a, 0x6a, 0x38, 0x54, 0x4c, 0x6e, 0x35, 0x51, 0x4b, 0x32, 0x64, 0x47, 0x63, 0x6a, 0x38, 0x37, 0x41, 0x55,
- 0x59, 0x62, 0x43, 0x7a, 0x56, 0x4a, 0x4f, 0x52, 0x6c, 0x77, 0x50, 0x51, 0x4a, 0x42, 0x44, 0x6a, 0x67, 0x46, 0x64, 0x6d, 0x56, 0x50,
- 0x4d, 0x57, 0x78, 0x65, 0x46, 0x77, 0x51, 0x56, 0x4e, 0x69, 0x5a, 0x6b, 0x4e, 0x42, 0x51, 0x58, 0x66, 0x41, 0x34, 0x4c, 0x57, 0x31,
- 0x56, 0x54, 0x61, 0x77, 0x42, 0x43, 0x51, 0x55, 0x38, 0x43, 0x58, 0x42, 0x4d, 0x4b, 0x4c, 0x43, 0x77, 0x2b, 0x45, 0x42, 0x51, 0x7a,
- 0x52, 0x58, 0x78, 0x36, 0x57, 0x6a, 0x46, 0x68, 0x4f, 0x51, 0x67, 0x69, 0x61, 0x68, 0x34, 0x50, 0x62, 0x78, 0x74, 0x73, 0x45, 0x31,
- 0x35, 0x35, 0x49, 0x48, 0x6c, 0x51, 0x59, 0x67, 0x59, 0x73, 0x64, 0x68, 0x63, 0x45, 0x4b, 0x79, 0x70, 0x31, 0x48, 0x77, 0x77, 0x33,
- 0x54, 0x67, 0x39, 0x37, 0x4c, 0x54, 0x52, 0x31, 0x59, 0x44, 0x46, 0x30, 0x4c, 0x67, 0x70, 0x4b, 0x45, 0x57, 0x78, 0x4a, 0x4a, 0x51,
- 0x45, 0x36, 0x50, 0x53, 0x49, 0x65, 0x62, 0x52, 0x68, 0x52, 0x65, 0x43, 0x31, 0x69, 0x4d, 0x55, 0x78, 0x51, 0x51, 0x42, 0x64, 0x4c,
- 0x62, 0x79, 0x49, 0x41, 0x66, 0x32, 0x45, 0x71, 0x4e, 0x44, 0x34, 0x41, 0x58, 0x79, 0x39, 0x66, 0x4c, 0x78, 0x51, 0x71, 0x56, 0x53,
- 0x63, 0x66, 0x52, 0x68, 0x38, 0x53, 0x52, 0x6c, 0x34, 0x65, 0x44, 0x48, 0x77, 0x34, 0x41, 0x57, 0x46, 0x6b, 0x64, 0x69, 0x4a, 0x75,
- 0x43, 0x43, 0x41, 0x34, 0x54, 0x33, 0x4e, 0x79, 0x56, 0x52, 0x4a, 0x43, 0x47, 0x56, 0x42, 0x68, 0x51, 0x33, 0x64, 0x39, 0x51, 0x53,
- 0x34, 0x31, 0x54, 0x7a, 0x30, 0x78, 0x4b, 0x46, 0x68, 0x6e, 0x47, 0x77, 0x4e, 0x52, 0x49, 0x44, 0x49, 0x63, 0x43, 0x47, 0x34, 0x33,
- 0x64, 0x54, 0x64, 0x45, 0x54, 0x32, 0x67, 0x5a, 0x42, 0x32, 0x51, 0x55, 0x4b, 0x43, 0x55, 0x72, 0x61, 0x54, 0x55, 0x59, 0x4a, 0x79,
- 0x59, 0x55, 0x45, 0x33, 0x42, 0x43, 0x47, 0x52, 0x4a, 0x31, 0x50, 0x67, 0x4a, 0x64, 0x66, 0x42, 0x4d, 0x66, 0x46, 0x6c, 0x4d, 0x37,
- 0x64, 0x45, 0x67, 0x38, 0x58, 0x6a, 0x6c, 0x73, 0x48, 0x42, 0x78, 0x30, 0x4f, 0x52, 0x38, 0x41, 0x47, 0x77, 0x59, 0x4b, 0x61, 0x44,
- 0x74, 0x53, 0x54, 0x78, 0x35, 0x75, 0x50, 0x44, 0x55, 0x4d, 0x4f, 0x41, 0x34, 0x4c, 0x4f, 0x78, 0x70, 0x32, 0x49, 0x79, 0x6c, 0x54,
- 0x48, 0x6c, 0x39, 0x42, 0x44, 0x45, 0x73, 0x4b, 0x5a, 0x53, 0x68, 0x34, 0x5a, 0x30, 0x68, 0x5a, 0x4a, 0x6d, 0x30, 0x78, 0x64, 0x69,
- 0x4e, 0x77, 0x59, 0x57, 0x51, 0x37, 0x4f, 0x48, 0x6c, 0x6d, 0x64, 0x46, 0x4d, 0x73, 0x5a, 0x47, 0x52, 0x55, 0x41, 0x31, 0x52, 0x6c,
- 0x52, 0x45, 0x77, 0x59, 0x54, 0x30, 0x67, 0x67, 0x54, 0x33, 0x49, 0x51, 0x50, 0x77, 0x78, 0x53, 0x4c, 0x51, 0x4d, 0x55, 0x41, 0x31,
- 0x46, 0x43, 0x45, 0x48, 0x64, 0x71, 0x4e, 0x41, 0x59, 0x79, 0x41, 0x33, 0x49, 0x55, 0x66, 0x41, 0x68, 0x64, 0x55, 0x68, 0x70, 0x69,
- 0x66, 0x44, 0x34, 0x77, 0x66, 0x6c, 0x39, 0x2f, 0x56, 0x41, 0x39, 0x45, 0x53, 0x56, 0x31, 0x65, 0x45, 0x47, 0x6f, 0x47, 0x4b, 0x77,
- 0x5a, 0x54, 0x45, 0x44, 0x6b, 0x33, 0x4d, 0x6b, 0x70, 0x4f, 0x50, 0x53, 0x74, 0x6c, 0x4f, 0x44, 0x6b, 0x48, 0x63, 0x6c, 0x52, 0x6b,
- 0x54, 0x56, 0x5a, 0x71, 0x41, 0x79, 0x4a, 0x77, 0x65, 0x31, 0x39, 0x67, 0x43, 0x79, 0x6f, 0x4c, 0x61, 0x78, 0x42, 0x6b, 0x46, 0x41,
- 0x55, 0x69, 0x41, 0x48, 0x4e, 0x41, 0x49, 0x31, 0x74, 0x52, 0x48, 0x79, 0x73, 0x61, 0x58, 0x57, 0x6c, 0x36, 0x52, 0x67, 0x78, 0x66,
- 0x4d, 0x6b, 0x74, 0x4b, 0x4b, 0x46, 0x4a, 0x35, 0x57, 0x78, 0x4a, 0x43, 0x47, 0x41, 0x42, 0x64, 0x4a, 0x7a, 0x46, 0x54, 0x50, 0x45,
- 0x77, 0x32, 0x54, 0x6a, 0x67, 0x2f, 0x63, 0x67, 0x4e, 0x78, 0x41, 0x6c, 0x73, 0x32, 0x57, 0x58, 0x39, 0x31, 0x62, 0x67, 0x68, 0x55,
- 0x44, 0x54, 0x51, 0x63, 0x4e, 0x46, 0x64, 0x64, 0x61, 0x55, 0x67, 0x41, 0x4f, 0x77, 0x55, 0x48, 0x62, 0x69, 0x64, 0x6c, 0x62, 0x6b,
- 0x41, 0x39, 0x4f, 0x6b, 0x39, 0x79, 0x58, 0x54, 0x6b, 0x57, 0x44, 0x32, 0x4d, 0x53, 0x45, 0x68, 0x55, 0x36, 0x63, 0x41, 0x31, 0x58,
- 0x47, 0x41, 0x31, 0x65, 0x50, 0x53, 0x4a, 0x6f, 0x61, 0x48, 0x78, 0x74, 0x54, 0x77, 0x78, 0x37, 0x43, 0x53, 0x31, 0x4b, 0x63, 0x79,
- 0x42, 0x48, 0x42, 0x31, 0x64, 0x31, 0x58, 0x56, 0x4e, 0x77, 0x4e, 0x43, 0x46, 0x41, 0x56, 0x31, 0x46, 0x65, 0x53, 0x55, 0x51, 0x41,
- 0x56, 0x43, 0x63, 0x45, 0x61, 0x48, 0x35, 0x5a, 0x56, 0x6c, 0x68, 0x30, 0x46, 0x44, 0x77, 0x57, 0x4d, 0x30, 0x45, 0x57, 0x53, 0x79,
- 0x39, 0x4a, 0x4e, 0x77, 0x70, 0x55, 0x43, 0x41, 0x67, 0x66, 0x4f, 0x57, 0x64, 0x32, 0x4b, 0x43, 0x67, 0x48, 0x48, 0x57, 0x46, 0x48,
- 0x55, 0x55, 0x31, 0x31, 0x4a, 0x6c, 0x4a, 0x48, 0x52, 0x77, 0x78, 0x58, 0x57, 0x48, 0x51, 0x2b, 0x59, 0x6d, 0x78, 0x59, 0x4f, 0x6b,
- 0x51, 0x65, 0x46, 0x69, 0x34, 0x68, 0x48, 0x48, 0x4e, 0x46, 0x5a, 0x33, 0x52, 0x50, 0x4d, 0x32, 0x59, 0x4f, 0x64, 0x47, 0x59, 0x6d,
- 0x48, 0x79, 0x34, 0x34, 0x52, 0x45, 0x42, 0x2b, 0x4b, 0x6c, 0x42, 0x53, 0x58, 0x6b, 0x4d, 0x42, 0x65, 0x6a, 0x68, 0x4a, 0x50, 0x46,
- 0x56, 0x4e, 0x57, 0x6b, 0x51, 0x49, 0x4a, 0x6c, 0x6c, 0x4e, 0x52, 0x51, 0x74, 0x49, 0x43, 0x6a, 0x4e, 0x65, 0x53, 0x6b, 0x31, 0x31,
- 0x46, 0x68, 0x64, 0x6a, 0x52, 0x67, 0x45, 0x71, 0x56, 0x58, 0x73, 0x50, 0x41, 0x6e, 0x4e, 0x71, 0x53, 0x33, 0x39, 0x31, 0x5a, 0x54,
- 0x78, 0x4d, 0x4d, 0x7a, 0x6c, 0x73, 0x64, 0x41, 0x56, 0x67, 0x44, 0x33, 0x38, 0x74, 0x51, 0x55, 0x31, 0x4e, 0x52, 0x6e, 0x45, 0x4a,
- 0x62, 0x30, 0x39, 0x67, 0x46, 0x51, 0x39, 0x47, 0x63, 0x32, 0x4e, 0x4d, 0x58, 0x6e, 0x51, 0x77, 0x44, 0x53, 0x68, 0x44, 0x43, 0x48,
- 0x49, 0x79, 0x42, 0x43, 0x34, 0x78, 0x4b, 0x53, 0x64, 0x45, 0x62, 0x52, 0x4d, 0x58, 0x53, 0x41, 0x39, 0x4a, 0x55, 0x68, 0x41, 0x54,
- 0x66, 0x78, 0x63, 0x57, 0x59, 0x6e, 0x6b, 0x31, 0x65, 0x44, 0x34, 0x42, 0x66, 0x43, 0x34, 0x50, 0x64, 0x6a, 0x35, 0x65, 0x55, 0x32,
- 0x78, 0x62, 0x58, 0x33, 0x77, 0x5a, 0x51, 0x51, 0x49, 0x76, 0x46, 0x32, 0x52, 0x42, 0x64, 0x52, 0x41, 0x45, 0x52, 0x33, 0x77, 0x39,
- 0x53, 0x31, 0x49, 0x41, 0x45, 0x46, 0x31, 0x52, 0x54, 0x6e, 0x6f, 0x6e, 0x4a, 0x56, 0x56, 0x41, 0x45, 0x6a, 0x56, 0x67, 0x42, 0x52,
- 0x73, 0x30, 0x4c, 0x51, 0x52, 0x36, 0x61, 0x6d, 0x6b, 0x43, 0x65, 0x51, 0x4d, 0x36, 0x4c, 0x77, 0x59, 0x4b, 0x65, 0x58, 0x73, 0x53,
- 0x58, 0x58, 0x78, 0x53, 0x4b, 0x55, 0x64, 0x59, 0x45, 0x6e, 0x4d, 0x2f, 0x4a, 0x31, 0x59, 0x46, 0x44, 0x45, 0x67, 0x79, 0x57, 0x47,
- 0x74, 0x58, 0x58, 0x41, 0x4e, 0x6b, 0x56, 0x68, 0x46, 0x53, 0x65, 0x6a, 0x41, 0x32, 0x4b, 0x52, 0x63, 0x37, 0x61, 0x48, 0x70, 0x38,
- 0x42, 0x57, 0x74, 0x72, 0x45, 0x32, 0x6f, 0x6b, 0x58, 0x47, 0x68, 0x43, 0x47, 0x44, 0x49, 0x44, 0x63, 0x32, 0x34, 0x45, 0x49, 0x53,
- 0x34, 0x42, 0x42, 0x47, 0x4e, 0x39, 0x52, 0x45, 0x45, 0x53, 0x4d, 0x51, 0x73, 0x56, 0x48, 0x33, 0x41, 0x41, 0x4c, 0x6d, 0x59, 0x55,
- 0x50, 0x48, 0x38, 0x72, 0x41, 0x42, 0x38, 0x4d, 0x4b, 0x46, 0x6b, 0x4b, 0x46, 0x6b, 0x6c, 0x61, 0x58, 0x47, 0x52, 0x6c, 0x53, 0x78,
- 0x45, 0x70, 0x46, 0x54, 0x5a, 0x61, 0x5a, 0x52, 0x6c, 0x50, 0x59, 0x43, 0x4d, 0x36, 0x4f, 0x68, 0x4d, 0x6c, 0x41, 0x6e, 0x68, 0x4d,
- 0x56, 0x41, 0x3d, 0x3d, 0x00};
+ 0x43, 0x7a, 0x42, 0x45, 0x59, 0x6e, 0x77, 0x69, 0x48, 0x77, 0x30, 0x46, 0x5a, 0x79, 0x77,
+ 0x71, 0x4f, 0x53, 0x46, 0x47, 0x43, 0x46, 0x42, 0x6d, 0x4e, 0x44, 0x63, 0x4c, 0x52, 0x55,
+ 0x73, 0x34, 0x4d, 0x67, 0x5a, 0x36, 0x50, 0x6e, 0x38, 0x4d, 0x51, 0x42, 0x68, 0x72, 0x4c,
+ 0x57, 0x42, 0x4d, 0x59, 0x41, 0x77, 0x6a, 0x51, 0x7a, 0x73, 0x2b, 0x47, 0x78, 0x59, 0x45,
+ 0x52, 0x6c, 0x67, 0x2f, 0x51, 0x47, 0x6f, 0x52, 0x42, 0x57, 0x4e, 0x78, 0x46, 0x44, 0x56,
+ 0x48, 0x65, 0x52, 0x4e, 0x76, 0x61, 0x79, 0x63, 0x59, 0x57, 0x30, 0x67, 0x6e, 0x50, 0x6d,
+ 0x38, 0x56, 0x4d, 0x30, 0x38, 0x2b, 0x58, 0x6c, 0x46, 0x7a, 0x61, 0x43, 0x55, 0x50, 0x42,
+ 0x6c, 0x74, 0x38, 0x63, 0x6e, 0x55, 0x2b, 0x50, 0x78, 0x74, 0x63, 0x62, 0x57, 0x6f, 0x35,
+ 0x66, 0x47, 0x4e, 0x6a, 0x59, 0x47, 0x78, 0x36, 0x4d, 0x33, 0x5a, 0x53, 0x45, 0x79, 0x55,
+ 0x7a, 0x66, 0x57, 0x55, 0x6a, 0x4a, 0x78, 0x45, 0x47, 0x42, 0x6b, 0x64, 0x78, 0x48, 0x68,
+ 0x52, 0x30, 0x59, 0x33, 0x41, 0x74, 0x46, 0x53, 0x63, 0x59, 0x55, 0x51, 0x59, 0x46, 0x4d,
+ 0x78, 0x45, 0x73, 0x61, 0x77, 0x41, 0x74, 0x64, 0x79, 0x42, 0x49, 0x44, 0x58, 0x4e, 0x52,
+ 0x52, 0x53, 0x56, 0x2f, 0x66, 0x7a, 0x55, 0x6d, 0x4c, 0x69, 0x5a, 0x54, 0x4a, 0x47, 0x67,
+ 0x65, 0x44, 0x6c, 0x67, 0x36, 0x57, 0x56, 0x42, 0x57, 0x4e, 0x31, 0x39, 0x6d, 0x41, 0x55,
+ 0x78, 0x61, 0x5a, 0x44, 0x4a, 0x51, 0x65, 0x32, 0x6f, 0x67, 0x63, 0x69, 0x73, 0x64, 0x66,
+ 0x6b, 0x4e, 0x37, 0x59, 0x55, 0x49, 0x4c, 0x59, 0x58, 0x4d, 0x6b, 0x65, 0x54, 0x70, 0x72,
+ 0x53, 0x6e, 0x6c, 0x75, 0x43, 0x51, 0x38, 0x6e, 0x4c, 0x51, 0x78, 0x65, 0x4d, 0x6b, 0x73,
+ 0x4e, 0x65, 0x55, 0x59, 0x35, 0x49, 0x51, 0x6f, 0x6d, 0x58, 0x7a, 0x6f, 0x41, 0x4a, 0x6a,
+ 0x38, 0x54, 0x4c, 0x6e, 0x35, 0x51, 0x4b, 0x32, 0x64, 0x47, 0x63, 0x6a, 0x38, 0x37, 0x41,
+ 0x55, 0x59, 0x62, 0x43, 0x7a, 0x56, 0x4a, 0x4f, 0x52, 0x6c, 0x77, 0x50, 0x51, 0x4a, 0x42,
+ 0x44, 0x6a, 0x67, 0x46, 0x64, 0x6d, 0x56, 0x50, 0x4d, 0x57, 0x78, 0x65, 0x46, 0x77, 0x51,
+ 0x56, 0x4e, 0x69, 0x5a, 0x6b, 0x4e, 0x42, 0x51, 0x58, 0x66, 0x41, 0x34, 0x4c, 0x57, 0x31,
+ 0x56, 0x54, 0x61, 0x77, 0x42, 0x43, 0x51, 0x55, 0x38, 0x43, 0x58, 0x42, 0x4d, 0x4b, 0x4c,
+ 0x43, 0x77, 0x2b, 0x45, 0x42, 0x51, 0x7a, 0x52, 0x58, 0x78, 0x36, 0x57, 0x6a, 0x46, 0x68,
+ 0x4f, 0x51, 0x67, 0x69, 0x61, 0x68, 0x34, 0x50, 0x62, 0x78, 0x74, 0x73, 0x45, 0x31, 0x35,
+ 0x35, 0x49, 0x48, 0x6c, 0x51, 0x59, 0x67, 0x59, 0x73, 0x64, 0x68, 0x63, 0x45, 0x4b, 0x79,
+ 0x70, 0x31, 0x48, 0x77, 0x77, 0x33, 0x54, 0x67, 0x39, 0x37, 0x4c, 0x54, 0x52, 0x31, 0x59,
+ 0x44, 0x46, 0x30, 0x4c, 0x67, 0x70, 0x4b, 0x45, 0x57, 0x78, 0x4a, 0x4a, 0x51, 0x45, 0x36,
+ 0x50, 0x53, 0x49, 0x65, 0x62, 0x52, 0x68, 0x52, 0x65, 0x43, 0x31, 0x69, 0x4d, 0x55, 0x78,
+ 0x51, 0x51, 0x42, 0x64, 0x4c, 0x62, 0x79, 0x49, 0x41, 0x66, 0x32, 0x45, 0x71, 0x4e, 0x44,
+ 0x34, 0x41, 0x58, 0x79, 0x39, 0x66, 0x4c, 0x78, 0x51, 0x71, 0x56, 0x53, 0x63, 0x66, 0x52,
+ 0x68, 0x38, 0x53, 0x52, 0x6c, 0x34, 0x65, 0x44, 0x48, 0x77, 0x34, 0x41, 0x57, 0x46, 0x6b,
+ 0x64, 0x69, 0x4a, 0x75, 0x43, 0x43, 0x41, 0x34, 0x54, 0x33, 0x4e, 0x79, 0x56, 0x52, 0x4a,
+ 0x43, 0x47, 0x56, 0x42, 0x68, 0x51, 0x33, 0x64, 0x39, 0x51, 0x53, 0x34, 0x31, 0x54, 0x7a,
+ 0x30, 0x78, 0x4b, 0x46, 0x68, 0x6e, 0x47, 0x77, 0x4e, 0x52, 0x49, 0x44, 0x49, 0x63, 0x43,
+ 0x47, 0x34, 0x33, 0x64, 0x54, 0x64, 0x45, 0x54, 0x32, 0x67, 0x5a, 0x42, 0x32, 0x51, 0x55,
+ 0x4b, 0x43, 0x55, 0x72, 0x61, 0x54, 0x55, 0x59, 0x4a, 0x79, 0x59, 0x55, 0x45, 0x33, 0x42,
+ 0x43, 0x47, 0x52, 0x4a, 0x31, 0x50, 0x67, 0x4a, 0x64, 0x66, 0x42, 0x4d, 0x66, 0x46, 0x6c,
+ 0x4d, 0x37, 0x64, 0x45, 0x67, 0x38, 0x58, 0x6a, 0x6c, 0x73, 0x48, 0x42, 0x78, 0x30, 0x4f,
+ 0x52, 0x38, 0x41, 0x47, 0x77, 0x59, 0x4b, 0x61, 0x44, 0x74, 0x53, 0x54, 0x78, 0x35, 0x75,
+ 0x50, 0x44, 0x55, 0x4d, 0x4f, 0x41, 0x34, 0x4c, 0x4f, 0x78, 0x70, 0x32, 0x49, 0x79, 0x6c,
+ 0x54, 0x48, 0x6c, 0x39, 0x42, 0x44, 0x45, 0x73, 0x4b, 0x5a, 0x53, 0x68, 0x34, 0x5a, 0x30,
+ 0x68, 0x5a, 0x4a, 0x6d, 0x30, 0x78, 0x64, 0x69, 0x4e, 0x77, 0x59, 0x57, 0x51, 0x37, 0x4f,
+ 0x48, 0x6c, 0x6d, 0x64, 0x46, 0x4d, 0x73, 0x5a, 0x47, 0x52, 0x55, 0x41, 0x31, 0x52, 0x6c,
+ 0x52, 0x45, 0x77, 0x59, 0x54, 0x30, 0x67, 0x67, 0x54, 0x33, 0x49, 0x51, 0x50, 0x77, 0x78,
+ 0x53, 0x4c, 0x51, 0x4d, 0x55, 0x41, 0x31, 0x46, 0x43, 0x45, 0x48, 0x64, 0x71, 0x4e, 0x41,
+ 0x59, 0x79, 0x41, 0x33, 0x49, 0x55, 0x66, 0x41, 0x68, 0x64, 0x55, 0x68, 0x70, 0x69, 0x66,
+ 0x44, 0x34, 0x77, 0x66, 0x6c, 0x39, 0x2f, 0x56, 0x41, 0x39, 0x45, 0x53, 0x56, 0x31, 0x65,
+ 0x45, 0x47, 0x6f, 0x47, 0x4b, 0x77, 0x5a, 0x54, 0x45, 0x44, 0x6b, 0x33, 0x4d, 0x6b, 0x70,
+ 0x4f, 0x50, 0x53, 0x74, 0x6c, 0x4f, 0x44, 0x6b, 0x48, 0x63, 0x6c, 0x52, 0x6b, 0x54, 0x56,
+ 0x5a, 0x71, 0x41, 0x79, 0x4a, 0x77, 0x65, 0x31, 0x39, 0x67, 0x43, 0x79, 0x6f, 0x4c, 0x61,
+ 0x78, 0x42, 0x6b, 0x46, 0x41, 0x55, 0x69, 0x41, 0x48, 0x4e, 0x41, 0x49, 0x31, 0x74, 0x52,
+ 0x48, 0x79, 0x73, 0x61, 0x58, 0x57, 0x6c, 0x36, 0x52, 0x67, 0x78, 0x66, 0x4d, 0x6b, 0x74,
+ 0x4b, 0x4b, 0x46, 0x4a, 0x35, 0x57, 0x78, 0x4a, 0x43, 0x47, 0x41, 0x42, 0x64, 0x4a, 0x7a,
+ 0x46, 0x54, 0x50, 0x45, 0x77, 0x32, 0x54, 0x6a, 0x67, 0x2f, 0x63, 0x67, 0x4e, 0x78, 0x41,
+ 0x6c, 0x73, 0x32, 0x57, 0x58, 0x39, 0x31, 0x62, 0x67, 0x68, 0x55, 0x44, 0x54, 0x51, 0x63,
+ 0x4e, 0x46, 0x64, 0x64, 0x61, 0x55, 0x67, 0x41, 0x4f, 0x77, 0x55, 0x48, 0x62, 0x69, 0x64,
+ 0x6c, 0x62, 0x6b, 0x41, 0x39, 0x4f, 0x6b, 0x39, 0x79, 0x58, 0x54, 0x6b, 0x57, 0x44, 0x32,
+ 0x4d, 0x53, 0x45, 0x68, 0x55, 0x36, 0x63, 0x41, 0x31, 0x58, 0x47, 0x41, 0x31, 0x65, 0x50,
+ 0x53, 0x4a, 0x6f, 0x61, 0x48, 0x78, 0x74, 0x54, 0x77, 0x78, 0x37, 0x43, 0x53, 0x31, 0x4b,
+ 0x63, 0x79, 0x42, 0x48, 0x42, 0x31, 0x64, 0x31, 0x58, 0x56, 0x4e, 0x77, 0x4e, 0x43, 0x46,
+ 0x41, 0x56, 0x31, 0x46, 0x65, 0x53, 0x55, 0x51, 0x41, 0x56, 0x43, 0x63, 0x45, 0x61, 0x48,
+ 0x35, 0x5a, 0x56, 0x6c, 0x68, 0x30, 0x46, 0x44, 0x77, 0x57, 0x4d, 0x30, 0x45, 0x57, 0x53,
+ 0x79, 0x39, 0x4a, 0x4e, 0x77, 0x70, 0x55, 0x43, 0x41, 0x67, 0x66, 0x4f, 0x57, 0x64, 0x32,
+ 0x4b, 0x43, 0x67, 0x48, 0x48, 0x57, 0x46, 0x48, 0x55, 0x55, 0x31, 0x31, 0x4a, 0x6c, 0x4a,
+ 0x48, 0x52, 0x77, 0x78, 0x58, 0x57, 0x48, 0x51, 0x2b, 0x59, 0x6d, 0x78, 0x59, 0x4f, 0x6b,
+ 0x51, 0x65, 0x46, 0x69, 0x34, 0x68, 0x48, 0x48, 0x4e, 0x46, 0x5a, 0x33, 0x52, 0x50, 0x4d,
+ 0x32, 0x59, 0x4f, 0x64, 0x47, 0x59, 0x6d, 0x48, 0x79, 0x34, 0x34, 0x52, 0x45, 0x42, 0x2b,
+ 0x4b, 0x6c, 0x42, 0x53, 0x58, 0x6b, 0x4d, 0x42, 0x65, 0x6a, 0x68, 0x4a, 0x50, 0x46, 0x56,
+ 0x4e, 0x57, 0x6b, 0x51, 0x49, 0x4a, 0x6c, 0x6c, 0x4e, 0x52, 0x51, 0x74, 0x49, 0x43, 0x6a,
+ 0x4e, 0x65, 0x53, 0x6b, 0x31, 0x31, 0x46, 0x68, 0x64, 0x6a, 0x52, 0x67, 0x45, 0x71, 0x56,
+ 0x58, 0x73, 0x50, 0x41, 0x6e, 0x4e, 0x71, 0x53, 0x33, 0x39, 0x31, 0x5a, 0x54, 0x78, 0x4d,
+ 0x4d, 0x7a, 0x6c, 0x73, 0x64, 0x41, 0x56, 0x67, 0x44, 0x33, 0x38, 0x74, 0x51, 0x55, 0x31,
+ 0x4e, 0x52, 0x6e, 0x45, 0x4a, 0x62, 0x30, 0x39, 0x67, 0x46, 0x51, 0x39, 0x47, 0x63, 0x32,
+ 0x4e, 0x4d, 0x58, 0x6e, 0x51, 0x77, 0x44, 0x53, 0x68, 0x44, 0x43, 0x48, 0x49, 0x79, 0x42,
+ 0x43, 0x34, 0x78, 0x4b, 0x53, 0x64, 0x45, 0x62, 0x52, 0x4d, 0x58, 0x53, 0x41, 0x39, 0x4a,
+ 0x55, 0x68, 0x41, 0x54, 0x66, 0x78, 0x63, 0x57, 0x59, 0x6e, 0x6b, 0x31, 0x65, 0x44, 0x34,
+ 0x42, 0x66, 0x43, 0x34, 0x50, 0x64, 0x6a, 0x35, 0x65, 0x55, 0x32, 0x78, 0x62, 0x58, 0x33,
+ 0x77, 0x5a, 0x51, 0x51, 0x49, 0x76, 0x46, 0x32, 0x52, 0x42, 0x64, 0x52, 0x41, 0x45, 0x52,
+ 0x33, 0x77, 0x39, 0x53, 0x31, 0x49, 0x41, 0x45, 0x46, 0x31, 0x52, 0x54, 0x6e, 0x6f, 0x6e,
+ 0x4a, 0x56, 0x56, 0x41, 0x45, 0x6a, 0x56, 0x67, 0x42, 0x52, 0x73, 0x30, 0x4c, 0x51, 0x52,
+ 0x36, 0x61, 0x6d, 0x6b, 0x43, 0x65, 0x51, 0x4d, 0x36, 0x4c, 0x77, 0x59, 0x4b, 0x65, 0x58,
+ 0x73, 0x53, 0x58, 0x58, 0x78, 0x53, 0x4b, 0x55, 0x64, 0x59, 0x45, 0x6e, 0x4d, 0x2f, 0x4a,
+ 0x31, 0x59, 0x46, 0x44, 0x45, 0x67, 0x79, 0x57, 0x47, 0x74, 0x58, 0x58, 0x41, 0x4e, 0x6b,
+ 0x56, 0x68, 0x46, 0x53, 0x65, 0x6a, 0x41, 0x32, 0x4b, 0x52, 0x63, 0x37, 0x61, 0x48, 0x70,
+ 0x38, 0x42, 0x57, 0x74, 0x72, 0x45, 0x32, 0x6f, 0x6b, 0x58, 0x47, 0x68, 0x43, 0x47, 0x44,
+ 0x49, 0x44, 0x63, 0x32, 0x34, 0x45, 0x49, 0x53, 0x34, 0x42, 0x42, 0x47, 0x4e, 0x39, 0x52,
+ 0x45, 0x45, 0x53, 0x4d, 0x51, 0x73, 0x56, 0x48, 0x33, 0x41, 0x41, 0x4c, 0x6d, 0x59, 0x55,
+ 0x50, 0x48, 0x38, 0x72, 0x41, 0x42, 0x38, 0x4d, 0x4b, 0x46, 0x6b, 0x4b, 0x46, 0x6b, 0x6c,
+ 0x61, 0x58, 0x47, 0x52, 0x6c, 0x53, 0x78, 0x45, 0x70, 0x46, 0x54, 0x5a, 0x61, 0x5a, 0x52,
+ 0x6c, 0x50, 0x59, 0x43, 0x4d, 0x36, 0x4f, 0x68, 0x4d, 0x6c, 0x41, 0x6e, 0x68, 0x4d, 0x56,
+ 0x41, 0x3d, 0x3d, 0x00};
char *b64_test;
plan_tests(1);
diff --git a/lib/tests/test_cmd.c b/lib/tests/test_cmd.c
index c8867dfb..ade0da90 100644
--- a/lib/tests/test_cmd.c
+++ b/lib/tests/test_cmd.c
@@ -67,7 +67,8 @@ int main(int argc, char **argv) {
result = cmd_run_array(command_line, &chld_out, &chld_err, 0);
ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines");
ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines");
- ok(strcmp(chld_out.line[0], "this is test one") == 0, "(array) Check for expected stdout output");
+ ok(strcmp(chld_out.line[0], "this is test one") == 0,
+ "(array) Check for expected stdout output");
ok(result == 0, "(array) Checking exit code");
/* ensure everything is empty again */
@@ -82,7 +83,8 @@ int main(int argc, char **argv) {
ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines");
ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines");
- ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output");
+ ok(strcmp(chld_out.line[0], "this is test one") == 0,
+ "(string) Check for expected stdout output");
ok(result == 0, "(string) Checking exit code");
diag("Running plain echo command, set two");
@@ -104,7 +106,8 @@ int main(int argc, char **argv) {
result = cmd_run_array(command_line, &chld_out, &chld_err, 0);
ok(chld_out.lines == 1, "(array) Check for expected number of stdout lines");
ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines");
- ok(strcmp(chld_out.line[0], "this is test two") == 0, "(array) Check for expected stdout output");
+ ok(strcmp(chld_out.line[0], "this is test two") == 0,
+ "(array) Check for expected stdout output");
ok(result == 0, "(array) Checking exit code");
/* ensure everything is empty again */
@@ -119,7 +122,8 @@ int main(int argc, char **argv) {
ok(chld_out.lines == 1, "(string) Check for expected number of stdout lines");
ok(chld_err.lines == 0, "(string) Check for expected number of stderr lines");
- ok(strcmp(chld_out.line[0], "this is test one") == 0, "(string) Check for expected stdout output");
+ ok(strcmp(chld_out.line[0], "this is test one") == 0,
+ "(string) Check for expected stdout output");
ok(result == 0, "(string) Checking exit code");
/* ensure everything is empty again */
@@ -130,7 +134,8 @@ int main(int argc, char **argv) {
ok(chld_err.lines == 0, "(initialised) Checking stderr is reset");
ok(result == UNSET, "(initialised) Checking exit code is reset");
- /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */
+ /* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line
+ * output */
command_line[0] = strdup("/bin/echo");
command_line[1] = strdup("this is a test via echo\nline two\nit's line 3");
command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated");
@@ -138,9 +143,12 @@ int main(int argc, char **argv) {
result = cmd_run_array(command_line, &chld_out, &chld_err, 0);
ok(chld_out.lines == 3, "(array) Check for expected number of stdout lines");
ok(chld_err.lines == 0, "(array) Check for expected number of stderr lines");
- ok(strcmp(chld_out.line[0], "this is a test via echo") == 0, "(array) Check line 1 for expected stdout output");
- ok(strcmp(chld_out.line[1], "line two") == 0, "(array) Check line 2 for expected stdout output");
- ok(strcmp(chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0,
+ ok(strcmp(chld_out.line[0], "this is a test via echo") == 0,
+ "(array) Check line 1 for expected stdout output");
+ ok(strcmp(chld_out.line[1], "line two") == 0,
+ "(array) Check line 2 for expected stdout output");
+ ok(strcmp(chld_out.line[2],
+ "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0,
"(array) Check line 3 for expected stdout output");
ok(result == 0, "(array) Checking exit code");
@@ -171,7 +179,8 @@ int main(int argc, char **argv) {
ok(chld_out.lines == 0, "/bin/sh returns no stdout when file is missing...");
ok(chld_err.lines == 1, "...but does give an error line");
- ok(strstr(chld_err.line[0], "non-existent-file") != NULL, "And missing filename is in error message");
+ ok(strstr(chld_err.line[0], "non-existent-file") != NULL,
+ "And missing filename is in error message");
ok(result != 0, "Get non-zero return code from /bin/sh");
/* ensure everything is empty again */
diff --git a/lib/tests/test_generic_output.c b/lib/tests/test_generic_output.c
index e67aefc9..e4a78bcd 100644
--- a/lib/tests/test_generic_output.c
+++ b/lib/tests/test_generic_output.c
@@ -110,7 +110,8 @@ void test_two_subchecks(void) {
sc1.output = "foobar";
sc1 = mp_set_subcheck_state(sc1, STATE_WARNING);
- ok(mp_compute_subcheck_state(sc1) == STATE_WARNING, "Test subcheck state directly after setting it");
+ ok(mp_compute_subcheck_state(sc1) == STATE_WARNING,
+ "Test subcheck state directly after setting it");
mp_perfdata pd1 = perfdata_init();
@@ -129,7 +130,8 @@ void test_two_subchecks(void) {
mp_add_subcheck_to_subcheck(&sc1, sc2);
- ok(mp_compute_subcheck_state(sc1) == STATE_WARNING, "Test subcheck state after adding a subcheck");
+ ok(mp_compute_subcheck_state(sc1) == STATE_WARNING,
+ "Test subcheck state after adding a subcheck");
mp_check check = mp_check_init();
mp_add_subcheck_to_check(&check, sc1);
diff --git a/lib/tests/test_ini1.c b/lib/tests/test_ini1.c
index 246c1250..3792d142 100644
--- a/lib/tests/test_ini1.c
+++ b/lib/tests/test_ini1.c
@@ -42,8 +42,9 @@ char *list2str(np_arg_list *optlst) {
free(optltmp);
}
/* Strip last whitespace */
- if (strlen(optstr) > 1)
+ if (strlen(optstr) > 1) {
optstr[strlen(optstr) - 1] = '\0';
+ }
return optstr;
}
@@ -54,15 +55,18 @@ int main(int argc, char **argv) {
plan_tests(12);
optstr = list2str(np_get_defaults("section@./config-tiny.ini", "check_disk"));
- ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "config-tiny.ini's section as expected");
+ ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"),
+ "config-tiny.ini's section as expected");
my_free(optstr);
optstr = list2str(np_get_defaults("@./config-tiny.ini", "section"));
- ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"), "Used default section name, without specific");
+ ok(!strcmp(optstr, "--one=two --Foo=Bar --this=Your Mother! --blank"),
+ "Used default section name, without specific");
my_free(optstr);
optstr = list2str(np_get_defaults("Section Two@./config-tiny.ini", "check_disk"));
- ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-tiny.ini's Section Two as expected");
+ ok(!strcmp(optstr, "--something else=blah --remove=whitespace"),
+ "config-tiny.ini's Section Two as expected");
my_free(optstr);
optstr = list2str(np_get_defaults("/path/to/file.txt@./config-tiny.ini", "check_disk"));
@@ -70,15 +74,18 @@ int main(int argc, char **argv) {
my_free(optstr);
optstr = list2str(np_get_defaults("section2@./config-tiny.ini", "check_disk"));
- ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section2 with whitespace before section name");
+ ok(!strcmp(optstr, "--this=that"),
+ "config-tiny.ini's section2 with whitespace before section name");
my_free(optstr);
optstr = list2str(np_get_defaults("section3@./config-tiny.ini", "check_disk"));
- ok(!strcmp(optstr, "--this=that"), "config-tiny.ini's section3 with whitespace after section name");
+ ok(!strcmp(optstr, "--this=that"),
+ "config-tiny.ini's section3 with whitespace after section name");
my_free(optstr);
optstr = list2str(np_get_defaults("check_mysql@./plugin.ini", "check_disk"));
- ok(!strcmp(optstr, "--username=operator --password=secret"), "plugin.ini's check_mysql as expected");
+ ok(!strcmp(optstr, "--username=operator --password=secret"),
+ "plugin.ini's check_mysql as expected");
my_free(optstr);
optstr = list2str(np_get_defaults("check_mysql2@./plugin.ini", "check_disk"));
@@ -90,29 +97,39 @@ int main(int argc, char **argv) {
my_free(optstr);
optstr = list2str(np_get_defaults("Section Two@./config-dos.ini", "check_disk"));
- ok(!strcmp(optstr, "--something else=blah --remove=whitespace"), "config-dos.ini's Section Two as expected");
+ ok(!strcmp(optstr, "--something else=blah --remove=whitespace"),
+ "config-dos.ini's Section Two as expected");
my_free(optstr);
optstr = list2str(np_get_defaults("section_twice@./plugin.ini", "check_disk"));
- ok(!strcmp(optstr, "--foo=bar --bar=foo"), "plugin.ini's section_twice defined twice in the file");
+ ok(!strcmp(optstr, "--foo=bar --bar=foo"),
+ "plugin.ini's section_twice defined twice in the file");
my_free(optstr);
optstr = list2str(np_get_defaults("tcp_long_lines@plugins.ini", "check_tcp"));
- ok(!strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar "
+ ok(!strcmp(optstr, "--escape --send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo bar "
"BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
- "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar "
+ "BAZ yadda yadda yadda Foo bar BAZ yadda "
"yadda yadda Foo bar BAZ yadda yadda yadda Foo "
- "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar BAZ yadda yadda "
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
- "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda --expect=Foo bar BAZ yadda yadda "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda --expect=Foo bar BAZ yadda yadda "
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
- "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo "
"bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
- "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar "
+ "BAZ yadda yadda yadda Foo bar BAZ yadda "
"yadda yadda Foo bar BAZ yadda yadda yadda Foo "
- "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar BAZ yadda yadda "
"yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
- "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo "
"bar BAZ yadda yadda yadda --jail"),
"Long options");
my_free(optstr);
diff --git a/lib/tests/test_opts1.c b/lib/tests/test_opts1.c
index 984183d3..99da5596 100644
--- a/lib/tests/test_opts1.c
+++ b/lib/tests/test_opts1.c
@@ -47,16 +47,18 @@ void my_free(int *argc, char **newargv, char **argv) {
printf("'%s' ", newargv[i]);
/* Stop freeing when we get to the start of the original array */
if (freeflag) {
- if (newargv[i] == argv[1])
+ if (newargv[i] == argv[1]) {
freeflag = 0;
- else
+ } else {
free(newargv[i]);
+ }
}
}
printf("\n");
/* Free only if it's a different array */
- if (newargv != argv)
+ if (newargv != argv) {
free(newargv);
+ }
*argc = 0;
}
#endif
@@ -69,8 +71,9 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
return 0;
}
for (i = 0; i <= i1; i++) {
- if (a1[i] == NULL && a2[i] == NULL)
+ if (a1[i] == NULL && a2[i] == NULL) {
continue;
+ }
if (a1[i] == NULL || a2[i] == NULL) {
printf(" Argument # %i null in one array!\n", i);
return 0;
@@ -110,27 +113,36 @@ int main(int argc, char **argv) {
{
char *argv_test[] = {"prog_name", "--extra-opts=@./config-opts.ini", (char *)NULL};
argc_test = 2;
- char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", (char *)NULL};
+ char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank",
+ (char *)NULL};
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts using default section");
my_free(&argc_test, argv_new, argv_test);
}
{
- char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts", "sect2@./config-opts.ini", (char *)NULL};
+ char *argv_test[] = {"prog_name", "--extra-opts=sect1@./config-opts.ini", "--extra-opts",
+ "sect2@./config-opts.ini", (char *)NULL};
argc_test = 4;
- char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that", (char *)NULL};
+ char *argv_known[] = {"prog_name", "--one=two", "--something else=oops", "--this=that",
+ (char *)NULL};
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
ok(array_diff(argc_test, argv_new, 4, argv_known), "Only extra opts specified twice");
my_free(&argc_test, argv_new, argv_test);
}
{
- char *argv_test[] = {"prog_name", "--arg1=val1", "--extra-opts=@./config-opts.ini", "--extra-opts", "sect1@./config-opts.ini",
- "--arg2", (char *)NULL};
+ char *argv_test[] = {"prog_name",
+ "--arg1=val1",
+ "--extra-opts=@./config-opts.ini",
+ "--extra-opts",
+ "sect1@./config-opts.ini",
+ "--arg2",
+ (char *)NULL};
argc_test = 6;
- char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!", "--blank", "--one=two",
- "--arg1=val1", "--arg2", (char *)NULL};
+ char *argv_known[] = {"prog_name", "--foo=Bar", "--this=Your Mother!",
+ "--blank", "--one=two", "--arg1=val1",
+ "--arg2", (char *)NULL};
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
ok(array_diff(argc_test, argv_new, 7, argv_known), "twice extra opts using two sections");
my_free(&argc_test, argv_new, argv_test);
diff --git a/lib/tests/test_opts2.c b/lib/tests/test_opts2.c
index 23496617..d1b0aca3 100644
--- a/lib/tests/test_opts2.c
+++ b/lib/tests/test_opts2.c
@@ -30,16 +30,18 @@ void my_free(int *argc, char **newargv, char **argv) {
printf("'%s' ", newargv[i]);
/* Stop freeing when we get to the start of the original array */
if (freeflag) {
- if (newargv[i] == argv[1])
+ if (newargv[i] == argv[1]) {
freeflag = 0;
- else
+ } else {
free(newargv[i]);
+ }
}
}
printf("\n");
/* Free only if it's a different array */
- if (newargv != argv)
+ if (newargv != argv) {
free(newargv);
+ }
*argc = 0;
}
@@ -51,8 +53,9 @@ int array_diff(int i1, char **a1, int i2, char **a2) {
return 0;
}
for (i = 0; i <= i1; i++) {
- if (a1[i] == NULL && a2[i] == NULL)
+ if (a1[i] == NULL && a2[i] == NULL) {
continue;
+ }
if (a1[i] == NULL || a2[i] == NULL) {
printf(" Argument # %i null in one array!\n", i);
return 0;
@@ -90,7 +93,8 @@ int main(int argc, char **argv) {
}
{
- char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1", "--arg3", "val2", (char *)NULL};
+ char *argv_test[] = {"prog_name", "arg1", "--extra-opts=section1",
+ "--arg3", "val2", (char *)NULL};
argc_test = 5;
char *argv_known[] = {"prog_name", "--foobar=baz", "arg1", "--arg3", "val2", (char *)NULL};
argv_new = np_extra_opts(&argc_test, argv_test, "check_disk");
@@ -108,30 +112,39 @@ int main(int argc, char **argv) {
}
{
- char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines", (char *)NULL};
+ char *argv_test[] = {"check_tcp", "--extra-opts", "--extra-opts=tcp_long_lines",
+ (char *)NULL};
argc_test = 3;
- char *argv_known[] = {
- "check_tcp",
- "--timeout=10",
- "--escape",
- "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
- "yadda Foo bar BAZ yadda "
- "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
- "yadda Foo bar BAZ "
- "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
- "yadda yadda Foo bar "
- "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda",
- "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
- "yadda Foo bar BAZ yadda "
- "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
- "yadda Foo bar BAZ "
- "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
- "yadda yadda Foo bar "
- "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
- "yadda yadda yadda Foo "
- "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda",
- "--jail",
- (char *)NULL};
+ char *argv_known[] = {"check_tcp",
+ "--timeout=10",
+ "--escape",
+ "--send=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda "
+ "Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar "
+ "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda",
+ "--expect=Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda "
+ "yadda Foo bar BAZ "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ yadda "
+ "yadda yadda Foo bar "
+ "BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
+ "yadda yadda yadda Foo "
+ "bar BAZ yadda yadda yadda Foo bar BAZ yadda yadda yadda Foo bar BAZ "
+ "yadda yadda yadda Foo bar BAZ yadda yadda yadda",
+ "--jail",
+ (char *)NULL};
argv_new = np_extra_opts(&argc_test, argv_test, "check_tcp");
ok(array_diff(argc_test, argv_new, 6, argv_known), "Long lines test");
my_free(&argc_test, argv_new, argv_test);
diff --git a/lib/tests/test_tcp.c b/lib/tests/test_tcp.c
index 1b3003e9..de3a2102 100644
--- a/lib/tests/test_tcp.c
+++ b/lib/tests/test_tcp.c
@@ -32,19 +32,28 @@ int main(void) {
server_expect[1] = strdup("bb");
server_expect[2] = strdup("CC");
- ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
+ ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
+ NP_MATCH_SUCCESS,
"Test matching any string at the beginning (first expect string)");
- ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_SUCCESS,
+ ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
+ NP_MATCH_SUCCESS,
"Test matching any string at the beginning (second expect string)");
ok(np_expect_match("b", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_RETRY,
"Test matching any string at the beginning (substring match)");
- ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE,
+ ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
+ NP_MATCH_FAILURE,
"Test with strings not matching at the beginning");
- ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) == NP_MATCH_FAILURE, "Test matching any string");
- ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY, "Test not matching any string");
- ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_SUCCESS,
+ ok(np_expect_match("XX CC XX", server_expect, server_expect_count, NP_MATCH_EXACT) ==
+ NP_MATCH_FAILURE,
+ "Test matching any string");
+ ok(np_expect_match("XX", server_expect, server_expect_count, 0) == NP_MATCH_RETRY,
+ "Test not matching any string");
+ ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) ==
+ NP_MATCH_SUCCESS,
"Test matching all strings");
- ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY, "Test not matching all strings");
+ ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, NP_MATCH_ALL) ==
+ NP_MATCH_RETRY,
+ "Test not matching all strings");
ok(np_expect_match("XX XX", server_expect, server_expect_count, NP_MATCH_ALL) == NP_MATCH_RETRY,
"Test not matching any string (testing all)");
diff --git a/lib/utils_base.c b/lib/utils_base.c
index e95eeaf0..69024bc9 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -254,7 +254,7 @@ bool check_range(double value, range *my_range) {
yes = false;
}
- if (!my_range->end_infinity&& !my_range->start_infinity) {
+ if (!my_range->end_infinity && !my_range->start_infinity) {
if ((my_range->start <= value) && (value <= my_range->end)) {
return no;
}
@@ -268,7 +268,7 @@ bool check_range(double value, range *my_range) {
return yes;
}
- if (my_range->start_infinity && !my_range->end_infinity ) {
+ if (my_range->start_infinity && !my_range->end_infinity) {
if (value <= my_range->end) {
return no;
}
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c
index 9b222409..d1feaa33 100644
--- a/lib/utils_cmd.c
+++ b/lib/utils_cmd.c
@@ -71,7 +71,7 @@ extern char **environ;
#endif
#ifndef WIFEXITED
-# define WIFEXITED(stat_val) (((stat_val)&255) == 0)
+# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
#endif
/* 4.3BSD Reno doesn't define SIG_ERR */
@@ -103,8 +103,9 @@ void cmd_init(void) {
maxfd = MAXFD_LIMIT;
}
- if (!_cmd_pids)
+ if (!_cmd_pids) {
_cmd_pids = calloc(maxfd, sizeof(pid_t));
+ }
}
/* Start running a command, array style */
@@ -116,13 +117,15 @@ static int _cmd_open(char *const *argv, int *pfd, int *pfderr) {
int i = 0;
- if (!_cmd_pids)
+ if (!_cmd_pids) {
CMD_INIT;
+ }
setenv("LC_ALL", "C", 1);
- if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0)
+ if (pipe(pfd) < 0 || pipe(pfderr) < 0 || (pid = fork()) < 0) {
return -1; /* errno set by the failing function */
+ }
/* child runs exceve() and _exit. */
if (pid == 0) {
@@ -147,9 +150,11 @@ static int _cmd_open(char *const *argv, int *pfd, int *pfderr) {
* This is executed in a separate address space (pure child),
* so we don't have to worry about async safety */
long maxfd = mp_open_max();
- for (i = 0; i < maxfd; i++)
- if (_cmd_pids[i] > 0)
+ for (i = 0; i < maxfd; i++) {
+ if (_cmd_pids[i] > 0) {
close(i);
+ }
+ }
execve(argv[0], argv, environ);
_exit(STATE_UNKNOWN);
@@ -172,17 +177,21 @@ static int _cmd_close(int fd) {
/* make sure the provided fd was opened */
long maxfd = mp_open_max();
- if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0)
+ if (fd < 0 || fd > maxfd || !_cmd_pids || (pid = _cmd_pids[fd]) == 0) {
return -1;
+ }
_cmd_pids[fd] = 0;
- if (close(fd) == -1)
+ if (close(fd) == -1) {
return -1;
+ }
/* EINTR is ok (sort of), everything else is bad */
- while (waitpid(pid, &status, 0) < 0)
- if (errno != EINTR)
+ while (waitpid(pid, &status, 0) < 0) {
+ if (errno != EINTR) {
return -1;
+ }
+ }
/* return child's termination status */
return (WIFEXITED(status)) ? WEXITSTATUS(status) : -1;
@@ -212,15 +221,17 @@ static int _cmd_fetch_output(int fd, output *op, int flags) {
/* some plugins may want to keep output unbroken, and some commands
* will yield no output, so return here for those */
- if (flags & CMD_NO_ARRAYS || !op->buf || !op->buflen)
+ if (flags & CMD_NO_ARRAYS || !op->buf || !op->buflen) {
return op->buflen;
+ }
/* and some may want both */
if (flags & CMD_NO_ASSOC) {
buf = malloc(op->buflen);
memcpy(buf, op->buf, op->buflen);
- } else
+ } else {
buf = op->buf;
+ }
op->line = NULL;
op->lens = NULL;
@@ -241,8 +252,9 @@ static int _cmd_fetch_output(int fd, output *op, int flags) {
op->line[lineno] = &buf[i];
/* hop to next newline or end of buffer */
- while (buf[i] != '\n' && i < op->buflen)
+ while (buf[i] != '\n' && i < op->buflen) {
i++;
+ }
buf[i] = '\0';
/* calculate the string length using pointer difference */
@@ -262,30 +274,36 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) {
char *cmd = NULL;
char *str = NULL;
- if (cmdstring == NULL)
+ if (cmdstring == NULL) {
return -1;
+ }
/* initialize the structs */
- if (out)
+ if (out) {
memset(out, 0, sizeof(output));
- if (err)
+ }
+ if (err) {
memset(err, 0, sizeof(output));
+ }
/* make copy of command string so strtok() doesn't silently modify it */
/* (the calling program may want to access it later) */
cmdlen = strlen(cmdstring);
- if ((cmd = malloc(cmdlen + 1)) == NULL)
+ if ((cmd = malloc(cmdlen + 1)) == NULL) {
return -1;
+ }
memcpy(cmd, cmdstring, cmdlen);
cmd[cmdlen] = '\0';
/* This is not a shell, so we don't handle "???" */
- if (strstr(cmdstring, "\""))
+ if (strstr(cmdstring, "\"")) {
return -1;
+ }
/* allow single quotes, but only if non-whitesapce doesn't occur on both sides */
- if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''"))
+ if (strstr(cmdstring, " ' ") || strstr(cmdstring, "'''")) {
return -1;
+ }
/* each arg must be whitespace-separated, so args can be a maximum
* of (len / 2) + 1. We add 1 extra to the mix for NULL termination */
@@ -304,8 +322,9 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) {
if (strstr(str, "'") == str) { /* handle SIMPLE quoted strings */
str++;
- if (!strstr(str, "'"))
+ if (!strstr(str, "'")) {
return -1; /* balanced? */
+ }
cmd = 1 + strstr(str, "'");
str[strcspn(str, "'")] = 0;
} else {
@@ -317,8 +336,9 @@ int cmd_run(const char *cmdstring, output *out, output *err, int flags) {
}
}
- if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n"))
+ if (cmd && strlen(cmd) == strspn(cmd, " \t\r\n")) {
cmd = NULL;
+ }
argv[i++] = str;
}
@@ -330,50 +350,61 @@ int cmd_run_array(char *const *argv, output *out, output *err, int flags) {
int fd, pfd_out[2], pfd_err[2];
/* initialize the structs */
- if (out)
+ if (out) {
memset(out, 0, sizeof(output));
- if (err)
+ }
+ if (err) {
memset(err, 0, sizeof(output));
+ }
- if ((fd = _cmd_open(argv, pfd_out, pfd_err)) == -1)
+ if ((fd = _cmd_open(argv, pfd_out, pfd_err)) == -1) {
die(STATE_UNKNOWN, _("Could not open pipe: %s\n"), argv[0]);
+ }
- if (out)
+ if (out) {
out->lines = _cmd_fetch_output(pfd_out[0], out, flags);
- if (err)
+ }
+ if (err) {
err->lines = _cmd_fetch_output(pfd_err[0], err, flags);
+ }
return _cmd_close(fd);
}
int cmd_file_read(const char *filename, output *out, int flags) {
int fd;
- if (out)
+ if (out) {
memset(out, 0, sizeof(output));
+ }
if ((fd = open(filename, O_RDONLY)) == -1) {
die(STATE_UNKNOWN, _("Error opening %s: %s"), filename, strerror(errno));
}
- if (out)
+ if (out) {
out->lines = _cmd_fetch_output(fd, out, flags);
+ }
- if (close(fd) == -1)
+ if (close(fd) == -1) {
die(STATE_UNKNOWN, _("Error closing %s: %s"), filename, strerror(errno));
+ }
return 0;
}
void timeout_alarm_handler(int signo) {
if (signo == SIGALRM) {
- printf(_("%s - Plugin timed out after %d seconds\n"), state_text(timeout_state), timeout_interval);
+ printf(_("%s - Plugin timed out after %d seconds\n"), state_text(timeout_state),
+ timeout_interval);
long maxfd = mp_open_max();
- if (_cmd_pids)
+ if (_cmd_pids) {
for (long int i = 0; i < maxfd; i++) {
- if (_cmd_pids[i] != 0)
+ if (_cmd_pids[i] != 0) {
kill(_cmd_pids[i], SIGKILL);
+ }
}
+ }
exit(timeout_state);
}
diff --git a/lib/utils_tcp.c b/lib/utils_tcp.c
index daae1d54..1482458b 100644
--- a/lib/utils_tcp.c
+++ b/lib/utils_tcp.c
@@ -29,18 +29,21 @@
#include "common.h"
#include "utils_tcp.h"
-#define VERBOSE(message) \
- do { \
- if (flags & NP_MATCH_VERBOSE) \
- puts(message); \
+#define VERBOSE(message) \
+ do { \
+ if (flags & NP_MATCH_VERBOSE) \
+ puts(message); \
} while (0)
-enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count, int flags) {
+enum np_match_result np_expect_match(char *status, char **server_expect, int expect_count,
+ int flags) {
int i, match = 0, partial = 0;
for (i = 0; i < expect_count; i++) {
- if (flags & NP_MATCH_VERBOSE)
- printf("looking for [%s] %s [%s]\n", server_expect[i], (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status);
+ if (flags & NP_MATCH_VERBOSE) {
+ printf("looking for [%s] %s [%s]\n", server_expect[i],
+ (flags & NP_MATCH_EXACT) ? "in beginning of" : "anywhere in", status);
+ }
if (flags & NP_MATCH_EXACT) {
if (strncmp(status, server_expect[i], strlen(server_expect[i])) == 0) {
@@ -60,10 +63,12 @@ enum np_match_result np_expect_match(char *status, char **server_expect, int exp
VERBOSE("couldn't find it");
}
- if ((flags & NP_MATCH_ALL && match == expect_count) || (!(flags & NP_MATCH_ALL) && match >= 1))
+ if ((flags & NP_MATCH_ALL && match == expect_count) ||
+ (!(flags & NP_MATCH_ALL) && match >= 1)) {
return NP_MATCH_SUCCESS;
- else if (partial > 0 || !(flags & NP_MATCH_EXACT))
+ } else if (partial > 0 || !(flags & NP_MATCH_EXACT)) {
return NP_MATCH_RETRY;
- else
+ } else {
return NP_MATCH_FAILURE;
+ }
}
diff --git a/lib/utils_tcp.h b/lib/utils_tcp.h
index a7d83c59..e5cdbb82 100644
--- a/lib/utils_tcp.h
+++ b/lib/utils_tcp.h
@@ -17,4 +17,5 @@ enum np_match_result {
NP_MATCH_RETRY
};
-enum np_match_result np_expect_match(char *status, char **server_expect, int server_expect_count, int flags);
+enum np_match_result np_expect_match(char *status, char **server_expect, int server_expect_count,
+ int flags);
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index daed9cb0..9a96547f 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -127,17 +127,17 @@ static long mac_addr_dlpi(const char *, int, u_char *);
#define MAX_DHCP_OPTIONS_LENGTH 312
typedef struct dhcp_packet_struct {
- uint8_t op; /* packet type */
- uint8_t htype; /* type of hardware address for this machine (Ethernet, etc) */
- uint8_t hlen; /* length of hardware address (of this machine) */
- uint8_t hops; /* hops */
- uint32_t xid; /* random transaction id number - chosen by this machine */
- uint16_t secs; /* seconds used in timing */
- uint16_t flags; /* flags */
- struct in_addr ciaddr; /* IP address of this machine (if we already have one) */
- struct in_addr yiaddr; /* IP address of this machine (offered by the DHCP server) */
- struct in_addr siaddr; /* IP address of next server */
- struct in_addr giaddr; /* IP address of DHCP relay */
+ uint8_t op; /* packet type */
+ uint8_t htype; /* type of hardware address for this machine (Ethernet, etc) */
+ uint8_t hlen; /* length of hardware address (of this machine) */
+ uint8_t hops; /* hops */
+ uint32_t xid; /* random transaction id number - chosen by this machine */
+ uint16_t secs; /* seconds used in timing */
+ uint16_t flags; /* flags */
+ struct in_addr ciaddr; /* IP address of this machine (if we already have one) */
+ struct in_addr yiaddr; /* IP address of this machine (offered by the DHCP server) */
+ struct in_addr siaddr; /* IP address of next server */
+ struct in_addr giaddr; /* IP address of DHCP relay */
unsigned char chaddr[MAX_DHCP_CHADDR_LENGTH]; /* hardware address of this machine */
char sname[MAX_DHCP_SNAME_LENGTH]; /* name of DHCP server */
char file[MAX_DHCP_FILE_LENGTH]; /* boot file name (used for diskless booting?) */
@@ -199,7 +199,8 @@ static void print_help(void);
static void resolve_host(const char * /*in*/, struct in_addr * /*out*/);
static unsigned char *mac_aton(const char * /*string*/);
static void print_hardware_address(const unsigned char * /*address*/);
-static int get_hardware_address(int /*sock*/, char * /*interface_name*/, unsigned char *client_hardware_address);
+static int get_hardware_address(int /*sock*/, char * /*interface_name*/,
+ unsigned char *client_hardware_address);
typedef struct get_ip_address_wrapper {
int error;
@@ -211,32 +212,40 @@ typedef struct send_dhcp_discover_wrapper {
int error;
uint32_t packet_xid;
} send_dhcp_discover_wrapper;
-static send_dhcp_discover_wrapper send_dhcp_discover(int socket, bool unicast, struct in_addr dhcp_ip, struct in_addr requested_address,
- bool request_specific_address, struct in_addr my_ip,
- unsigned char *client_hardware_address);
+static send_dhcp_discover_wrapper
+send_dhcp_discover(int socket, bool unicast, struct in_addr dhcp_ip,
+ struct in_addr requested_address, bool request_specific_address,
+ struct in_addr my_ip, unsigned char *client_hardware_address);
typedef struct get_dhcp_offer_wrapper {
int error;
int valid_responses;
dhcp_offer *dhcp_offer_list;
} get_dhcp_offer_wrapper;
-static get_dhcp_offer_wrapper get_dhcp_offer(int /*sock*/, int dhcpoffer_timeout, uint32_t packet_xid, dhcp_offer *dhcp_offer_list,
+static get_dhcp_offer_wrapper get_dhcp_offer(int /*sock*/, int dhcpoffer_timeout,
+ uint32_t packet_xid, dhcp_offer *dhcp_offer_list,
const unsigned char *client_hardware_address);
-static mp_subcheck get_results(bool exclusive, int requested_servers, struct in_addr requested_address, bool request_specific_address,
- requested_server *requested_server_list, int valid_responses, dhcp_offer *dhcp_offer_list);
+static mp_subcheck get_results(bool exclusive, int requested_servers,
+ struct in_addr requested_address, bool request_specific_address,
+ requested_server *requested_server_list, int valid_responses,
+ dhcp_offer *dhcp_offer_list);
typedef struct add_dhcp_offer_wrapper {
int error;
dhcp_offer *dhcp_offer_list;
} add_dhcp_offer_wrapper;
-static add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr /*source*/, dhcp_packet * /*offer_packet*/, dhcp_offer *dhcp_offer_list);
+static add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr /*source*/,
+ dhcp_packet * /*offer_packet*/,
+ dhcp_offer *dhcp_offer_list);
static int free_dhcp_offer_list(dhcp_offer *dhcp_offer_list);
static int free_requested_server_list(requested_server *requested_server_list);
static int create_dhcp_socket(bool /*unicast*/, char *network_interface_name);
static int close_dhcp_socket(int /*sock*/);
-static int send_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/, struct sockaddr_in * /*dest*/);
-static int receive_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/, int /*timeout*/, struct sockaddr_in * /*address*/);
+static int send_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/,
+ struct sockaddr_in * /*dest*/);
+static int receive_dhcp_packet(void * /*buffer*/, int /*buffer_size*/, int /*sock*/,
+ int /*timeout*/, struct sockaddr_in * /*address*/);
int main(int argc, char **argv) {
setlocale(LC_ALL, "");
@@ -271,7 +280,8 @@ int main(int argc, char **argv) {
struct in_addr my_ip = {0};
if (config.unicast_mode) { /* get IP address of client machine */
- get_ip_address_wrapper tmp_get_ip = get_ip_address(dhcp_socket, config.network_interface_name);
+ get_ip_address_wrapper tmp_get_ip =
+ get_ip_address(dhcp_socket, config.network_interface_name);
if (tmp_get_ip.error == OK) {
my_ip = tmp_get_ip.my_ip;
} else {
@@ -281,8 +291,9 @@ int main(int argc, char **argv) {
}
/* send DHCPDISCOVER packet */
- send_dhcp_discover_wrapper disco_res = send_dhcp_discover(dhcp_socket, config.unicast_mode, config.dhcp_ip, config.requested_address,
- config.request_specific_address, my_ip, client_hardware_address);
+ send_dhcp_discover_wrapper disco_res = send_dhcp_discover(
+ dhcp_socket, config.unicast_mode, config.dhcp_ip, config.requested_address,
+ config.request_specific_address, my_ip, client_hardware_address);
if (disco_res.error != OK) {
// DO something?
@@ -290,8 +301,8 @@ int main(int argc, char **argv) {
}
/* wait for a DHCPOFFER packet */
- get_dhcp_offer_wrapper offer_res =
- get_dhcp_offer(dhcp_socket, config.dhcpoffer_timeout, disco_res.packet_xid, NULL, client_hardware_address);
+ get_dhcp_offer_wrapper offer_res = get_dhcp_offer(
+ dhcp_socket, config.dhcpoffer_timeout, disco_res.packet_xid, NULL, client_hardware_address);
int valid_responses = 0;
dhcp_offer *dhcp_offer_list = NULL;
@@ -308,8 +319,10 @@ int main(int argc, char **argv) {
mp_check overall = mp_check_init();
/* determine state/plugin output to return */
- mp_subcheck sc_res = get_results(config.exclusive_mode, config.num_of_requested_servers, config.requested_address,
- config.request_specific_address, config.requested_server_list, valid_responses, dhcp_offer_list);
+ mp_subcheck sc_res =
+ get_results(config.exclusive_mode, config.num_of_requested_servers,
+ config.requested_address, config.request_specific_address,
+ config.requested_server_list, valid_responses, dhcp_offer_list);
mp_add_subcheck_to_check(&overall, sc_res);
/* free allocated memory */
free_dhcp_offer_list(dhcp_offer_list);
@@ -357,17 +370,20 @@ int get_hardware_address(int sock, char *interface_name, unsigned char *client_h
}
if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
- printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"), interface_name, strerror(errno));
+ printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"),
+ interface_name, strerror(errno));
exit(STATE_UNKNOWN);
}
if ((buf = malloc(len)) == NULL) {
- printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"), interface_name, strerror(errno));
+ printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"),
+ interface_name, strerror(errno));
exit(4);
}
if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
- printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"), interface_name, strerror(errno));
+ printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"),
+ interface_name, strerror(errno));
exit(STATE_UNKNOWN);
}
@@ -398,12 +414,16 @@ int get_hardware_address(int sock, char *interface_name, unsigned char *client_h
unit = atoi(p);
strncat(dev, interface_name, 6);
} else {
- printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg lnc0.\n"), interface_name);
+ printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg "
+ "lnc0.\n"),
+ interface_name);
exit(STATE_UNKNOWN);
}
stat = mac_addr_dlpi(dev, unit, client_hardware_address);
if (stat != 0) {
- printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
+ printf(
+ _("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"),
+ dev, unit);
exit(STATE_UNKNOWN);
}
@@ -415,7 +435,9 @@ int get_hardware_address(int sock, char *interface_name, unsigned char *client_h
stat = mac_addr_dlpi(dev, unit, client_hardware_address);
if (stat != 0) {
- printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
+ printf(
+ _("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"),
+ dev, unit);
exit(STATE_UNKNOWN);
}
/* Kompf 2000-2003 */
@@ -463,8 +485,10 @@ get_ip_address_wrapper get_ip_address(int sock, char *interface_name) {
}
/* sends a DHCPDISCOVER broadcast message in an attempt to find DHCP servers */
-static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, struct in_addr dhcp_ip, struct in_addr requested_address,
- bool request_specific_address, struct in_addr my_ip,
+static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, struct in_addr dhcp_ip,
+ struct in_addr requested_address,
+ bool request_specific_address,
+ struct in_addr my_ip,
unsigned char *client_hardware_address) {
dhcp_packet discover_packet = {0};
/* boot request flag (backward compatible with BOOTP servers) */
@@ -506,8 +530,9 @@ static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, str
unsigned short opts = 4;
/* DHCP message type is embedded in options field */
- discover_packet.options[opts++] = DHCP_OPTION_MESSAGE_TYPE; /* DHCP message type option identifier */
- discover_packet.options[opts++] = '\x01'; /* DHCP message option length in bytes */
+ discover_packet.options[opts++] =
+ DHCP_OPTION_MESSAGE_TYPE; /* DHCP message type option identifier */
+ discover_packet.options[opts++] = '\x01'; /* DHCP message option length in bytes */
discover_packet.options[opts++] = DHCPDISCOVER;
/* the IP address we're requesting */
@@ -535,8 +560,10 @@ static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, str
};
if (verbose) {
- printf(_("DHCPDISCOVER to %s port %d\n"), inet_ntoa(sockaddr_broadcast.sin_addr), ntohs(sockaddr_broadcast.sin_port));
- printf("DHCPDISCOVER XID: %u (0x%X)\n", ntohl(discover_packet.xid), ntohl(discover_packet.xid));
+ printf(_("DHCPDISCOVER to %s port %d\n"), inet_ntoa(sockaddr_broadcast.sin_addr),
+ ntohs(sockaddr_broadcast.sin_port));
+ printf("DHCPDISCOVER XID: %u (0x%X)\n", ntohl(discover_packet.xid),
+ ntohl(discover_packet.xid));
printf("DHCDISCOVER ciaddr: %s\n", inet_ntoa(discover_packet.ciaddr));
printf("DHCDISCOVER yiaddr: %s\n", inet_ntoa(discover_packet.yiaddr));
printf("DHCDISCOVER siaddr: %s\n", inet_ntoa(discover_packet.siaddr));
@@ -554,7 +581,8 @@ static send_dhcp_discover_wrapper send_dhcp_discover(int sock, bool unicast, str
}
/* waits for a DHCPOFFER message from one or more DHCP servers */
-get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t packet_xid, dhcp_offer *dhcp_offer_list,
+get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t packet_xid,
+ dhcp_offer *dhcp_offer_list,
const unsigned char *client_hardware_address) {
time_t start_time;
time(&start_time);
@@ -578,7 +606,8 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
dhcp_packet offer_packet = {0};
result = OK;
- result = receive_dhcp_packet(&offer_packet, sizeof(offer_packet), sock, dhcpoffer_timeout, &source);
+ result = receive_dhcp_packet(&offer_packet, sizeof(offer_packet), sock, dhcpoffer_timeout,
+ &source);
if (result != OK) {
if (verbose) {
@@ -607,8 +636,9 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
/* check packet xid to see if its the same as the one we used in the discover packet */
if (ntohl(offer_packet.xid) != packet_xid) {
if (verbose) {
- printf(_("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"), ntohl(offer_packet.xid),
- packet_xid);
+ printf(
+ _("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"),
+ ntohl(offer_packet.xid), packet_xid);
}
continue;
@@ -648,7 +678,8 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
printf("DHCPOFFER giaddr: %s\n", inet_ntoa(offer_packet.giaddr));
}
- add_dhcp_offer_wrapper add_res = add_dhcp_offer(source.sin_addr, &offer_packet, dhcp_offer_list);
+ add_dhcp_offer_wrapper add_res =
+ add_dhcp_offer(source.sin_addr, &offer_packet, dhcp_offer_list);
if (add_res.error != OK) {
// TODO
} else {
@@ -673,7 +704,8 @@ get_dhcp_offer_wrapper get_dhcp_offer(int sock, int dhcpoffer_timeout, uint32_t
/* sends a DHCP packet */
int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in *dest) {
- int result = sendto(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)dest, sizeof(*dest));
+ int result =
+ sendto(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)dest, sizeof(*dest));
if (verbose) {
printf(_("send_dhcp_packet result: %d\n"), result);
@@ -687,7 +719,8 @@ int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in
}
/* receives a DHCP packet */
-int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address) {
+int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout,
+ struct sockaddr_in *address) {
/* wait for data to arrive (up time timeout) */
struct timeval timeout_val = {
.tv_sec = timeout,
@@ -711,7 +744,8 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st
struct sockaddr_in source_address = {0};
socklen_t address_size = sizeof(source_address);
- int recv_result = recvfrom(sock, (char *)buffer, buffer_size, 0, (struct sockaddr *)&source_address, &address_size);
+ int recv_result = recvfrom(sock, (char *)buffer, buffer_size, 0,
+ (struct sockaddr *)&source_address, &address_size);
if (verbose) {
printf("recv_result: %d\n", recv_result);
}
@@ -775,7 +809,8 @@ int create_dhcp_socket(bool unicast, char *network_interface_name) {
strncpy(interface.ifr_ifrn.ifrn_name, network_interface_name, IFNAMSIZ - 1);
interface.ifr_ifrn.ifrn_name[IFNAMSIZ - 1] = '\0';
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, (char *)&interface, sizeof(interface)) < 0) {
- printf(_("Error: Could not bind socket to interface %s. Check your privileges...\n"), network_interface_name);
+ printf(_("Error: Could not bind socket to interface %s. Check your privileges...\n"),
+ network_interface_name);
exit(STATE_UNKNOWN);
}
@@ -786,7 +821,8 @@ int create_dhcp_socket(bool unicast, char *network_interface_name) {
/* bind the socket */
if (bind(sock, (struct sockaddr *)&myname, sizeof(myname)) < 0) {
- printf(_("Error: Could not bind to DHCP socket (port %d)! Check your privileges...\n"), DHCP_CLIENT_PORT);
+ printf(_("Error: Could not bind to DHCP socket (port %d)! Check your privileges...\n"),
+ DHCP_CLIENT_PORT);
exit(STATE_UNKNOWN);
}
@@ -800,7 +836,8 @@ int close_dhcp_socket(int sock) {
}
/* adds a requested server address to list in memory */
-int add_requested_server(struct in_addr server_address, int *requested_servers, requested_server **requested_server_list) {
+int add_requested_server(struct in_addr server_address, int *requested_servers,
+ requested_server **requested_server_list) {
requested_server *new_server = (requested_server *)malloc(sizeof(requested_server));
if (new_server == NULL) {
return ERROR;
@@ -822,7 +859,8 @@ int add_requested_server(struct in_addr server_address, int *requested_servers,
}
/* adds a DHCP OFFER to list in memory */
-add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet, dhcp_offer *dhcp_offer_list) {
+add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr source, dhcp_packet *offer_packet,
+ dhcp_offer *dhcp_offer_list) {
if (offer_packet == NULL) {
add_dhcp_offer_wrapper tmp = {
.error = ERROR,
@@ -859,15 +897,18 @@ add_dhcp_offer_wrapper add_dhcp_offer(struct in_addr source, dhcp_packet *offer_
dhcp_lease_time = ntohl(dhcp_lease_time);
break;
case DHCP_OPTION_RENEWAL_TIME:
- memcpy(&dhcp_renewal_time, &offer_packet->options[dchp_opt_idx], sizeof(dhcp_renewal_time));
+ memcpy(&dhcp_renewal_time, &offer_packet->options[dchp_opt_idx],
+ sizeof(dhcp_renewal_time));
dhcp_renewal_time = ntohl(dhcp_renewal_time);
break;
case DHCP_OPTION_REBINDING_TIME:
- memcpy(&dhcp_rebinding_time, &offer_packet->options[dchp_opt_idx], sizeof(dhcp_rebinding_time));
+ memcpy(&dhcp_rebinding_time, &offer_packet->options[dchp_opt_idx],
+ sizeof(dhcp_rebinding_time));
dhcp_rebinding_time = ntohl(dhcp_rebinding_time);
break;
case DHCP_OPTION_SERVER_IDENTIFIER:
- memcpy(&serv_ident.s_addr, &offer_packet->options[dchp_opt_idx], sizeof(serv_ident.s_addr));
+ memcpy(&serv_ident.s_addr, &offer_packet->options[dchp_opt_idx],
+ sizeof(serv_ident.s_addr));
break;
}
@@ -955,7 +996,8 @@ int free_dhcp_offer_list(dhcp_offer *dhcp_offer_list) {
/* frees memory allocated to requested server list */
int free_requested_server_list(requested_server *requested_server_list) {
requested_server *next_server;
- for (requested_server *this_server = requested_server_list; this_server != NULL; this_server = next_server) {
+ for (requested_server *this_server = requested_server_list; this_server != NULL;
+ this_server = next_server) {
next_server = this_server->next;
free(this_server);
}
@@ -964,8 +1006,10 @@ int free_requested_server_list(requested_server *requested_server_list) {
}
/* gets state and plugin output to return */
-mp_subcheck get_results(bool exclusive, const int requested_servers, const struct in_addr requested_address, bool request_specific_address,
- requested_server *requested_server_list, int valid_responses, dhcp_offer *dhcp_offer_list) {
+mp_subcheck get_results(bool exclusive, const int requested_servers,
+ const struct in_addr requested_address, bool request_specific_address,
+ requested_server *requested_server_list, int valid_responses,
+ dhcp_offer *dhcp_offer_list) {
mp_subcheck sc_dhcp_results = mp_subcheck_init();
sc_dhcp_results = mp_set_subcheck_default_state(sc_dhcp_results, STATE_OK);
@@ -995,22 +1039,28 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
/* checks responses from requested servers */
int requested_responses = 0;
if (requested_servers > 0) {
- for (requested_server *temp_server = requested_server_list; temp_server != NULL; temp_server = temp_server->next) {
- for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL; temp_offer = temp_offer->next) {
+ for (requested_server *temp_server = requested_server_list; temp_server != NULL;
+ temp_server = temp_server->next) {
+ for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL;
+ temp_offer = temp_offer->next) {
/* get max lease time we were offered */
- if (temp_offer->lease_time > max_lease_time || temp_offer->lease_time == DHCP_INFINITE_TIME) {
+ if (temp_offer->lease_time > max_lease_time ||
+ temp_offer->lease_time == DHCP_INFINITE_TIME) {
max_lease_time = temp_offer->lease_time;
}
/* see if we got the address we requested */
- if (!memcmp(&requested_address, &temp_offer->offered_address, sizeof(requested_address))) {
+ if (!memcmp(&requested_address, &temp_offer->offered_address,
+ sizeof(requested_address))) {
received_requested_address = true;
}
/* see if the servers we wanted a response from, talked to us or not */
- if (!memcmp(&temp_offer->server_address, &temp_server->server_address, sizeof(temp_server->server_address))) {
+ if (!memcmp(&temp_offer->server_address, &temp_server->server_address,
+ sizeof(temp_server->server_address))) {
if (verbose) {
- printf(_("DHCP Server Match: Offerer=%s"), inet_ntoa(temp_offer->server_address));
+ printf(_("DHCP Server Match: Offerer=%s"),
+ inet_ntoa(temp_offer->server_address));
printf(_(" Requested=%s"), inet_ntoa(temp_server->server_address));
if (temp_server->answered) {
printf(_(" (duplicate)"));
@@ -1028,7 +1078,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
}
/* exclusive mode: check for undesired offers */
- for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL; temp_offer = temp_offer->next) {
+ for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL;
+ temp_offer = temp_offer->next) {
if (!temp_offer->desired) {
undesired_offer = temp_offer; /* Checks only for the first undesired offer */
break; /* no further checks needed */
@@ -1036,7 +1087,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
}
mp_subcheck sc_rqust_srvs = mp_subcheck_init();
- xasprintf(&sc_rqust_srvs.output, "%d of %d requested servers responded", requested_responses, requested_servers);
+ xasprintf(&sc_rqust_srvs.output, "%d of %d requested servers responded",
+ requested_responses, requested_servers);
if (requested_responses == requested_servers) {
sc_rqust_srvs = mp_set_subcheck_state(sc_rqust_srvs, STATE_OK);
@@ -1053,14 +1105,17 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
} else {
/* else check and see if we got our requested address from any server */
- for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL; temp_offer = temp_offer->next) {
+ for (dhcp_offer *temp_offer = dhcp_offer_list; temp_offer != NULL;
+ temp_offer = temp_offer->next) {
/* get max lease time we were offered */
- if (temp_offer->lease_time > max_lease_time || temp_offer->lease_time == DHCP_INFINITE_TIME) {
+ if (temp_offer->lease_time > max_lease_time ||
+ temp_offer->lease_time == DHCP_INFINITE_TIME) {
max_lease_time = temp_offer->lease_time;
}
/* see if we got the address we requested */
- if (!memcmp(&requested_address, &temp_offer->offered_address, sizeof(requested_address))) {
+ if (!memcmp(&requested_address, &temp_offer->offered_address,
+ sizeof(requested_address))) {
received_requested_address = true;
}
}
@@ -1069,7 +1124,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
if (max_lease_time == DHCP_INFINITE_TIME) {
xasprintf(&sc_dhcp_results.output, "%s, max lease time = Infinity", sc_dhcp_results.output);
} else {
- xasprintf(&sc_dhcp_results.output, "%s, max lease time = %" PRIu32 " seconds", sc_dhcp_results.output, max_lease_time);
+ xasprintf(&sc_dhcp_results.output, "%s, max lease time = %" PRIu32 " seconds",
+ sc_dhcp_results.output, max_lease_time);
}
if (exclusive) {
@@ -1083,8 +1139,8 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
// Get the addresses for printout
// 1.address of the sending server
char server_address[INET_ADDRSTRLEN];
- const char *server_address_transformed =
- inet_ntop(AF_INET, &undesired_offer->server_address, server_address, sizeof(server_address));
+ const char *server_address_transformed = inet_ntop(
+ AF_INET, &undesired_offer->server_address, server_address, sizeof(server_address));
if (server_address != server_address_transformed) {
die(STATE_UNKNOWN, "inet_ntop failed");
@@ -1093,13 +1149,15 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
// 2.address offered
char offered_address[INET_ADDRSTRLEN];
const char *offered_address_transformed =
- inet_ntop(AF_INET, &undesired_offer->offered_address, offered_address, sizeof(offered_address));
+ inet_ntop(AF_INET, &undesired_offer->offered_address, offered_address,
+ sizeof(offered_address));
if (offered_address != offered_address_transformed) {
die(STATE_UNKNOWN, "inet_ntop failed");
}
- xasprintf(&sc_rogue_server.output, "Rogue DHCP Server detected! Server %s offered %s", server_address, offered_address);
+ xasprintf(&sc_rogue_server.output, "Rogue DHCP Server detected! Server %s offered %s",
+ server_address, offered_address);
} else {
sc_rogue_server = mp_set_subcheck_state(sc_rogue_server, STATE_OK);
xasprintf(&sc_rogue_server.output, "No Rogue DHCP Server detected");
@@ -1112,10 +1170,12 @@ mp_subcheck get_results(bool exclusive, const int requested_servers, const struc
if (received_requested_address) {
sc_rqustd_addr = mp_set_subcheck_state(sc_rqustd_addr, STATE_OK);
- xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was offered", inet_ntoa(requested_address));
+ xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was offered",
+ inet_ntoa(requested_address));
} else {
sc_rqustd_addr = mp_set_subcheck_state(sc_rqustd_addr, STATE_WARNING);
- xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was NOT offered", inet_ntoa(requested_address));
+ xasprintf(&sc_rqustd_addr.output, "Requested address (%s) was NOT offered",
+ inet_ntoa(requested_address));
}
mp_add_subcheck_to_subcheck(&sc_dhcp_results, sc_rqustd_addr);
@@ -1138,18 +1198,19 @@ process_arguments_wrapper process_arguments(int argc, char **argv) {
};
int option_index = 0;
- static struct option long_options[] = {{"serverip", required_argument, 0, 's'},
- {"requestedip", required_argument, 0, 'r'},
- {"timeout", required_argument, 0, 't'},
- {"interface", required_argument, 0, 'i'},
- {"mac", required_argument, 0, 'm'},
- {"unicast", no_argument, 0, 'u'},
- {"exclusive", no_argument, 0, 'x'},
- {"verbose", no_argument, 0, 'v'},
- {"version", no_argument, 0, 'V'},
- {"help", no_argument, 0, 'h'},
- {"output-format", required_argument, 0, output_format_index},
- {0, 0, 0, 0}};
+ static struct option long_options[] = {
+ {"serverip", required_argument, 0, 's'},
+ {"requestedip", required_argument, 0, 'r'},
+ {"timeout", required_argument, 0, 't'},
+ {"interface", required_argument, 0, 'i'},
+ {"mac", required_argument, 0, 'm'},
+ {"unicast", no_argument, 0, 'u'},
+ {"exclusive", no_argument, 0, 'x'},
+ {"verbose", no_argument, 0, 'v'},
+ {"version", no_argument, 0, 'V'},
+ {"help", no_argument, 0, 'h'},
+ {"output-format", required_argument, 0, output_format_index},
+ {0, 0, 0, 0}};
check_dhcp_config config = check_dhcp_config_init();
int option_char = 0;
@@ -1163,7 +1224,8 @@ process_arguments_wrapper process_arguments(int argc, char **argv) {
switch (option_char) {
case 's': /* DHCP server address */
resolve_host(optarg, &config.dhcp_ip);
- add_requested_server(config.dhcp_ip, &config.num_of_requested_servers, &config.requested_server_list);
+ add_requested_server(config.dhcp_ip, &config.num_of_requested_servers,
+ &config.requested_server_list);
break;
case 'r': /* address we are requested from DHCP servers */
@@ -1187,7 +1249,8 @@ process_arguments_wrapper process_arguments(int argc, char **argv) {
break;
case 'i': /* interface name */
- strncpy(config.network_interface_name, optarg, sizeof(config.network_interface_name) - 1);
+ strncpy(config.network_interface_name, optarg,
+ sizeof(config.network_interface_name) - 1);
config.network_interface_name[sizeof(config.network_interface_name) - 1] = '\x0';
break;
@@ -1289,7 +1352,8 @@ static int put_ctrl(int fd, int len, int pri) {
ctl.len = len;
if (putmsg(fd, &ctl, 0, pri) < 0) {
- printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"), strerror(errno));
+ printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"),
+ strerror(errno));
exit(STATE_UNKNOWN);
}
@@ -1302,7 +1366,8 @@ static int put_both(int fd, int clen, int dlen, int pri) {
ctl.len = clen;
dat.len = dlen;
if (putmsg(fd, &ctl, &dat, pri) < 0) {
- printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"), strerror(errno));
+ printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"),
+ strerror(errno));
exit(STATE_UNKNOWN);
}
@@ -1314,7 +1379,8 @@ static int dl_open(const char *dev, int unit, int *fd) {
dl_attach_req_t *attach_req = (dl_attach_req_t *)ctl_area;
if ((*fd = open(dev, O_RDWR)) == -1) {
- printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"), dev, strerror(errno));
+ printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"),
+ dev, strerror(errno));
exit(STATE_UNKNOWN);
}
attach_req->dl_primitive = DL_ATTACH_REQ;
@@ -1338,7 +1404,8 @@ static int dl_bind(int fd, int sap, u_char *addr) {
put_ctrl(fd, sizeof(dl_bind_req_t), 0);
get_msg(fd);
if (GOT_ERR == check_ctrl(DL_BIND_ACK)) {
- printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"), strerror(errno));
+ printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"),
+ strerror(errno));
exit(STATE_UNKNOWN);
}
bcopy((u_char *)bind_ack + bind_ack->dl_addr_offset, addr, bind_ack->dl_addr_length);
@@ -1455,7 +1522,8 @@ void print_help(void) {
printf(" %s\n", "-u, --unicast");
printf(" %s\n", _("Unicast testing: mimic a DHCP relay, requires -s"));
printf(" %s\n", "-x, --exclusive");
- printf(" %s\n", _("Only requested DHCP server may response (rogue DHCP server detection), requires -s"));
+ printf(" %s\n",
+ _("Only requested DHCP server may response (rogue DHCP server detection), requires -s"));
printf(UT_SUPPORT);
}
diff --git a/plugins-root/check_icmp.d/config.h b/plugins-root/check_icmp.d/config.h
index c348bef5..be388d0a 100644
--- a/plugins-root/check_icmp.d/config.h
+++ b/plugins-root/check_icmp.d/config.h
@@ -97,7 +97,7 @@ typedef struct icmp_ping_data {
/* 80 msec packet interval by default */
// DEPRECATED, remove when removing the option
-#define DEFAULT_PKT_INTERVAL 80000
+#define DEFAULT_PKT_INTERVAL 80000
#define DEFAULT_TARGET_INTERVAL 0
diff --git a/plugins-root/pst3.c b/plugins-root/pst3.c
index 1f69f3a6..1bfe3d35 100644
--- a/plugins-root/pst3.c
+++ b/plugins-root/pst3.c
@@ -1,45 +1,45 @@
/*****************************************************************************
-*
-* pst3
-*
-* License: GPL
-* Copyright (c) 2008 Monitoring Plugins Development Team
-*
-* Description:
-*
-* This file contains the pst3 executable. This is a replacement ps command
-* for Solaris to get output which provides a long argument listing, which
-* is not possible with the standard ps command (due to truncation). /usr/ucb/ps
-* also has issues where some fields run into each other.
-*
-* This executable works by reading process address structures, so needs
-* to be executed as root
-*
-* Originally written by R.W.Ingraham
-* Rewritten by Duncan Ferguson (Altinity Ltd, June 2008)
-* The rewrite was necessary as /dev/kmem is not available within
-* non-global zones on Solaris 10
-*
-* Details for rewrite came from
-* source of /usr/ucb/ps on Solaris:
-* http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbcmd/ps/ps.c#argvoff
-* usenet group posting
-* http://groups.google.com/group/comp.unix.solaris/tree/browse_frm/month/2001-09/bfa40c08bac819a2?rnum=141&_done=%2Fgroup%2Fcomp.unix.solaris%2Fbrowse_frm%2Fmonth%2F2001-09%3F
-*
-* This program is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation, either version 3 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program. If not, see .
-*
-*****************************************************************************/
+ *
+ * pst3
+ *
+ * License: GPL
+ * Copyright (c) 2008 Monitoring Plugins Development Team
+ *
+ * Description:
+ *
+ * This file contains the pst3 executable. This is a replacement ps command
+ * for Solaris to get output which provides a long argument listing, which
+ * is not possible with the standard ps command (due to truncation). /usr/ucb/ps
+ * also has issues where some fields run into each other.
+ *
+ * This executable works by reading process address structures, so needs
+ * to be executed as root
+ *
+ * Originally written by R.W.Ingraham
+ * Rewritten by Duncan Ferguson (Altinity Ltd, June 2008)
+ * The rewrite was necessary as /dev/kmem is not available within
+ * non-global zones on Solaris 10
+ *
+ * Details for rewrite came from
+ * source of /usr/ucb/ps on Solaris:
+ * http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/ucbcmd/ps/ps.c#argvoff
+ * usenet group posting
+ * http://groups.google.com/group/comp.unix.solaris/tree/browse_frm/month/2001-09/bfa40c08bac819a2?rnum=141&_done=%2Fgroup%2Fcomp.unix.solaris%2Fbrowse_frm%2Fmonth%2F2001-09%3F
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ *****************************************************************************/
#include
#include
@@ -55,14 +55,14 @@
* Constants
*/
-#define PROC_DIR "/proc"
-#define ARGS 30
+#define PROC_DIR "/proc"
+#define ARGS 30
/*
* Globals
*/
-static char * szProg;
+static char *szProg;
/*
* Prototypes
@@ -71,192 +71,179 @@ void usage();
/*----------------------------------------------------------------------------*/
-int main (int argc, char **argv)
-{
- DIR *procdir;
- struct dirent *proc;
- char ps_name[ARGS];
- char as_name[ARGS];
- psinfo_t psinfo;
-
- /* Set our program name global */
- if ((szProg = strrchr(argv[0], '/')) != NULL)
- szProg++;
- else
- szProg = argv[0];
-
- /* if given any parameters, print out help */
- if(argc > 1) {
- (void)usage();
- exit(1);
- }
-
- /* Make sure that our euid is root */
- if (geteuid() != 0)
- {
- fprintf(stderr, "%s: This program can only be run by the root user!\n", szProg);
- exit(1);
- }
-
- if ((procdir = opendir(PROC_DIR)) == NULL) {
- fprintf(stderr, "%s: cannot open PROC directory %s\n", szProg, PROC_DIR);
- exit(1);
- }
-
- /* Display column headings */
- printf("%c %5s %5s %5s %6s %6s %4s %s %s\n",
- 'S',
- "UID",
- "PID",
- "PPID",
- "VSZ",
- "RSS",
- "%CPU",
- "COMMAND",
- "ARGS"
- );
-
- /* Zip through all of the process entries */
- while((proc = readdir(procdir))) {
- int ps_fd;
- int as_fd;
- off_t argoff;
- int i;
- char *args;
- char *procname;
- char *ptr;
- int argslen;
- uintptr_t args_addr;;
- uintptr_t *args_vecs;;
- int args_count;
-
- if(proc->d_name[0] == '.')
- continue;
-
- sprintf(ps_name,"%s/%s/%s",PROC_DIR,proc->d_name,"psinfo");
- sprintf(as_name,"%s/%s/%s",PROC_DIR,proc->d_name,"as");
-try_again:
- if((ps_fd = open(ps_name, O_RDONLY)) == -1)
- continue;
-
- if((as_fd = open(as_name, O_RDONLY)) == -1) {
- close(ps_fd);
- continue;
- }
-
- if(read(ps_fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) {
- int err = errno;
- close(ps_fd);
- close(as_fd);
- if(err == EAGAIN) goto try_again;
- if(err != ENOENT)
- fprintf(stderr, "%s: read() on %s: %s\n", szProg,
- ps_name, strerror(err));
- continue;
- }
- close(ps_fd);
-
- /* system process, ignore since the previous version did */
- if(
- psinfo.pr_nlwp == 0 ||
- strcmp(psinfo.pr_lwp.pr_clname, "SYS") == 0
- ) {
- continue;
- }
-
- /* get the procname to match previous versions */
- procname = strdup(psinfo.pr_psargs);
- if((ptr = strchr(procname, ' ')) != NULL)
- *ptr = '\0';
- if((ptr = strrchr(procname, '/')) != NULL)
- ptr++;
- else
- ptr = procname;
-
- /*
- * print out what we currently know
- */
- printf("%c %5d %5d %5d %6lu %6lu %4.1f %s ",
- psinfo.pr_lwp.pr_sname,
- psinfo.pr_euid,
- psinfo.pr_pid,
- psinfo.pr_ppid,
- psinfo.pr_size,
- psinfo.pr_rssize,
- ((float)(psinfo.pr_pctcpu) / 0x8000 * 100.0),
- ptr
- );
- free(procname);
-
- /*
- * and now for the command line stuff
- */
-
- args_addr = psinfo.pr_argv;
- args_count = psinfo.pr_argc;
- args_vecs = malloc(args_count * sizeof(uintptr_t));
-
- if(psinfo.pr_dmodel == PR_MODEL_NATIVE) {
- /* this process matches target process */
- pread(as_fd,args_vecs, args_count * sizeof(uintptr_t),
- args_addr);
- } else {
- /* this process is 64bit, target process is 32 bit*/
- caddr32_t *args_vecs32 = (caddr32_t *)args_vecs;
- pread(as_fd,args_vecs32,args_count * sizeof(caddr32_t),
- args_addr);
- for (i=args_count-1;i>=0;--i)
- args_vecs[i]=args_vecs32[i];
- }
-
- /*
- * now read in the args - if what we read in fills buffer
- * resize buffer and reread that bit again
- */
- argslen=ARGS;
- args=malloc(argslen+1);
- for(i=0;i 1) {
+ (void)usage();
+ exit(1);
+ }
+
+ /* Make sure that our euid is root */
+ if (geteuid() != 0) {
+ fprintf(stderr, "%s: This program can only be run by the root user!\n", szProg);
+ exit(1);
+ }
+
+ if ((procdir = opendir(PROC_DIR)) == NULL) {
+ fprintf(stderr, "%s: cannot open PROC directory %s\n", szProg, PROC_DIR);
+ exit(1);
+ }
+
+ /* Display column headings */
+ printf("%c %5s %5s %5s %6s %6s %4s %s %s\n", 'S', "UID", "PID", "PPID", "VSZ", "RSS", "%CPU",
+ "COMMAND", "ARGS");
+
+ /* Zip through all of the process entries */
+ while ((proc = readdir(procdir))) {
+ int ps_fd;
+ int as_fd;
+ off_t argoff;
+ int i;
+ char *args;
+ char *procname;
+ char *ptr;
+ int argslen;
+ uintptr_t args_addr;
+ ;
+ uintptr_t *args_vecs;
+ ;
+ int args_count;
+
+ if (proc->d_name[0] == '.') {
+ continue;
+ }
+
+ sprintf(ps_name, "%s/%s/%s", PROC_DIR, proc->d_name, "psinfo");
+ sprintf(as_name, "%s/%s/%s", PROC_DIR, proc->d_name, "as");
+ try_again:
+ if ((ps_fd = open(ps_name, O_RDONLY)) == -1) {
+ continue;
+ }
+
+ if ((as_fd = open(as_name, O_RDONLY)) == -1) {
+ close(ps_fd);
+ continue;
+ }
+
+ if (read(ps_fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) {
+ int err = errno;
+ close(ps_fd);
+ close(as_fd);
+ if (err == EAGAIN) {
+ goto try_again;
+ }
+ if (err != ENOENT) {
+ fprintf(stderr, "%s: read() on %s: %s\n", szProg, ps_name, strerror(err));
+ }
+ continue;
+ }
+ close(ps_fd);
+
+ /* system process, ignore since the previous version did */
+ if (psinfo.pr_nlwp == 0 || strcmp(psinfo.pr_lwp.pr_clname, "SYS") == 0) {
+ continue;
+ }
+
+ /* get the procname to match previous versions */
+ procname = strdup(psinfo.pr_psargs);
+ if ((ptr = strchr(procname, ' ')) != NULL) {
+ *ptr = '\0';
+ }
+ if ((ptr = strrchr(procname, '/')) != NULL) {
+ ptr++;
+ } else {
+ ptr = procname;
+ }
+
+ /*
+ * print out what we currently know
+ */
+ printf("%c %5d %5d %5d %6lu %6lu %4.1f %s ", psinfo.pr_lwp.pr_sname, psinfo.pr_euid,
+ psinfo.pr_pid, psinfo.pr_ppid, psinfo.pr_size, psinfo.pr_rssize,
+ ((float)(psinfo.pr_pctcpu) / 0x8000 * 100.0), ptr);
+ free(procname);
+
+ /*
+ * and now for the command line stuff
+ */
+
+ args_addr = psinfo.pr_argv;
+ args_count = psinfo.pr_argc;
+ args_vecs = malloc(args_count * sizeof(uintptr_t));
+
+ if (psinfo.pr_dmodel == PR_MODEL_NATIVE) {
+ /* this process matches target process */
+ pread(as_fd, args_vecs, args_count * sizeof(uintptr_t), args_addr);
+ } else {
+ /* this process is 64bit, target process is 32 bit*/
+ caddr32_t *args_vecs32 = (caddr32_t *)args_vecs;
+ pread(as_fd, args_vecs32, args_count * sizeof(caddr32_t), args_addr);
+ for (i = args_count - 1; i >= 0; --i) {
+ args_vecs[i] = args_vecs32[i];
+ }
+ }
+
+ /*
+ * now read in the args - if what we read in fills buffer
+ * resize buffer and reread that bit again
+ */
+ argslen = ARGS;
+ args = malloc(argslen + 1);
+ for (i = 0; i < args_count; i++) {
+ memset(args, '\0', argslen + 1);
+ if (pread(as_fd, args, argslen, args_vecs[i]) <= 0) {
+ break;
+ }
+ args[argslen] = '\0';
+ if (strlen(args) == argslen) {
+ argslen += ARGS;
+ args = realloc(args, argslen + 1);
+ i--;
+ continue;
+ }
+ printf(" %s", args);
+ }
+ free(args_vecs);
+ free(args);
+ close(as_fd);
+ printf("\n");
+ }
+
+ (void)closedir(procdir);
+
+ return (0);
}
/*----------------------------------------------------------------------------*/
void usage() {
- printf("%s: Help output\n\n", szProg);
- printf("If this program is given any arguments, this help is displayed.\n");
- printf("This command is used to print out the full command line for all\n");
- printf("running processes because /usr/bin/ps is limited to 80 chars and\n");
- printf("/usr/ucb/ps can merge columns together.\n\n");
- printf("Columns are:\n");
- printf("\tS - State of process - see 'ps' man page\n");
- printf("\tUID - UID of the process owner\n");
- printf("\tPID - PID of the process\n");
- printf("\tPPID - PID of the parent process\n");
- printf("\tVSZ - Virtual memory usage (kilobytes)\n");
- printf("\tRSS - Real memory usage (kilobytes)\n");
- printf("\t%%CPU - CPU usage\n");
- printf("\tCOMMAND - Command being run\n");
- printf("\tARGS - Full command line with arguments\n");
- return;
+ printf("%s: Help output\n\n", szProg);
+ printf("If this program is given any arguments, this help is displayed.\n");
+ printf("This command is used to print out the full command line for all\n");
+ printf("running processes because /usr/bin/ps is limited to 80 chars and\n");
+ printf("/usr/ucb/ps can merge columns together.\n\n");
+ printf("Columns are:\n");
+ printf("\tS - State of process - see 'ps' man page\n");
+ printf("\tUID - UID of the process owner\n");
+ printf("\tPID - PID of the process\n");
+ printf("\tPPID - PID of the parent process\n");
+ printf("\tVSZ - Virtual memory usage (kilobytes)\n");
+ printf("\tRSS - Real memory usage (kilobytes)\n");
+ printf("\t%%CPU - CPU usage\n");
+ printf("\tCOMMAND - Command being run\n");
+ printf("\tARGS - Full command line with arguments\n");
+ return;
}
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