]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: Add hostname sample fetch
authorNenad Merdanovic <nmerdan@haproxy.com>
Sun, 12 Mar 2017 21:00:00 +0000 (22:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 13 Mar 2017 17:26:05 +0000 (18:26 +0100)
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 <nmerdan@haproxy.com>
doc/configuration.txt
src/sample.c

index 78f0f134eb2a5bdd4898c768735a3f516726e06e..3ca40c3a6c5a6474d547c28fe05779c88710800c 100644 (file)
@@ -13025,6 +13025,9 @@ fe_sess_rate([<frontend>]) : integer
             tcp-request content accept if ! too_fast
             tcp-request content accept if WAIT_END
 
+hostname : string
+  Returns the system hostname.
+
 int(<integer>) : signed integer
   Returns a signed integer.
 
index 3cbe76279f38eaf0b186dc9929d9597bd09e918a..014913d74d2918174dff16a4d22e696969e5ca95 100644 (file)
@@ -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 },