diff options
author | Gergely Nagy <algernon@balabit.hu> | 2012-03-21 12:57:19 +0100 |
---|---|---|
committer | Gergely Nagy <algernon@balabit.hu> | 2012-03-21 12:57:19 +0100 |
commit | dcea6d50ba8cfd7985c5628a20ce19f0b9ce9993 (patch) | |
tree | a7c0f6e25114bb42fd6fdc92850c692ab4cbcd92 /lib | |
parent | 70e16501eae0d5990df75d6a57f60cb827754d74 (diff) | |
download | libumberlog-dcea6d50ba8cfd7985c5628a20ce19f0b9ce9993.tar.gz libumberlog-dcea6d50ba8cfd7985c5628a20ce19f0b9ce9993.tar.xz libumberlog-dcea6d50ba8cfd7985c5628a20ce19f0b9ce9993.zip |
Include the hostname in the JSON payload.
Include the hostname (as returned by gethostname()) in the JSON
payload. Test case updated to verify this.
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cee-syslog.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/cee-syslog.c b/lib/cee-syslog.c index bac8435..6ad7abb 100644 --- a/lib/cee-syslog.c +++ b/lib/cee-syslog.c @@ -37,6 +37,7 @@ #include <stdlib.h> #include <string.h> #include <syslog.h> +#include <limits.h> #include "cee-syslog.h" @@ -56,6 +57,7 @@ static __thread struct uid_t uid; gid_t gid; const char *ident; + char hostname[HOST_NAME_MAX + 1]; } cee_sys_settings; static void @@ -77,6 +79,8 @@ cee_openlog (const char *ident, int option, int facility) cee_sys_settings.gid = getgid (); cee_sys_settings.uid = getuid (); cee_sys_settings.ident = ident; + + gethostname (cee_sys_settings.hostname, HOST_NAME_MAX); } /** HELPERS **/ @@ -137,6 +141,14 @@ _get_gid (void) return cee_sys_settings.gid; } +static inline const char * +_get_hostname (void) +{ + if (cee_sys_settings.flags & LOG_CEE_NOCACHE) + gethostname (cee_sys_settings.hostname, HOST_NAME_MAX); + return cee_sys_settings.hostname; +} + static struct json_object * _cee_json_vappend (struct json_object *json, va_list ap) { @@ -179,6 +191,7 @@ _cee_discover (struct json_object *jo, int priority) "program", "%s", cee_sys_settings.ident, "uid", "%d", _get_uid (), "gid", "%d", _get_gid (), + "host", "%s", _get_hostname (), NULL); } |