Advertisement
Guest User

Logstash-JSON-Decode

a guest
May 1st, 2017
992
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. # https://stackoverflow.com/questions/43674663/how-to-filter-json-using-logstash-filebeat-and-gork
  2.  
  3. input {
  4. beats {
  5. port => 5044
  6. }
  7.  
  8. generator {
  9. lines => [
  10. '2017-04-13 17:15:34.649 INFO [http-bio-8080-exec-5] Adapter:132 |Empty|Empty|===Request object=== GetTransKey=============',
  11. '2017-04-13 17:15:34.699 INFO [http-bio-8080-exec-5] Adapter:133 |Empty|Empty|Request object : sessionId:null, busiCode:GetTransKey, reqPubInfo:{"appId":"com.info.tss","sessionId":null,"version":"10000","timestamp":"20150206165957","lang":"EN","userId":null,"serviceId":null,"circleId":null,"route":null,"customerId":null,"osType":null}, param:{"type":0,"key":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCKmsCyw+YomiNbvkUP3D7OtvOMd7jq0aNa0APSp5E5PsYW7fpaUMniWkQeAwD3EmhzF5v3oXGA2bqAZ+b0ZJgv2BoEGYPoaCzOZBglDzUe8xldK5mMJHLiMwL0enkwURQvubnTUAxXMS0SPcXq4/jyX9mBu27Ht+zjT8Y3vO51JwIDAQAB","deviceInfo":null}',
  12. '2017-04-13 17:15:34.699 INFO [http-bio-8080-exec-5] Adapter:137 |Empty|Empty|Event:GetTransKey|StartTime:1492083934699ms',
  13. '2017-04-13 17:15:34.713 DEBUG [http-bio-8080-exec-5] RedisCache:72 |Empty|Empty|===mode=1 Redis cache connect to host:10.135.25.108 port:28333',
  14. '2017-04-13 17:15:34.720 DEBUG [http-bio-8080-exec-5] RedisCache:159 |Empty|Empty|{"lifo":true,"fairness":false,"maxWaitMillis":20,"minEvictableIdleTimeMillis":60000,"softMinEvictableIdleTimeMillis":1800000,"numTestsPerEvictionRun":-1,"evictionPolicyClassName":"org.apache.commons.pool2.impl.DefaultEvictionPolicy","testOnCreate":false,"testOnBorrow":false,"testOnReturn":true,"testWhileIdle":true,"timeBetweenEvictionRunsMillis":30000,"blockWhenExhausted":true,"jmxEnabled":true,"jmxNamePrefix":"pool","jmxNameBase":null,"maxTotal":50,"maxIdle":10,"minIdle":0}',
  15. '2017-04-13 17:15:42.830 INFO [http-bio-8080-exec-5] Adapter:145 |Empty|Empty|Event:GetTransKey|End Time:1492083942830ms|Total Time:8131ms|Status:0',
  16. '2017-04-13 17:15:42.831 INFO [http-bio-8080-exec-5] Adapter:148 |Empty|Empty|===Resp data=== GetTransKey=============',
  17. '2017-04-13 17:15:42.831 INFO [http-bio-8080-exec-5] Adapter:149 |Empty|Empty|Resp object : sessionId:null, busiCode:GetTransKey, respData:{"transKey":"W73GHuCMhSXnihDxlBA/QKzbF4dhqZlLWylINlvi4Ben1ViECepll2zL7Az489Uk4/e0HsT3/zkG\nSyIB9M9EDbp9rLqZIARCcBRUIYJ/N3YIDrQSvD7SyoIjg+ti/my17U/TLVgi3BLPkMQw9/0XhNpA\n/LYePHed2pe0FYun3xo=","sessionId":"216bc5f3-cdec-4998-9494-717c8e3769a6"}'
  18. ]
  19. count => 8
  20. }
  21. }
  22.  
  23. filter {
  24. # Parse the log message.
  25. grok {
  26. pattern_definitions => {
  27. "LOGDATE" => "[\d]{4}-[\d]{2}-[\d]{2} %{TIME}"
  28. "LOGHEADER" => "%{LOGDATE:logdate} %{LOGLEVEL:level}\s+\[%{GREEDYDATA:thread}\] %{NOTSPACE:file}:%{NUMBER:line}\s?"
  29. }
  30. match => {
  31. message => [
  32. "%{LOGHEADER} %{GREEDYDATA:message} reqPubInfo:%{GREEDYDATA:reqPubInfo}, param:%{GREEDYDATA:param}",
  33. "%{LOGHEADER} %{GREEDYDATA:message} respData:%{GREEDYDATA:respData}",
  34. "%{LOGHEADER} %{GREEDYDATA:message}"
  35. ]
  36. }
  37. overwrite => [ "message" ]
  38. }
  39.  
  40. # Set @timestamp using the date in the log message.
  41. date {
  42. match => [ "logdate", "yyyy-MM-dd HH:mm:ss.SSS" ]
  43. remove_field => [ "logdate" ]
  44. }
  45.  
  46. # Parse the JSON data.
  47. if [reqPubInfo] {
  48. json {
  49. source => "reqPubInfo"
  50. target => "reqPubInfo"
  51. }
  52. json {
  53. source => "param"
  54. target => "param"
  55. }
  56. } else if [respData] {
  57. json {
  58. source => "respData"
  59. target => "respData"
  60. }
  61. }
  62. }
  63.  
  64. output {
  65. stdout { codec => rubydebug { metadata => true } }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement