Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Add handler for rocketchat handler #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@
[[constraint]]
name = "k8s.io/client-go"
revision = "78700dec6369ba22221b72770783300f143df150"

[[constraint]]
branch = "master"
name = "github.com/RocketChat/Rocket.Chat.Go.SDK"
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ func init() {
configCmd.AddCommand(resourceConfigCmd)
configCmd.AddCommand(flockConfigCmd)
configCmd.AddCommand(webhookConfigCmd)
configCmd.AddCommand(rocketchatConfigCmd)
}
103 changes: 103 additions & 0 deletions cmd/rocketchat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright 2016 Skippbox, Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"github.com/Sirupsen/logrus"
"github.com/bitnami-labs/kubewatch/config"
"github.com/spf13/cobra"
)

// rocketChatCmd represents the rocketChat subcommand
var rocketchatConfigCmd = &cobra.Command{
Use: "rocketchat FLAG",
Short: "specific rocketchat configuration",
Long: `specific rocketchat configuration`,
Run: func(cmd *cobra.Command, args []string) {
conf, err := config.New()
if err != nil {
logrus.Fatal(err)
}

host, err := cmd.Flags().GetString("host")
if err == nil {
if len(host) > 0 {
conf.Handler.Rocketchat.Host = host
}
} else {
logrus.Fatal(err)
}
port, err := cmd.Flags().GetInt("port")
if err == nil {

conf.Handler.Rocketchat.Port = port

} else {
logrus.Fatal(err)
}

user, err := cmd.Flags().GetString("user")
if err == nil {
if len(user) > 0 {
conf.Handler.Rocketchat.User = user
}
} else {
logrus.Fatal(err)
}
password, err := cmd.Flags().GetString("password")
if err == nil {
if len(password) > 0 {
conf.Handler.Rocketchat.Host = password
}
} else {
logrus.Fatal(err)
}

scheme, err := cmd.Flags().GetString("scheme")
if err == nil {
if len(scheme) > 0 {
conf.Handler.Rocketchat.Scheme = scheme
}
} else {
logrus.Fatal(err)
}

channel, err := cmd.Flags().GetString("channel")
if err == nil {
if len(channel) > 0 {
conf.Handler.Rocketchat.Channel = channel
}
} else {
logrus.Fatal(err)
}

if err = conf.Write(); err != nil {
logrus.Fatal(err)
}
},
}

func init() {
rocketchatConfigCmd.Flags().StringP("scheme", "", "", "Specify rocketchat host scheme eg http")
rocketchatConfigCmd.Flags().StringP("host", "", "", "Specify rocketchat host rocketchat.com")
rocketchatConfigCmd.Flags().IntP("port", "", 80, "Specify rocketchat port")
rocketchatConfigCmd.Flags().StringP("user", "", "kubewatch", "Specify rocketchat user")
rocketchatConfigCmd.Flags().StringP("password", "", "", "Specify rocketchat password")
rocketchatConfigCmd.Flags().StringP("channel", "", "", "Specify rocketchat channel")
rocketchatConfigCmd.Flags().StringP("email", "", "", "Specify rocketchat user email")

}
30 changes: 21 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Handler struct {
Mattermost Mattermost `json:"mattermost"`
Flock Flock `json:"flock"`
Webhook Webhook `json:"webhook"`
Rocketchat Rocketchat `json:"rocketchat"`
}

// Resource contains resource configuration
Expand Down Expand Up @@ -91,6 +92,17 @@ type Webhook struct {
Url string `json:"url"`
}

// RocketChat contains RocketChat configuration
type Rocketchat struct {
Scheme string `json:"scheme"`
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Email string `json:"email"`
Password string `json:"password"`
Channel string `json:"channel"`
}

// New creates new config object
func New() (*Config, error) {
c := &Config{}
Expand Down Expand Up @@ -212,15 +224,15 @@ func getConfigFile() string {
}

func configDir() string {
if configDir := os.Getenv("KW_CONFIG"); configDir != "" {
return configDir
}

if runtime.GOOS == "windows" {
home := os.Getenv("USERPROFILE")
return home
}
return os.Getenv("HOME")
if configDir := os.Getenv("KW_CONFIG"); configDir != "" {
return configDir
}

if runtime.GOOS == "windows" {
home := os.Getenv("USERPROFILE")
return home
}
return os.Getenv("HOME")
//path := "/etc/kubewatch"
//if _, err := os.Stat(path); os.IsNotExist(err) {
// os.Mkdir(path, 755)
Expand Down
19 changes: 19 additions & 0 deletions examples/conf/kubewatch.conf.rocketchat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
handler:
rocketchat:
scheme: "http"
host: "localhost"
port: 8080
user: "Kubewatch"
password: "Kubewatch"
email: "[email protected]"
channel: "GENERAL"
resource:
deployment: true
replicationcontroller: false
replicaset: false
daemonset: false
services: false
pod: false
job: false
persistentvolume: false
ingress: false
3 changes: 3 additions & 0 deletions pkg/client/run.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/mattermost"
"github.com/bitnami-labs/kubewatch/pkg/handlers/flock"
"github.com/bitnami-labs/kubewatch/pkg/handlers/webhook"
"github.com/bitnami-labs/kubewatch/pkg/handlers/rocketchat"
)

// Run runs the event loop processing with given handler
Expand All @@ -43,6 +44,8 @@ func Run(conf *config.Config) {
eventHandler = new(flock.Flock)
case len(conf.Handler.Webhook.Url) > 0:
eventHandler = new(webhook.Webhook)
case len(conf.Handler.Rocketchat.Host) > 0:
eventHandler = new(rocketchat.Rocketchat)
default:
eventHandler = new(handlers.Default)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/bitnami-labs/kubewatch/pkg/handlers/mattermost"
"github.com/bitnami-labs/kubewatch/pkg/handlers/flock"
"github.com/bitnami-labs/kubewatch/pkg/handlers/webhook"
"github.com/bitnami-labs/kubewatch/pkg/handlers/rocketchat"
)

// Handler is implemented by any handler.
Expand All @@ -42,6 +43,7 @@ var Map = map[string]interface{}{
"mattermost": &mattermost.Mattermost{},
"flock": &flock.Flock{},
"webhook": &webhook.Webhook{},
"rocketchat": &rocketchat.Rocketchat{},
}

// Default handler implements Handler interface,
Expand Down
Loading