diff --git a/doc/configuration.txt b/doc/configuration.txt index 10ccf2f3a..09dec9b59 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -20103,6 +20103,18 @@ thread : integer the function, between 0 and (global.nbthread-1). This is useful for logging and debugging purposes. +txn.sess_term_state : string + Retruns the TCP or HTTP session termination state, as reported in the log. It + is a 2-characters string, The final session state followed by the event which + caused its to terminate. See section 8.5 about session state at disconnection + for the list of possible events. The current value at time the sample fetch + is evaluated is returned. It is subject to change. Except used with ACLs in + "http-after-response" rule sets or in log messages, it will always be "--". + + Example: + # Return a 429-Too-Many-Requests if session timed out in queue + http-after-response set-status 429 if { txn.sess_term_state "sQ" } + uuid([]) : string Returns a UUID following the RFC4122 standard. If the version is not specified, a UUID version 4 (fully random) is returned. @@ -24050,6 +24062,7 @@ Please refer to the table below for currently defined variables : | | | %[ssl_fc_protocol] | string | +---+------+------------------------------------------------------+---------+ | | %ts | termination_state | string | + | | | %[txn.sess_term_state] | | +---+------+------------------------------------------------------+---------+ | H | %tsc | termination_state with cookie status | string | +---+------+------------------------------------------------------+---------+ diff --git a/include/haproxy/log.h b/include/haproxy/log.h index d36e1840f..68b820734 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -43,6 +43,9 @@ extern char default_https_log_format[]; extern char default_rfc5424_sd_log_format[]; +extern const char sess_term_cond[]; +extern const char sess_fin_state[]; + extern unsigned int dropped_logs; /* lof forward proxy list */ diff --git a/src/stream.c b/src/stream.c index 392dc79cc..9c4e9ad0b 100644 --- a/src/stream.c +++ b/src/stream.c @@ -3971,6 +3971,24 @@ static int smp_fetch_last_rule_line(const struct arg *args, struct sample *smp, return 1; } +static int smp_fetch_sess_term_state(const struct arg *args, struct sample *smp, const char *km, void *private) +{ + struct buffer *trash = get_trash_chunk(); + + smp->flags = SMP_F_VOLATILE; + smp->data.type = SMP_T_STR; + if (!smp->strm) + return 0; + + trash->area[trash->data++] = sess_term_cond[(smp->strm->flags & SF_ERR_MASK) >> SF_ERR_SHIFT]; + trash->area[trash->data++] = sess_fin_state[(smp->strm->flags & SF_FINST_MASK) >> SF_FINST_SHIFT]; + + smp->data.u.str = *trash; + smp->data.type = SMP_T_STR; + smp->flags &= ~SMP_F_CONST; + return 1; +} + /* Note: must not be declared as its list will be overwritten. * Please take care of keeping this list alphabetically sorted. */ @@ -3980,6 +3998,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { { "cur_tunnel_timeout", smp_fetch_cur_tunnel_timeout, 0, NULL, SMP_T_SINT, SMP_USE_BKEND, }, { "last_rule_file", smp_fetch_last_rule_file, 0, NULL, SMP_T_STR, SMP_USE_INTRN, }, { "last_rule_line", smp_fetch_last_rule_line, 0, NULL, SMP_T_SINT, SMP_USE_INTRN, }, + { "txn.sess_term_state",smp_fetch_sess_term_state, 0, NULL, SMP_T_STR, SMP_USE_INTRN, }, { NULL, NULL, 0, 0, 0 }, }};