8000 fix: welcome msg version by Andrew44Ashraf · Pull Request #16 · abahmed/kwatch · GitHub
[go: up one dir, main page]

Skip to content
8000
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
40 changes: 32 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,41 @@ kubectl apply -f https://raw.githubusercontent.com/abahmed/kwatch/v0.0.7/deploy/

### Configuration

#### General

| Parameter | Description |
|:-------------------------------------|:------------------------------------------- |
| `maxRecentLogLines` | Max tail log lines in messages |
| `providers.slack.webhook` | Slack webhook URL |
| `providers.slack.title` | Customized title in slack message |
| `providers.slack.text` | Customized text in slack message |
| `providers.discord.webhook` | Discord webhook URL |
| `providers.discord.title` | Customized title in discord message |
| `providers.discord.text` | Customized text in discord message |
| `providers.pagerduty.integrationKey` | PagerDuty integration key [more info](https://support.pagerduty.com/docs/services-and-integrations) |
| `maxRecentLogLines` | optional Max tail log lines in messages |

#### Slack

If you want to enable Slack, provide the webhook with optional text and title.


| Parameter | Description |
|:---------------------------------|:------------------------------------------- |
| `alert.slack.webhook` | Slack webhook URL |
| `alert.slack.title` | Customized title in slack message |
| `alert.slack.text` | Customized text in slack message |

#### Discord

If you want to enable Discord, provide the webhook with optional text and title.


| Parameter | Description |
|:---------------------------------|:------------------------------------------- |
| `alert.discord.webhook` | Discord webhook URL |
| `alert.discord.title` | Customized title in discord message |
| `alert.discord.text` | Customized text in discord message |

#### PagerDuty

If you want to enable PagerDuty, provide the integration key.

| Parameter | Description |
|:---------------------------------|:------------------------------------------- |
| `alert.pagerduty.integrationKey` | PagerDuty integration key [more info](https://support.pagerduty.com/docs/services-and-integrations) |

### Cleanup

Expand Down
23 changes: 4 additions & 19 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"errors"
"fmt"
"time"

"github.com/abahmed/kwatch/constant"
Expand Down Expand Up @@ -45,16 +46,7 @@ func (c *Controller) run(workers int, stopCh chan struct{}) {
logrus.Infof("%s controller synced and ready", c.name)

// send notification to providers
for _, prv := range c.providers {
err :=
prv.SendMessage(constant.WelcomeMsg)
if err != nil {
logrus.Errorf(
"failed to send msg with %s: %s",
prv.Name(),
err.Error())
}
}
util.SendProvidersMsg(c.providers, fmt.Sprintf(constant.WelcomeMsg, constant.Version))

// start workers
for i := 0; i < workers; i++ {
Expand Down Expand Up @@ -173,15 +165,8 @@ func (c *Controller) processItem(key string) error {
Events: eventsString,
}

// send notification to providers
for _, prv := range c.providers {
if err := prv.SendEvent(&evnt); err != nil {
logrus.Errorf(
"failed to send event with %s: %s",
prv.Name(),
err.Error())
}
}
// send event to providers
util.SendProvidersEvent(c.providers, evnt)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion deploy/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ spec:
serviceAccountName: kwatch
containers:
- name: kwatch
image: ghcr.io/abahmed/kwatch:v0.0.4
image: ghcr.io/abahmed/kwatch:v0.0.7
imagePullPolicy: Always
volumeMounts:
- name: config-volume
Expand Down
32 changes: 30 additions & 2 deletions util/util.go
CC30
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/abahmed/kwatch/event"
"strings"

"github.com/abahmed/kwatch/provider"
Expand All @@ -17,15 +18,15 @@ import (

// GetPodEventsStr returns formatted events as a string for specified pod
func GetPodEventsStr(c kubernetes.Interface, name, namespace string) string {
evnts, err := getPodEvents(c, name, namespace)
events, err := getPodEvents(c, name, namespace)

eventsString := ""
if err != nil {
logrus.Warnf("failed to get events for %s@%s: %s", name, namespace, err.Error())
return eventsString
}

for _, ev := range evnts.Items {
for _, ev := range events.Items {
eventsString +=
fmt.Sprintf(
"[%s] %s %s\n",
Expand Down Expand Up @@ -112,3 +113,30 @@ func GetProviders() []provider.Provider {

return providers
}

// SendProvidersMsg sends string msg to all providers
func SendProvidersMsg(p []provider.Provider, msg string) {
for _, prv := range p {
err :=
prv.SendMessage(msg)
if err != nil {
logrus.Errorf(
"failed to send msg with %s: %s",
prv.Name(),
err.Error())
}
}
}

// SendProvidersEvent sends event to all providers
func SendProvidersEvent(p []provider.Provider, event event.Event) {
for _, prv := range p {
if err := prv.SendEvent(&event); err != nil {
logrus.Errorf(
"failed to send event with %s: %s",
prv.Name(),
err.Error(),
)
}
}
}
0