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

🐛 send alerts to channels #306

Merged
merged 2 commits into from
May 31, 2024
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

```shell
helm repo add kwatch https://kwatch.dev/charts
helm install [RELEASE_NAME] kwatch/kwatch --namespace kwatch --create-namespace --version 0.8.5
helm install [RELEASE_NAME] kwatch/kwatch --namespace kwatch --create-namespace --version 0.9.0
```

To get more details, please check [chart's configuration](https://github.com/abahmed/kwatch/blob/main/deploy/chart/README.md)
Expand All @@ -46,7 +46,7 @@ To get more details, please check [chart's configuration](https://github.com/aba
You need to get config template to add your configs

```shell
curl -L https://raw.githubusercontent.com/abahmed/kwatch/v0.8.5/deploy/config.yaml -o config.yaml
curl -L https://raw.githubusercontent.com/abahmed/kwatch/v0.9.0/deploy/config.yaml -o config.yaml
```

Then edit `config.yaml` file and apply your configuration
Expand All @@ -58,7 +58,7 @@ kubectl apply -f config.yaml
To deploy **kwatch**, execute following command:

```shell
kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.8.5/deploy/deploy.yaml
kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.9.0/deploy/deploy.yaml
```

## High Level Architecture
Expand Down Expand Up @@ -326,8 +326,8 @@ basic auth
### Cleanup

```shell
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.8.5/deploy/config.yaml
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.8.5/deploy/deploy.yaml
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.9.0/deploy/config.yaml
kubectl delete -f https://raw.githubusercontent.com/abahmed/kwatch/v0.9.0/deploy/deploy.yaml
```

## 👍 Contribute & Support
Expand Down
10 changes: 5 additions & 5 deletions alertmanager/dingtalk/dingtalk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ func TestSendEvent(t *testing.T) {
c.url = s.URL + "/send?accessToken=%s"

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
4 changes: 2 additions & 2 deletions alertmanager/discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (s *Discord) SendEvent(ev *event.Event) error {
},
{
Name: "Name",
Value: ev.Name,
Value: ev.PodName,
Inline: true,
},
{
Name: "Container",
Value: ev.Container,
Value: ev.ContainerName,
Inline: true,
},
{
Expand Down
8 changes: 4 additions & 4 deletions alertmanager/discord/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func TestSendEvent(t *testing.T) {
c.send = mockedSend

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "Nam quis nulla. Integer malesuada. In in enim a arcu " +
"imperdiet malesuada. Sed vel lectus. Donec odio urna, tempus " +
"molestie, porttitor ut, iaculis quis, sem. Phasellus rhoncus.\n" +
Expand Down
6 changes: 3 additions & 3 deletions alertmanager/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ func (e *Email) buildMessageSubjectAndBody(
logsText = util.JsonEscape(ev.Logs)
}

subject := fmt.Sprintf("⛑ Kwatch detected a crash in pod %s ", ev.Container)
subject := fmt.Sprintf("⛑ Kwatch detected a crash in pod %s ", ev.ContainerName)
body := fmt.Sprintf(
"An alert for cluster: *%s* Name: *%s* Container: *%s* "+
"Namespace: *%s* "+
"has been triggered:\\n—\\n "+
"Logs: *%s* \\n "+
"Events: *%s* ",
e.appCfg.ClusterName,
ev.Name,
ev.Container,
ev.PodName,
ev.ContainerName,
ev.Namespace,
logsText,
eventsText,
Expand Down
10 changes: 5 additions & 5 deletions alertmanager/email/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ func TestSendEvent(t *testing.T) {

c.send = mockedSend
ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
22 changes: 11 additions & 11 deletions alertmanager/feishu/feishu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func TestBuildRequestBodyFeiShu(t *testing.T) {
c := NewFeiShu(configMap, &config.App{ClusterName: "dev"})
assertions.NotNil(c)
ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "test",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "test",
}
formattedMsg := ev.FormatMarkdown(c.appCfg.ClusterName, "", "")

Expand Down Expand Up @@ -113,11 +113,11 @@ func TestSendEvent(t *testing.T) {
assertions.NotNil(c)

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
10 changes: 5 additions & 5 deletions alertmanager/googlechat/googlechat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func TestSendEvent(t *testing.T) {
assert.NotNil(c)

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
10 changes: 5 additions & 5 deletions alertmanager/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func TestSendEvent(t *testing.T) {
assert.NotNil(c)

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
4 changes: 2 additions & 2 deletions alertmanager/mattermost/mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ func (m *Mattermost) buildMessage(e *event.Event, msg *string) []byte {
},
{
Title: "Name",
Value: e.Name,
Value: e.PodName,
Short: true,
},
{
Title: "Container",
Value: e.Container,
Value: e.ContainerName,
Short: true,
},
{
Expand Down
10 changes: 5 additions & 5 deletions alertmanager/mattermost/mattermost_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func TestSendEvent(t *testing.T) {
assert.NotNil(c)

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
8 changes: 4 additions & 4 deletions alertmanager/opsgenie/opsgenie.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,21 @@ func (m *Opsgenie) buildMessage(e *event.Event) []byte {
// use custom title if it's provided, otherwise use default
title := m.title
if len(title) == 0 {
title = fmt.Sprintf(defaultOpsgenieTitle, e.Name)
title = fmt.Sprintf(defaultOpsgenieTitle, e.PodName)
}
payload.Message = title

// use custom text if it's provided, otherwise use default
text := m.text
if len(text) == 0 {
text = fmt.Sprintf(defaultOpsgenieText, e.Container, e.Name)
text = fmt.Sprintf(defaultOpsgenieText, e.ContainerName, e.PodName)
}

payload.Description = text
payload.Details = map[string]string{
"Cluster": m.appCfg.ClusterName,
"Name": e.Name,
"Container": e.Container,
"Name": e.PodName,
"Container": e.ContainerName,
"Namespace": e.Namespace,
"Reason": e.Reason,
"Events": events,
Expand Down
30 changes: 15 additions & 15 deletions alertmanager/opsgenie/opsgenie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func TestSendEvent(t *testing.T) {
c.url = s.URL

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand All @@ -91,11 +91,11 @@ func TestSendEventError(t *testing.T) {
c.url = s.URL

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand All @@ -113,11 +113,11 @@ func TestInvaildHttpRequest(t *testing.T) {
c.url = "h ttp://localhost"

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
8 changes: 4 additions & 4 deletions alertmanager/pagerduty/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func (s *Pagerduty) buildRequestBodyPagerDuty(
}
}`,
key,
fmt.Sprintf(defaultEventTitle, ev.Container),
ev.Container,
fmt.Sprintf(defaultEventTitle, ev.ContainerName),
ev.ContainerName,
s.appCfg.ClusterName,
ev.Name,
ev.Container,
ev.PodName,
ev.ContainerName,
ev.Namespace,
ev.Reason,
eventsText,
Expand Down
30 changes: 15 additions & 15 deletions alertmanager/pagerduty/pagerduty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func TestSendEvent(t *testing.T) {
assert.NotNil(c)

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand All @@ -88,11 +88,11 @@ func TestSendEventError(t *testing.T) {
c.url = s.URL

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand All @@ -110,11 +110,11 @@ func TestInvaildHttpRequest(t *testing.T) {
c.url = "h ttp://localhost"

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
10 changes: 5 additions & 5 deletions alertmanager/rocketchat/rocketchat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ func TestSendEvent(t *testing.T) {
assert.NotNil(c)

ev := event.Event{
Name: "test-pod",
Container: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
PodName: "test-pod",
ContainerName: "test-container",
Namespace: "default",
Reason: "OOMKILLED",
Logs: "test\ntestlogs",
Events: "event1-event2-event3-event1-event2-event3-event1-event2-" +
"event3\nevent5\nevent6-event8-event11-event12",
}
Expand Down
4 changes: 2 additions & 2 deletions alertmanager/slack/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func (s *Slack) SendEvent(ev *event.Event) error {
Type: "section",
Fields: []*slackClient.TextBlockObject{
markdownF("*Cluster*\n%s", s.appCfg.ClusterName),
markdownF("*Name*\n%s", ev.Name),
markdownF("*Container*\n%s", ev.Container),
markdownF("*Name*\n%s", ev.PodName),
markdownF("*Container*\n%s", ev.ContainerName),
markdownF("*Namespace*\n%s", ev.Namespace),
markdownF("*Reason*\n%s", ev.Reason),
},
Expand Down
Loading
Loading