Skip to content

Commit ff5f866

Browse files
author
Yoichi Kawasaki
committed
Add description and sample for field cast pattern
1 parent a578f75 commit ff5f866

File tree

3 files changed

+69
-9
lines changed

3 files changed

+69
-9
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,41 @@ fluent-plugin-azure-loganalytics adds **time** and **tag** attributes by default
111111
tag_field_name mytag
112112
</match>
113113
```
114+
### (3) Configuration with Typecast file
115+
116+
You want to add typecast filter when you want to cast fields type. The filed type of code and size are cast by typecast filter.
117+
<u>fluent.conf</u>
118+
```
119+
<source>
120+
@type tail # input plugin
121+
path /var/log/apache2/access.log # monitoring file
122+
pos_file /tmp/fluentd_pos_file # position file
123+
format apache # format
124+
tag azure-loganalytics.access # tag
125+
</source>
126+
127+
<filter **>
128+
@type typecast
129+
types host:string,user:string,method:string,path:string,referer:string,agent:string,code:integer,size:integer
130+
</filter>
131+
132+
<match azure-loganalytics.**>
133+
@type azure-loganalytics
134+
customer_id 818f7bbc-8034-4cc3-b97d-f068dd4cd658
135+
shared_key ppC5500KzCcDsOKwM1yWUvZydCuC3m+ds/2xci0byeQr1G3E0Jkygn1N0Rxx/yVBUrDE2ok3vf4ksCzvBmQXHw==(dummy)
136+
log_type ApacheAccessLog
137+
add_time_field true
138+
time_field_name mytime
139+
time_format %s
140+
localtime true
141+
add_tag_field true
142+
tag_field_name mytag
143+
</match>
144+
```
145+
[note] you need to install [fluent-plugin-filter-typecast](https://github.com/sonots/fluent-plugin-filter_typecast) for the sample configuration above.
146+
```
147+
gem install fluent-plugin-filter_typecast
148+
```
114149

115150
## Sample inputs and expected records
116151

examples/fluent_typecast.conf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<source>
2+
@type tail # input plugin
3+
path /var/log/apache2/access.log # monitoring file
4+
pos_file /tmp/fluentd_pos_file # position file
5+
format apache # format
6+
tag azure-loganalytics.access # tag
7+
</source>
8+
9+
<filter **>
10+
@type typecast
11+
types host:string,user:string,method:string,path:string,referer:string,agent:string,code:integer,size:integer
12+
</filter>
13+
14+
<match azure-loganalytics.**>
15+
@type azure-loganalytics
16+
customer_id CUSTOMER_ID # Customer ID aka WorkspaceID String
17+
shared_key KEY_STRING # The primary or the secondary Connected Sources client authentication key
18+
log_type EVENT_TYPE_NAME # The name of the event type. ex) ApacheAccessLog
19+
add_time_field true
20+
time_field_name mytime
21+
time_format %s
22+
localtime true
23+
add_tag_field true
24+
tag_field_name mytag
25+
</match>

test/plugin/test_azure_loganalytics.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_configure
3131

3232
def test_format
3333
d = create_driver
34-
time = event_time("2011-01-02 13:14:15 UTC")
34+
time = event_time("2017-11-24 01:14:15 UTC")
3535
d.run(default_tag: 'test') do
3636
d.feed(time, {"a"=>1})
3737
d.feed(time, {"a"=>2})
@@ -55,33 +55,33 @@ def test_write
5555
d.feed(
5656
time,
5757
{
58-
:Log_ID => "5cdad72f-c848-4df0-8aaa-ffe033e75d57",
59-
:date => "2016-12-10 09:44:32 JST",
60-
:processing_time => "372",
58+
:Log_ID => "5cdad72a-c848-4df0-8aaa-ffe033e75d57",
59+
:date => "2017-11-24 01:44:32 JST",
60+
:processing_time => 372,
6161
:remote => "101.202.74.59",
6262
:user => "-",
6363
:method => "GET / HTTP/1.1",
6464
:status => "304",
6565
:size => "-",
6666
:referer => "-",
6767
:agent => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0",
68-
:eventtime => "2016-12-10T09:44:32Z"
68+
:eventtime => "2017-11-24T01:44:32Z"
6969
})
7070

7171
d.feed(
7272
time,
7373
{
74-
:Log_ID => "7260iswx-8034-4cc3-uirtx-f068dd4cd659",
75-
:date => "2016-12-10 09:45:14 JST",
76-
:processing_time => "105",
74+
:Log_ID => "7260iswa-8034-4cc3-uirtx-f068dd4cd659",
75+
:date => "2017-11-24 01:45:14 JST",
76+
:processing_time => 105,
7777
:remote => "201.78.74.59",
7878
:user => "-",
7979
:method => "GET /manager/html HTTP/1.1",
8080
:status =>"200",
8181
:size => "-",
8282
:referer => "-",
8383
:agent => "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0",
84-
:eventtime => "2016-12-10T09:45:14Z"
84+
:eventtime => "2017-11-24T01:45:14Z"
8585
})
8686
end
8787
data = d.events

0 commit comments

Comments
 (0)