Sha256: 4cae0ac2343f361c3564a7929e03edc7ee6609faaaf01eef36ca230a74e96ed9

Contents?: true

Size: 877 Bytes

Versions: 9

Compression:

Stored size: 877 Bytes

Contents

class PositionFile

  def initialize(pos_file_path)
    @pos_file_path = pos_file_path
  end

  def processed?(violation)
    File.exist?(pos_file_name(violation)) && found?(violation)
  end

  def write(violation)
    File.open(pos_file_name(violation), 'a') do |f|
      f << violation_entry(violation)
      f << "\n"
    end
  end

  private
  def found?(violation)
    return File.open(pos_file_name(violation)) { |f| f.find { |line| line.include? violation_entry(violation) } }
  end

  def violation_entry(violation)
    created_date = DateTime.parse(violation['created']).strftime("%Y-%m-%dT%H:%M:%SZ")
    [created_date, violation['watch_name'], violation['issue_id']].join(',')
  end

  def pos_file_name(violation)
    pos_file_date = DateTime.parse(violation['created']).strftime("%Y-%m-%d")
    @pos_file_path + "jfrog_siem_log_#{pos_file_date}.siem.pos"
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
fluent-plugin-jfrog-siem-2.0.8 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.7 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.6 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.5 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.4 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.3 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.2 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.1 lib/fluent/plugin/position_file.rb
fluent-plugin-jfrog-siem-2.0.0 lib/fluent/plugin/position_file.rb