diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | THANKS.in | 2 | ||||
-rw-r--r-- | plugins/check_apt.c | 10 | ||||
-rw-r--r-- | plugins/check_http.c | 4 | ||||
-rw-r--r-- | plugins/check_nt.c | 16 | ||||
-rw-r--r-- | plugins/check_ntp_peer.c | 32 | ||||
-rw-r--r-- | plugins/check_smtp.c | 26 | ||||
-rw-r--r-- | plugins/t/check_http.t | 11 |
9 files changed, 58 insertions, 45 deletions
@@ -191,6 +191,7 @@ NP-VERSION-FILE /plugins/.libs /plugins/Makefile /plugins/Makefile.in +/plugins/libnpcommon.a /plugins/negate /plugins/stamp-h* /plugins/urlize @@ -4,6 +4,7 @@ This file documents the major additions and syntax changes between releases. ENHANCEMENTS New check_dbi plugin for checking an (SQL) database using DBI Let OpenSSL load its configuration file (see the OPENSSL_config(3) man page) + Add performance data to check_apt Add performance data to check_procs Added -4/-6 options to check_dig (Ville Mattila) New check_oracle --connect option to perform real login @@ -280,3 +280,5 @@ Alex Bradley Brian De Wolf Richard Leitner Diego Elio Pettenò +Vaclav Ovsik +Roman Fiedler diff --git a/plugins/check_apt.c b/plugins/check_apt.c index 7ec2d55a..daeb7578 100644 --- a/plugins/check_apt.c +++ b/plugins/check_apt.c @@ -112,11 +112,11 @@ int main (int argc, char **argv) { result = max_state(result, STATE_CRITICAL); } else if(packages_available > 0){ result = max_state(result, STATE_WARNING); - } else { - result = max_state(result, STATE_OK); + } else if(result > STATE_UNKNOWN){ + result = STATE_UNKNOWN; } - printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s\n"), + printf(_("APT %s: %d packages available for %s (%d critical updates). %s%s%s%s|available_upgrades=%d;;;0 critical_updates=%d;;;0\n"), state_text(result), packages_available, (upgrade==DIST_UPGRADE)?"dist-upgrade":"upgrade", @@ -124,7 +124,9 @@ int main (int argc, char **argv) { (stderr_warning)?" warnings detected":"", (stderr_warning && exec_warning)?",":"", (exec_warning)?" errors detected":"", - (stderr_warning||exec_warning)?". run with -v for information.":"" + (stderr_warning||exec_warning)?". run with -v for information.":"", + packages_available, + sec_count ); return result; diff --git a/plugins/check_http.c b/plugins/check_http.c index 9231a559..110875d6 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c @@ -43,7 +43,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "base64.h" #include <ctype.h> -#define INPUT_DELIMITER ";" #define STICKY_NONE 0 #define STICKY_HOST 1 #define STICKY_PORT 2 @@ -854,8 +853,7 @@ check_http (void) /* optionally send any other header tag */ if (http_opt_headers_count) { for (i = 0; i < http_opt_headers_count ; i++) { - for ((pos = strtok(http_opt_headers[i], INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) - xasprintf (&buf, "%s%s\r\n", buf, pos); + xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); } /* This cannot be free'd here because a redirection will then try to access this and segfault */ /* Covered in a testcase in tests/check_http.t */ diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 89c4d8d3..52bbd1c5 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c @@ -94,6 +94,7 @@ int main(int argc, char **argv){ char *description=NULL,*counter_unit = NULL; char *minval = NULL, *maxval = NULL, *errcvt = NULL; char *fds=NULL, *tds=NULL; + char *numstr; double total_disk_space=0; double free_disk_space=0; @@ -265,7 +266,10 @@ int main(int argc, char **argv){ xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list); fetch_data (server_address, server_port, send_buffer); - return_code=atoi(strtok(recv_buffer,"&")); + numstr = strtok(recv_buffer,"&"); + if (numstr == NULL) + die(STATE_UNKNOWN, _("could not fetch information from server\n")); + return_code=atoi(numstr); temp_string=strtok(NULL,"&"); output_message = strdup (temp_string); } @@ -275,8 +279,14 @@ int main(int argc, char **argv){ xasprintf(&send_buffer,"%s&7", req_password); fetch_data (server_address, server_port, send_buffer); - mem_commitLimit=atof(strtok(recv_buffer,"&")); - mem_commitByte=atof(strtok(NULL,"&")); + numstr = strtok(recv_buffer,"&"); + if (numstr == NULL) + die(STATE_UNKNOWN, _("could not fetch information from server\n")); + mem_commitLimit=atof(numstr); + numstr = strtok(NULL,"&"); + if (numstr == NULL) + die(STATE_UNKNOWN, _("could not fetch information from server\n")); + mem_commitByte=atof(numstr); percent_used_space = (mem_commitByte / mem_commitLimit) * 100; warning_used_space = ((float)warning_value / 100) * mem_commitLimit; critical_used_space = ((float)critical_value / 100) * mem_commitLimit; diff --git a/plugins/check_ntp_peer.c b/plugins/check_ntp_peer.c index b59c056d..76152e17 100644 --- a/plugins/check_ntp_peer.c +++ b/plugins/check_ntp_peer.c @@ -241,15 +241,19 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji 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); - DBG(printf("recieving READSTAT response")) - if(read(conn, &req, SIZEOF_NTPCM(req)) == -1) - die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n"); - DBG(print_ntp_control_message(&req)); - /* discard obviously invalid packets */ - if (ntohs(req.count) > MAX_CM_SIZE) - die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); + + do { + /* Attempt to read the largest size packet possible */ + req.count=htons(MAX_CM_SIZE); + DBG(printf("recieving READSTAT response")) + if(read(conn, &req, SIZEOF_NTPCM(req)) == -1) + die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n"); + DBG(print_ntp_control_message(&req)); + /* discard obviously invalid packets */ + if (ntohs(req.count) > MAX_CM_SIZE) + die(STATE_CRITICAL, "NTP CRITICAL: Invalid packet received from NTP server\n"); + } while (!(req.op&OP_READSTAT && ntohs(req.seq) == 1)); + if (LI(req.flags) == LI_ALARM) li_alarm = 1; /* Each peer identifier is 4 bytes in the data section, which * we represent as a ntp_assoc_status_pair datatype. @@ -312,10 +316,12 @@ int ntp_request(const char *host, double *offset, int *offset_result, double *ji write(conn, &req, SIZEOF_NTPCM(req)); DBG(print_ntp_control_message(&req)); - req.count = htons(MAX_CM_SIZE); - DBG(printf("receiving READVAR response...\n")); - read(conn, &req, SIZEOF_NTPCM(req)); - DBG(print_ntp_control_message(&req)); + do { + req.count = htons(MAX_CM_SIZE); + DBG(printf("receiving READVAR response...\n")); + read(conn, &req, SIZEOF_NTPCM(req)); + DBG(print_ntp_control_message(&req)); + } while (!(req.op&OP_READVAR && ntohs(req.seq) == 2)); if(!(req.op&REM_ERROR)) xasprintf(&data, "%s%s", data, req.data); diff --git a/plugins/check_smtp.c b/plugins/check_smtp.c index 79fa4824..d477a51e 100644 --- a/plugins/check_smtp.c +++ b/plugins/check_smtp.c @@ -99,9 +99,9 @@ char **responses = NULL; char *authtype = NULL; char *authuser = NULL; char *authpass = NULL; -int warning_time = 0; +double warning_time = 0; int check_warning_time = FALSE; -int critical_time = 0; +double critical_time = 0; int check_critical_time = FALSE; int verbose = 0; int use_ssl = FALSE; @@ -417,9 +417,9 @@ main (int argc, char **argv) elapsed_time = (double)microsec / 1.0e6; if (result == STATE_OK) { - if (check_critical_time && elapsed_time > (double) critical_time) + if (check_critical_time && elapsed_time > critical_time) result = STATE_CRITICAL; - else if (check_warning_time && elapsed_time > (double) warning_time) + else if (check_warning_time && elapsed_time > warning_time) result = STATE_WARNING; } @@ -552,21 +552,19 @@ process_arguments (int argc, char **argv) nresponses++; break; case 'c': /* critical time threshold */ - if (is_intnonneg (optarg)) { - critical_time = atoi (optarg); - check_critical_time = TRUE; - } + if (!is_nonnegative (optarg)) + usage4 (_("Critical time must be a positive")); else { - usage4 (_("Critical time must be a positive integer")); + critical_time = strtod (optarg, NULL); + check_critical_time = TRUE; } break; case 'w': /* warning time threshold */ - if (is_intnonneg (optarg)) { - warning_time = atoi (optarg); - check_warning_time = TRUE; - } + if (!is_nonnegative (optarg)) + usage4 (_("Warning time must be a positive")); else { - usage4 (_("Warning time must be a positive integer")); + warning_time = strtod (optarg, NULL); + check_warning_time = TRUE; } break; case 'v': /* verbose */ diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 0a25c775..6299791f 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t @@ -8,7 +8,7 @@ use strict; use Test::More; use NPTest; -plan tests => 28; +plan tests => 27; my $successOutput = '/OK.*HTTP.*second/'; @@ -45,14 +45,9 @@ cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" ); like( $res->output, $successOutput, "Output OK" ); $res = NPTest->testCmd( - "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here'" + "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'" ); -like( $res->output, '/bob:there\r\nfred:here\r\n/', "Got headers, delimited with ';'" ); - -$res = NPTest->testCmd( - "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here' -k 'carl:frown'" - ); -like( $res->output, '/bob:there\r\nfred:here\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); +like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" ); $res = NPTest->testCmd( "./check_http $host_nonresponsive -wt 1 -ct 2" |