From c122337b530ef24e12aa35f86634e4e4eecfe5ad Mon Sep 17 00:00:00 2001 From: Luca Bigliardi Date: Thu, 5 Mar 2020 08:49:31 +0000 Subject: [PATCH] Add config option to skip SSL certs checks This addresses https://github.com/google/alertmanager-irc-relay/issues/3 Signed-off-by: Luca Bigliardi --- config.go | 48 +++++++++++++++++++++++++----------------------- irc.go | 5 ++++- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/config.go b/config.go index 41f7cf2..97adfb7 100644 --- a/config.go +++ b/config.go @@ -30,33 +30,35 @@ type IRCChannel struct { } type Config struct { - HTTPHost string `yaml:"http_host"` - HTTPPort int `yaml:"http_port"` - IRCNick string `yaml:"irc_nickname"` - IRCNickPass string `yaml:"irc_nickname_password"` - IRCRealName string `yaml:"irc_realname"` - IRCHost string `yaml:"irc_host"` - IRCPort int `yaml:"irc_port"` - IRCUseSSL bool `yaml:"irc_use_ssl"` - IRCChannels []IRCChannel `yaml:"irc_channels"` - MsgTemplate string `yaml:"msg_template"` - MsgOnce bool `yaml:"msg_once_per_alert_group"` - UsePrivmsg bool `yaml:"use_privmsg"` + HTTPHost string `yaml:"http_host"` + HTTPPort int `yaml:"http_port"` + IRCNick string `yaml:"irc_nickname"` + IRCNickPass string `yaml:"irc_nickname_password"` + IRCRealName string `yaml:"irc_realname"` + IRCHost string `yaml:"irc_host"` + IRCPort int `yaml:"irc_port"` + IRCUseSSL bool `yaml:"irc_use_ssl"` + IRCVerifySSL bool `yaml:"irc_verify_ssl"` + IRCChannels []IRCChannel `yaml:"irc_channels"` + MsgTemplate string `yaml:"msg_template"` + MsgOnce bool `yaml:"msg_once_per_alert_group"` + UsePrivmsg bool `yaml:"use_privmsg"` } func LoadConfig(configFile string) (*Config, error) { config := &Config{ - HTTPHost: "localhost", - HTTPPort: 8000, - IRCNick: "alertmanager-irc-relay", - IRCNickPass: "", - IRCRealName: "Alertmanager IRC Relay", - IRCHost: "irc.freenode.net", - IRCPort: 7000, - IRCUseSSL: true, - IRCChannels: []IRCChannel{IRCChannel{Name: "#airtest"}}, - MsgOnce: false, - UsePrivmsg: false, + HTTPHost: "localhost", + HTTPPort: 8000, + IRCNick: "alertmanager-irc-relay", + IRCNickPass: "", + IRCRealName: "Alertmanager IRC Relay", + IRCHost: "irc.freenode.net", + IRCPort: 7000, + IRCUseSSL: true, + IRCVerifySSL: true, + IRCChannels: []IRCChannel{IRCChannel{Name: "#airtest"}}, + MsgOnce: false, + UsePrivmsg: false, } if configFile != "" { diff --git a/irc.go b/irc.go index 8658ed7..875cdef 100644 --- a/irc.go +++ b/irc.go @@ -77,7 +77,10 @@ func NewIRCNotifier(config *Config, alertMsgs chan AlertMsg) (*IRCNotifier, erro ircConfig.Server = strings.Join( []string{config.IRCHost, strconv.Itoa(config.IRCPort)}, ":") ircConfig.SSL = config.IRCUseSSL - ircConfig.SSLConfig = &tls.Config{ServerName: config.IRCHost} + ircConfig.SSLConfig = &tls.Config{ + ServerName: config.IRCHost, + InsecureSkipVerify: !config.IRCVerifySSL, + } ircConfig.PingFreq = pingFrequencySecs * time.Second ircConfig.Timeout = connectionTimeoutSecs * time.Second ircConfig.NewNick = func(n string) string { return n + "^" }