forked from fabianlee/blogcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby-logstash.conf
76 lines (61 loc) · 1.57 KB
/
ruby-logstash.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
input {
stdin { }
}
filter {
grok {
match => { "message" => "%{DATA:justtime} %{DATA:logsource} %{GREEDYDATA:msg}" }
} #
# incorrectly autopopulates to first day of year
date {
match => [ "justtime", "HH:mm.ss" ]
target => "incorrectfulldatetime"
timezone => "America/Los_Angeles"
} # date
# use ruby to augment with current day
ruby {
code => "
event['fulldatetime'] = Time.now.strftime('%Y-%m-%d') + ' ' + event['justtime']
"
}
date {
match => [ "fulldatetime", "YYYY-MM-dd HH:mm.ss" ]
# target => "correctfulldatetime"
target => "@timestamp"
timezone => "America/Los_Angeles"
} # date
# split apart log source to extract service name
ruby {
code => "
fpath = event['logsource'].split('/')
event['serviceName'] = fpath[fpath.length-2].downcase
"
}
# append msg field to disk
ruby {
code => "
File.open('/tmp/mydebug.log','a') { |f| f.puts event['msg'] }
"
}
# call out to REST based echo service
ruby {
init => "
require 'net/http'
require 'json'
"
code => "
firstWord = event['msg'].split(' ')[0]
uri = URI.parse('http://echo.jsontest.com/word/' + firstWord)
response = Net::HTTP.get_response(uri)
if response.code == '200'
result = JSON.parse(response.body)
returnWord = result['word']
event['echo'] = firstWord + ' echoed back as: ' + returnWord
else
event['echo'] = 'ERROR reaching web service'
end
"
}
} # filter
output {
stdout { codec => rubydebug }
}