Class: Fluent::SendmailInput
- Inherits:
-
TailInput
- Object
- TailInput
- Fluent::SendmailInput
- Defined in:
- lib/fluent/plugin/in_sendmail.rb
Instance Method Summary collapse
- #configure_parser(conf) ⇒ Object
-
#initialize ⇒ SendmailInput
constructor
A new instance of SendmailInput.
- #log_bundled(es, deliveryid, time) ⇒ Object
- #log_single(es, deliveryid, time, record) ⇒ Object
- #receive_lines(lines) ⇒ Object
Constructor Details
#initialize ⇒ SendmailInput
Returns a new instance of SendmailInput.
14 15 16 17 |
# File 'lib/fluent/plugin/in_sendmail.rb', line 14 def initialize super @delivers = LruRedux::ThreadSafeCache.new(@lrucache_size) end |
Instance Method Details
#configure_parser(conf) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/fluent/plugin/in_sendmail.rb', line 19 def configure_parser(conf) @parser = SendmailParser.new(conf) if @unbundle == 'yes' @do_unbundle = true else @do_unbundle = false end end |
#log_bundled(es, deliveryid, time) ⇒ Object
111 112 113 114 |
# File 'lib/fluent/plugin/in_sendmail.rb', line 111 def log_bundled(es, deliveryid, time) log = @delivers[deliveryid] es.add(time, log.record) end |
#log_single(es, deliveryid, time, record) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/fluent/plugin/in_sendmail.rb', line 103 def log_single(es, deliveryid, time, record) log = @delivers[deliveryid] records = log.record_unbundle(time, record) for record in records do es.add(time, record) end end |
#receive_lines(lines) ⇒ Object
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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/fluent/plugin/in_sendmail.rb', line 28 def receive_lines(lines) es = Fluent::MultiEventStream.new lines.each {|line| begin line.chomp! # remove \n logline = parse_line(line) if logline.nil? next end type = logline["type"] mta = logline["mta"] qid = logline["qid"] time = logline["time"] # a qid is not uniq worldwide. # make delivery id uniq even if multiple MTA's log are mixed. deliveryid = mta + qid type = logline["type"] noncommon = logline["noncommon"] case type when :from # new log from = noncommon record = from.record @delivers[deliveryid] = SendmailLog.new(mta, time, record) when :to to = noncommon status = to.status record = noncommon.record if @delivers.has_key?(deliveryid) to = noncommon status = to.status case status when :sent, :sent_local, :bounced @delivers[deliveryid].dequeued(time, record) if @do_unbundle log_single(es, deliveryid, time, record) end # bulked queue in an attempt have been dequeued completely. if @delivers[deliveryid].status == :all_dequeued # bundled logs are outputed here if not @do_unbundle log_bundled(es, deliveryid, time) end # log.destroy @delivers.delete(qid) end when :deferred if @do_unbundle log_single(es, deliveryid, time, record) end when :other $log.warn "cannot find this kind of delivery status: " + line.dump end else # cannot find any 'from' line corresponded to the 'to' line end end rescue $log.warn line.dump, :error=>$!.to_s $log.debug_backtrace end } unless es.empty? begin Fluent::Engine.emit_stream(@tag, es) rescue # ignore errors. Engine shows logs and backtraces. end end end |