# The "Hello World" of Sensu Assets

**URL:** https://discourse.sensu.io/t/the-hello-world-of-sensu-assets/1422
**Category:** Sensu Go
**Created:** [October 29, 2019, 8:05pm UTC](https://discourse.sensu.io/t/the-hello-world-of-sensu-assets/1422 "2019-10-29T20:05:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![aaronsachs](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.sensu.io/aaronsachs/32/47_2.png) [@aaronsachs](https://discourse.sensu.io/u/aaronsachs)
#### Post date: [October 29, 2019, 8:05pm UTC](https://discourse.sensu.io/t/the-hello-world-of-sensu-assets/1422/1 "2019-10-29T20:05:02Z")

</div>

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

```bash
hello-world.sh

#!/bin/sh

STRING="Hello World"

echo $STRING

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

```

The first step is to ensure that our directory structure is in place. As noted in [Sensu Go example asset structure](https://docs.sensu.io/sensu-go/latest/reference/assets/#example-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` :

```bash
$ mkdir sensu-go-hello-world

$ cd sensu-go-hello-world

$ mkdir bin

$ cp hello-world.sh bin/

$ tree
.
└── bin
    └── hello-world.sh

```

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

```bash
$ chmod +x bin/hello-world.sh 
mode of 'hello-world.sh' 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:

```auto
$ 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):

```auto
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](https://help.github.com/en/articles/creating-releases). Click **Create a new release** :

 ![gh-release-01](https://us1.discourse-cdn.com/flex016/uploads/sensu/original/1X/eb86cdfedcc9a3bb5768459fdab2abe39949704c.png)

We will see the following screen:

 ![gh-release-02](https://us1.discourse-cdn.com/flex016/uploads/sensu/original/1X/dbc6cc1e5b65c1a2ca59c8bfca970f74f26b884d.png)

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:

 ![gh-release-03](https://us1.discourse-cdn.com/flex016/uploads/sensu/original/1X/0476b8acb3a9bbc6a3d3acdb7bb4b0c15e34b3da.png)

Click **Publish release**. The latest release page will load:

 ![gh-release-04](https://us1.discourse-cdn.com/flex016/uploads/sensu/original/1X/da9131f74164d781ec1b9f22e06f0d515398daf1.png)

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:

```auto
---
type: Asset
api_version: core/v2
metadata:
  name: sensu-go-hello-world-asset
  namespace: default
spec:
  url: https://github.com/yourusername/sensu-go-hello-world/releases/download/0.0.1/sensu-go-hello-world-0.0.1.tar.gz
  sha512: dbfd4a714c0c51c57f77daeb62f4a21141665ae71440951399be2d899bf44b3634dad2e6f2516fff1ef4b154c198b9c7cdfe1e8867788c820db7bb5bcad83827

```

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

```auto
type: CheckConfig
api_version: core/v2
metadata:
  name: sensu-go-hello-world
  namespace: default
spec:
  command: hello-world.sh
  runtime_assets:
  - sensu-go-hello-world-asset
  interval: 10
  publish: true
  handlers:
    - debug
  subscriptions:
  - linux

```

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

```auto
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:

 ![sensu-agent-01](https://us1.discourse-cdn.com/flex016/uploads/sensu/original/1X/fa917237aa93748a535efac6792bf12ea21dccec.png)

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.
