The "Hello World" of Sensu Assets

In this tutorial, I’ll walk you through packaging up a pretty standard bash script. The goal here is to show that you can take some of those scripts that are hanging around in the nooks and crannies of your organization and package them up as assets.

The Setup


STRING="Hello World"

echo $STRING

if [ $? -eq 0 ]; then
    exit 0
    exit 2

The first step is to ensure that our directory structure is in place. As noted in Sensu Go example asset structure, our script could live in three potential directories in the project: /bin , /lib , or /include . For the purpose of this tutorial, we will put our script in the /bin directory. We’ll create the directories sensu-go-hello-world and /bin :

$ mkdir sensu-go-hello-world

$ cd sensu-go-hello-world

$ mkdir bin

$ cp bin/

$ tree
└── bin

Next, we’ll ensure that the script is marked as executable:

$ chmod +x bin/ 
mode of '' changed from 0644 (rw-r--r--) to 0755 (rwxr-xr-x)

Now that the script is in the directory, let’s move on to the next step: packaging the sensu-go-hello-world directory as an asset tarball.

Packaging the asset

Assets are archives, so the first step in packaging the asset is to create a tar.gz archive of our project. This assumes we’re in the directory we want to tar up:

$ cd ..
$ tar -C sensu-go-hello-world -cvzf sensu-go-hello-world-0.0.1.tar.gz .

Excellent. Now that we’ve created an archive, we’ll need to generate a SHA512 sum for it (this is required–otherwise, the asset won’t work):

sha512sum sensu-go-hello-world-0.0.1.tar.gz | tee sha512sum.txt
dbfd4a714c0c51c57f77daeb62f4a21141665ae71440951399be2d899bf44b3634dad2e6f2516fff1ef4b154c198b9c7cdfe1e8867788c820db7bb5bcad83827 sensu-go-hello-world-0.0.1.tar.gz

Now that we have our sha512sum, we’ll need to host the release (archive and sha512sum) somewhere. You can do this with S3, a GitHub release, or even just serving the files out of a directory using Nginx/Apache.

In this case, we’ll use GitHub to serve our release. Click Create a new release :

We will see the following screen:

On this screen, we’ll enter a tag version, release title, and release description details and drag and drop our asset and checksum so they will be uploaded as part of the release. When we’ve done that, the screen will look something like this:

Click Publish release . The latest release page will load:

Next, we need to create definitions for the asset and the check.

Generating the definitions

So far, we’ve created a directory for our asset with our script present in /bin , packaged up the asset and generated a checksum for it, and hosted our release on GitHub. Now, let’s generate some definitions for our asset to make it work.

First, let’s generate our asset definition:

type: Asset
api_version: core/v2
  name: sensu-go-hello-world-asset
  namespace: default
  sha512: dbfd4a714c0c51c57f77daeb62f4a21141665ae71440951399be2d899bf44b3634dad2e6f2516fff1ef4b154c198b9c7cdfe1e8867788c820db7bb5bcad83827

Second, we’ll create a basic check that uses the asset:

type: CheckConfig
api_version: core/v2
  name: sensu-go-hello-world
  namespace: default
  - sensu-go-hello-world-asset
  interval: 10
  publish: true
    - debug
  - linux

Third, we’ll apply both definitions to our Sensu Go deployment:

sensuctl create -f sensu-go-hello-world-asset.yml
sensuctl create -f sensu-go-hello-world-check.yml

Finally, let’s take a look in the dashboard to see our check using our asset. In this case, we have an entity named sensu-agent-01 , and we can see that the check successfully executes:

Congratulations! You created an asset from a script, uploaded the asset to GitHub as a release, and created your own definitions to use the asset.