Open swetasgit opened 4 months ago
Pinging code owners:
receiver/journald: @sumo-drosiek @djaglowski
See Adding Labels via Comments if you do not have permissions to add labels yourself.
When I add transform, i start getting the message but strangely only SU message. I haven't added any filter at journals receiver end as when I use file exporter I get all journald logs but not in syslog server:
transform:
log_statements:
- context: log
statements:
- set(attributes["message"], body)
- context: log
Logs on syslog:
Aug 1 14:51:25 192.168.1.8 1072 <165>1 2024-08-01T09:21:20.85347Z - - - - - {"MESSAGE":"(to root) sweta on pts/1","PRIORITY":"5","SYSLOG_FACILITY":"4","SYSLOG_IDENTIFIER":"su","SYSLOG_PID":"6816","SYSLOG_TIMESTAMP":"Aug 1 14:51:20 ","_AUDIT_LOGINUID":"1000","_AUDIT_SESSION":"5","_BOOT_ID":"a4aae1ad370f427586f59b9f11140774","_CAP_EFFECTIVE":"1ffffffffff","_CMDLINE":"su -","_COMM":"su","_EXE":"/usr/bin/su","_GID":"1000","_HOSTNAME":"debian","_MACHINE_ID":"97f0f0c26cfa4e04bbb07a29a1800ab1","_PID":"6816","_RUNTIME_SCOPE":"system","_SELINUX_CONTEXT":"unconfined\n","_SOURCE_REALTIME_TIMESTAMP":"1722504080853417","_SYSTEMD_CGROUP":"/user.slice/user-1000.slice/session-5.scope","_SYSTEMD_INVOCATION_ID":"c4af78074a364d0491d562993d2d4f50","_SYSTEMD_OWNER_UID":"1000","_SYSTEMD_SESSION":"5","_SYSTEMD_SLICE":"user-1000.slice","_SYSTEMD_UNIT":"session-5.scope","_SYSTEMD_USER_SLICE":"-.slice","_TRANSPORT":"syslog","_UID":"1000","__CURSOR":"s=5e91832a0ef440de854b15cc2fd5f3fc;i=1034068;b=a4aae1ad370f427586f59b9f11140774;m=588fb0bf;t=61e9bbbdd09de;x=13b360bea81c1800","__MONOTONIC_TIMESTAMP":"1485811903"}
Aug 1 14:51:25 192.168.1.8 1128 <165>1 2024-08-01T09:21:20.856469Z - - - - - {"MESSAGE":"pam_unix(su-l:session): session opened for user root(uid=0) by sweta(uid=1000)","PRIORITY":"6","SYSLOG_FACILITY":"10","SYSLOG_IDENTIFIER":"su","SYSLOG_PID":"6816","SYSLOG_TIMESTAMP":"Aug 1 14:51:20 ","_AUDIT_LOGINUID":"1000","_AUDIT_SESSION":"5","_BOOT_ID":"a4aae1ad370f427586f59b9f11140774","_CAP_EFFECTIVE":"1ffffffffff","_CMDLINE":"su -","_COMM":"su","_EXE":"/usr/bin/su","_GID":"1000","_HOSTNAME":"debian","_MACHINE_ID":"97f0f0c26cfa4e04bbb07a29a1800ab1","_PID":"6816","_RUNTIME_SCOPE":"system","_SELINUX_CONTEXT":"unconfined\n","_SOURCE_REALTIME_TIMESTAMP":"1722504080853814","_SYSTEMD_CGROUP":"/user.slice/user-1000.slice/session-5.scope","_SYSTEMD_INVOCATION_ID":"c4af78074a364d0491d562993d2d4f50","_SYSTEMD_OWNER_UID":"1000","_SYSTEMD_SESSION":"5","_SYSTEMD_SLICE":"user-1000.slice","_SYSTEMD_UNIT":"session-5.scope","_SYSTEMD_USER_SLICE":"-.slice","_TRANSPORT":"syslog","_UID":"1000","__CURSOR":"s=5e91832a0ef440de854b15cc2fd5f3fc;i=1034069;b=a4aae1ad370f427586f59b9f11140774;m=588fbc76;t=61e9bbbdd1595;x=70242952deb0161c","__MONOTONIC_TIMESTAMP":"1485814902"}
Please suggest if there is any other way to export journald logs to syslog server format or do we have to use transform to get each attribute for RFC5424 https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/exporter/syslogexporter/README.md#rfc5424 ?
I was able to get some values using transform below:
transform:
error_mode: ignore
log_statements:
- context: log
statements:
- set(attributes["appname"], body["_COMM"])
- set(attributes["hostname"], body["_HOSTNAME"])
- set(attributes["message"], body["MESSAGE"])
- set(attributes["priority"], body["PRIORITY"])
But cant we have some feature to parse the journald logs to syslog server in easier way
Based on discussion on CNCF slack I believe this is an issue with the exporter and not the receiver.
To generalize the issue a bit, does the exporter have any requirements for the format of the logs it consumes? In other words, does it fail if a certain attribute is missing, etc?
If so, this is unlike how users typically expect to work with exporters. It would be much better if any plog.Logs
can be consumed in a generic way, even if some fields of the syslog format must be given default values or remain unutilized.
If this is already the intention of the receiver, then I think this might be a bug.
@djaglowski Yes you are right. The issue is with exporter, not consuming logs from journald receiver as it is but only if the attributes are preset or are manually added.
If an attribute is missing, the default value is used. The log's timestamp field is used for the syslog message's time.
I think this is a pretty clear bug given that we are not handling missing attributed as stated in the documentation. I'll remove the triage label.
The Syslog exporter expects the input to be structured in a specific way. The docs could probably be improved, but you can get this by looking at the Examples section: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/v0.111.0/exporter/syslogexporter/README.md#examples.
Specifically, in RFC5424, the details of the syslog message are expected to be specified in log record's attributes: appname
, hostname
, message
, priority
. If any of these is empty, the syslog message is still exported, containing default values as documented. I believe the above comment confirms it: when the data is put in the attributes that the exporter expects, syslog messages come out as expected. If you believe there is still bug in here, please describe a specific reproduction scenario and the actual vs. expected result.
But cant we have some feature to parse the journald logs to syslog server in easier way
There is definitely space for discussion on how to make this easier. I'm open to suggestions.
Component(s)
exporter/syslog
What happened?
Description
Sending to logs collected by journals receiver from host system to syslog-ng server using syslog exporter.
Steps to Reproduce
Expected Result
System journald logs are collected and sent to syslog-ng server using syslog exporter
Actual Result
No useful logs collected at syslog server
Collector version
0.95.0
Environment information
Environment
OS: Debian Bookworm k3s version v1.29.6+k3s2
OpenTelemetry Collector configuration
Log output
Additional context
No response