Since a tcp handler requires a socket attribute, I would expect sensuctl create to fail in some way, or for sensuctl handler list to report invalid configurations.
I can create a handler that crashes sensuctl
Add some error checking in sensuctl? (That's kind of naive suggestion not knowing this codebase well)
handler.json:
{
"type": "handler",
"spec": {
"name": "tcp_handler",
"environment": "default",
"organization": "default",
"timeout": 30,
"type": "tcp"
}
}
# sensuctl create -f handler.json
# sensuctl handler list
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x88f324]
goroutine 1 [running]:
github.com/sensu/sensu-go/cli/commands/handler.printToTable.func6(0x9a0760, 0xc420238000, 0x4, 0x4)
/go/src/github.com/sensu/sensu-go/cli/commands/handler/list.go:102 +0x234
github.com/sensu/sensu-go/cli/elements/table.(*Table).writeRow(0xc42004fbd8, 0xc42021e040)
/go/src/github.com/sensu/sensu-go/cli/elements/table/standard.go:90 +0xcb
github.com/sensu/sensu-go/cli/elements/table.(*Table).writeRows(0xc42004fbd8, 0x8f8da0, 0xc4201f4160)
/go/src/github.com/sensu/sensu-go/cli/elements/table/standard.go:83 +0x24e
github.com/sensu/sensu-go/cli/elements/table.(*Table).Render(0xc42004fbd8, 0xa31400, 0xc420096008, 0x8f8da0, 0xc4201f4160)
/go/src/github.com/sensu/sensu-go/cli/elements/table/standard.go:66 +0x82
github.com/sensu/sensu-go/cli/commands/handler.printToTable(0x8f8da0, 0xc4201f4160, 0xa31400, 0xc420096008)
/go/src/github.com/sensu/sensu-go/cli/commands/handler/list.go:132 +0x30a
github.com/sensu/sensu-go/cli/commands/helpers.Print(0xc4201a3400, 0xc4200930f0, 0x7, 0x9f21d0, 0x8f8da0, 0xc4201f4160, 0x0, 0x0)
/go/src/github.com/sensu/sensu-go/cli/commands/helpers/print.go:23 +0xb3
github.com/sensu/sensu-go/cli/commands/handler.ListCommand.func1(0xc4201a3400, 0xd14408, 0x0, 0x0, 0x0, 0x0)
/go/src/github.com/sensu/sensu-go/cli/commands/handler/list.go:41 +0x252
github.com/sensu/sensu-go/vendor/github.com/spf13/cobra.(*Command).execute(0xc4201a3400, 0xd14408, 0x0, 0x0, 0xc4201a3400, 0xd14408)
/go/src/github.com/sensu/sensu-go/vendor/github.com/spf13/cobra/command.go:753 +0x468
github.com/sensu/sensu-go/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc420180280, 0xc4201b0f00, 0xc4201b2000, 0xc4201b2280)
/go/src/github.com/sensu/sensu-go/vendor/github.com/spf13/cobra/command.go:843 +0x30a
github.com/sensu/sensu-go/vendor/github.com/spf13/cobra.(*Command).Execute(0xc420180280, 0xc4201473e0, 0xc4200d9628)
/go/src/github.com/sensu/sensu-go/vendor/github.com/spf13/cobra/command.go:791 +0x2b
main.main()
/go/src/github.com/sensu/sensu-go/cli/cmd/start.go:26 +0xbd
How has this issue affected you? Minor pain, blurred vision, slight headache.
What are you trying to accomplish? Writing custom chef resources to manage this stuff.
sensu-ctl version dev-nightly#9bba4cf, build 9bba4cf6af864bbabf0a3120ec2ad6d187552a8b, built 2018-05-06T09:24:10+0000Nice find, thank you for reporting this.
The solution here is to add some logic to the Validate() method on the type. When handler.Type == "tcp", the handler should be well-specified. (valid host and port fields)
This will cause both the client and the server to reject attempts to create these broken handlers.
After building sensuctl with PR 1488, users get the following error on invalid handlers:
$ echo '{"type":"handler","spec":{"name":"a","environment":"b","organization":"c","type":"tcp"}}' | sensuctl create
error validating resource 0 (/handlers/a): tcp and udp handlers need a valid socket
Error: resource validation failed
Most helpful comment
After building sensuctl with PR 1488, users get the following error on invalid handlers: