Sha256: a4eead05b1563026758eb60a759dfaaac8b902c9c372ab115d476048c91a84f5

Contents?: true

Size: 857 Bytes

Versions: 3

Compression:

Stored size: 857 Bytes

Contents

#
# DESCRIPTION:
#   Filter methods for aws queries
#
# DEPENDENCIES:
#
# USAGE:
#   Filter.parse(string)
#
# NOTES:
#
# LICENSE:
#   Justin McCarty (jmccarty3@gmail.com)
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

module Filter
  def self.parse(input)
    filter = []

    if input == '{}'
      return filter
    end

    items = input.scan(/{.*?}/)

    items.each do |item|
      if item.strip.empty?
        fail 'Invalid filter syntax'
      end

      entry = {}
      name = item.scan(/name:(.*?),/)
      value = item.scan(/values:\[(.*?)\]/)

      if name.nil? || name.empty? || value.nil? || value.empty?
        fail 'Unable to parse filter entry'
      end

      entry[:name] = name[0][0].strip
      entry[:values] = value[0][0].split(',')
      filter << entry
    end
    filter
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sensu-plugins-aws-2.1.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-2.0.1 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-2.0.0 lib/sensu-plugins-aws/filter.rb