svn commit: r526977 - in head/net-mgmt/nagios-plugins: . files
Craig Leres
leres at freebsd.org
Wed Feb 26 18:53:52 UTC 2020
On 2020-02-24 07:38, Mathieu Arnold wrote:
> Author: mat
> Date: Mon Feb 24 15:38:17 2020
> New Revision: 526977
> URL:https://svnweb.freebsd.org/changeset/ports/526977
>
> Log:
> Update to 2.3.2.
After upgrading I'm unable to get any of the -s, -r, or -R flags to work
with check_http:
# 2.3.1 works
fun 235 % pkg info nagios-plugins | fgrep Version
Version : 2.3.1,1
fun 236 % /usr/local/libexec/nagios/check_http -S -H www.freebsd.org
-s operating
HTTP OK: HTTP/1.1 200 OK - 26414 bytes in 0.393 second response time
|time=0.393414s;;;0.000000 size=26414B;;;0
# 2.3.2 fails
dot 241 % pkg info nagios-plugins | fgrep Version
Version : 2.3.2,1
dot 242 % /usr/local/libexec/nagios/check_http -S -H www.freebsd.org
-s operating
HTTP CRITICAL: HTTP/1.1 200 OK - string 'operating' not found on
'https://www.freebsd.org:443/' - 8195 bytes in 0.351 second response
time |time=0.350931s;;;0.000000 size=8195B;;;0
My guess was an upstream bug possibly related to this change:
* plugins/check_http.c: Resolve #507 - stop reading when
Content-Length matches the amount of content received
Prior to this commit, check_http relied on read() returning
0 or erroring in order to exit the loop. This commit keeps
the same behavior, but once headers have been received, it
also reads the Content-Length and compares it to the number
of bytes received after the start of the body.
While the change sounds reasonable when I add -v to check_http the
www.freebsd.org example gets 583 lines of content/body with 2.3.1 but
only 177 with 2.3.2. Reverting the changes to document_headers_done()
between 2.3.1 and 2.3.2 unbreaks this. I've attached a patch that does this.
Looks like only paying customers can file bug reports but I posted
something to the plugin dev forum:
https://support.nagios.com/forum/viewtopic.php?f=35&t=57665
Craig
-------------- next part --------------
--- plugins/check_http.c.orig 2020-02-20 19:14:52 UTC
+++ plugins/check_http.c
@@ -608,11 +608,9 @@ enable_ssl:
-/* Returns 0 if we're still retrieving the headers.
- * Otherwise, returns the length of the header (not including the final newlines)
- */
+/* Returns 1 if we're done processing the document body; 0 to keep going */
static int
-document_headers_done (const char *full_page)
+document_headers_done (char *full_page)
{
const char *body;
@@ -624,7 +622,8 @@ document_headers_done (const char *full_
if (!*body)
return 0; /* haven't read end of headers yet */
- return body - full_page;
+ full_page[body - full_page] = 0;
+ return 1;
}
static time_t
@@ -1014,10 +1013,6 @@ check_http (void)
char *page;
char *auth;
int http_status;
- int header_end;
- int content_length;
- int content_start;
- int seen_length;
int i = 0;
size_t pagesize = 0;
char *full_page;
@@ -1200,40 +1195,11 @@ check_http (void)
full_page = full_page_new;
pagesize += i;
- header_end = document_headers_done(full_page);
- if (header_end) {
+ if (no_body && document_headers_done (full_page)) {
i = 0;
break;
}
}
-
- if (no_body) {
- full_page[header_end] = '\0';
- }
- else {
- content_length = get_content_length(full_page);
-
- content_start = header_end + 1;
- while (full_page[content_start] == '\n' || full_page[content_start] == '\r') {
- content_start += 1;
- }
- seen_length = pagesize - content_start;
- /* Continue receiving the body until content-length is met */
- while (seen_length < content_length
- && (i = my_recv(buffer, MAX_INPUT_BUFFER-1) > 0)) {
-
- buffer[i] = '\0';
-
- if ((full_page_new = realloc(full_page, pagesize + i + 1)) == NULL)
- die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate memory for full_page\n"));
- memmove(&full_page_new[pagesize], buffer, i);
- full_page = full_page_new;
-
- pagesize += i;
- seen_length = pagesize - content_start;
- }
- }
-
microsec_transfer = deltime (tv_temp);
elapsed_time_transfer = (double)microsec_transfer / 1.0e6;
More information about the svn-ports-all
mailing list