Sha256: ecffb1c3d9b894d8eff7ccbbe7ce0feb0b93ee5a5e7cc5dbf279fae671e1dd89

Contents?: true

Size: 859 Bytes

Versions: 78

Compression:

Stored size: 859 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?
        raise 'Invalid filter syntax'
      end

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

      if name.nil? || name.empty? || value.nil? || value.empty?
        raise '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

78 entries across 78 versions & 2 rubygems

Version Path
sensu-plugins-aws-18.6.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-boutetnico-1.4.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-boutetnico-1.3.4 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-boutetnico-1.2.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-boutetnico-1.1.1 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-boutetnico-1.0.6 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.5.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.4.2 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.4.1 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.4.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.3.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.2.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.1.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-18.0.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-17.2.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-17.1.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-17.0.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-16.2.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-16.1.0 lib/sensu-plugins-aws/filter.rb
sensu-plugins-aws-16.0.0 lib/sensu-plugins-aws/filter.rb