influxdata / influxdata/kapacitor
httppost handler throws unsupported protocol scheme when endpoint is created using REST API
- Dominant language
- Go
- Stars
- 2.4k
- Forks
- 479
- Avg merge
- 4d 16h
- Merged PRs (30d)
- 4
Description
**kapacitor version**: 1.5.4
**Environment**: docker-compose/kubernetes
**Docker image used**: 1.5.4-alpine
I'm trying to create a handler using httppost. If I specify the httppost endpoint in the kapacitor config file, it works fine and POST gets triggered. But when I try to create similar endpoint using kapacitor's REST API, I get `Post : unsupported protocol scheme \"\"" on handling the alert`. I confirmed that the URL has the http protocol specified. These are the logs (first request returned an error response, dont mind it. Atleast it reached the server):
**httppost endpoint defined in kapacitor config file:**
```
kapacitor_1 | ts=2020-06-19T07:37:20.002Z lvl=debug msg="alert triggered" service=kapacitor task_master=main task=arista_interface node=alert4 level=CRITICAL id=Arista event_message="Arista: Arista ifcounters CRITICAL map[value:false]" data="&{ifcounters map[host:telegraf name:Loopback1 source:54.202.79.126] [time value] [[2020-06-19 07:37:00 +0000 UTC false]]}"
kapacitor_1 | ts=2020-06-19T07:37:20.012Z lvl=error msg="POST returned non 2xx status code" service=httppost handler=post-interface-loopback-down-alert topic=interface err="{\"errors\":{\"error\":[{\"error-type\":\"protocol\",\"error-tag\":\"data-missing\",\"error-message\":\"Mount point does not exist.\"}]}}" code=404
```
**httppost created using REST API:**
```
kapacitor_1 | ts=2020-06-19T07:37:20.003Z lvl=debug msg="alert triggered" service=kapacitor task_master=main task=arista_interface-duplicate node=alert4 level=CRITICAL id=Arista event_message="Arista: Arista ifcounters CRITICAL map[value:false]" data="&{ifcounters map[host:telegraf name:Loopback1 source:54.202.79.126] [time value] [[2020-06-19 07:37:00 +0000 UTC false]]}"
kapacitor_1 | ts=2020-06-19T07:37:20.003Z lvl=error msg="failed to POST alert data" service=httppost handler=post-interface-loopback-down-alert-duplicate topic=interface err="Post : unsupported protocol scheme \"\""
```
This is the list of httppost endpoints obtained using REST API: `curl kapacitor:9092/kapacitor/v1/config/httppost`
```
{
"link": {
"rel": "self",
"href": "/kapacitor/v1/config/httppost"
},
"elements": [{
"link": {
"rel": "self",
"href": "/kapacitor/v1/config/httppost/loopback-interface-alert"
},
"options": {
"alert-template": "",
"alert-template-file": "/etc/kapacitor/loopback-interface-alert-template.html",
"basic-auth": true,
"endpoint": "loopback-interface-alert",
"headers": {
"Content-Type": "application/json"
},
"row-template": "",
"row-template-file": "",
"url": "http://lsc:8181/restconf/operations/jsonrpc:config/configured-endpoints/napalm/yang-ext:mount/ldk-napalm:send-config"
},
"redacted": ["basic-auth"]
}, {
"link": {
"rel": "self",
"href": "/kapacitor/v1/config/httppost/loopback-interface-alert-duplicate"
},
"options": {
"alert-template": "",
"alert-template-file": "/etc/kapacitor/loopback-interface-alert-template.html",
"basic-auth": true,
"endpoint": "loopback-interface-alert-duplicate",
"headers": {
"Content-Type": "application/json"
},
"row-template": "",
"row-template-file": "",
"url": "http://lsc:8181/restconf/operations/jsonrpc:config/configured-endpoints/napalm/yang-ext:mount/ldk-napalm:send-config"
},
"redacted": ["basic-auth"]
}]
}
```
**Steps to reproduce issue:**
1. Start kapacitor using default config (either docker-compose or kubernetes, or just plain vanilla docker container)
2. Create a http-post endpoint through REST API. Check if it has been created successfully either through REST API or kapacitor cli command
3. Create a task with some arbitrary rule, which triggers alert to specific topic
4. Create an http-post topic handler which subscribes to the topic, and calls the endpoint created in step 2. Check the logs to see the response of the POST request. The reason I am creating a defined handler and not calling the endpoint directly from TICKscript is to trigger the alert only when the level is CRITICAL. This can be set only through a defined handler, and not in TICKscript.
Contributor guide
Research direction
Start by reproducing the discrepancy between an httppost endpoint configured in Kapacitor's config and one created through the REST API, then inspect the REST API's httppost configuration and handler path. Confirm that an API-created endpoint preserves its URL when the handler posts an alert; the existing reproduction logs provide the expected successful request and the failing unsupported-protocol error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker-compose, go, kubernetes
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100