u-ichi / fluent-plugin-mail

Fluentd output plugin to send mail
https://rubygems.org/gems/fluent-plugin-mail
Other
48 stars 20 forks source link

can't JST??? #22

Closed my-dev closed 9 years ago

my-dev commented 9 years ago

Mr.sonots. nice to meet you.

Thank You Your Nice Plugin... But, In ReceiveMail, TIme is UTC...

I need JST ( GMT +09:00 ).

Under the situation...such like this.

  1. Read Log
  2. Send Mail In MatchTag
type mail
host localhost
port 25
domain aiueo.com
from alert@aiueo.com
to xxx@yyy.zzz
subject 日本語タイトル♪%s
subject_out_keys time
message 日本語本文\n\n[時間]:%s\n[curlRes]:%s\n[requestURL]:%s\n[totalTime]%s
message_out_keys time,curlRes,requestURL,totalTime
time_key time
\# time_key @timestamp
time_format %Y-%m-%d %H:%M:%S
\# 以下、全滅
\#    time_locale UTC
\#    time_locale JST
\#    time_locale Asia/Tokyo
\#    time_locale +09:00
  1. Receive Mail time is UTC...

Please, Check it And help me. Thank you.

sonots commented 9 years ago

Did not time_locale work? It is weird. I will investigate later.

my-dev commented 9 years ago

Hi! Mr.sonots Thank you, Your response.

I tried some pattern of [ time_local ]...but not work...

my environment is as below. file format is such like this ( tab separated )

ERROR 2015-06-12 00:00:00 http://xxx/xxx.html?11111 200 0.00282400 0.00001500 0.00094900 0.00095000 0.00281100


and td-agent.conf is such like this

type tail
path /path/to/log/file.log
read_from_head true
format /^(?<res>[^ ]_)\t(?<time>[^]]_)\t(?<requestURL>[^ ]_)\t(?<code>[^ ]_)\t(?<totalTime>[^ ]_)\t(?<number1>[^ ]_)\t(?<number2>[^ ]_)\t(?<number3>[^ ]_)\t(?<number4>[^ ]_)\t(?<string>[^._]*)$/
time_format %Y-%m-%d %H:%M:%S
refresh_interval 5s
pos_file /var/log/td-agent/xxx.pos
tag tag.for.rewrite

type rewrite_tag_filter rewriterule1 res^[NOLOG]+$ tag.no.log rewriterule2 res^[ERROR]+$ tag.mail.log rewriterule3 res.\* hogehoge.tag type null type mail host localhost port 25 domain aiueo.com from alert@aiueo.com to mail@test.com subject 日本語タイトル♪%s +09:00 subject_out_keys time message 日本語本文\n\n[時間]:%s +09:00\n[res]:%s\n[requestURL]:%s\n[totalTime]%s message_out_keys time,res,requestURL,totalTime time_key time time_format %Y-%m-%d %H:%M:%S # time_locale UTC

Then Result In ReceiveMail is.....

2015-06-12 00:00:00 -> 2015-06-11 15:00:00

Changed...You see.

Please, please, invastigate, thank you.

sonots commented 9 years ago

I tested, and it seems working fine. It would be your machine environment problem.

time_locale option is actually not necessary because Date: header has timezone information %z and the default is localtime > https://github.com/u-ichi/fluent-plugin-mail/blob/829c3ff9ac221266479a6bf0778019b801a1cf2c/lib/fluent/plugin/out_mail.rb#L200

I wrote how to test using mailcatcher gem on README > https://github.com/u-ichi/fluent-plugin-mail#development. Can you try this on your machine? You can see mail contents including mail header on http://localhost:1080 with mailcatcher gem. Please check the Received time and Source headers.

my-dev commented 9 years ago

Hi! Mr.sonots.

Thank you, Your testing.

I will try again too, and see you.

my-dev commented 9 years ago

Hi! Mr.sonots

nnn----T_T

I checked my Machine's localtime, below Thu Jun 25 09:29:07 JST 2015

and this issue means by reading from a file. Recieved time and Source headers is valid. it's no problem...

In Log file, it's just [ 2015-06-12 00:00:00 ] ...but it's changed to 2015-06-11 15:00:00...

sorry, many times. I will try again...and again.

thanks.

sonots commented 9 years ago

Do you mean the time is changed on reading with in_tail?

You probably need to add

localtime true

for your in_tail configuration.

my-dev commented 9 years ago

Hi! Mr.sonots.

un----

Now I tried it. But.....T_T

My Environment is below... 2015年 6月 25日 木曜日 10:03:21 JST /etc/sysconfig/clock -> ZONE="Asia/Tokyo"

it's no have relation directly, locale info is below... LANG=ja_JP.UTF-8 LC_CTYPE="ja_JP.UTF-8" LC_NUMERIC="ja_JP.UTF-8" LC_TIME="ja_JP.UTF-8" LC_COLLATE="ja_JP.UTF-8" LC_MONETARY="ja_JP.UTF-8" LC_MESSAGES="ja_JP.UTF-8" LC_PAPER="ja_JP.UTF-8" LC_NAME="ja_JP.UTF-8" LC_ADDRESS="ja_JP.UTF-8" LC_TELEPHONE="ja_JP.UTF-8" LC_MEASUREMENT="ja_JP.UTF-8" LC_IDENTIFICATION="ja_JP.UTF-8" LC_ALL=

Maybe, my environment JST perfectly.

this problem is not in mail header infomaition... By reading from logfile, just 2015-06-12 00:00:00 in this logfile... But in Mail Body, change to 2015-06-11 15:00:00...

uh...m

sonots commented 9 years ago

But in Mail Body

Uh, understand. So, you meant the mail body, not date header. I could reproduce it, I will fix it.

my-dev commented 9 years ago

Hi! Mr.sonots.

Please investigate Line62 - 72 In out_mail.rb...

Maybe...this part is reason

sonots commented 9 years ago

Yes, you're right. Hold on.

my-dev commented 9 years ago

Oh! sorry. pass each other...

Thank You for your supporting...

sonots commented 9 years ago

@my-dev Fixed with this commit https://github.com/u-ichi/fluent-plugin-mail/commit/03e88179989248f880714eacc149b35e5be1c6fa. Could you try with the latest version (0.2.0)?

my-dev commented 9 years ago

Mr.sonots...

oh!!! thanks... it's my pleasure.