Can't import check definition created with sensuctl check info name --format json

Using sensuctl check info check_name --format I can export check definition in either JSON or YAML format.
I can import it back from YAML but not from JSON format.

Example:

$ sensuctl check info my_test
=== my_test
Name:              my_test
Interval:          120
Command:           exit 0
Cron:              
Timeout:           0
TTL:               0
Subscriptions:     Sensu_backend
Handlers:          rfdefault
Runtime Assets:    rf-base, sensu-ruby-runtime
Hooks:             
Publish?:          true
Stdin?:            false
Proxy Entity Name: 
Namespace:         prod
Metric Format:     
Metric Handlers:   

.

$ sensuctl check info my_test --format yaml > /tmp/c.yaml
$ sensuctl check info my_test --format json > /tmp/c.json

$ sensuctl check delete my_test
? Are you sure you would like to delete resource 'my_test'? Yes
Deleted

Problem:

sensuctl can’t import definition back from JSON file.
sensuctl create -f file.JSON fails with error:

$ sensuctl create -f /tmp/c.json
resource 0: error parsing spec: type could not be found: ""
Error: in /tmp/c.json: some resources couldn't be parsed

.

$ sensuctl create -f /tmp/c.yaml
$

is successffully completed without error.
Check definition:

$ sensuctl check info my_test
=== my_test
Name:              my_test
Interval:          120
Command:           exit 0
Cron:              
Timeout:           0
TTL:               0
Subscriptions:     Sensu_backend
Handlers:          default
Runtime Assets:    base, sensu-ruby-runtime
Hooks:             
Publish?:          true
Stdin?:            false
Proxy Entity Name: 
Namespace:         prod
Metric Format:     
Metric Handlers: 

Is this a bug in sensuctl, or I’m just using it wrong ?

No, there’s a special format for this. If you export it with --format wrapped-json you should then be able to import it. I can’t remember the exact reason why this is required.

Hey @anatolijd,

I think the reason for wrapped-json versus json is that wrapped-json provides the necessary information to figure out which resource endpoint to use in the Sensu API.

The json output is appropriate for use to work with the Sensu REST API directly once you know which API endpoint you want to use.

1 Like

Thanks a lot!

Now it all makes sense for me :slight_smile: