Skip to content

Commit

Permalink
Merge pull request #53 from ssahani/namespace
Browse files Browse the repository at this point in the history
Allow to send from journal namespace
  • Loading branch information
ssahani authored May 1, 2024
2 parents d685486 + 888ec05 commit 4a64666
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ systemd-netlogd reads configuration files named `/etc/systemd/netlogd.conf` and
Directory=
Takes a directory path. Specifies whether to operate on the specified journal directory DIR instead of the default runtime and system journal paths.

Optional settings
NameSpace=
Takes a journal namespace identifier string as argument. If not specified the data collected by the default namespace is shown. If specified
shows the log data of the specified namespace instead. If the namespace is specified as "*" data from all namespaces is shown, interleaved.
If the namespace identifier is prefixed with "+" data from the specified namespace and the default namespace is shown, interleaved, but no other

Optional settings

StructuredData=
Meta information about the syslog message, which can be used for Cloud Based
Expand Down
6 changes: 6 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ This will create a user systemd-journal-netlog
| Directory=
Takes a directory path. Specifies whether to operate on the specified journal directory DIR instead of the default runtime and system journal paths.
| NameSpace=
Takes a journal namespace identifier string as argument. If not specified the data collected by the default namespace is shown.
If specified shows the log data of the specified namespace instead. If the namespace is specified as "*" data from all namespaces
is shown, interleaved. If the namespace identifier is prefixed with "+" data from the specified namespace and the default namespace is shown,
interleaved, but no other.
| Optional settings
| StructuredData=
Expand Down
33 changes: 33 additions & 0 deletions src/netlog/netlog-conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,39 @@ int config_parse_log_format(const char *unit,
return 0;
}

int config_parse_namespace(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) {
Manager *m = userdata;

assert(filename);
assert(lvalue);
assert(rvalue);
assert(data);

if (streq(rvalue, "*"))
m->namespace_flags = SD_JOURNAL_ALL_NAMESPACES;
else if (startswith(rvalue, "+")) {
m->namespace_flags = SD_JOURNAL_INCLUDE_DEFAULT_NAMESPACE;
m->namespace = strdup(rvalue);
if (!m->namespace)
return log_oom();
} else {
m->namespace = strdup(rvalue);
if (!m->namespace)
return log_oom();
}

return 0;
}

int manager_parse_config_file(Manager *m) {
assert(m);

Expand Down
11 changes: 11 additions & 0 deletions src/netlog/netlog-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,15 @@ int config_parse_log_format(const char *unit,
void *data,
void *userdata);

int config_parse_namespace(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);

int manager_parse_config_file(Manager *m);
1 change: 1 addition & 0 deletions src/netlog/netlog-gperf.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Network.Address, config_parse_netlog_remote_address, 0, 0
Network.Protocol, config_parse_protocol, 0, offsetof(Manager, protocol)
Network.LogFormat, config_parse_log_format, 0, offsetof(Manager, log_format)
Network.Directory, config_parse_string, 0, offsetof(Manager, dir)
Network.NameSpace, config_parse_namespace, 0, offsetof(Manager, namespace)
Network.StructuredData, config_parse_string, 0, offsetof(Manager, structured_data)
Network.UseSysLogStructuredData, config_parse_bool, 0, offsetof(Manager, syslog_structured_data)
Network.UseSysLogMsgId, config_parse_bool, 0, offsetof(Manager, syslog_msgid)
5 changes: 4 additions & 1 deletion src/netlog/netlog-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ static int open_journal(Manager *m) {

if (m->dir)
r = sd_journal_open_directory(&m->journal, m->dir, 0);
else if (m->namespace)
r = sd_journal_open_namespace(&m->journal, m->namespace, SD_JOURNAL_LOCAL_ONLY | m->namespace_flags);
else
r = sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY);

Expand Down Expand Up @@ -472,6 +474,8 @@ void manager_free(Manager *m) {
free(m->current_cursor);

free(m->state_file);
free(m->dir);
free(m->namespace);

sd_event_source_unref(m->network_event_source);
sd_network_monitor_unref(m->network_monitor);
Expand All @@ -480,7 +484,6 @@ void manager_free(Manager *m) {
sd_event_source_unref(m->sigint_event);

sd_event_unref(m->event);

free(m);
}

Expand Down
6 changes: 5 additions & 1 deletion src/netlog/netlog-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ struct Manager {

/* journal */
int journal_watch_fd;
int namespace_flags;

sd_journal *journal;

char *state_file;
char *last_cursor, *current_cursor;
char *last_cursor;
char *current_cursor;
char *structured_data;
char *dir;
char *namespace;

SysLogTransmissionProtocol protocol;
SysLogTransmissionLogFormat log_format;
Expand Down

0 comments on commit 4a64666

Please sign in to comment.