-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
An HTTP server which used to handle webhooks triggered by [OpenDistro for Elasticsearch Alerting](https://opendistro.github.io/for-elasticsearch-docs/docs/alerting) | ||
|
||
> Notice, the readme is for `0.2.x` version | ||
## Why? | ||
|
||
As for time of writing `destination` options that `ODFE` provides are limited. | ||
|
@@ -46,26 +48,37 @@ Download latest version for your platform from [releases](https://github.com/bri | |
|
||
1. Go to `Alerting` > `Destinations` | ||
2. Create the destination with type `Custom webhook` | ||
3. Chose `Define endpoint by custom attributes URL` | ||
3. Choose `Define endpoint by URL` | ||
- For `slack` set the url to have path with `/slack`, like `http://odfe-server:8080/slack` | ||
- For `email` set the url to have path with `/email`, like `http://odfe-server:8080/email` | ||
|
||
### Sending Email from triggers | ||
|
||
Fill in `Type`, `Host` and `Port` according to how and where you installed `odfe-alerts-handler`. | ||
1. Select destination which was created with the `/email` path | ||
2. The `Message` body look like below: | ||
|
||
### Configuring for Email | ||
```yaml | ||
to: ['[email protected]'] | ||
subject: ['Optional subject param'] | ||
--- | ||
This is the body of the message | ||
Here you can use the templeting as usual... | ||
``` | ||
|
||
1. Set `Path` to `email` | ||
2. Set `Query parameters` as follows: | ||
- Key: `addresses` | ||
- Value: comma separated list of emails to send | ||
`subject` is optional, if not provided the default one, see [#usage](usage). | ||
|
||
You can also override the default subject. | ||
If the first line of the alert message contains `Subject:`, that line will be used as a subject for the email. | ||
### Sending Slack from triggers | ||
|
||
### Configuring for Slack | ||
1. Select destination which was created with the `/slack` path | ||
2. The `Message` body look like below: | ||
|
||
1. Set `Path` to `slack` | ||
2. Set `Query parameters` as follows: | ||
- Key: `channels` or `users` | ||
- Value: comma separated list of user **emails** or list of channels | ||
```yaml | ||
channels: ['#alerts'] | ||
users: ['[email protected]'] | ||
--- | ||
This is the body of the message | ||
Here you can use the templeting as usual... | ||
``` | ||
|
||
You can have both `channels` and `users` keys if you desire to send to both. | ||
Optionally, for `channels` you can omit the leading `#`. | ||
|
@@ -74,7 +87,7 @@ Optionally, for `channels` you can omit the leading `#`. | |
|
||
```shell | ||
RELEASE_TITLE="First release" | ||
RELEASE_VERSION=0.1.0 | ||
RELEASE_VERSION=0.2.0 | ||
|
||
git tag -a v${RELEASE_VERSION} -m "${RELEASE_TITLE}" | ||
git push --tags | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,34 @@ | ||
package handlers | ||
|
||
import "strings" | ||
import ( | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"regexp" | ||
|
||
func fields(s string, sep rune) []string { | ||
return strings.FieldsFunc(s, func(c rune) bool { | ||
return c == sep | ||
}) | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
var bodySep = regexp.MustCompile("(?:^|\\s*\n)---\\s*") | ||
|
||
func parseBody(requestBody io.ReadCloser, target interface{}) (string, error) { | ||
body, err := ioutil.ReadAll(requestBody) | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("failed to read body, %v", err) | ||
} | ||
|
||
docs := bodySep.Split(string(body), 2) | ||
|
||
if len(docs) != 2 { | ||
return "", fmt.Errorf("cannot split body, got %d elements after split, but 2 elements required", len(docs)) | ||
} | ||
|
||
params, data := []byte(docs[0]), docs[1] | ||
|
||
if err := yaml.Unmarshal(params, target); err != nil { | ||
return "", fmt.Errorf("cannot unmarshal params, %v", err) | ||
} | ||
|
||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters