Method: Fluent::SendmailInput#receive_lines

Defined in:
lib/fluent/plugin/in_sendmail.rb

#receive_lines(lines) ⇒ Object



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
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/fluent/plugin/in_sendmail.rb', line 56

def receive_lines(lines)
  es = Fluent::MultiEventStream.new
  lines.each {|line|
    begin
      line.chomp!  # remove \n
      record = parse_line(line)
      if record.nil?
        next
      end

      type   = record["type"]
      mta    = record["mta"]
      qid    = record["qid"]
      time   = record["time"]
      # a qid is not uniq worldwide.
      # make delivery id uniq even if multiple MTA"s log are mixed.
      deliveryid = mta + qid
      type   = record["type"]
      # remove unnecessary key `type"
      record.delete("type")

      case type
      when "from"
        # new log
        if @delivers.has_key?(deliveryid)
          $log.warn "duplicate sender line found. " + line.dump
        else
          @delivers[deliveryid] = SendmailLog.new(time, record)
        end
      when "to"
        if @delivers.has_key?(deliveryid)
          case record["status_canonical"]
          when "sent", "sent_local", "bounced"
            sent(es, deliveryid, time, record)
          when "deferred"
            queued(es, deliveryid, time, record)
          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
      raise
    end
  }

  unless es.empty?
    begin
      Fluent::Engine.emit_stream(@tag, es)
    rescue
      # ignore errors. Engine shows logs and backtraces.
      raise
    end
  end
end