From 65c434682106efdc6812a21e7cb25a9b691b43a0 Mon Sep 17 00:00:00 2001 From: Florian Schwab Date: Sun, 12 May 2019 22:15:03 +0200 Subject: [PATCH 1/3] * switch to viper * read flags from config file --- .gitignore | 3 ++ Gopkg.lock | 95 +++++++++++++++++++++++++++++++++++++++++ Gopkg.toml | 4 ++ cmd/event.go | 96 ++++++++++++++++++++++++++++++++---------- cmd/redmine.go | 23 +++++----- cmd/redmineImport.go | 7 +-- cmd/root.go | 76 ++++++++++++++++----------------- config.yml.sample | 13 ++++++ handler/handler.go | 2 +- handler/helpers.go | 2 +- handler/slack.go | 8 +++- recipient/project.go | 4 +- recipient/recipient.go | 2 +- redmine/import.go | 2 +- 14 files changed, 253 insertions(+), 84 deletions(-) create mode 100644 config.yml.sample diff --git a/.gitignore b/.gitignore index 4e63896..34b2111 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,8 @@ # deploy /dist +# config +/config.yml + # misc /.data diff --git a/Gopkg.lock b/Gopkg.lock index a5ddd99..f78f1a0 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -37,6 +37,14 @@ revision = "d7c2918981322d4d437f7a52f3a15c7ec5a4f488" version = "v1.0.0" +[[projects]] + digest = "1:7fc160b460a6fc506b37fcca68332464c3f2cd57b6e3f111f26c5bbfd2d5518e" + name = "github.com/fsnotify/fsnotify" + packages = ["."] + pruneopts = "T" + revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" + version = "v1.4.7" + [[projects]] digest = "1:19a4d1c7e0df2c11ac937d9960d190522ef1a98d5f0f5098ae4dc7eacc6dd173" name = "github.com/go-redis/redis" @@ -79,6 +87,25 @@ revision = "b5d812f8a3706043e23a9cd5babf2e5423744d30" version = "v1.3.1" +[[projects]] + digest = "1:071bcbf82c289fba4d3f63c876bf4f0ba7eda625cd60795e0a03ccbf949e517a" + name = "github.com/hashicorp/hcl" + packages = [ + ".", + "hcl/ast", + "hcl/parser", + "hcl/printer", + "hcl/scanner", + "hcl/strconv", + "hcl/token", + "json/parser", + "json/scanner", + "json/token", + ] + pruneopts = "T" + revision = "8cb6e5b959231cc1119e43259c4a608f9c51a241" + version = "v1.0.0" + [[projects]] digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be" name = "github.com/inconshreveable/mousetrap" @@ -94,6 +121,14 @@ pruneopts = "T" revision = "f7279a603edee96fe7764d3de9c6ff8cf9970994" +[[projects]] + digest = "1:d7cc16f6f66fd3f5864ff77480288704b02e5263f6f243dae62b43fdf4bb638e" + name = "github.com/magiconair/properties" + packages = ["."] + pruneopts = "T" + revision = "de8848e004dd33dc07a2947b3d76f618a7fc7ef1" + version = "v1.8.1" + [[projects]] branch = "master" digest = "1:bc5cab5853a232c09c8103cb4604919b9ec0b6da0d11d5355f802775fe9df931" @@ -102,6 +137,22 @@ pruneopts = "T" revision = "2267b9239bac0bb8a7123648f080f264fc5b3973" +[[projects]] + digest = "1:53bc4cd4914cd7cd52139990d5170d6dc99067ae31c56530621b18b35fc30318" + name = "github.com/mitchellh/mapstructure" + packages = ["."] + pruneopts = "T" + revision = "3536a929edddb9a5b34bd6861dc4a9647cb459fe" + version = "v1.1.2" + +[[projects]] + digest = "1:abc5966f690dedc4943d8bed4cdddb0c4fb6e4490ff7702fa4ce2a7c35efbaf7" + name = "github.com/pelletier/go-toml" + packages = ["."] + pruneopts = "T" + revision = "728039f679cbcd4f6a54e080d2219a4c4928c546" + version = "v1.4.0" + [[projects]] branch = "master" digest = "1:94c421703a0bb21759a4c91b817ed69044563e7104caa260589ba8fe4a785650" @@ -138,6 +189,25 @@ revision = "32aea478ae74c3753710887d2ce2556b598d82bb" version = "5.7.0" +[[projects]] + digest = "1:dee0cc3252ce6fcc3334c9529abd32925f2aaf072c90336a5a38254953564aa5" + name = "github.com/spf13/afero" + packages = [ + ".", + "mem", + ] + pruneopts = "T" + revision = "588a75ec4f32903aa5e39a2619ba6a4631e28424" + version = "v1.2.2" + +[[projects]] + digest = "1:08d65904057412fc0270fc4812a1c90c594186819243160dc779a402d4b6d0bc" + name = "github.com/spf13/cast" + packages = ["."] + pruneopts = "T" + revision = "8c9545af88b134710ab1cd196795e7f2388358d7" + version = "v1.3.0" + [[projects]] digest = "1:8be8b3743fc9795ec21bbd3e0fc28ff6234018e1a269b0a7064184be95ac13e0" name = "github.com/spf13/cobra" @@ -146,6 +216,14 @@ revision = "ef82de70bb3f60c65fb8eebacbb2d122ef517385" version = "v0.0.3" +[[projects]] + digest = "1:1b753ec16506f5864d26a28b43703c58831255059644351bbcb019b843950900" + name = "github.com/spf13/jwalterweatherman" + packages = ["."] + pruneopts = "T" + revision = "94f6ae3ed3bceceafa716478c5fbf8d29ca601a1" + version = "v1.1.0" + [[projects]] digest = "1:0f775ea7a72e30d5574267692aaa9ff265aafd15214a7ae7db26bc77f2ca04dc" name = "github.com/spf13/pflag" @@ -154,6 +232,14 @@ revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" +[[projects]] + digest = "1:2eeca55c5718eafa5ee2538e920ca43a30c334acfed5404ac650ecda1c06e97c" + name = "github.com/spf13/viper" + packages = ["."] + pruneopts = "T" + revision = "9e56dacc08fbbf8c9ee2dbc717553c758ce42bc9" + version = "v1.3.2" + [[projects]] branch = "master" digest = "1:dadb7a0fd6196a294db8552352b41554ff862c6d632db861761d89570757a103" @@ -263,6 +349,14 @@ revision = "6e83acea0053641eff084973fee085f0c193c61a" version = "v1.0.5" +[[projects]] + digest = "1:4d2e5a73dc1500038e504a8d78b986630e3626dc027bc030ba5c75da257cdb96" + name = "gopkg.in/yaml.v2" + packages = ["."] + pruneopts = "T" + revision = "51d6538a90f86fe93ac480b35f37b2be17fef232" + version = "v2.2.2" + [solve-meta] analyzer-name = "dep" analyzer-version = 1 @@ -272,6 +366,7 @@ "github.com/mattn/go-redmine", "github.com/sensu/sensu-go/types", "github.com/spf13/cobra", + "github.com/spf13/viper", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 5b69bb0..05bc127 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -5,6 +5,10 @@ name = "github.com/spf13/cobra" version = "0.0.3" +[[constraint]] + name = "github.com/spf13/viper" + version = "1.3.2" + [[constraint]] name = "github.com/sensu/sensu-go" version = "5.7.0" diff --git a/cmd/event.go b/cmd/event.go index 9d973c9..413e00a 100644 --- a/cmd/event.go +++ b/cmd/event.go @@ -3,24 +3,21 @@ package cmd import ( - "encoding/json" - "errors" + "os" "fmt" + "errors" + "strings" "io/ioutil" - "os" + "encoding/json" "github.com/sensu/sensu-go/types" "github.com/spf13/cobra" + "github.com/spf13/viper" "sensu-sic-handler/handler" "sensu-sic-handler/recipient" ) -var ( - annotationPrefix string - handlerConfig = &handler.Config{} -) - // eventCmd represents the "event" command var eventCmd = &cobra.Command{ Use: "event", @@ -49,35 +46,48 @@ var eventCmd = &cobra.Command{ func init() { rootCmd.AddCommand(eventCmd) - eventCmd.PersistentFlags().StringVar(&annotationPrefix, + eventCmd.PersistentFlags().String( + "outputs", + "mail,slack,xmpp", + "The outputs to use, defaults to 'mail,slack,xmpp'") + + eventCmd.PersistentFlags().String( "annotation-prefix", - os.Getenv("ANNOTATION_PREFIX"), - "The annotation prefix to use, defaults to value of ANNOTATION_PREFIX env variable") + "sic.software", + "The annotation prefix to use") - eventCmd.PersistentFlags().StringVar(&handlerConfig.SMTPAddress, + eventCmd.PersistentFlags().String( "smtp-address", - os.Getenv("SMTP_ADDRESS"), - "The address of the SMTP server to use, defaults to value of SMTP_ADDRESS env variable") + "localhost", + "The address of the SMTP server to use, defaults to localhost") - eventCmd.PersistentFlags().StringVar(&handlerConfig.MailFrom, + eventCmd.PersistentFlags().String( "mail-from", - os.Getenv("MAIL_FROM"), - "The sender address for emails, defaults to value of MAIL_FROM env variable") + "", + "The sender address for emails") - eventCmd.PersistentFlags().StringVar(&handlerConfig.SlackWebhookURL, + eventCmd.PersistentFlags().String( "slack-webhook-url", - os.Getenv("SLACK_WEBHOOK_URL"), - "The webhook url to send messages to, defaults to value of SLACK_WEBHOOK_URL env variable") + "", + "The webhook url to send messages to") - eventCmd.PersistentFlags().StringVar(&handlerConfig.SlackUsername, + eventCmd.PersistentFlags().String( "slack-username", "sensu", "The username that messages will be sent as") - eventCmd.PersistentFlags().StringVar(&handlerConfig.SlackIconURL, + eventCmd.PersistentFlags().String( "slack-icon-url", "http://s3-us-west-2.amazonaws.com/sensuapp.org/sensu.png", "A URL to an image to use as the user avatar") + + viper.BindPFlag("outputs", eventCmd.PersistentFlags().Lookup("outputs")) + viper.BindPFlag("annotation-prefix", eventCmd.PersistentFlags().Lookup("annotation-prefix")) + viper.BindPFlag("smtp-address", eventCmd.PersistentFlags().Lookup("smtp-address")) + viper.BindPFlag("mail-from", eventCmd.PersistentFlags().Lookup("mail-from")) + viper.BindPFlag("slack-webhook-url", eventCmd.PersistentFlags().Lookup("slack-webhook-url")) + viper.BindPFlag("slack-username", eventCmd.PersistentFlags().Lookup("slack-username")) + viper.BindPFlag("slack-icon-url", eventCmd.PersistentFlags().Lookup("slack-icon-url")) } func loadEvent() (*types.Event, error) { @@ -125,9 +135,19 @@ func handleEvent(event *types.Event) error { return nil } - if val, ok := event.Entity.Annotations[fmt.Sprintf("%s/recipients", annotationPrefix)]; ok { + if val, ok := event.Entity.Annotations[fmt.Sprintf("%s/recipients", viper.GetString("annotation-prefix"))]; ok { + handlerConfig := &handler.Config{ + SMTPAddress: viper.GetString("smtp-address"), + MailFrom: viper.GetString("mail-from"), + SlackWebhookURL: viper.GetString("slack-webhook-url"), + SlackUsername: viper.GetString("slack-username"), + SlackIconURL: viper.GetString("slack-icon-url"), + } + recipients := recipient.Parse(redisClient, val) + recipients = filterRecipients(recipients) + err := handler.Handle(recipients, event, handlerConfig) if err != nil { return err @@ -136,3 +156,33 @@ func handleEvent(event *types.Event) error { return nil } + +func filterRecipients(recipients []*recipient.Recipient) []*recipient.Recipient { + filtered := make([]*recipient.Recipient, 0) + + useMail, useSlack, useXMPP := false, false, false + + for _, output := range strings.Split(viper.GetString("outputs"), ",") { + switch output { + case "mail": + useMail = true + case "slack": + useSlack = true + case "xmpp": + useXMPP = true + } + } + + for _, rcpt := range recipients { + switch rcpt.Type { + case recipient.HandlerTypeMail: + if useMail { filtered = append(filtered, rcpt) } + case recipient.HandlerTypeSlack: + if useSlack { filtered = append(filtered, rcpt) } + case recipient.HandlerTypeXMPP: + if useXMPP { filtered = append(filtered, rcpt) } + } + } + + return filtered +} diff --git a/cmd/redmine.go b/cmd/redmine.go index 6e0c589..ad1a25c 100644 --- a/cmd/redmine.go +++ b/cmd/redmine.go @@ -3,14 +3,8 @@ package cmd import ( - "os" - "github.com/spf13/cobra" -) - -var ( - redmineURL string - redmineToken string + "github.com/spf13/viper" ) // redmineCmd represents the "redmine" command @@ -22,13 +16,16 @@ var redmineCmd = &cobra.Command{ func init() { rootCmd.AddCommand(redmineCmd) - redmineCmd.PersistentFlags().StringVar(&redmineURL, + redmineCmd.PersistentFlags().String( "redmine-url", - os.Getenv("REDMINE_URL"), - "The redmine url to import data from, defaults to value of REDMINE_URL env variable") + "", + "The redmine url to import data from") - redmineCmd.PersistentFlags().StringVar(&redmineToken, + redmineCmd.PersistentFlags().String( "redmine-token", - os.Getenv("REDMINE_TOKEN"), - "The redmine token used for authentication, defaults to value of REDMINE_TOKEN env variable") + "", + "The redmine token used for authentication") + + viper.BindPFlag("redmine-url", redmineCmd.PersistentFlags().Lookup("redmine-url")) + viper.BindPFlag("redmine-token", redmineCmd.PersistentFlags().Lookup("redmine-token")) } diff --git a/cmd/redmineImport.go b/cmd/redmineImport.go index 933e664..b6a0b52 100644 --- a/cmd/redmineImport.go +++ b/cmd/redmineImport.go @@ -4,6 +4,7 @@ package cmd import ( "github.com/spf13/cobra" + "github.com/spf13/viper" "sensu-sic-handler/redmine" ) @@ -18,17 +19,17 @@ var redmineImportCmd = &cobra.Command{ return } - if redmineURL == "" { + if viper.GetString("redmine-url") == "" { terminateWithHelpAndMessage(cmd, "redmine url is empty") return } - if redmineToken == "" { + if viper.GetString("redmine-token") == "" { terminateWithHelpAndMessage(cmd, "redmine token is empty") return } - err := redmine.Import(redmineURL, redmineToken, redisClient) + err := redmine.Import(viper.GetString("redmine-url"), viper.GetString("redmine-token"), redisClient) if err != nil { terminateWithHelpAndMessage(cmd, err.Error()) return diff --git a/cmd/root.go b/cmd/root.go index ef54fa5..8ee13ef 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,18 +3,16 @@ package cmd import ( - "fmt" "os" - "strconv" + "fmt" "github.com/go-redis/redis" "github.com/spf13/cobra" + "github.com/spf13/viper" ) var ( - redisHost string - redisPort int - redisDB int + cfgFile string redisClient *redis.Client ) @@ -36,50 +34,47 @@ func Execute() { func init() { cobra.OnInitialize(initConfig) - rootCmd.PersistentFlags().StringVar(&redisHost, + rootCmd.PersistentFlags().StringVarP(&cfgFile, + "config", + "c", + os.Getenv("SIC_CONFIG"), + "Configuration file to use, defaults to value of SIC_CONFIG env variable") + + rootCmd.PersistentFlags().String( "redis-host", - os.Getenv("REDIS_HOST"), - "The redis hostname, defaults to value of REDIS_HOST env variable") + "localhost", + "The redis hostname") - rootCmd.PersistentFlags().IntVar(&redisPort, + rootCmd.PersistentFlags().Int( "redis-port", - -1, - "The redis port, defaults to value of REDIS_PORT env variable") + 6379, + "The redis port") - rootCmd.PersistentFlags().IntVar(&redisDB, + rootCmd.PersistentFlags().Int( "redis-db", - -1, - "The redis db, defaults to value of REDIS_DB env variable") + 0, + "The redis db number") + + viper.BindPFlag("redis-host", rootCmd.PersistentFlags().Lookup("redis-host")) + viper.BindPFlag("redis-port", rootCmd.PersistentFlags().Lookup("redis-port")) + viper.BindPFlag("redis-db", rootCmd.PersistentFlags().Lookup("redis-db")) } // setup default values and variables func initConfig() { - if redisHost == "" { - redisHost = "localhost" - } - - if redisPort == -1 { - redisPort = intValueFromEnvWithDefault("REDIS_PORT", 6379) - } - - if redisDB == -1 { - redisDB = intValueFromEnvWithDefault("REDIS_DB", 0) + if cfgFile != "" { + // Use config file from the flag. + viper.SetConfigFile(cfgFile) + + // If a config file is found, read it in. + err := viper.ReadInConfig() + if err != nil { + terminateWithError(err) + } } - redisClient = redis.NewClient(&redis.Options{Addr: fmt.Sprintf("%s:%d", redisHost, redisPort), DB: redisDB}) -} - -func intValueFromEnvWithDefault(env string, defaultValue int) int { - if os.Getenv(env) == "" { - return defaultValue - } - - i, err := strconv.Atoi(os.Getenv(env)) - if err != nil { - return defaultValue - } - - return i + redisAddr := fmt.Sprintf("%s:%d", viper.GetString("redis-host"), viper.GetInt("redis-port")) + redisClient = redis.NewClient(&redis.Options{Addr: redisAddr, DB: viper.GetInt("redis-db")}) } func terminateWithHelpAndMessage(cmd *cobra.Command, msg string) { @@ -88,3 +83,8 @@ func terminateWithHelpAndMessage(cmd *cobra.Command, msg string) { fmt.Fprintln(os.Stderr, "") fmt.Fprintln(os.Stderr, msg) } + +func terminateWithError(err error) { + fmt.Println(err) + os.Exit(1) +} diff --git a/config.yml.sample b/config.yml.sample new file mode 100644 index 0000000..43e1f2f --- /dev/null +++ b/config.yml.sample @@ -0,0 +1,13 @@ +redis-host: redis +redis-port: 6379 +redis-db: 0 + +redmine-url: https://redmine.example.org +redmine-token: 43787d62a102ca4e37b5cf6f8d92129e99d5f425 + +annotation-prefix: example.org +smtp-address: mail.example.org +mail-from: sensu@example.org +slack-webhook-url: https://hooks.slack.com/services/foo/bar +slack-username: sensu +slack-icon-url: http://s3-us-west-2.amazonaws.com/sensuapp.org/sensu.png diff --git a/handler/handler.go b/handler/handler.go index 28f0558..dd3da12 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -3,8 +3,8 @@ package handler import ( - "fmt" "os" + "fmt" sensu "github.com/sensu/sensu-go/types" diff --git a/handler/helpers.go b/handler/helpers.go index 455d9cf..db91482 100644 --- a/handler/helpers.go +++ b/handler/helpers.go @@ -3,8 +3,8 @@ package handler import ( - "bytes" "fmt" + "bytes" "strings" "text/template" diff --git a/handler/slack.go b/handler/slack.go index 8d5b944..a3e9104 100644 --- a/handler/slack.go +++ b/handler/slack.go @@ -4,14 +4,20 @@ package handler import ( - "github.com/bluele/slack" + "errors" + sensu "github.com/sensu/sensu-go/types" + "github.com/bluele/slack" "sensu-sic-handler/recipient" ) // HandleSlack handles slack recipients (recipient.HandlerTypeSlack) func HandleSlack(recipient *recipient.Recipient, event *sensu.Event, config *Config) error { + if len(config.SlackWebhookURL) == 0 { + return errors.New("webhook url is empty") + } + hook := slack.NewWebHook(config.SlackWebhookURL) return hook.PostMessage(&slack.WebHookPostPayload{ diff --git a/recipient/project.go b/recipient/project.go index c424c30..cad8f6f 100644 --- a/recipient/project.go +++ b/recipient/project.go @@ -3,10 +3,10 @@ package recipient import ( - "encoding/json" "fmt" - "strconv" "strings" + "strconv" + "encoding/json" "github.com/go-redis/redis" diff --git a/recipient/recipient.go b/recipient/recipient.go index 95cc7cf..38c6555 100644 --- a/recipient/recipient.go +++ b/recipient/recipient.go @@ -3,8 +3,8 @@ package recipient import ( - "fmt" "os" + "fmt" "strings" "github.com/go-redis/redis" diff --git a/redmine/import.go b/redmine/import.go index dedee4b..34d7bf9 100644 --- a/redmine/import.go +++ b/redmine/import.go @@ -3,8 +3,8 @@ package redmine import ( - "encoding/json" "errors" + "encoding/json" "github.com/go-redis/redis" redmine "github.com/mattn/go-redmine" From 1e2f240efe68bd2ebd70c45f6f0c8f4be5d716f6 Mon Sep 17 00:00:00 2001 From: Florian Schwab Date: Sun, 12 May 2019 22:17:02 +0200 Subject: [PATCH 2/3] gofmt --- cmd/event.go | 20 +++++++++++++------- cmd/root.go | 2 +- handler/handler.go | 2 +- handler/helpers.go | 2 +- handler/slack.go | 2 +- recipient/project.go | 4 ++-- recipient/recipient.go | 2 +- redmine/import.go | 2 +- 8 files changed, 21 insertions(+), 15 deletions(-) diff --git a/cmd/event.go b/cmd/event.go index 413e00a..b16128c 100644 --- a/cmd/event.go +++ b/cmd/event.go @@ -3,12 +3,12 @@ package cmd import ( - "os" - "fmt" + "encoding/json" "errors" - "strings" + "fmt" "io/ioutil" - "encoding/json" + "os" + "strings" "github.com/sensu/sensu-go/types" "github.com/spf13/cobra" @@ -176,11 +176,17 @@ func filterRecipients(recipients []*recipient.Recipient) []*recipient.Recipient for _, rcpt := range recipients { switch rcpt.Type { case recipient.HandlerTypeMail: - if useMail { filtered = append(filtered, rcpt) } + if useMail { + filtered = append(filtered, rcpt) + } case recipient.HandlerTypeSlack: - if useSlack { filtered = append(filtered, rcpt) } + if useSlack { + filtered = append(filtered, rcpt) + } case recipient.HandlerTypeXMPP: - if useXMPP { filtered = append(filtered, rcpt) } + if useXMPP { + filtered = append(filtered, rcpt) + } } } diff --git a/cmd/root.go b/cmd/root.go index 8ee13ef..10dd29f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -3,8 +3,8 @@ package cmd import ( - "os" "fmt" + "os" "github.com/go-redis/redis" "github.com/spf13/cobra" diff --git a/handler/handler.go b/handler/handler.go index dd3da12..28f0558 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -3,8 +3,8 @@ package handler import ( - "os" "fmt" + "os" sensu "github.com/sensu/sensu-go/types" diff --git a/handler/helpers.go b/handler/helpers.go index db91482..455d9cf 100644 --- a/handler/helpers.go +++ b/handler/helpers.go @@ -3,8 +3,8 @@ package handler import ( - "fmt" "bytes" + "fmt" "strings" "text/template" diff --git a/handler/slack.go b/handler/slack.go index a3e9104..b60bd36 100644 --- a/handler/slack.go +++ b/handler/slack.go @@ -6,8 +6,8 @@ package handler import ( "errors" - sensu "github.com/sensu/sensu-go/types" "github.com/bluele/slack" + sensu "github.com/sensu/sensu-go/types" "sensu-sic-handler/recipient" ) diff --git a/recipient/project.go b/recipient/project.go index cad8f6f..c424c30 100644 --- a/recipient/project.go +++ b/recipient/project.go @@ -3,10 +3,10 @@ package recipient import ( + "encoding/json" "fmt" - "strings" "strconv" - "encoding/json" + "strings" "github.com/go-redis/redis" diff --git a/recipient/recipient.go b/recipient/recipient.go index 38c6555..95cc7cf 100644 --- a/recipient/recipient.go +++ b/recipient/recipient.go @@ -3,8 +3,8 @@ package recipient import ( - "os" "fmt" + "os" "strings" "github.com/go-redis/redis" diff --git a/redmine/import.go b/redmine/import.go index 34d7bf9..dedee4b 100644 --- a/redmine/import.go +++ b/redmine/import.go @@ -3,8 +3,8 @@ package redmine import ( - "errors" "encoding/json" + "errors" "github.com/go-redis/redis" redmine "github.com/mattn/go-redmine" From e363a45768c743e3c2cad35e4ddeb68db35bf6a8 Mon Sep 17 00:00:00 2001 From: Florian Schwab Date: Sun, 12 May 2019 22:23:54 +0200 Subject: [PATCH 3/3] explicitly ignore error --- cmd/event.go | 14 +++++++------- cmd/redmine.go | 4 ++-- cmd/root.go | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/event.go b/cmd/event.go index b16128c..255b7ec 100644 --- a/cmd/event.go +++ b/cmd/event.go @@ -81,13 +81,13 @@ func init() { "http://s3-us-west-2.amazonaws.com/sensuapp.org/sensu.png", "A URL to an image to use as the user avatar") - viper.BindPFlag("outputs", eventCmd.PersistentFlags().Lookup("outputs")) - viper.BindPFlag("annotation-prefix", eventCmd.PersistentFlags().Lookup("annotation-prefix")) - viper.BindPFlag("smtp-address", eventCmd.PersistentFlags().Lookup("smtp-address")) - viper.BindPFlag("mail-from", eventCmd.PersistentFlags().Lookup("mail-from")) - viper.BindPFlag("slack-webhook-url", eventCmd.PersistentFlags().Lookup("slack-webhook-url")) - viper.BindPFlag("slack-username", eventCmd.PersistentFlags().Lookup("slack-username")) - viper.BindPFlag("slack-icon-url", eventCmd.PersistentFlags().Lookup("slack-icon-url")) + _ = viper.BindPFlag("outputs", eventCmd.PersistentFlags().Lookup("outputs")) + _ = viper.BindPFlag("annotation-prefix", eventCmd.PersistentFlags().Lookup("annotation-prefix")) + _ = viper.BindPFlag("smtp-address", eventCmd.PersistentFlags().Lookup("smtp-address")) + _ = viper.BindPFlag("mail-from", eventCmd.PersistentFlags().Lookup("mail-from")) + _ = viper.BindPFlag("slack-webhook-url", eventCmd.PersistentFlags().Lookup("slack-webhook-url")) + _ = viper.BindPFlag("slack-username", eventCmd.PersistentFlags().Lookup("slack-username")) + _ = viper.BindPFlag("slack-icon-url", eventCmd.PersistentFlags().Lookup("slack-icon-url")) } func loadEvent() (*types.Event, error) { diff --git a/cmd/redmine.go b/cmd/redmine.go index ad1a25c..754f2ba 100644 --- a/cmd/redmine.go +++ b/cmd/redmine.go @@ -26,6 +26,6 @@ func init() { "", "The redmine token used for authentication") - viper.BindPFlag("redmine-url", redmineCmd.PersistentFlags().Lookup("redmine-url")) - viper.BindPFlag("redmine-token", redmineCmd.PersistentFlags().Lookup("redmine-token")) + _ = viper.BindPFlag("redmine-url", redmineCmd.PersistentFlags().Lookup("redmine-url")) + _ = viper.BindPFlag("redmine-token", redmineCmd.PersistentFlags().Lookup("redmine-token")) } diff --git a/cmd/root.go b/cmd/root.go index 10dd29f..d08e765 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -55,9 +55,9 @@ func init() { 0, "The redis db number") - viper.BindPFlag("redis-host", rootCmd.PersistentFlags().Lookup("redis-host")) - viper.BindPFlag("redis-port", rootCmd.PersistentFlags().Lookup("redis-port")) - viper.BindPFlag("redis-db", rootCmd.PersistentFlags().Lookup("redis-db")) + _ = viper.BindPFlag("redis-host", rootCmd.PersistentFlags().Lookup("redis-host")) + _ = viper.BindPFlag("redis-port", rootCmd.PersistentFlags().Lookup("redis-port")) + _ = viper.BindPFlag("redis-db", rootCmd.PersistentFlags().Lookup("redis-db")) } // setup default values and variables