Skip to content

Can't filter using "_SYSTEMD_UNIT" #36

@cryzed

Description

@cryzed

I want to monitor the journal of a running vpn-client unit. To do so I first used sudo journalctl -f --output=json to get an idea of the general structure of each entry's catalog (unimportant information truncated):

{
  "SYSLOG_IDENTIFIER" : "openvpn",
  "_COMM" : "openvpn",
  "_EXE" : "/usr/bin/openvpn",
  "_CMDLINE" : "/usr/sbin/openvpn --suppress-timestamps --nobind --config VPN.conf",
  "_SYSTEMD_CGROUP" : "/system.slice/system-openvpn\\x2dclient.slice/openvpn-client@VPN.service",
  "_SYSTEMD_UNIT" : "openvpn-client@VPN.service",
  "_SYSTEMD_SLICE" : "system-openvpn\\x2dclient.slice",
  "MESSAGE" : "...",
  "_PID" : "4586"
}

Based on this, I figured I could use .add_match(_SYSTEMD_UNIT='openvpn-client@VPN.service') as documented to get access to the corresponding journal.

However I can't seem to fetch and journal entries when doing so:

reader = systemd.journal.Reader()
reader.this_boot()
reader.add_match(_SYSTEMD_UNIT='openvpn-client@VPN.service')
for entry in reader:
    print(entry)

Will simply print nothing, while confusingly (to me) specifying the SYSLOG_IDENTIFIER instead will work:

reader = systemd.journal.Reader()
reader.this_boot()
reader.add_match(SYSLOG_IDENTIFIER='openvpn')
for entry in reader:
    print(entry)

However this fetches the entries of all openvpn journals, which I don't want. I also made sure using journalctl --boot --unit openvpn-client@VPN.service that journal entries matching the specified filter exist. (Removing the this_boot()-filter also doesn't lead to any entries being fetched).

Any advice?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions