Sensu-go: Unable to load simple asset for check-cpu.sh

Created on 7 Sep 2018  ·  2Comments  ·  Source: sensu/sensu-go

Expected Behavior




I'd expect a simple asset to be usable by a simple check.

Current Behavior


[root@sensu-backend ~]# sensuctl event list
           Entity               Check                 Output               Status   Silenced             Timestamp
 ─────────────────────────── ─────────── ──────────────────────────────── ──────── ────────── ───────────────────────────────
  el7-agent.example.com       check-cpu   error installing dependencies:        3   false      2018-09-06 23:49:43 +0000 UTC
                                          given file of format '' does
                                          not appear valid
  el7-agent.example.com       keepalive                                         0   false      2018-09-06 23:49:54 +0000 UTC
  sensu-backend.example.com   check-cpu   CPU OK - Usage:1.01                   0   false      2018-08-21 23:50:50 +0000 UTC
  sensu-backend.example.com   keepalive                                         0   false      2018-09-06 23:50:09 +0000 UTC

Possible Solution


Steps to Reproduce (for bugs)



The asset:

[root@sensu-backend ~]# sensuctl asset list --format json
[
  {
    "name": "check-cpu.sh",
    "url": "https://raw.githubusercontent.com/sensu-plugins/sensu-plugins-cpu-checks/03a99bab0237c81121ce702b0c5a5a3b44908535/bin/check-cpu.sh",
    "sha512": "f14e488c3a8822f5bbde0d14303cfaa4c58e485c53a4ac636263a956f858c8f77ad1261daaa8fdefa6a32f69f4b79305548c0335f9ec2859e924a9e5e88fd7f3",
    "metadata": null,
    "filters": null,
    "organization": "default"
  }
]

The check:

[root@sensu-backend ~]# sensuctl check list --format json
[
  {
    "check_hooks": null,
    "command": "check-cpu.sh -w 75 -c 90",
    "env_vars": null,
    "environment": "default",
    "handlers": [],
    "high_flap_threshold": 0,
    "interval": 30,
    "low_flap_threshold": 0,
    "name": "check-cpu",
    "organization": "default",
    "output_metric_format": "",
    "output_metric_handlers": null,
    "proxy_entity_id": "",
    "publish": true,
    "round_robin": false,
    "runtime_assets": [
      "check-cpu.sh"
    ],
    "stdin": false,
    "subdue": null,
    "subscriptions": [
      "test"
    ],
    "timeout": 0,
    "ttl": 0,
    "executed": 0,
    "history": null,
    "issued": 0,
    "last_ok": 0,
    "occurrences": 0,
    "occurrences_watermark": 0,
    "status": 0,
    "total_state-change": 0
  }
]

Context



I was wanting to test sensu-puppet with some real-world scripts and checks and decided to use an asset instead of curl to fetch check-cpu.sh that is documented in v2 docs. CC @ghoneycutt

Your Environment

  • Sensu version used (sensuctl, sensu-backend, and/or sensu-agent):sensuctl version 2.0.0-nightly#cf3305e, build cf3305eecc6cbd62ef9641ca6a5923d18615100c, built 2018-07-29T09:21:53+0000
  • Installation method (packages, binaries, docker etc.): RPM
  • Operating System and version (e.g. Ubuntu 14.04): EL7

Most helpful comment

Currently, sensu-go only supports tarball and gzipped tarball assets. I've discussed the issue with the team, and plan to provide better documentation on wrapping things like shell scripts into sensu assets.

I've created a tarball out of the check-cpu.sh and put it on Github. If you use this asset definition:

{
  "type": "Asset",
  "spec": {
    "name": "check-cpu.sh",
    "url": "https://github.com/cyphus/test-asset-host/releases/download/0.0.1/check-cpu-sh.tgz",
    "sha512": "58a4d415f82ac9750ecf92d25a6b782393e00461d66c287e6eca56bb1d1789d78de5d04477ff1994d989916f39d290ef67f3bdeab9299a6fb94c9d6df95fe36b",
    "metadata": null,
    "filters": null,
    "organization": "default"
  }
}

You'll be able to use check-cpu.sh as an asset.

Here's the steps I ran to wrap check-cpu.sh in a sensu-go compatible tarball in case you need to use this pattern on other assets:

cd $(mktemp -d)
mkdir -p asset/bin
curl -Lo asset/bin/check-cpu.sh https://raw.githubusercontent.com/sensu-plugins/sensu-plugins-cpu-checks/03a99bab0237c81121ce702b0c5a5a3b44908535/bin/check-cpu.sh
chmod +x asset/bin/check-cpu.sh
tar -zcvf check-cpu.tar.gz -C asset .

I'm closing this issue for now, but feel free to reopen if necessary. Cheers!

All 2 comments

Hi @treydock, thanks for submitting this issue! I'm going to try to reproduce this on my end. I'll let you know how it goes.

Currently, sensu-go only supports tarball and gzipped tarball assets. I've discussed the issue with the team, and plan to provide better documentation on wrapping things like shell scripts into sensu assets.

I've created a tarball out of the check-cpu.sh and put it on Github. If you use this asset definition:

{
  "type": "Asset",
  "spec": {
    "name": "check-cpu.sh",
    "url": "https://github.com/cyphus/test-asset-host/releases/download/0.0.1/check-cpu-sh.tgz",
    "sha512": "58a4d415f82ac9750ecf92d25a6b782393e00461d66c287e6eca56bb1d1789d78de5d04477ff1994d989916f39d290ef67f3bdeab9299a6fb94c9d6df95fe36b",
    "metadata": null,
    "filters": null,
    "organization": "default"
  }
}

You'll be able to use check-cpu.sh as an asset.

Here's the steps I ran to wrap check-cpu.sh in a sensu-go compatible tarball in case you need to use this pattern on other assets:

cd $(mktemp -d)
mkdir -p asset/bin
curl -Lo asset/bin/check-cpu.sh https://raw.githubusercontent.com/sensu-plugins/sensu-plugins-cpu-checks/03a99bab0237c81121ce702b0c5a5a3b44908535/bin/check-cpu.sh
chmod +x asset/bin/check-cpu.sh
tar -zcvf check-cpu.tar.gz -C asset .

I'm closing this issue for now, but feel free to reopen if necessary. Cheers!

Was this page helpful?
0 / 5 - 0 ratings