diff options
| -rw-r--r-- | configure.ac | 28 | ||||
| -rw-r--r-- | lib/utils_cmd.c | 12 | ||||
| -rw-r--r-- | lib/utils_cmd.h | 4 | ||||
| -rw-r--r-- | plugins-root/check_icmp.c | 11 | ||||
| -rw-r--r-- | plugins/check_by_ssh.c | 34 | ||||
| -rw-r--r-- | plugins/check_smtp.c | 1 |
6 files changed, 53 insertions, 37 deletions
diff --git a/configure.ac b/configure.ac index 2bf94014..abd90413 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -205,32 +205,46 @@ fi | |||
| 205 | dnl Check for PostgreSQL libraries | 205 | dnl Check for PostgreSQL libraries |
| 206 | _SAVEDLIBS="$LIBS" | 206 | _SAVEDLIBS="$LIBS" |
| 207 | _SAVEDCPPFLAGS="$CPPFLAGS" | 207 | _SAVEDCPPFLAGS="$CPPFLAGS" |
| 208 | case $host in | ||
| 209 | *openbsd*) | ||
| 210 | _CRYPTLIB="crypto" | ||
| 211 | ;; | ||
| 212 | *) | ||
| 213 | _CRYPTLIB="crypt" | ||
| 214 | esac | ||
| 215 | |||
| 208 | AC_ARG_WITH(pgsql, | 216 | AC_ARG_WITH(pgsql, |
| 209 | ACX_HELP_STRING([--with-pgsql=DIR], | 217 | ACX_HELP_STRING([--with-pgsql=DIR], |
| 210 | [sets path to pgsql installation]), | 218 | [sets path to pgsql installation]), |
| 211 | PGSQL=$withval,) | 219 | PGSQL=$withval,) |
| 212 | AC_CHECK_LIB(crypt,main) | 220 | AC_CHECK_LIB(crypt,main) |
| 213 | if test "$ac_cv_lib_crypt_main" = "yes" -a "x$PGSQL" != "xno"; then | 221 | AC_CHECK_LIB(crypto,main) |
| 222 | if test \( "$ac_cv_lib_crypt_main" = "yes" -o "$ac_cv_lib_crypto_main" = "yes" \) -a "x$PGSQL" != "xno"; then | ||
| 214 | if test -n "$PGSQL"; then | 223 | if test -n "$PGSQL"; then |
| 215 | LDFLAGS="$LDFLAGS -L$PGSQL/lib" | 224 | LDFLAGS="$LDFLAGS -L$PGSQL/lib" |
| 216 | CPPFLAGS="$CPPFLAGS -I$PGSQL/include" | 225 | CPPFLAGS="$CPPFLAGS -I$PGSQL/include" |
| 217 | fi | 226 | fi |
| 218 | AC_CHECK_LIB(pq,PQsetdbLogin,,,-lcrypt) | 227 | AC_CHECK_LIB(pq,PQsetdbLogin,,,"-l$_CRYPTLIB") |
| 219 | if test "$ac_cv_lib_pq_PQsetdbLogin" = "yes"; then | 228 | if test "$ac_cv_lib_pq_PQsetdbLogin" = "yes"; then |
| 220 | AC_CHECK_HEADERS(pgsql/libpq-fe.h) | 229 | AC_CHECK_HEADERS(pgsql/libpq-fe.h) |
| 221 | AC_CHECK_HEADERS(postgresql/libpq-fe.h) | 230 | AC_CHECK_HEADERS(postgresql/libpq-fe.h) |
| 222 | AC_CHECK_HEADERS(libpq-fe.h) | 231 | AC_CHECK_HEADERS(libpq-fe.h) |
| 223 | if [[ -n "$PGSQL" -a "$ac_cv_header_libpq_fe_h" = "yes" ]]; then | 232 | if [[ -n "$PGSQL" -a "$ac_cv_header_libpq_fe_h" = "yes" ]]; then |
| 224 | PGLIBS="-L$PGSQL/lib -lpq -lcrypt" | 233 | PGLIBS="-L$PGSQL/lib -lpq -l$_CRYPTLIB" |
| 225 | PGINCLUDE="-I$PGSQL/include" | 234 | PGINCLUDE="-I$PGSQL/include" |
| 226 | elif test "$ac_cv_header_pgsql_libpq_fe_h" = "yes"; then | 235 | elif test "$ac_cv_header_pgsql_libpq_fe_h" = "yes"; then |
| 227 | PGLIBS="-lpq -lcrypt" | 236 | PGLIBS="-lpq -l$_CRYPTLIB" |
| 228 | PGINCLUDE="-I/usr/include/pgsql" | 237 | PGINCLUDE="-I/usr/include/pgsql" |
| 229 | elif test "$ac_cv_header_postgresql_libpq_fe_h" = "yes"; then | 238 | elif test "$ac_cv_header_postgresql_libpq_fe_h" = "yes"; then |
| 230 | PGLIBS="-L$PGSQL/lib -lpq -lcrypt" | 239 | PGLIBS="-L$PGSQL/lib -lpq -l$_CRYPTLIB" |
| 231 | PGINCLUDE="-I/usr/include/postgresql" | 240 | case $host in |
| 241 | *openbsd*) | ||
| 242 | PGINCLUDE="-I$PGSQL/include/postgresql" ;; | ||
| 243 | *) | ||
| 244 | PGINCLUDE="-I/usr/include/postgresql" | ||
| 245 | esac | ||
| 232 | elif test "$ac_cv_header_libpq_fe_h" = "yes"; then | 246 | elif test "$ac_cv_header_libpq_fe_h" = "yes"; then |
| 233 | PGLIBS="-L$PGSQL/lib -lpq -lcrypt" | 247 | PGLIBS="-L$PGSQL/lib -lpq -l$_CRYPTLIB" |
| 234 | PGINCLUDE="-I$PGSQL/include" | 248 | PGINCLUDE="-I$PGSQL/include" |
| 235 | fi | 249 | fi |
| 236 | if test -z "$PGINCLUDE"; then | 250 | if test -z "$PGINCLUDE"; then |
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 42c81793..23d42168 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
| @@ -489,14 +489,14 @@ cmd_run_result cmd_run2(const char *cmd_string, int flags) { | |||
| 489 | cmd_run_result result = { | 489 | cmd_run_result result = { |
| 490 | .cmd_error_code = 0, | 490 | .cmd_error_code = 0, |
| 491 | .error_code = 0, | 491 | .error_code = 0, |
| 492 | .stderr = | 492 | .err = |
| 493 | { | 493 | { |
| 494 | .buf = NULL, | 494 | .buf = NULL, |
| 495 | .buflen = 0, | 495 | .buflen = 0, |
| 496 | .line = NULL, | 496 | .line = NULL, |
| 497 | .lines = 0, | 497 | .lines = 0, |
| 498 | }, | 498 | }, |
| 499 | .stdout = | 499 | .out = |
| 500 | { | 500 | { |
| 501 | .buf = NULL, | 501 | .buf = NULL, |
| 502 | .buflen = 0, | 502 | .buflen = 0, |
| @@ -581,14 +581,14 @@ cmd_run_result cmd_run_array2(char *const *cmd, int flags) { | |||
| 581 | cmd_run_result result = { | 581 | cmd_run_result result = { |
| 582 | .cmd_error_code = 0, | 582 | .cmd_error_code = 0, |
| 583 | .error_code = 0, | 583 | .error_code = 0, |
| 584 | .stderr = | 584 | .err = |
| 585 | { | 585 | { |
| 586 | .buf = NULL, | 586 | .buf = NULL, |
| 587 | .buflen = 0, | 587 | .buflen = 0, |
| 588 | .line = NULL, | 588 | .line = NULL, |
| 589 | .lines = 0, | 589 | .lines = 0, |
| 590 | }, | 590 | }, |
| 591 | .stdout = | 591 | .out = |
| 592 | { | 592 | { |
| 593 | .buf = NULL, | 593 | .buf = NULL, |
| 594 | .buflen = 0, | 594 | .buflen = 0, |
| @@ -610,9 +610,9 @@ cmd_run_result cmd_run_array2(char *const *cmd, int flags) { | |||
| 610 | int pfd_err[2] = {cmd_open_result.stderr_pipe_fd[0], cmd_open_result.stderr_pipe_fd[1]}; | 610 | int pfd_err[2] = {cmd_open_result.stderr_pipe_fd[0], cmd_open_result.stderr_pipe_fd[1]}; |
| 611 | 611 | ||
| 612 | int_cmd_fetch_output2 tmp_stdout = _cmd_fetch_output2(pfd_out[0], flags); | 612 | int_cmd_fetch_output2 tmp_stdout = _cmd_fetch_output2(pfd_out[0], flags); |
| 613 | result.stdout = tmp_stdout.output_container; | 613 | result.out = tmp_stdout.output_container; |
| 614 | int_cmd_fetch_output2 tmp_stderr = _cmd_fetch_output2(pfd_err[0], flags); | 614 | int_cmd_fetch_output2 tmp_stderr = _cmd_fetch_output2(pfd_err[0], flags); |
| 615 | result.stderr = tmp_stderr.output_container; | 615 | result.err = tmp_stderr.output_container; |
| 616 | 616 | ||
| 617 | result.cmd_error_code = _cmd_close(file_descriptor); | 617 | result.cmd_error_code = _cmd_close(file_descriptor); |
| 618 | return result; | 618 | return result; |
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index d3a8f14f..04a624b8 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h | |||
| @@ -24,8 +24,8 @@ int cmd_file_read(const char *, output *, int); | |||
| 24 | typedef struct { | 24 | typedef struct { |
| 25 | int error_code; | 25 | int error_code; |
| 26 | int cmd_error_code; | 26 | int cmd_error_code; |
| 27 | output stdout; | 27 | output out; |
| 28 | output stderr; | 28 | output err; |
| 29 | } cmd_run_result; | 29 | } cmd_run_result; |
| 30 | cmd_run_result cmd_run2(const char *cmd, int flags); | 30 | cmd_run_result cmd_run2(const char *cmd, int flags); |
| 31 | cmd_run_result cmd_run_array2(char * const *cmd, int flags); | 31 | cmd_run_result cmd_run_array2(char * const *cmd, int flags); |
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index d46d2ccc..35cae3ed 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c | |||
| @@ -54,6 +54,9 @@ const char *email = "devel@monitoring-plugins.org"; | |||
| 54 | #endif | 54 | #endif |
| 55 | 55 | ||
| 56 | #include <sys/time.h> | 56 | #include <sys/time.h> |
| 57 | #if defined(SIOCGIFADDR) | ||
| 58 | #include <sys/ioctl.h> | ||
| 59 | #endif /* SIOCGIFADDR */ | ||
| 57 | #include <errno.h> | 60 | #include <errno.h> |
| 58 | #include <signal.h> | 61 | #include <signal.h> |
| 59 | #include <ctype.h> | 62 | #include <ctype.h> |
| @@ -146,7 +149,7 @@ static get_timevar_wrapper get_timevar(const char *str); | |||
| 146 | static time_t get_timevaldiff(struct timeval earlier, struct timeval later); | 149 | static time_t get_timevaldiff(struct timeval earlier, struct timeval later); |
| 147 | static time_t get_timevaldiff_to_now(struct timeval earlier); | 150 | static time_t get_timevaldiff_to_now(struct timeval earlier); |
| 148 | 151 | ||
| 149 | static in_addr_t get_ip_address(const char *ifname); | 152 | static in_addr_t get_ip_address(const char *ifname, const int icmp_sock); |
| 150 | static void set_source_ip(char *arg, int icmp_sock, sa_family_t addr_family); | 153 | static void set_source_ip(char *arg, int icmp_sock, sa_family_t addr_family); |
| 151 | 154 | ||
| 152 | /* Receiving data */ | 155 | /* Receiving data */ |
| @@ -1769,7 +1772,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil | |||
| 1769 | memset(&src, 0, sizeof(src)); | 1772 | memset(&src, 0, sizeof(src)); |
| 1770 | src.sin_family = addr_family; | 1773 | src.sin_family = addr_family; |
| 1771 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) { | 1774 | if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) { |
| 1772 | src.sin_addr.s_addr = get_ip_address(arg); | 1775 | src.sin_addr.s_addr = get_ip_address(arg, icmp_sock); |
| 1773 | } | 1776 | } |
| 1774 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) { | 1777 | if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) { |
| 1775 | crash("Cannot bind to IP address %s", arg); | 1778 | crash("Cannot bind to IP address %s", arg); |
| @@ -1777,7 +1780,7 @@ static void set_source_ip(char *arg, const int icmp_sock, sa_family_t addr_famil | |||
| 1777 | } | 1780 | } |
| 1778 | 1781 | ||
| 1779 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ | 1782 | /* TODO: Move this to netutils.c and also change check_dhcp to use that. */ |
| 1780 | static in_addr_t get_ip_address(const char *ifname) { | 1783 | static in_addr_t get_ip_address(const char *ifname, const int icmp_sock) { |
| 1781 | // TODO: Rewrite this so the function return an error and we exit somewhere else | 1784 | // TODO: Rewrite this so the function return an error and we exit somewhere else |
| 1782 | struct sockaddr_in ip_address; | 1785 | struct sockaddr_in ip_address; |
| 1783 | ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy | 1786 | ip_address.sin_addr.s_addr = 0; // Fake initialization to make compiler happy |
| @@ -1792,7 +1795,7 @@ static in_addr_t get_ip_address(const char *ifname) { | |||
| 1792 | crash("Cannot determine IP address of interface %s", ifname); | 1795 | crash("Cannot determine IP address of interface %s", ifname); |
| 1793 | } | 1796 | } |
| 1794 | 1797 | ||
| 1795 | memcpy(&ip, &ifr.ifr_addr, sizeof(ip)); | 1798 | memcpy(&ip_address, &ifr.ifr_addr, sizeof(ip_address)); |
| 1796 | #else | 1799 | #else |
| 1797 | (void)ifname; | 1800 | (void)ifname; |
| 1798 | errno = 0; | 1801 | errno = 0; |
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index df8907d9..7ffa0ded 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
| @@ -98,7 +98,7 @@ int main(int argc, char **argv) { | |||
| 98 | if (child_result.cmd_error_code == 255 && config.unknown_timeout) { | 98 | if (child_result.cmd_error_code == 255 && config.unknown_timeout) { |
| 99 | mp_subcheck sc_ssh_execution = mp_subcheck_init(); | 99 | mp_subcheck sc_ssh_execution = mp_subcheck_init(); |
| 100 | xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s", | 100 | xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s", |
| 101 | child_result.stderr.lines > 0 ? child_result.stderr.line[0] | 101 | child_result.err.lines > 0 ? child_result.err.line[0] |
| 102 | : "(no error output)"); | 102 | : "(no error output)"); |
| 103 | 103 | ||
| 104 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); | 104 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); |
| @@ -107,34 +107,34 @@ int main(int argc, char **argv) { | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | if (verbose) { | 109 | if (verbose) { |
| 110 | for (size_t i = 0; i < child_result.stdout.lines; i++) { | 110 | for (size_t i = 0; i < child_result.out.lines; i++) { |
| 111 | printf("stdout: %s\n", child_result.stdout.line[i]); | 111 | printf("stdout: %s\n", child_result.out.line[i]); |
| 112 | } | 112 | } |
| 113 | for (size_t i = 0; i < child_result.stderr.lines; i++) { | 113 | for (size_t i = 0; i < child_result.err.lines; i++) { |
| 114 | printf("stderr: %s\n", child_result.stderr.line[i]); | 114 | printf("stderr: %s\n", child_result.err.line[i]); |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | size_t skip_stdout = 0; | 118 | size_t skip_stdout = 0; |
| 119 | if (config.skip_stdout) { /* --skip-stdout specified without argument */ | 119 | if (config.skip_stdout) { /* --skip-stdout specified without argument */ |
| 120 | skip_stdout = child_result.stdout.lines; | 120 | skip_stdout = child_result.out.lines; |
| 121 | } else { | 121 | } else { |
| 122 | skip_stdout = config.stdout_lines_to_ignore; | 122 | skip_stdout = config.stdout_lines_to_ignore; |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | size_t skip_stderr = 0; | 125 | size_t skip_stderr = 0; |
| 126 | if (config.skip_stderr) { /* --skip-stderr specified without argument */ | 126 | if (config.skip_stderr) { /* --skip-stderr specified without argument */ |
| 127 | skip_stderr = child_result.stderr.lines; | 127 | skip_stderr = child_result.err.lines; |
| 128 | } else { | 128 | } else { |
| 129 | skip_stderr = config.sterr_lines_to_ignore; | 129 | skip_stderr = config.sterr_lines_to_ignore; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | /* Allow UNKNOWN or WARNING state for (non-skipped) output found on stderr */ | 132 | /* Allow UNKNOWN or WARNING state for (non-skipped) output found on stderr */ |
| 133 | if (child_result.stderr.lines > skip_stderr && | 133 | if (child_result.err.lines > skip_stderr && |
| 134 | (config.unknown_on_stderr || config.warn_on_stderr)) { | 134 | (config.unknown_on_stderr || config.warn_on_stderr)) { |
| 135 | mp_subcheck sc_stderr = mp_subcheck_init(); | 135 | mp_subcheck sc_stderr = mp_subcheck_init(); |
| 136 | xasprintf(&sc_stderr.output, "remote command execution failed: %s", | 136 | xasprintf(&sc_stderr.output, "remote command execution failed: %s", |
| 137 | child_result.stderr.line[skip_stderr]); | 137 | child_result.err.line[skip_stderr]); |
| 138 | 138 | ||
| 139 | if (config.unknown_on_stderr) { | 139 | if (config.unknown_on_stderr) { |
| 140 | sc_stderr = mp_set_subcheck_state(sc_stderr, STATE_UNKNOWN); | 140 | sc_stderr = mp_set_subcheck_state(sc_stderr, STATE_UNKNOWN); |
| @@ -154,10 +154,10 @@ int main(int argc, char **argv) { | |||
| 154 | mp_subcheck sc_active_check = mp_subcheck_init(); | 154 | mp_subcheck sc_active_check = mp_subcheck_init(); |
| 155 | xasprintf(&sc_active_check.output, "command stdout:"); | 155 | xasprintf(&sc_active_check.output, "command stdout:"); |
| 156 | 156 | ||
| 157 | if (child_result.stdout.lines > skip_stdout) { | 157 | if (child_result.out.lines > skip_stdout) { |
| 158 | for (size_t i = skip_stdout; i < child_result.stdout.lines; i++) { | 158 | for (size_t i = skip_stdout; i < child_result.out.lines; i++) { |
| 159 | xasprintf(&sc_active_check.output, "%s\n%s", sc_active_check.output, | 159 | xasprintf(&sc_active_check.output, "%s\n%s", sc_active_check.output, |
| 160 | child_result.stdout.line[i]); | 160 | child_result.out.line[i]); |
| 161 | } | 161 | } |
| 162 | } else { | 162 | } else { |
| 163 | xasprintf(&sc_active_check.output, "remote command '%s' returned status %d", | 163 | xasprintf(&sc_active_check.output, "remote command '%s' returned status %d", |
| @@ -209,10 +209,10 @@ int main(int argc, char **argv) { | |||
| 209 | char *status_text; | 209 | char *status_text; |
| 210 | int cresult; | 210 | int cresult; |
| 211 | mp_subcheck sc_parse_passive = mp_subcheck_init(); | 211 | mp_subcheck sc_parse_passive = mp_subcheck_init(); |
| 212 | for (size_t i = skip_stdout; i < child_result.stdout.lines; i++) { | 212 | for (size_t i = skip_stdout; i < child_result.out.lines; i++) { |
| 213 | status_text = child_result.stdout.line[i++]; | 213 | status_text = child_result.out.line[i++]; |
| 214 | if (i == child_result.stdout.lines || | 214 | if (i == child_result.out.lines || |
| 215 | strstr(child_result.stdout.line[i], "STATUS CODE: ") == NULL) { | 215 | strstr(child_result.out.line[i], "STATUS CODE: ") == NULL) { |
| 216 | 216 | ||
| 217 | sc_parse_passive = mp_set_subcheck_state(sc_parse_passive, STATE_UNKNOWN); | 217 | sc_parse_passive = mp_set_subcheck_state(sc_parse_passive, STATE_UNKNOWN); |
| 218 | xasprintf(&sc_parse_passive.output, "failed to parse output"); | 218 | xasprintf(&sc_parse_passive.output, "failed to parse output"); |
| @@ -221,7 +221,7 @@ int main(int argc, char **argv) { | |||
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | if (config.service[commands] && status_text && | 223 | if (config.service[commands] && status_text && |
| 224 | sscanf(child_result.stdout.line[i], "STATUS CODE: %d", &cresult) == 1) { | 224 | sscanf(child_result.out.line[i], "STATUS CODE: %d", &cresult) == 1) { |
| 225 | fprintf(output_file, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, | 225 | fprintf(output_file, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, |
| 226 | config.host_shortname, config.service[commands++], cresult, status_text); | 226 | config.host_shortname, config.service[commands++], cresult, status_text); |
| 227 | } | 227 | } |
diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index e806ad29..e8c35f58 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c | |||
| @@ -37,7 +37,6 @@ | |||
| 37 | #include "base64.h" | 37 | #include "base64.h" |
| 38 | #include "regex.h" | 38 | #include "regex.h" |
| 39 | 39 | ||
| 40 | #include <bits/getopt_ext.h> | ||
| 41 | #include <ctype.h> | 40 | #include <ctype.h> |
| 42 | #include <string.h> | 41 | #include <string.h> |
| 43 | #include "check_smtp.d/config.h" | 42 | #include "check_smtp.d/config.h" |
