confi content
input {
jdbc {
jdbc_driver_library => "D:\repo\com\microsoft\sqlserver\sqljdbc4\4.0\sqljdbc4-4.0.jar"
jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
jdbc_connection_string => "jdbc:sqlserver://xxx:8838;DatabaseName=LieBiDe"
jdbc_user => "xxx"
jdbc_password => "xxx"
statement => "SELECT TOP 1 j.Id, j.Name AS title, j.Location, f.Name AS company, f.ShortName, j.EmergencyDegree, j.created, r.JobId, r.created FROM Jobs j LEFT JOIN Firms f ON j.FirmId = f.Id LEFT JOIN Recommendations r ON j.id = r.JobId;"
#parameters => { "id" => 3510 }
codec => plain{ charset => "GBK" }
}
}
filter {
jdbc_streaming {
jdbc_driver_library => "D:\repo\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar"
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_connection_string => "jdbc:mysql://xxx:3306/dict?characterEncoding=UTF-8"
jdbc_user => "xxx"
jdbc_password => "xxx"
statement => "SELECT location_name_cn FROM dict_location WHERE location_id = 1"
parameters => { "codeParam" => "location"}
target => "location"
add_field => { "location_name" => "%{[location][0][location_name_cn]}" }
}
mutate {
add_field => { "standard_company" => ""}
}
ruby {
code => " puts event.get('location')[0]['location_name_cn']"
}
rest {
request => {
url => "http://localhost:8080/lbd/lbdId2tbdId"
method => "post"
headers => { "Content-Type" => "application/json" }
body => { "userId" => "%{company}" }
}
target => "company"
}
}
output {
stdout {
codec => rubydebug{}
}
}
and logstash log is
[2019-06-25T14:03:44,930][INFO ][logstash.inputs.jdbc ] (0.060000s) SELECT TOP 1 j.Id, j.Name AS title, j.Location, f.Name AS company, f.ShortName, j.EmergencyDegree, j.created, r.JobId, r.created FROM Jobs j LEFT JOIN Firms f ON j.FirmId = f.Id LEFT JOIN Recommendations r ON j.id = r.JobId;
地区根类
[2019-06-25T14:03:45,462][WARN ][logstash.filters.rest ] JSON parsing error {:response=>"", :event=>2019-06-25T06:03:44.981Z %{host} %{message}}
{
"emergencydegree" => 0,
"standard_company" => "",
"created" => 2015-08-08T01:46:40.863Z,
"title" => "web测试工程师",
"shortname" => "八爪测试",
"tags" => [
[0] "_jsonparsefailure"
],
"jobid" => "a4ee0215-b10b-4eb0-b985-92a7f7ef45bc",
"location_name" => "\x{B5D8}\x{C7F8}\x{B8F9}\x{C0E0}",
"@timestamp" => 2019-06-25T06:03:44.981Z,
"@version" => "1",
"location" => [
[0] {
"location_name_cn" => "地区根类"
}
],
"company" => "八爪网络测试有限公司",
"id" => "a4ee0215-b10b-4eb0-b985-92a7f7ef45bc"
}
[2019-06-25T14:03:47,498][WARN ][logstash.agent ] stopping pipeline {:id=>"main"}
Q1:
i use add_field => { "location_name" => "%{[location][0][location_name_cn]}" }
and result is
"location_name" => "\x{B5D8}\x{C7F8}\x{B8F9}\x{C0E0}"
but i use ruby code puts event.get('location')[0]['location_name_cn']
result is 地区根类" and is correct
Am I using it incorrectly?
Q2:
i use logstash-filter-http and i send requet to my server, my server log is
{"userId":"��צ�����������˾"}
{"userId":"��צ�����������˾"}
{"userId":"��צ�����������˾"}
{"userId":"��צ�����������˾"}
{"userId":"��צ�����������˾"}
if i send body => { "userId" => "测试" }
my server will be correct!
Am I using it incorrectly?