Repository: abahmed/kwatch
Pull request #306 (2024-05-31 16:55:52)

🐛 send alerts to channels
Changes proposed in this pull request:
- 🐛 send alerts to channels



Patch:
diff --git a/alertmanager/discord/discord.go b/alertmanager/discord/discord.go
index bde4f5b..dbe5940 100644
--- a/alertmanager/discord/discord.go
+++ b/alertmanager/discord/discord.go
@@ -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,
 		},
 		{
diff --git a/alertmanager/email/email.go b/alertmanager/email/email.go
index 2ec2ecc..3a7bf75 100644
--- a/alertmanager/email/email.go
+++ b/alertmanager/email/email.go
@@ -114,7 +114,7 @@ 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*  "+
@@ -122,8 +122,8 @@ func (e *Email) buildMessageSubjectAndBody(
 			"Logs: *%s* \\n "+
 			"Events: *%s* ",
 		e.appCfg.ClusterName,
-		ev.Name,
-		ev.Container,
+		ev.PodName,
+		ev.ContainerName,
 		ev.Namespace,
 		logsText,
 		eventsText,
diff --git a/alertmanager/mattermost/mattermost.go b/alertmanager/mattermost/mattermost.go
index 5b35d6f..160dd56 100644
--- a/alertmanager/mattermost/mattermost.go
+++ b/alertmanager/mattermost/mattermost.go
@@ -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,
 					},
 					{
diff --git a/alertmanager/opsgenie/opsgenie.go b/alertmanager/opsgenie/opsgenie.go
index 720535c..30051a1 100644
--- a/alertmanager/opsgenie/opsgenie.go
+++ b/alertmanager/opsgenie/opsgenie.go
@@ -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,
diff --git a/alertmanager/pagerduty/pagerduty.go b/alertmanager/pagerduty/pagerduty.go
index 9af6d08..9f9a573 100644
--- a/alertmanager/pagerduty/pagerduty.go
+++ b/alertmanager/pagerduty/pagerduty.go
@@ -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,
diff --git a/alertmanager/slack/slack.go b/alertmanager/slack/slack.go
index f86c168..f281907 100644
--- a/alertmanager/slack/slack.go
+++ b/alertmanager/slack/slack.go
@@ -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),
 			},
diff --git a/alertmanager/telegram/telegram.go b/alertmanager/telegram/telegram.go
index 70086b5..c9e671b 100644
--- a/alertmanager/telegram/telegram.go
+++ b/alertmanager/telegram/telegram.go
@@ -102,8 +102,8 @@ func (t *Telegram) buildRequestBodyTelegram(
 				"Logs: *%s* \\n "+
 				"Events: *%s* ",
 			t.appCfg.ClusterName,
-			e.Name,
-			e.Container,
+			e.PodName,
+			e.ContainerName,
 			e.Namespace,
 			logsText,
 			eventsText,
diff --git a/alertmanager/webhook/webhook.go b/alertmanager/webhook/webhook.go
index db2e6ea..38977cd 100644
--- a/alertmanager/webhook/webhook.go
+++ b/alertmanager/webhook/webhook.go
@@ -132,8 +132,8 @@ func (w *Webhook) buildRequestBody(
 
 	postBody, _ := json.Marshal(map[string]interface{}{
 		"Cluster":   w.appCfg.ClusterName,
-		"Name":      ev.Name,
-		"Container": ev.Container,
+		"Name":      ev.PodName,
+		"Container": ev.ContainerName,
 		"Namespace": ev.Namespace,
 		"Reason":    ev.Reason,
 		"Events":    eventsText,
diff --git a/alertmanager/zenduty/zenduty.go b/alertmanager/zenduty/zenduty.go
index c25fc56..89417e6 100644
--- a/alertmanager/zenduty/zenduty.go
+++ b/alertmanager/zenduty/zenduty.go
@@ -126,7 +126,7 @@ func (m *Zenduty) buildMessage(e *event.Event) []byte {
 		events = (e.Events)
 	}
 
-	payload.Message = fmt.Sprintf(defaultZendutyTitle, e.Name)
+	payload.Message = fmt.Sprintf(defaultZendutyTitle, e.PodName)
 	payload.Summary = fmt.Sprintf(
 		"An alert has been triggered for\n\n"+
 			"cluster: %s\n"+
@@ -137,8 +137,8 @@ func (m *Zenduty) buildMessage(e *event.Event) []byte {
 			"Events:\n%s\n\n"+
 			"Logs:\n%s\n\n",
 		m.appCfg.ClusterName,
-		e.Name,
-		e.Container,
+		e.PodName,
+		e.ContainerName,
 		e.Namespace,
 		e.Reason,
 		events,
diff --git a/event/event.go b/event/event.go
index 486259f..8d68156 100644
--- a/event/event.go
+++ b/event/event.go
@@ -2,11 +2,11 @@ package event
 
 // Event used to represent info needed by providers to send messages
 type Event struct {
-	Name      string
-	Container string
-	Namespace string
-	Reason    string
-	Events    string
-	Logs      string
-	Labels    map[string]string
+	PodName       string
+	ContainerName string
+	Namespace     string
+	Reason        string
+	Events        string
+	Logs          string
+	Labels        map[string]string
 }
diff --git a/event/format.go b/event/format.go
index c7eb10a..37eb98a 100644
--- a/event/format.go
+++ b/event/format.go
@@ -41,8 +41,8 @@ func (e *Event) FormatMarkdown(clusterName, text, delimiter string) string {
 			"**Events:**\n```\n%s\n```"+delimiter+
 			"**Logs:**\n```\n%s\n```",
 		text,
-		clusterName, e.Name,
-		e.Container,
+		clusterName, e.PodName,
+		e.ContainerName,
 		e.Namespace,
 		e.Reason,
 		eventsText,
@@ -84,8 +84,8 @@ func (e *Event) FormatHtml(clusterName, text string) string {
 			"<b>Logs:</b> <br/><blockquote>%s</blockquote>",
 		text,
 		clusterName,
-		e.Name,
-		e.Container,
+		e.PodName,
+		e.ContainerName,
 		e.Namespace,
 		e.Reason,
 		strings.ReplaceAll(eventsText, "\n", "<br/>"),
@@ -126,8 +126,8 @@ func (e *Event) FormatText(clusterName, text string) string {
 			"Events:\n%s\n\n"+
 			"Logs:\n%s\n\n",
 		clusterName,
-		e.Name,
-		e.Container,
+		e.PodName,
+		e.ContainerName,
 		e.Namespace,
 		e.Reason,
 		eventsText,
diff --git a/handler/executeContainersFilters.go b/handler/executeContainersFilters.go
index e9d08c0..dbafd43 100644
--- a/handler/executeContainersFilters.go
+++ b/handler/executeContainersFilters.go
@@ -3,8 +3,10 @@ package handler
 import (
 	"time"
 
+	"github.com/abahmed/kwatch/event"
 	"github.com/abahmed/kwatch/filter"
 	"github.com/abahmed/kwatch/storage"
+	"github.com/abahmed/kwatch/util"
 	"github.com/sirupsen/logrus"
 )
 
@@ -51,6 +53,16 @@ func (h *handler) executeContainersFilters(ctx *filter.Context) {
 				ctx.Container.Reason,
 				ctx.Container.Msg,
 				ctx.Container.ExitCode)
+
+			h.alertManager.NotifyEvent(event.Event{
+				PodName:       ctx.Pod.Name,
+				ContainerName: ctx.Container.Container.Name,
+				Namespace:     ctx.Pod.Namespace,
+				Reason:        ctx.Container.Reason,
+				Events:        util.GetPodEventsStr(ctx.Events),
+				Logs:          ctx.Container.Logs,
+				Labels:        ctx.Pod.Labels,
+			})
 		}
 	}
 }
diff --git a/handler/executePodFilters.go b/handler/executePodFilters.go
index 9d0afad..05139bf 100644
--- a/handler/executePodFilters.go
+++ b/handler/executePodFilters.go
@@ -1,8 +1,10 @@
 package handler
 
 import (
+	"github.com/abahmed/kwatch/event"
 	"github.com/abahmed/kwatch/filter"
 	"github.com/abahmed/kwatch/storage"
+	"github.com/abahmed/kwatch/util"
 	"github.com/sirupsen/logrus"
 )
 
@@ -38,4 +40,14 @@ func (h *handler) executePodFilters(ctx *filter.Context) {
 	)
 
 	logrus.Printf("pod only issue %s %s %s %s", ctx.Pod.Name, ownerName, ctx.PodReason, ctx.PodMsg)
+
+	h.alertManager.NotifyEvent(event.Event{
+		PodName:       ctx.Pod.Name,
+		ContainerName: "",
+		Namespace:     ctx.Pod.Namespace,
+		Reason:        ctx.PodReason,
+		Events:        util.GetPodEventsStr(ctx.Events),
+		Logs:          "",
+		Labels:        ctx.Pod.Labels,
+	})
 }
diff --git a/util/util.go b/util/util.go
index 2355c86..1b276dd 100644
--- a/util/util.go
+++ b/util/util.go
@@ -17,20 +17,10 @@ import (
 )
 
 // GetPodEventsStr returns formatted events as a string for specified pod
-func GetPodEventsStr(c kubernetes.Interface, name, namespace string) string {
-	events, err := GetPodEvents(c, name, namespace)
-
+func GetPodEventsStr(events *[]v1.Event) string {
 	eventsString := ""
-	if err != nil {
-		logrus.Warnf(
-			"failed to get events for %s@%s: %s",
-			name,
-			namespace,
-			err.Error())
-		return eventsString
-	}
 
-	for _, ev := range events.Items {
+	for _, ev := range *events {
 		eventsString +=
 			fmt.Sprintf(
 				"[%s] %s %s\n",


Test patch:
diff --git a/alertmanager/dingtalk/dingtalk_test.go b/alertmanager/dingtalk/dingtalk_test.go
index 5e60fe9..c271a46 100644
--- a/alertmanager/dingtalk/dingtalk_test.go
+++ b/alertmanager/dingtalk/dingtalk_test.go
@@ -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",
 	}
diff --git a/alertmanager/discord/discord_test.go b/alertmanager/discord/discord_test.go
index 0e5ea17..14537b4 100644
--- a/alertmanager/discord/discord_test.go
+++ b/alertmanager/discord/discord_test.go
@@ -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" +
diff --git a/alertmanager/email/email_test.go b/alertmanager/email/email_test.go
index c79b941..86be012 100644
--- a/alertmanager/email/email_test.go
+++ b/alertmanager/email/email_test.go
@@ -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",
 	}
diff --git a/alertmanager/feishu/feishu_test.go b/alertmanager/feishu/feishu_test.go
index 3d98a61..ac17934 100644
--- a/alertmanager/feishu/feishu_test.go
+++ b/alertmanager/feishu/feishu_test.go
@@ -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, "", "")
 
@@ -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",
 	}
diff --git a/alertmanager/googlechat/googlechat_test.go b/alertmanager/googlechat/googlechat_test.go
index 0c50e6b..8309e2a 100644
--- a/alertmanager/googlechat/googlechat_test.go
+++ b/alertmanager/googlechat/googlechat_test.go
@@ -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",
 	}
diff --git a/alertmanager/matrix/matrix_test.go b/alertmanager/matrix/matrix_test.go
index 26e9c93..d376629 100644
--- a/alertmanager/matrix/matrix_test.go
+++ b/alertmanager/matrix/matrix_test.go
@@ -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",
 	}
diff --git a/alertmanager/mattermost/mattermost_test.go b/alertmanager/mattermost/mattermost_test.go
index c3fb1e9..7a6c309 100644
--- a/alertmanager/mattermost/mattermost_test.go
+++ b/alertmanager/mattermost/mattermost_test.go
@@ -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",
 	}
diff --git a/alertmanager/opsgenie/opsgenie_test.go b/alertmanager/opsgenie/opsgenie_test.go
index 259ecf5..077ff0c 100644
--- a/alertmanager/opsgenie/opsgenie_test.go
+++ b/alertmanager/opsgenie/opsgenie_test.go
@@ -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",
 	}
@@ -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",
 	}
@@ -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",
 	}
diff --git a/alertmanager/pagerduty/pagerduty_test.go b/alertmanager/pagerduty/pagerduty_test.go
index ebba3c2..c302c1b 100644
--- a/alertmanager/pagerduty/pagerduty_test.go
+++ b/alertmanager/pagerduty/pagerduty_test.go
@@ -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",
 	}
@@ -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",
 	}
@@ -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",
 	}
diff --git a/alertmanager/rocketchat/rocketchat_test.go b/alertmanager/rocketchat/rocketchat_test.go
index 68ebdca..689992b 100644
--- a/alertmanager/rocketchat/rocketchat_test.go
+++ b/alertmanager/rocketchat/rocketchat_test.go
@@ -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",
 	}
diff --git a/alertmanager/slack/slack_test.go b/alertmanager/slack/slack_test.go
index e4934c8..7f7cbc1 100644
--- a/alertmanager/slack/slack_test.go
+++ b/alertmanager/slack/slack_test.go
@@ -55,10 +55,10 @@ func TestSendEvent(t *testing.T) {
 	s.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" +
diff --git a/alertmanager/teams/teams_test.go b/alertmanager/teams/teams_test.go
index 4550a7f..5d9f031 100644
--- a/alertmanager/teams/teams_test.go
+++ b/alertmanager/teams/teams_test.go
@@ -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",
 	}
diff --git a/alertmanager/telegram/telegram_test.go b/alertmanager/telegram/telegram_test.go
index 0cd22c6..52efd92 100644
--- a/alertmanager/telegram/telegram_test.go
+++ b/alertmanager/telegram/telegram_test.go
@@ -107,11 +107,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",
 	}
diff --git a/alertmanager/webhook/webhook_test.go b/alertmanager/webhook/webhook_test.go
index 0f3ac19..c390027 100644
--- a/alertmanager/webhook/webhook_test.go
+++ b/alertmanager/webhook/webhook_test.go
@@ -96,11 +96,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",
 	}
@@ -134,11 +134,11 @@ func TestSendEventError(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",
 	}
@@ -155,11 +155,11 @@ func TestInvaildHttpRequest(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",
 	}
diff --git a/alertmanager/zenduty/zenduty_test.go b/alertmanager/zenduty/zenduty_test.go
index 9ba1b57..4e458c8 100644
--- a/alertmanager/zenduty/zenduty_test.go
+++ b/alertmanager/zenduty/zenduty_test.go
@@ -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",
 	}
@@ -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",
 	}
@@ -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",
 	}
diff --git a/util/util_test.go b/util/util_test.go
index 1e62b5a..2ba4841 100644
--- a/util/util_test.go
+++ b/util/util_test.go
@@ -63,44 +63,19 @@ func TestJsonEscape(t *testing.T) {
 func TestGetPodEventsStr(t *testing.T) {
 	assert := assert.New(t)
 
-	cli := fake.NewSimpleClientset()
 	event := v1.Event{
 		Reason:        "test reason",
 		Message:       "test message",
 		LastTimestamp: metav1.Now(),
 	}
-	cli.PrependReactor(
-		"list",
-		"events",
-		func(action k8stesting.Action) (bool, runtime.Object, error) {
-			return true, &v1.EventList{
-				Items: []v1.Event{event},
-			}, nil
-		})
 
-	result := GetPodEventsStr(cli, "dummy-app-579f7cd745-t6fdg", "test")
+	result := GetPodEventsStr(&[]v1.Event{event})
 	expectedOutput :=
 		"[" + event.LastTimestamp.String() + "] " + event.Reason + " " +
 			event.Message
 	assert.Equal(result, expectedOutput)
 }
 
-func TestGetPodEventsStrError(t *testing.T) {
-	assert := assert.New(t)
-
-	cli := fake.NewSimpleClientset()
-
-	cli.PrependReactor(
-		"list",
-		"events",
-		func(action k8stesting.Action) (bool, runtime.Object, error) {
-			return true, nil, errors.New("ssss")
-		})
-
-	result := GetPodEventsStr(cli, "dummy-app-579f7cd745-t6fdg", "test")
-	assert.Equal(result, "")
-}
-
 func TestContainsKillingStoppingContainerEvents(t *testing.T) {
 	assert := assert.New(t)