sensu / sensu-chef

Sensu Chef cookbook.
https://supermarket.chef.io/cookbooks/sensu
Apache License 2.0
222 stars 280 forks source link

Remediation not defined in check provider #566

Closed bobhlo closed 7 years ago

bobhlo commented 7 years ago

Expected Behavior

When attribute remediation defined in data bag, it should be populated in the check definition on sensu server

Attribute remediation should be populated in the check definition

Current Behavior

Possible Solution

Add attribute remediation to check provider - https://github.com/sensu/sensu-chef/blob/develop/providers/check.rb#L16-L19

Steps to Reproduce (for bugs)

1. 2. 3. 4.

Context

Your Environment

cwjohnston commented 7 years ago

@bobhlo because remediation is a custom check attribute, i.e. not defined in the Sensu check attributes specification, we will not be adding it as a first-class attribute in the sensu_check provider.

I understand that you are asking that this be implemented in order to better support generating sensu_check resources from checks defined in a data bag items. Instead I suggest that you use Ruby logic to ensure that custom attributes, like remediation, are passed as a hash to the sensu_check resource's additional attribute.

Here's an untested example of what I think the implementation would look like:

data_bag(checks_data_bag).each do |data_bag_item|
  check = data_bag_item(checks_data_bag, data_bag_item)
  custom_attrs = Hash.new
  sensu_check check["id"] do
    check.each do |key, value|
      if respond_to?(key.to_sym)
        send(key.to_sym, value)
      else
        custom_attrs.merge!(key => value)
      end
      additional custom_attrs
    end
  end
end