How to migrate own ruby script to Sensu GO

Hi dear sensu-go community,

i am having an issue figuring out how to migrate my self written ruby script to work with sensu-go. I am pretty sure i am missing some gems but unsure where to install them.

I looked at the other post but having issues using my ruby script which i packaged with the new asset system.

I think i am missing gems in the ruby runtime asset but i am unsure how to add them.

Any help would be muich appriciated

Thanks in advance

Hey!

You probably don’t need add anything to the ruby runtime asset itself it may just be a matter of turning your ruby script into a proper ruby gem so you can have the additional gems installed into the asset you are trying to build following the pattern we are using for sensu-plugins.

Or if your script is simple enough and only requires pure ruby gems you can use inline bundle and have the extra requirements installed at runtime if needed. I built a toy example of a ruby script asset that uses inline bundle here:
https://github.com/jspaleta/sensu-asset-playground/tree/bundler-inline-asset/bundler-inline-asset

Can you share the ruby script? If I can look at the ruby script I can give you my opinion as to whether the inline bundle solution will work for you.

Hi jspaleta,

ahhh so i need the script to be a proper gem for it to install the gems into the runtime that makes sense.

I will take a loook at your repo later a bit short on time right now.

I can share the script later just need to make some minor tweaks to it.

Thanks for your help.

HI,
sorry i am answering this late this week is pretty busy and i got not as much time as i would like for sensu.

This is one of the costum scripts we are using the others are similar in complexity.
If i interpreted the link you’ve posted right this should work for our purposes.

This one checks for Orders in a database and gives back a fatal when those are missing for a set amount of time.

This should also work for handlers right?

Sadly with the inline method i am still running into problems.

/var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `require': /var/cache/sensu/sensu-
agent/a28952fd93fc63db1f8988c7bc40b0ad815eb9f35ef7317d6caf5d77ecfbfd824a9db54184400aa0c81c29b34cb48c7e8c6e3f17891aaf84cafa3c134266a61a/lib/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20) - /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/mysql2-0.5.3/lib/mysql2/mysql2.so (LoadError)
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/mysql2-0.5.3/lib/mysql2.rb:36:in `<top (required)>'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `require'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/runtime.rb:74:in `block (2 levels) in require'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `each'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/runtime.rb:69:in `block in require'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `each'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/runtime.rb:58:in `require'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/inline.rb:70:in `block in gemfile'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/settings.rb:124:in `temporary'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/gem/gems/bundler-2.1.4/lib/bundler/inline.rb:54:in `gemfile'
	from /var/cache/sensu/sensu-agent/5195c470f8d1e8023fda16f07c49d05222de37f82cd28f89abfbea283057afe7077b8a3b7f44363f2af655bf46104fc2766d7b58cc96914c72554976ec7f5c74/rubyexec/check-orders.rb:11:in `<main>'

openssl is installed in that specific version so i don’t get why mysql2 is running into an error.

I guess there is no way around creating my own gem :frowning:

Edit: ok i just fixed this one myself i just copied the missing librarys manually inside the local asset and made some minor tweaks to my script now i am getting the expected out put but sensu go is still not changeing the event status: i am reaching this statement

critical " Keine Order in den letzten #{interval} Minuten" if error

I get the message as output in sensu go but not the critical status. Did something change with how sensu-plugin check cli is handling statuses?

Yeah… the bundle inline only really works cleanly if all the deps are pure ruby Once you get into needing to make sure additional dynamic C libraries are installed things get harder. It can be done, as the sensu assets let you bundle libraries if you need them. But maybe for you this isn’t the best way forward right now, unless you intend to share these across your larger org and are looking to internally host assets as a way to do that.

But to be very clear, you do not have to use assets for your in house ruby. A lot of internal use only scripting not intended to be shared widely will be written in all sorts of tooling(i have so many one off bash scripts), noone expects all of this stuff to be shared or turned into assets, that’s just highly impracticable. That’s fine, you can still prep your running sensu environments using config management (or a volume mount in the case of a container) to have those plugin scripts in place if that’s what you have to do.

For your in-house ruby plugins you can use any compatible ruby environment… install ruby gems and C libraries as you need… that’s perfectly okay to do if that’s what you need to do. In fact for linux we still offer a pre-packaged ruby environment to help with sensu-plugins for those situations where assets won’t work. It installs into /opt/ so you should be able to use it with the community sensu-plugins gems and your own ruby scripts. Take a look at this:
https://docs.sensu.io/sensu-go/latest/installation/plugins/#install-plugins-with-the-sensu-install-tool

To be perfectly honest, assets are a pretty forward looking new concept, with the idea that people will ideally contribute sharable golang plugins that can be statically compiled cross platform to make life easier for everyone. Being able to statically compile so easily makes golang a great asset language as it simplifies so much when you plan to statically compile. Interpreted languages like ruby that are designed to rely heavily onruntime linked libraries, require more thought, it can be done… anything can be done if you spend enough clever points. The best possible assets future that I see definitely involves transitioning to golang assets, which is why we’ve spun up golang plugin template repos and an sdk to help get people started there.

The ruby runtime assets right now are a best effort to provide a bridge into that future for the existing collection of shared community maintained sensu plugin gems. It works, because we’re able to offer a ruby runtime (to build assets against)… but it does depend on well groomed gem build automation (which all the sensu-plugins in the collection have) together with docker build environments (this is why the ruby asset stuff is linux only). Even still there are some community ruby plugins that need to be redesigned before they’ll work as assets.

Thanks for the clerification ya i tried to do it all with the new asset system since i like the shareability. Since we are part of a big group which is maybe planning to use sensu with a local asset server for every plugin that feature especially is very compeling to us.
Right now though it’s not necessary.

I will try to locally install my plugins then and see if that’s going to easily work for me. Thanks for all your help this has been really insightful.