Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
kubewatch
.vscode
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ supported webhooks:
- webhook
- cloudevent
- smtp
- webex

Usage:
kubewatch [flags]
Expand Down Expand Up @@ -473,6 +474,10 @@ handler:
token: ""
room: ""
url: ""
webex:
token: ""
room: ""
url: ""
mattermost:
channel: ""
url: ""
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ supported webhooks:
- flock
- webhook
- lark
- webex
`,

Run: func(cmd *cobra.Command, args []string) {
Expand Down
10 changes: 10 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type Handler struct {
MSTeams MSTeams `json:"msteams"`
SMTP SMTP `json:"smtp"`
Lark Lark `json:"lark"`
Webex Webex `json:"webex"`
}

// Resource contains resource configuration
Expand Down Expand Up @@ -128,6 +129,15 @@ type Hipchat struct {
Url string `json:"url"`
}

type Webex struct {
// Webex token.
Token string `json:"token"`
// Room name.
Room string `json:"room"`
// URL of the webex server.
Url string `json:"url"`
}

// Mattermost contains mattermost configuration
type Mattermost struct {
Channel string `json:"room"`
Expand Down
6 changes: 3 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package config

import (
//"io/ioutil"
//"os"
//"testing"
// "io/ioutil"
// "os"
// "testing"
)

var configStr = `
Expand Down
7 changes: 7 additions & 0 deletions config/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ handler:
room: ""
# URL of the hipchat server.
url: ""
webex:
# Webex token.
token: ""
# Room name.
room: ""
# URL of the webex server.
url: ""
mattermost:
room: ""
url: ""
Expand Down
1 change: 1 addition & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ With each event get from k8s and matched filtering from configuration, it is pas
- `Slack`: which send notification to Slack channel based on information from config
- `Smtp`: which sends notifications to email recipients using a SMTP server obtained from config
- `Lark`: which sends notifications to Lark incoming webhook based on information from config
- `Webex`: which send notification to Webex room based on information from config

More handlers will be added in future.

Expand Down
18 changes: 18 additions & 0 deletions examples/conf/kubewatch.conf.webex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
handler:
webex:
enabled: true
token: token
room: room_id
url: https://webexapis.com/v1/messages
resource:
deployment: true
replicationcontroller: false
replicaset: false
daemonset: false
services: false
pod: false
job: false
persistentvolume: false
ingress: false
event: false
coreevent: false
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.14

require (
github.com/fatih/structtag v1.2.0
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jbogarin/go-cisco-webex-teams v0.4.3 // indirect
github.com/magiconair/properties v1.7.4 // indirect
github.com/mkmik/multierror v0.3.0
github.com/pelletier/go-toml v1.0.1 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-pdf/fpdf v0.5.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
github.com/go-pdf/fpdf v0.6.0/go.mod h1:HzcnA+A23uwogo0tp9yU+l3V+KXhiESpt1PMayhOh5M=
github.com/go-resty/resty/v2 v2.7.0 h1:me+K9p3uhSmXtrBZ4k9jcEAfJmuC8IivWHwaLZwPrFY=
github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSMVIq3w7q0I=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
Expand Down Expand Up @@ -802,6 +804,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 h1:zLTLjkaOFEFIOxY5BWLFLwh+cL8vOBW4XJ2aqLE/Tf0=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down Expand Up @@ -875,6 +879,8 @@ github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jbogarin/go-cisco-webex-teams v0.4.3 h1:gXRwLi5qNmqNS3EXj9ikVhXWNXGzbc4RFFzOtTA1WYE=
github.com/jbogarin/go-cisco-webex-teams v0.4.3/go.mod h1:UVLsP1NjEO9QfRcZsuO6R4AD/xMJLarkLuhcehSZlAA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down Expand Up @@ -953,6 +959,8 @@ github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa
github.com/pelletier/go-toml v1.0.1 h1:0nx4vKBl23+hEaCOV1mFhKS9vhhBtFYWC7rQY0vJAyE=
github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/peterhellberg/link v1.1.0 h1:s2+RH8EGuI/mI4QwrWGSYQCRz7uNgip9BaM04HKu5kc=
github.com/peterhellberg/link v1.1.0/go.mod h1:gtSlOT4jmkY8P47hbTc8PTgiDDWpdPbFYl75keYyBB8=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
Expand Down Expand Up @@ -1213,7 +1221,9 @@ golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qx
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
Expand Down
1 change: 1 addition & 0 deletions helm/kubewatch/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ keywords:
- mattermost
- flock
- msteams
- webex
maintainers: []
name: kubewatch
sources:
Expand Down
4 changes: 4 additions & 0 deletions helm/kubewatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ The command removes all the Kubernetes components associated with the chart and
| `hipchat.room` | HipChat room to notify | `""` |
| `hipchat.token` | HipChat token | `""` |
| `hipchat.url` | HipChat URL | `""` |
| `webex.enabled` | Enable Webex notifications | `false` |
| `webex.room` | Webex room to notify | `""` |
| `webex.token` | Webex token | `""` |
| `webex.url` | Webex URL | `""` |
| `mattermost.enabled` | Enable Mattermost notifications | `false` |
| `mattermost.channel` | Mattermost channel to notify | `""` |
| `mattermost.url` | Mattermost URL | `""` |
Expand Down
3 changes: 3 additions & 0 deletions helm/kubewatch/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ data:
{{- if .Values.webhook.enabled }}
webhook: {{- toYaml .Values.webhook | nindent 8 }}
{{- end }}
{{- if .Values.webex.enabled }}
webex: {{- toYaml .Values.webex | nindent 8 }}
{{- end }}
{{- if .Values.cloudevent.enabled }}
cloudevent: {{- toYaml .Values.cloudevent | nindent 8 }}
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions helm/kubewatch/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ spec:
- name: configuration
mountPath: /opt/bitnami/kubewatch/.kubewatch.yaml
subPath: .kubewatch.yaml
- name: configuration
mountPath: /root/.kubewatch.yaml
subPath: .kubewatch.yaml
{{- if .Values.extraVolumeMounts }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraVolumeMounts "context" $) | nindent 12 }}
{{- end }}
Expand Down
14 changes: 13 additions & 1 deletion helm/kubewatch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ hipchat:
room: ""
token: ""
url: ""
## @param webex.enabled Enable Webex notifications
## @param webex.room Webex room to notify
## @param webex.token Webex token
## @param webex.url Webex URL
##
webex:
enabled: false
room: ""
token: ""
url: ""
## @param mattermost.enabled Enable Mattermost notifications
## @param mattermost.channel Mattermost channel to notify
## @param mattermost.url Mattermost URL
Expand Down Expand Up @@ -238,7 +248,9 @@ lifecycleHooks: {}
## - name: FOO
## value: "bar"
##
extraEnvVars: []
extraEnvVars:
- name: KUBEWATCH_NAME
value: ""
## @param extraEnvVarsCM Name of existing ConfigMap containing extra env vars
##
extraEnvVarsCM: ""
Expand Down
5 changes: 4 additions & 1 deletion pkg/client/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package client

import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"net/http"
"os"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/bitnami-labs/kubewatch/config"
"github.com/bitnami-labs/kubewatch/pkg/controller"
Expand All @@ -33,6 +33,7 @@ import (
"github.com/bitnami-labs/kubewatch/pkg/handlers/slack"
"github.com/bitnami-labs/kubewatch/pkg/handlers/slackwebhook"
"github.com/bitnami-labs/kubewatch/pkg/handlers/smtp"
"github.com/bitnami-labs/kubewatch/pkg/handlers/webex"
"github.com/bitnami-labs/kubewatch/pkg/handlers/webhook"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -67,6 +68,8 @@ func ParseEventHandler(conf *config.Config) handlers.Handler {
eventHandler = new(slackwebhook.SlackWebhook)
case len(conf.Handler.Hipchat.Room) > 0 || len(conf.Handler.Hipchat.Token) > 0:
eventHandler = new(hipchat.Hipchat)
case len(conf.Handler.Webex.Room) > 0 || len(conf.Handler.Webex.Token) > 0:
eventHandler = new(webex.Webex)
case len(conf.Handler.Mattermost.Channel) > 0 || len(conf.Handler.Mattermost.Url) > 0:
eventHandler = new(mattermost.Mattermost)
case len(conf.Handler.Flock.Url) > 0:
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
"k8s.io/client-go/util/workqueue"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promauto"
)

const maxRetries = 5
Expand Down Expand Up @@ -96,7 +96,7 @@ func objName(obj interface{}) string {
func Start(conf *config.Config, eventHandler handlers.Handler) {
var kubeClient kubernetes.Interface
var dynamicClient dynamic.Interface

kubewatchEventsMetrics := promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "kubewatch_events_total",
Expand Down
26 changes: 18 additions & 8 deletions pkg/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package event

import (
"fmt"
"os"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down Expand Up @@ -44,50 +45,59 @@ var m = map[string]string{
// included as a part of event packege to enhance code resuablity across handlers.
func (e *Event) Message() (msg string) {
// using switch over if..else, since the format could vary based on the kind of the object in future.
kubewatchName := os.Getenv("KUBEWATCH_NAME")
switch e.Kind {
case "namespace":
msg = fmt.Sprintf(
"A namespace `%s` has been `%s`",
"`%s` - A namespace `%s` has been `%s`",
kubewatchName,
e.Name,
e.Reason,
)
case "node":
msg = fmt.Sprintf(
"A node `%s` has been `%s`",
"`%s` - A node `%s` has been `%s`",
kubewatchName,
e.Name,
e.Reason,
)
case "cluster role":
msg = fmt.Sprintf(
"A cluster role `%s` has been `%s`",
"`%s` - A cluster role `%s` has been `%s`",
kubewatchName,
e.Name,
e.Reason,
)
case "NodeReady":
msg = fmt.Sprintf(
"Node `%s` is Ready : \nNodeReady",
"`%s` - Node `%s` is Ready : \nNodeReady",
kubewatchName,
e.Name,
)
case "NodeNotReady":
msg = fmt.Sprintf(
"Node `%s` is Not Ready : \nNodeNotReady",
"`%s` - Node `%s` is Not Ready : \nNodeNotReady",
kubewatchName,
e.Name,
)
case "NodeRebooted":
msg = fmt.Sprintf(
"Node `%s` Rebooted : \nNodeRebooted",
"`%s` - Node `%s` Rebooted : \nNodeRebooted",
kubewatchName,
e.Name,
)
case "Backoff":
msg = fmt.Sprintf(
"Pod `%s` in `%s` Crashed : \nCrashLoopBackOff %s",
"`%s` - Pod `%s` in `%s` Crashed : \nCrashLoopBackOff %s",
kubewatchName,
e.Name,
e.Namespace,
e.Reason,
)
default:
msg = fmt.Sprintf(
"A `%s` in namespace `%s` has been `%s`:\n`%s`",
"`%s` - A `%s` in namespace `%s` has been `%s`:\n`%s`",
kubewatchName,
e.Kind,
e.Namespace,
e.Reason,
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/bitnami-labs/kubewatch/pkg/handlers/slack"
"github.com/bitnami-labs/kubewatch/pkg/handlers/slackwebhook"
"github.com/bitnami-labs/kubewatch/pkg/handlers/smtp"
"github.com/bitnami-labs/kubewatch/pkg/handlers/webex"
"github.com/bitnami-labs/kubewatch/pkg/handlers/webhook"
)

Expand All @@ -49,6 +50,7 @@ var Map = map[string]interface{}{
"ms-teams": &msteam.MSTeams{},
"smtp": &smtp.SMTP{},
"lark": &lark.Webhook{},
"webex": &webex.Webex{},
}

// Default handler implements Handler interface,
Expand Down
Loading