Skip to content

Commit 3fbf411

Browse files
authored
Merge pull request #1 from SKOV-DK/master
Add the possiblilty for configuring structured-data, so the systemd.n…
2 parents b3d18dc + a8333f8 commit 3fbf411

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ Create a user **systemd-journal-netlog**
2727

2828
The the address string format is similar to socket units. See systemd.socket(1)
2929

30+
Optional settings
31+
32+
StructuredData=
33+
Meta information about the syslog message, which can be used for Cloud Based
34+
syslog servers, such as Loggly
35+
3036
**EXAMPLE**
3137

3238
Example 1. /etc/systemd/systemd-netlogd.conf
@@ -38,3 +44,9 @@ Example 2. /etc/systemd/systemd-netlogd.conf
3844

3945
[Network]
4046
Address=192.168.8.101:514
47+
48+
Example 3. /etc/systemd/systemd-netlogd.conf
49+
50+
[Network]
51+
Address=192.168.8.101:514
52+
StructuredData=[1ab456b6-90bb-6578-abcd-5b734584aaaa@41058]

man/systemd-netlogd.conf.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@
8080
</para>
8181
</listitem>
8282
</varlistentry>
83+
<varlistentry>
84+
<term><varname>StructuredData=</varname></term>
85+
<listitem><para>Meta information about the syslog message,
86+
which can be used for Cloud Based syslog servers, such as Loggly</para>
87+
88+
<para>The StructureData is only an optional setting</para>
89+
</listitem>
90+
</varlistentry>
8391
</variablelist>
8492
</refsect1>
8593

@@ -103,6 +111,17 @@ Address=192.168.8.101:514
103111
</example>
104112
</refsect1>
105113

114+
<refsect1>
115+
<title>Example</title>
116+
<example>
117+
<title>/etc/systemd/systemd-netlogd.conf</title>
118+
<programlisting>[Network]
119+
Address=192.168.8.101:514
120+
StructuredData=[1ab456b6-90bb-6578-abcd-5b734584aaaa@41058]
121+
</programlisting>
122+
</example>
123+
</refsect1>
124+
106125
<refsect1>
107126
<title>See Also</title>
108127
<para>

src/conf-parser.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,41 @@ int config_parse_many(const char *conf_file,
458458
return 0; \
459459
} \
460460
struct __useless_struct_to_allow_trailing_semicolon__
461+
462+
int config_parse_string(
463+
const char *unit,
464+
const char *filename,
465+
unsigned line,
466+
const char *section,
467+
unsigned section_line,
468+
const char *lvalue,
469+
int ltype,
470+
const char *rvalue,
471+
void *data,
472+
void *userdata) {
473+
474+
char **s = data, *n;
475+
476+
assert(filename);
477+
assert(lvalue);
478+
assert(rvalue);
479+
assert(data);
480+
481+
if (!utf8_is_valid(rvalue)) {
482+
log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
483+
return 0;
484+
}
485+
486+
if (isempty(rvalue))
487+
n = NULL;
488+
else {
489+
n = strdup(rvalue);
490+
if (!n)
491+
return log_oom();
492+
}
493+
494+
free(*s);
495+
*s = n;
496+
497+
return 0;
498+
}

src/conf-parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ int config_parse_many(const char *conf_file, /* possibly NULL */
103103
bool relaxed,
104104
void *userdata);
105105

106+
/* Generic parsers */
107+
int config_parse_string(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
108+
106109
#define DEFINE_CONFIG_PARSE_ENUM(function,name,type,msg) \
107110
int function(const char *unit, \
108111
const char *filename, \

src/netlog-gperf.gperf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ struct ConfigPerfItem;
1616
%includes
1717
%%
1818
Network.Address, config_parse_netlog_remote_address, 0, 0
19+
Network.StructuredData, config_parse_string, 0, offsetof(Manager, structured_data)

src/netlog-manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct Manager {
5252
char *state_file;
5353

5454
char *last_cursor, *current_cursor;
55+
char *structured_data;
5556
};
5657

5758
int manager_new(Manager **ret, const char *state_file, const char *cursor);

src/netlog-network.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ int manager_push_to_network(Manager *m,
161161
IOVEC_SET_STRING(iov[n++], " ");
162162

163163
/* Eighth: [structured-data] */
164-
IOVEC_SET_STRING(iov[n++], RFC_5424_NILVALUE);
164+
if (m->structured_data)
165+
IOVEC_SET_STRING(iov[n++], m->structured_data);
166+
else
167+
IOVEC_SET_STRING(iov[n++], RFC_5424_NILVALUE);
168+
165169
IOVEC_SET_STRING(iov[n++], " ");
166170

167171
/* Ninth: message */

0 commit comments

Comments
 (0)