Sha256: b061a3c3c6399b5ac604a0354f9ff164f65eb4511af257c5ad41be5828c92072

Contents?: true

Size: 881 Bytes

Versions: 3

Compression:

Stored size: 881 Bytes

Contents

require 'date'

module SEKOIA
  class Formatter
    SekoiaID = "SEKOIA@53288"
    Format = "<%d>1 %s %s %s %s %s %s %s"

    class << self
      def format(
        priority: 14,
        timestamp: nil,
        log: "",
        hostname: "-",
        app_name: "-",
        proc_id: "-",
        msg_id: "-",
        intake_key: ""
      )
        Format % [priority, format_time(timestamp), hostname[0..254], app_name[0..47], proc_id[0..127], msg_id[0..31], format_structured_data(intake_key), log]
      end

      def format_structured_data(intake_key)
        %{[#{SekoiaID} intake_key="#{intake_key}"]}
      end

      def format_time(timestamp)
        return "-" if timestamp.nil?
        return Time.at(timestamp.to_r).utc.to_datetime.rfc3339(6) if timestamp.is_a?(Fluent::EventTime)

        DateTime.strptime(timestamp.to_s, '%s').rfc3339(6)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fluent-plugin-sekoia-io-0.0.3 lib/sekoia/formatter.rb
fluent-plugin-sekoia-io-0.0.2 lib/sekoia/formatter.rb
fluent-plugin-sekoia-io-0.0.1 lib/sekoia/formatter.rb