From: Nenad Merdanovic Date: Sun, 12 Mar 2017 21:00:00 +0000 (+0100) Subject: MINOR: Add hostname sample fetch X-Git-Tag: v1.8-dev1~94 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=807a6e7856eb5fa88131e34e5a259684917c6d3f;p=thirdparty%2Fhaproxy.git MINOR: Add hostname sample fetch It adds "hostname" as a new sample fetch. It does exactly the same as "%H" in a log format except that it can be used outside of log formats. Signed-off-by: Nenad Merdanovic --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 78f0f134eb..3ca40c3a6c 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -13025,6 +13025,9 @@ fe_sess_rate([]) : integer tcp-request content accept if ! too_fast tcp-request content accept if WAIT_END +hostname : string + Returns the system hostname. + int() : signed integer Returns a signed integer. diff --git a/src/sample.c b/src/sample.c index 3cbe76279f..014913d74d 100644 --- a/src/sample.c +++ b/src/sample.c @@ -2511,6 +2511,17 @@ smp_fetch_date(const struct arg *args, struct sample *smp, const char *kw, void return 1; } +/* returns the hostname */ +static int +smp_fetch_hostname(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + smp->data.type = SMP_T_STR; + smp->flags = SMP_F_CONST; + smp->data.u.str.str = hostname; + smp->data.u.str.len = strlen(hostname); + return 1; +} + /* returns the number of processes */ static int smp_fetch_nbproc(const struct arg *args, struct sample *smp, const char *kw, void *private) @@ -2684,6 +2695,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { { "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_STR, SMP_USE_INTRN }, { "date", smp_fetch_date, ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_INTRN }, + { "hostname", smp_fetch_hostname, 0, NULL, SMP_T_STR, SMP_USE_INTRN }, { "nbproc", smp_fetch_nbproc,0, NULL, SMP_T_SINT, SMP_USE_INTRN }, { "proc", smp_fetch_proc, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, { "rand", smp_fetch_rand, ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_INTRN },