Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimential slack sink. #43

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ For UPTRACE_SINK_ENCODING Vector expects one of `avro`, `gelf`, `json`, `logfmt`
| `HTTP_URL` | HTTP/HTTPS Endpoint |
| `HTTP_TOKEN` | HTTP Bearer auth token |

### Slack ( experimental )

HTTP sink that can be used for sending log alerts to Slack.

| Secret | Description |
| ---------------------- | ---------------------- |
| `SLACK_WEBHOOK_URL` | Slack WebHook URL |
| `SLACK_ALERT_KEYWORDS` | Keywords to alert on |

Example for setting keywords `fly secrets set SLACK_ALERT_KEYWORDS="[r'SIGTERM', r'reboot']"`

---

# NATS
Expand Down
33 changes: 33 additions & 0 deletions vector-configs/sinks/slack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[transforms.log_filter]
type = "filter"
inputs = [ "log_json" ]
condition = '''
match_any!(.message, ${SLACK_ALERT_KEYWORDS})
'''

[transforms.log_throttle]
type = "throttle"
inputs = [ "log_filter" ]
threshold = 1
window_secs = 1

[transforms.log_parse]
type = "remap"
inputs = [ "log_throttle" ]
source = '''
.blocks = [{"type": "section", "text": {"type": "mrkdwn", "text":"New alert from *" + .fly.app.name + "*"}},{ "type":"section", "text":{"type": "mrkdwn", "text": "*AppId:* " + .fly.app.instance + "\n*Message:*\n" + "\`\`\`" + .message + "\`\`\`"} }] ?? {}
del(.message)
del(.event)
del(.fly)
del(.host)
del(.log)
del(.timestamp)
. = {"message": encode_json(.)}
'''

[sinks.log_http]
type = "http"
inputs = ["log_parse"]
method = "post"
encoding.codec = "text"
uri = "${SLACK_WEBHOOK_URL}"