From 66255f7bbf9dfa18545d96f87d7a0f6fb8684d1c Mon Sep 17 00:00:00 2001 From: Tim Duesterhus Date: Thu, 28 Oct 2021 17:24:02 +0200 Subject: [PATCH] MINOR: halog: Add support for extracting captures using -hdr This patch adds support for extracting captured header fields to halog. A field can be extracted by passing the `-hdr :` output filter. Both `` and `` are 1-indexed. `` refers to the index of the brace-delimited list of headers. If both request and response headers are captured, then request headers are referenced by ` = 1`, response headers are `2`. If only one direction is captured, there will only be a single block `1`. `` refers to a single field within the selected block. The output will contain one line, possibly empty, per log line processed. Passing a non-existent `` or `` will result in an empty line. Example: capture request header a len 50 capture request header b len 50 capture request header c len 50 capture response header d len 50 capture response header e len 50 capture response header f len 50 `-srv 1:1` will extract request header `a` `-srv 1:2` will extract request header `b` `-srv 1:3` will extract request header `c` `-srv 2:3` will extract response header `f` This resolves GitHub issue #1146. --- admin/halog/halog.c | 109 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 105 insertions(+), 4 deletions(-) diff --git a/admin/halog/halog.c b/admin/halog/halog.c index fe11aa81d..900cf5d46 100644 --- a/admin/halog/halog.c +++ b/admin/halog/halog.c @@ -119,6 +119,7 @@ struct url_stat { #define FILT2_TIMESTAMP 0x01 #define FILT2_PRESERVE_QUERY 0x02 +#define FILT2_EXTRACT_CAPTURE 0x04 unsigned int filter = 0; unsigned int filter2 = 0; @@ -139,6 +140,7 @@ void filter_count_term_codes(const char *accept_field, const char *time_field, s void filter_count_status(const char *accept_field, const char *time_field, struct timer **tptr); void filter_graphs(const char *accept_field, const char *time_field, struct timer **tptr); void filter_output_line(const char *accept_field, const char *time_field, struct timer **tptr); +void filter_extract_capture(const char *accept_field, const char *time_field, unsigned int, unsigned int); void filter_accept_holes(const char *accept_field, const char *time_field, struct timer **tptr); void usage(FILE *output, const char *msg) @@ -147,9 +149,11 @@ void usage(FILE *output, const char *msg) "%s" "Usage: halog [-h|--help] for long help\n" " halog [-q] [-c] [-m ]\n" - " {-cc|-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt|-ic}\n" + " {-cc|-gt|-pct|-st|-tc|-srv|-u|-uc|-ue|-ua|-ut|-uao|-uto|-uba|-ubt|-ic\n" + " |-hdr :\n" + " }\n" " [-s ] [-e|-E] [-H] [-rt|-RT