sensu / sensu-chef

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

How do I add keys to a `sensu_check` resources that are not part of the spec? #622

Closed jfineberg closed 5 years ago

jfineberg commented 5 years ago

Expected Behavior

I should be able to provide a contact name that has been defined in the "contacts" definition (Sensu Enterprise feature)

sensu_check "stats_check" do
  command "stats-check.py"
  handlers ["slack"]
  contact "dev"
  subscribers ["some_stats_subscriber"]
  interval 60
end

Current Behavior

The sensu_check resource will throw an error with this unknown 'contact' attribute.

    sensu_check "stats_check" do
       command "stats-check.py"
       handlers ["slack"]
>>     contact "dev"
       subscribers ["some_stats_subscriber"]
       interval 60
    end
...
[2018-10-17T00:19:26+00:00] FATAL: NoMethodError: undefined method `contact' for Custom resource sensu_check from cookbook sensu

Possible Solution

Allow a "contact" attribute in sensu_check. Ideally, also provide a sensu_contact resource that puts JSON files in node["sensu"]["directory"]/conf.d/contacts/

Context

My organization is using this Chef cookbook with Sensu Enterprise, and we have the need to add special Contact Routing for certain checks. We can use sensu_snippet to generate the contacts JSON, but without the sensu_check resource supporting a contact name, it's quite troublesome to take full advantage of Sensu Enterprise and Contact Routing.

Your Environment

majormoses commented 5 years ago

@jfineberg you can use the additional hash to add arbitrary keys, see: https://github.com/sensu/sensu-chef#define-a-check or https://gist.github.com/majormoses/6b670730551bf59c60165b19a3afdefe for examples

jfineberg commented 5 years ago

Gosh, I don't know how I forgot about "additional" attributes. Thanks, this is working well now. Feel free to close the issue.