How to use the sensu-plugins-kubernetes plugin

Hey folks,

I’ve been trying to use the https://github.com/sensu-plugins/sensu-plugins-kubernetes plugin as an asset.

I repackaged the source code to make the directory structure fit with the specification at https://docs.sensu.io/sensu-go/5.2/reference/assets/#sharing-an-asset-on-bonsai (ensuring that /bin, /lib, etc are at the root of the tar.gz)

I’ve created my asset YAML which seems to be correctly accepted by sensuctl create, and an associated check. However, when the check is executed, I get the error below:

/var/lib/sensu/5e8ec99e5a13e07891c6426e8be9293036f5fe1075dbc3634ddf670d5e4032295373c11f8b25e8c3af8787c8db9094aba45197645e66571fc9dfd921f3930dcf/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- sensu-plugins-kubernetes/cli (LoadError)
	from /var/lib/sensu/5e8ec99e5a13e07891c6426e8be9293036f5fe1075dbc3634ddf670d5e4032295373c11f8b25e8c3af8787c8db9094aba45197645e66571fc9dfd921f3930dcf/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /var/lib/sensu/b50efa3b8c20166aa220b48e4ff11e9d474b2812d5c7e42a58c3cca6ae9cbaf63bd778702e213f15227858ffc40ecaadeb957536e7f430c0c4b3d12db835734c/bin/check-kube-nodes-ready.rb:40:in `<main>'

I’m a beginner, so hopefully someone can tell me what I’m doing wrong!

My asset YAML (I’m hosting it locally for now) looks like this:

---
type: Asset
api_version: core/v2
metadata:
  name: sensu-plugins-kubernetes
  labels: 
spec:
  url: https://sensu-assets.elpenguino.net/sensu-plugins-kubernetes-4.0.0.tar.gz
  sha512: b50efa3b8c20166aa220b48e4ff11e9d474b2812d5c7e42a58c3cca6ae9cbaf63bd778702e213f15227858ffc40ecaadeb957536e7f430c0c4b3d12db835734c

And my check YAML looks like this:

type: CheckConfig
api_version: core/v2
metadata:
  name: check-kube-nodes-ready
  namespace: default
spec:
  check_hooks: null
  command: check-kube-nodes-ready.rb --kube-config=/root/admin.conf
  env_vars: null
  handlers: []
  high_flap_threshold: 0
  interval: 60
  low_flap_threshold: 0
  output_metric_format: ""
  output_metric_handlers: null
  proxy_entity_name: ""
  publish: true
  round_robin: false
  runtime_assets:
  - sensu-ruby-runtime
  - sensu-plugins-kubernetes
  stdin: false
  subdue: null
  subscriptions:
  - proxy
  timeout: 0
  ttl: 0

Any suggestions would be appreciated! :slight_smile:

Cheers!
David

1 Like

Hi David, thanks for sharing your question.

In the Ruby world, RubyGems (a.k.a. gems) are the predominant method of packaging and distributing code for use by other developers.

Due to the details of how the Ruby runtime loads gems from the file system, it’s not sufficient to pack up the content of the lib and bin directories from a repo like sensu-plugins/sensu-plugins-kubernetes to create a working asset.

The recommended way to create an asset for projects like sensu-plugins-kubernetes is to follow the steps documented in Contributing Assets for Existing Ruby Sensu Plugins

If you’d like take a shot at this yourself, you might want to look at pull requests from similar plugin collections which have already been packaged as assets to guide you. Examples include sensu-plugins-elasticsearch and sensu-plugins-disk-checks.

I hope this helps to put you on the right path. I’ve also opened https://github.com/sensu/sensu-docs/issues/1648 to track the need for these details to be noted in our asset reference documentation.

1 Like

Thank you, I’ve learned something now :slight_smile: PR is at https://github.com/sensu-plugins/sensu-plugins-kubernetes/pull/86 :wink: