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 <nmerdan@haproxy.com>
diff --git a/doc/configuration.txt b/doc/configuration.txt
index 78f0f13..3ca40c3 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -13025,6 +13025,9 @@
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.
diff --git a/src/sample.c b/src/sample.c
index 3cbe762..014913d 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -2511,6 +2511,17 @@
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 @@
{ "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 },