Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to send log from a directory #52

Merged
merged 4 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Creating user:
sudo useradd -r -d / -s /usr/sbin/nologin -g systemd-journal systemd-journal-netlog
```
or via sysusers

``` /usr/lib/sysusers.d/systemd-netlogd.conf```
```bash
#Type Name ID GECOS Home directory Shell
Expand Down Expand Up @@ -63,7 +63,11 @@ systemd-netlogd reads configuration files named `/etc/systemd/netlogd.conf` and

LogFormat=
Specifies whether to use RFC 5424 format or RFC 3339 format. Takes one of rfc5424 or rfc3339. Defaults to rfc5424.
Optional settings

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

StructuredData=
Meta information about the syslog message, which can be used for Cloud Based
Expand Down
3 changes: 3 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ This will create a user systemd-journal-netlog
| LogFormat=
Specifies whether to use RFC 5424 format or RFC 3339 format. Takes one of rfc5424 or rfc3339. Defaults to rfc5424.

| 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

| StructuredData=
Expand Down
1 change: 1 addition & 0 deletions src/netlog/netlog-gperf.gperf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct ConfigPerfItem;
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.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)
24 changes: 19 additions & 5 deletions src/netlog/netlog-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,34 @@ static int manager_signal_event_handler(sd_event_source *event, const struct sig
return 0;
}

static int open_journal(Manager *m) {
int r;

assert(m);

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

if (r < 0)
log_error_errno(r, "Failed to open %s: %m", m->dir ?: "journal");

return 0;
}

static int manager_journal_monitor_listen(Manager *m) {
int r, events;

assert(m);

r = sd_journal_open(&m->journal, SD_JOURNAL_LOCAL_ONLY);
if (r < 0) {
log_error_errno(r, "Failed to open journal: %m");
r = open_journal(m);
if (r < 0)
return r;
}

sd_journal_set_data_threshold(m->journal, 0);

m->journal_watch_fd = sd_journal_get_fd(m->journal);
m->journal_watch_fd = sd_journal_get_fd(m->journal);
if (m->journal_watch_fd < 0)
return log_error_errno(m->journal_watch_fd, "Failed to get journal fd: %m");

Expand Down
1 change: 1 addition & 0 deletions src/netlog/netlog-manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct Manager {
char *state_file;
char *last_cursor, *current_cursor;
char *structured_data;
char *dir;

SysLogTransmissionProtocol protocol;
SysLogTransmissionLogFormat log_format;
Expand Down