Class: Fluent::MailRelayOutput
- Inherits:
-
BufferedOutput
- Object
- BufferedOutput
- Fluent::MailRelayOutput
- Defined in:
- lib/fluent/plugin/out_mailrelay.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #format(tag, time, record) ⇒ Object
-
#initialize ⇒ MailRelayOutput
constructor
A new instance of MailRelayOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
- #str2ipaddr(sipaddrs) ⇒ Object
- #write(chunk) ⇒ Object
Constructor Details
#initialize ⇒ MailRelayOutput
Returns a new instance of MailRelayOutput.
11 12 13 14 |
# File 'lib/fluent/plugin/out_mailrelay.rb', line 11 def initialize super @transactions = LruRedux::ThreadSafeCache.new(@lrucache_size) end |
Instance Method Details
#configure(conf) ⇒ Object
25 26 27 28 |
# File 'lib/fluent/plugin/out_mailrelay.rb', line 25 def configure(conf) super @mynetworks = str2ipaddr(@mynetworks) end |
#format(tag, time, record) ⇒ Object
38 39 40 |
# File 'lib/fluent/plugin/out_mailrelay.rb', line 38 def format(tag, time, record) [tag, time, record].to_msgpack end |
#shutdown ⇒ Object
34 35 36 |
# File 'lib/fluent/plugin/out_mailrelay.rb', line 34 def shutdown super end |
#start ⇒ Object
30 31 32 |
# File 'lib/fluent/plugin/out_mailrelay.rb', line 30 def start super end |
#str2ipaddr(sipaddrs) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fluent/plugin/out_mailrelay.rb', line 16 def str2ipaddr(sipaddrs) ipaddrs = Array.new() sipaddrs.each do |sipaddr| ipaddr = IPAddr.new(sipaddr) ipaddrs.push(ipaddr) end ipaddrs end |
#write(chunk) ⇒ Object
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 |
# File 'lib/fluent/plugin/out_mailrelay.rb', line 42 def write(chunk) begin # Fluentd doesn't guarantee message order # For tracking relay of mail, this plugin should buffer logs and sort it by date order. = (chunk.to_enum(:msgpack_each)) readys = [] .each do |tag, time, record| ready, mail_id = push2relaylog(tag, time, record) # this plugin does not output relay log until the mail relayed to outer mynetworks. # Therefore, if a mail is deferred, the relay log will not be outputed until the mail is bounced or sent. if ready readys.push([mail_id, tag, time]) end end readys.each { |ready| mail_id, tag, time = ready log = @transactions[mail_id] router.emit(tag, time, log.record) @transactions.delete(mail_id) } rescue $log.warn 'mailrelay: error write() ', :error=>$!.to_s $log.debug_backtrace end end |