sensu / sensu-go-chef

Chef Library Cookbook for Sensu Go
https://sensu.io
MIT License
11 stars 22 forks source link

Feature Request: sensu_bonsai_asset #133

Open kmf opened 3 years ago

kmf commented 3 years ago

Would love to use an asset like this

sensu_bonsai_asset 'asset_influxdb_handler' 
majormoses commented 3 years ago

@kmf thanks for opening this feature request. I want to make sure I understand the request and the value it brings before I dive too much into the feasability. I see we already have a generic sensu_asset resource: https://github.com/sensu/sensu-go-chef/blob/1.3.0/resources/asset.rb

Internally at my org we use it like so:

node['CUSTOM_NAMESPACE']['sensu-go']['namespaces'].each do |namespace|
  # do non asset things across all namespace
  ...
# create assets from attributes
  node['CUSTOM_NAMESPACE']['sensu-go']['assets'].each do |asset, property|
    sensu_asset asset do
      url property['url']
      sha512 property['checksum']
      namespace namespace
    end
  end
end
In our attributes we are defining a hash of assets to deploy ```ruby # NOTE: pared down the list of assets to save screen real estate default['CUSTOM_NAMESPACE']['sensu-go']['assets'] = { 'sensu-ruby-runtime' => { url: 'https://assets.bonsai.sensu.io/102d2b8c9dc264b98fa7973bf7657e9216bfb0a8/sensu-ruby-runtime_0.1.0_ruby-2.4.4_debian_linux_amd64.tar.gz', checksum: '956806ab6a1d12a3bdb476c2b5fb9b047db4394eafd6d5956554909db0f1b0367d9139c1f63b2ed966d3f5364e356adb424cc112888e09d2af316869d1a7ccb3', }, 'sensu-slack-handler' => { url: 'https://assets.bonsai.sensu.io/55861a7587f59a7e2ad960703f0ec44699a2be64/sensu-slack-handler_1.3.2_linux_amd64.tar.gz', checksum: 'eaaecf4609d872fd01b914c98ae5f09089ce773fa651dca368f4c804b44dae239fa4c39898967c6d04db087a5ae4aa5a1e84f87b32c99bf63448531629fb12cc', }, 'sensu-plugins-http' => { url: 'https://assets.bonsai.sensu.io/33783747d3af1939808944c2253c262d9d5b3fb7/sensu-plugins-http_6.0.0_debian_linux_amd64.tar.gz', checksum: 'bfa025fcda806a36673e252f693635ea9283f7ba9e1ddcfa3c541fdf7ab96e6d90746e44e3377b7d973cdc7cb3c851114ce886fd9d8ec532d7371b7a3f237fa2', }, 'sensu-deregistration-handler' => { url: 'https://assets.bonsai.sensu.io/4c486c532fce60f46f6493e81e6affc4dbfeb43c/sensu-deregistration-handler_0.1.0_linux_amd64.tar.gz', checksum: 'f76669c3ee1ffdafaa251e1412bc6f2ff2aecc6854654061695a0623e336ea01e3cdcb8d17de0bdc98c644569363416724af406996c764a11f06c0f9953fa07a', } } ```

We could probably create a "wrapper" resource that could build the asset but I suspect that we would need to realistically force each of the same bits but could construct the URL.

For example to use sensu-deregistration-handler we need to specify:

bonsai_asset 'sensu-deregistration-handler' do
  version   '0.1.0'
  platform 'linux'
  arch     'amd64'
end

It's tempting to assume we can use ohai data to tell us some of the answers of that I do not think that is a good stance as we are likely creating assets for multiple systems/platforms on the backend which may not represent all the required clients to support.

kmf commented 3 years ago

This functionality sensuctl asset add sensu/sensu-influxdb-handler is what I was looking for

majormoses commented 3 years ago

Gotch, from what I read here https://docs.sensu.io/sensu-go/latest/plugins/assets/ it seems the URL is a required field in the spec. I suspect the sensuctl command itself is providing that sugar. I think its doable but we can't be idempotent because we won't know when we need to run it again. I will see if I can do some additional digging.

evandam commented 3 years ago

Bumping this since it seems really useful. It's a lot to keep track of all the URLs/SHAs especially if an asset has multiple builds.

Also pointing out it seems there's a bonsai_asset in the sensu-go Ansible collection.