Hi,
I'm trying to have some dynamic naming for my data streams based on some syslog fields.
Here is my rsyslog conf file for sending datas in JSON format to logstash.
# cat logstash-json.conf
template(name="json-template"
type="list"
option.json="on") {
constant(value="{")
constant(value="\"@timestamp\":\"") property(name="timereported" dateFormat="rfc3339")
constant(value="\",\"@version\":\"1")
constant(value="\",\"message\":\"") property(name="msg")
constant(value="\",\"hostname\":\"") property(name="hostname")
constant(value="\",\"severity\":\"") property(name="syslogseverity-text")
constant(value="\",\"facility\":\"") property(name="syslogfacility-text")
constant(value="\",\"programname\":\"") property(name="programname")
constant(value="\",\"procid\":\"") property(name="procid")
constant(value="\"}\n")
}
action(type="omfwd" target="elkglbvprd1" port="10514" protocol="tcp" template="json-template")
And here is my logstash conf file:
input {
tcp {
port => 10514
codec => "json_lines"
type => "syslog"
}
}
filter {
mutate {
rename => { "hostname" => "[host][name]" }
add_field => { "[@metadata][dataset]" => "%{facility}" }
add_field => { "[@metadata][namespace]" => "%{programname}" }
}
if [facility] == "authpriv" {
grok {
match => { "message" => "pam_unix\(%{GREEDYDATA}\): session %{WORD:session_state} for user %{USERNAME:user}(\(uid=%{INT:uid}\) by (%{USERNAME:ruser})?\(
uid=%{INT:ruid}\))?" }
}
}
}
output {
# stdout { codec => rubydebug }
elasticsearch {
hosts => "https://localhost:9200"
ssl => true
cacert => "/etc/logstash/certs/http_ca.crt"
user => "logstash_writer"
password => "myLogstashPassword"
data_stream => "true"
data_stream_type => "logs"
data_stream_dataset => "%{ [@metadata][dataset] }"
data_stream_namespace => "%{ [@metadata][namespace] }"
}
}
EDIT : The error is
[ERROR] 2023-02-10 16:25:32.891 [Converge PipelineAction::Create<main>] elasticsearch - Invalid setting for elasticsearch output plugin:
output {
elasticsearch {
# This setting must be a dataset_identifier
# Invalid characters detected ["\\", "/", "*", "?", "\"", "<", ">", "|", " ", ",", "#", ":"] are not allowed
data_stream_dataset => "%{ [@metadata][dataset] }"
...
}
}
Am I doing something wrong or is it just not possible?
Maybe someone of here can share his thoughts.
Regards