New sensuctl command asset to help test template strings

Hey everyone!
I’ve been head down working on a couple of new things that might be of interest to Sensu users out there and it’s time to tell everyone about them.

First thing I want to tell you about is a new sensu template-toolkit-command asset that will hopefully help operators working with the advanced templating capabilities of some of the sensu-plugin-sdk.

Bonsai Asset page: https://bonsai.sensu.io/assets/sensu/template-toolkit-command
Github repo: https://github.com/sensu/template-toolkit-command

I’m gonna take a couple of minutes and break down.

YES! we can extend sensuctl with additional commands using assets!
After we had assets up and running to support monitoring pipelines, it was clear that it would be useful to be able to extend sensuctl with additional adhoc behavior for operator interactions that you can’t fully automate. It was pretty obvious that golang assets would be a great way to do it so operators can share extensions that work in whatever host environment they are running sensuctl.

Sensuctl command assets are a little different from the runtime assets meant to be used in checks and handlers, in that they are installed into your personal sensuctl environment, they are not part of the shared Sensu resources. Basically they are a way to extend/customize your personal sensuctl environment and to share that extended capability with other operators, who need to take similar actions.

You can read about using sensuctl commands here:

https://docs.sensu.io/sensu-go/latest/sensuctl/sensuctl-bonsai/#extend-sensuctl-with-commands

If you are an operator and you are thinking about building some scripted logic that interacts with the Sensu api, think about sharing it with the Sensu operator community as a sensuctl command asset.

Sensuctl command assets are a new concept, and I’m sure we still need to smooth out the on-ramp for people looking to build and share them. If you need help getting started building your own sensuctl command, find me and I’ll help.

So what’s the template-toolkit-command exactly?
Several of the new plugins based on the sensu-plugin-sdk that make use of golang templating so you can reference attributes from the Sensu event passed into the handler. For example the sensu-slack-handler lets you use templating to customize the slack message you send out.

But it’s easy to get the template wrong, and that leads to frustration and a lot of trial and error. With this sensuctl command, you can now much more easily test your template string with real Sensu events you have access to, and make sure it works as you expect before you use it in the handler config! Customizing the template strings is a good example of the sort of thing operators really can’t automate, its just part of your process of tuning your Sensu resource definitions for your workflows. The functionality in the template-toolkit-command is just basic right now, but if people find it useful, we can extend it further, pull request welcome.

1 Like