I have this config file (logstash):
input {
beats {
port => 5044
host => "0.0.0.0"
}
}
filter {
json {
source => "message"
target => "log"
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "logs-%{+YYYY.MM.dd}"
}
jdbc {
driver_jar_path => "/etc/logstash/mysql-connector-java-8.0.11.jar"
driver_class => "com.mysql.cj.jdbc.Driver"
connection_string => "jdbc:mysql://localhost:3306/cste?user=master&password=testets!123"
statement => ["INSERT INTO cste_log (ip, log, event, created, inserted) VALUES(?,?,?,?,?)", "log.userid", "log", "log.event", "@timestamp", "@timestamp"]
}
stdout {
codec => "rubydebug"
}
for save data as mySQL Database. but it doesn't work with an error message (column 'ip', 'event' cannot be null)
I think the grammar of 'jdbc.statement' is wrong, and I'm trying to fix it. 'output.elasticsearch' works very nice.
{
"agent" => {
"version" => "7.10.0",
"name" => "DESKTOP-GEB1AGR",
"id" => "7e109ece-5874-4149-9842-21acb86c9da0",
"type" => "filebeat",
"hostname" => "DESKTOP-GEB1AGR",
"ephemeral_id" => "0730755e-f234-48c4-b7f1-2d2339df0e86"
},
"@version" => "1",
"@timestamp" => 2020-11-23T06:31:59.005Z,
"log" => {
"userid" => "192.111.11.111",
"writetime" => "2020/11/23 15:31:51",
"target" => "crackme.exe - PID: 5528 - Module: ntdll.dll - Thread: Main Thread 3240 (switched from 19C0)",
"event" => "dbgRestart"
},
"input" => {
"type" => "log"
},
"ecs" => {
"version" => "1.6.0"
},
"message" => "{\"writetime\": \"2020/11/23 15:31:51\", \"userid\": \"111.111.111.111\", \"target\": \"crackme.exe - PID: 5528 - Module: ntdll.dll - Thread: Main Thread 3240 (switched from 19C0)\", \"event\": \"dbgRestart\"} ",
"host" => {
"name" => "DESKTOP-GEB1AGR",
"architecture" => "x86_64",
"os" => {
"version" => "10.0",
"name" => "Windows 10 Home",
"build" => "16299.1087",
"family" => "windows",
"platform" => "windows",
"kernel" => "10.0.16299.1087 (WinBuild.160101.0800)"
},
"id" => "659f1b29-3-2cb22793a39c",
"ip" => [
[0] "fe80::adb9:b",
[1] "192.168.43.",
[2] "2001:0:348b:",
[3] "fe80::180947e"
],
"hostname" => "DESKTOP-GEB1AGR",
"mac" => [
[0] "00:0c:6c:d7",
[1] "00:00:00:e0"
]
},
"tags" => [
[0] "beats_input_codec_plain_applied"
]
}
How can I use the value 'writetime' and 'event'? Please give me some advice.
"log" => {
"userid" => "192.168.43.129",
"writetime" => "2020/11/23 15:31:51",
"target" => "crackme.exe - PID: 5528 - Module: ntdll.dll - Thread: Main Thread 3240 (switched from 19C0)",
"event" => "dbgRestart"},
If event is a field inside the log object then in logstash you refer to that as "[log][event]". [log.event] refers to a field that has a period in its name. Similarly for "[log][userid]".