Add config option to skip SSL certs checks

This addresses https://github.com/google/alertmanager-irc-relay/issues/3

Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
Luca Bigliardi 2020-03-05 08:49:31 +00:00
parent 286efdd365
commit c122337b53
2 changed files with 29 additions and 24 deletions

View File

@ -30,33 +30,35 @@ type IRCChannel struct {
} }
type Config struct { type Config struct {
HTTPHost string `yaml:"http_host"` HTTPHost string `yaml:"http_host"`
HTTPPort int `yaml:"http_port"` HTTPPort int `yaml:"http_port"`
IRCNick string `yaml:"irc_nickname"` IRCNick string `yaml:"irc_nickname"`
IRCNickPass string `yaml:"irc_nickname_password"` IRCNickPass string `yaml:"irc_nickname_password"`
IRCRealName string `yaml:"irc_realname"` IRCRealName string `yaml:"irc_realname"`
IRCHost string `yaml:"irc_host"` IRCHost string `yaml:"irc_host"`
IRCPort int `yaml:"irc_port"` IRCPort int `yaml:"irc_port"`
IRCUseSSL bool `yaml:"irc_use_ssl"` IRCUseSSL bool `yaml:"irc_use_ssl"`
IRCChannels []IRCChannel `yaml:"irc_channels"` IRCVerifySSL bool `yaml:"irc_verify_ssl"`
MsgTemplate string `yaml:"msg_template"` IRCChannels []IRCChannel `yaml:"irc_channels"`
MsgOnce bool `yaml:"msg_once_per_alert_group"` MsgTemplate string `yaml:"msg_template"`
UsePrivmsg bool `yaml:"use_privmsg"` MsgOnce bool `yaml:"msg_once_per_alert_group"`
UsePrivmsg bool `yaml:"use_privmsg"`
} }
func LoadConfig(configFile string) (*Config, error) { func LoadConfig(configFile string) (*Config, error) {
config := &Config{ config := &Config{
HTTPHost: "localhost", HTTPHost: "localhost",
HTTPPort: 8000, HTTPPort: 8000,
IRCNick: "alertmanager-irc-relay", IRCNick: "alertmanager-irc-relay",
IRCNickPass: "", IRCNickPass: "",
IRCRealName: "Alertmanager IRC Relay", IRCRealName: "Alertmanager IRC Relay",
IRCHost: "irc.freenode.net", IRCHost: "irc.freenode.net",
IRCPort: 7000, IRCPort: 7000,
IRCUseSSL: true, IRCUseSSL: true,
IRCChannels: []IRCChannel{IRCChannel{Name: "#airtest"}}, IRCVerifySSL: true,
MsgOnce: false, IRCChannels: []IRCChannel{IRCChannel{Name: "#airtest"}},
UsePrivmsg: false, MsgOnce: false,
UsePrivmsg: false,
} }
if configFile != "" { if configFile != "" {

5
irc.go
View File

@ -77,7 +77,10 @@ func NewIRCNotifier(config *Config, alertMsgs chan AlertMsg) (*IRCNotifier, erro
ircConfig.Server = strings.Join( ircConfig.Server = strings.Join(
[]string{config.IRCHost, strconv.Itoa(config.IRCPort)}, ":") []string{config.IRCHost, strconv.Itoa(config.IRCPort)}, ":")
ircConfig.SSL = config.IRCUseSSL 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.PingFreq = pingFrequencySecs * time.Second
ircConfig.Timeout = connectionTimeoutSecs * time.Second ircConfig.Timeout = connectionTimeoutSecs * time.Second
ircConfig.NewNick = func(n string) string { return n + "^" } ircConfig.NewNick = func(n string) string { return n + "^" }