Sensu-go: Unable to create hook using sensuctl create -f

Created on 8 Dec 2018  路  4Comments  路  Source: sensu/sensu-go

Expected Behavior




I'd expect to be able to create a hook via sensuctl create -f just like other resources.

Current Behavior


[root@sensu_backend /]# sensuctl create -f hook.json
Error: PUT "/hooks/test": {"code":2,"message":"not found"}

Possible Solution


Steps to Reproduce (for bugs)


[root@sensu_backend /]# cat hook.json
{
  "type": "Hook",
  "spec": {
    "metadata": {
      "name": "test",
      "namespace": "default",
      "labels": {
        "foo": "baz"
      }
    },
    "command": "ps aux",
    "timeout": 60
  }
}
[root@sensu_backend /]# sensuctl create -f hook.json
Error: PUT "/hooks/test": {"code":2,"message":"not found"}

Context



I rely very heavily on sensuctl create -f in the sensu Puppet module. This was not an issue I recall facing during beta. CC @ghoneycutt

Your Environment

  • Sensu version used (sensuctl, sensu-backend, and/or sensu-agent): 5.0.0
  • Installation method (packages, binaries, docker etc.): RPM
  • Operating System and version (e.g. Ubuntu 14.04): CentOS 7
bug

All 4 comments

This is somewhat confusing for people, unfortunately.

A Hook is a runtime Hook object - not designed to be created by users.

The actual type that should be created is HookConfig, and that is the type we do QA on.

We had an alias for Hook that people could use, to support sensuctl create, which didn't get updated when we refactored our API. Turns out it wasn't covered by our testing.

You can use "type": "HookConfig" to work around this for now.

The long term fix is to update the Hook's URIPath method to respect namespaces properly.

I can confirm using HookConfig works.

@echlebek I don't think we need an alias for "Hook" here. Hooks weren't a first class object in Sensu (classic), they were only an attribute of checks. Hook objects have only existed during Sensu Go alpha and beta releases, so deprecating then in favor of HookConfig should be fine.

Regardless, the CLI shouldn't try to PUT on /hooks/{hook-name}.

I missed the URIPath() for Hook when updating the API routes, see here. It should really look like the URIPath() defined for HookConfig in the same file here.

Was this page helpful?
0 / 5 - 0 ratings