kapacitor icon indicating copy to clipboard operation
kapacitor copied to clipboard

Add headers to the POST notifications

Open 0xdavidm opened this issue 10 years ago • 7 comments

It would be great if we will be able to add headers to the POST alert handler call, since we can add auth and other tokens to the request and make it more generic for many 3rd party services.

Thanks D.

0xdavidm avatar Dec 22 '15 23:12 0xdavidm

Something like this:

.alert()
   .post('http://example.com/path/to/something')
      .header('Authorization', 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==')

This creates a new problem in that you probably don't want to expose the auth in plain text in the TICKscript. As a result we probably need a method for grabbing values from the config or environment:

Maybe?

.alert()
   .post('http://example.com/path/to/something')
      .header('Authorization', config('example.com-password'))

with corresponding config:

[tickscript]
   example.com-password = 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='

Or env based without config:

.alert()
   .post('http://example.com/path/to/something')
      .header('Authorization', env('EXAMPLE_COM_PASSWORD'))

Follow up question: Would being able to set header as static strings (independent of whether they are directly in the TICKscript, or come from config/env) be enough flexibility to do what you need? Or would you need to be able to specify the header value as a function of the data?

nathanielc avatar Dec 22 '15 23:12 nathanielc

I personally prefer the ENV option since it's allow me to work closely with Vault, and grab the secrets from there directly to the ENV var of the system.

0xdavidm avatar Dec 22 '15 23:12 0xdavidm

Is this already implemented?

fcastello avatar May 10 '16 18:05 fcastello

@fcastello nope

nathanielc avatar May 10 '16 19:05 nathanielc

Lets support both the env and config options.

nhaugo avatar Mar 06 '17 17:03 nhaugo

After discussion, the option that we've decided on going with the following

|alert()
  .post()
    .endpoint('example')

Which requires the configuration

[[post]]
endpoint = "example"
url = "http://example.com"
headers = { Authorization = "...", others = "..." }

This way values may be set through the configuration file, environment variables (via the config), and the API.

desa avatar Mar 06 '17 20:03 desa

@panda87 @fcastello We just recently implemented this feature. It would be great if you could give it a try. We've added a section to the configuration file like so

 [[httppost]]
    endpoint = "example"
    url = "http://example.com"
    headers = { Example = "result" }
    basic-auth = { username = "my-user", password = "my-pass" }

Then to use it in a tickscript you simply

...
|alert()
 ...
 .post()
  .endpoint('example')

You can also set headers that are not the authorization header directly in tickscript

|alert()
 ...
 .post('http://example.com')
  .header('my', 'header')
  .header('heres', 'another')

desa avatar May 08 '17 20:05 desa