mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2024-11-05 11:19:21 +01:00
Handle IRC server password
Introduce optional config parameter 'irc_host_password' to specify the IRC server password. Signed-off-by: Luca Bigliardi <shammash@google.com>
This commit is contained in:
parent
91da0c3744
commit
826f088241
@ -25,6 +25,8 @@ http_port: 8000
|
|||||||
# Note: SSL is enabled by default, use "irc_use_ssl: no" to disable.
|
# Note: SSL is enabled by default, use "irc_use_ssl: no" to disable.
|
||||||
irc_host: irc.example.com
|
irc_host: irc.example.com
|
||||||
irc_port: 7000
|
irc_port: 7000
|
||||||
|
# Optionally set the server password
|
||||||
|
irc_host_password: myserver_password
|
||||||
|
|
||||||
# Use this IRC nickname.
|
# Use this IRC nickname.
|
||||||
irc_nickname: myalertbot
|
irc_nickname: myalertbot
|
||||||
|
@ -37,6 +37,7 @@ type Config struct {
|
|||||||
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"`
|
||||||
|
IRCHostPass string `yaml:"irc_host_password"`
|
||||||
IRCUseSSL bool `yaml:"irc_use_ssl"`
|
IRCUseSSL bool `yaml:"irc_use_ssl"`
|
||||||
IRCVerifySSL bool `yaml:"irc_verify_ssl"`
|
IRCVerifySSL bool `yaml:"irc_verify_ssl"`
|
||||||
IRCChannels []IRCChannel `yaml:"irc_channels"`
|
IRCChannels []IRCChannel `yaml:"irc_channels"`
|
||||||
@ -54,6 +55,7 @@ func LoadConfig(configFile string) (*Config, error) {
|
|||||||
IRCRealName: "Alertmanager IRC Relay",
|
IRCRealName: "Alertmanager IRC Relay",
|
||||||
IRCHost: "example.com",
|
IRCHost: "example.com",
|
||||||
IRCPort: 7000,
|
IRCPort: 7000,
|
||||||
|
IRCHostPass: "",
|
||||||
IRCUseSSL: true,
|
IRCUseSSL: true,
|
||||||
IRCVerifySSL: true,
|
IRCVerifySSL: true,
|
||||||
IRCChannels: []IRCChannel{},
|
IRCChannels: []IRCChannel{},
|
||||||
|
@ -40,6 +40,7 @@ func TestLoadGoodConfig(t *testing.T) {
|
|||||||
IRCNick: "foo",
|
IRCNick: "foo",
|
||||||
IRCHost: "irc.example.com",
|
IRCHost: "irc.example.com",
|
||||||
IRCPort: 1234,
|
IRCPort: 1234,
|
||||||
|
IRCHostPass: "hostsecret",
|
||||||
IRCUseSSL: true,
|
IRCUseSSL: true,
|
||||||
IRCChannels: []IRCChannel{IRCChannel{Name: "#foobar"}},
|
IRCChannels: []IRCChannel{IRCChannel{Name: "#foobar"}},
|
||||||
MsgTemplate: defaultMsgTemplate,
|
MsgTemplate: defaultMsgTemplate,
|
||||||
|
1
irc.go
1
irc.go
@ -95,6 +95,7 @@ func NewIRCNotifier(config *Config, alertMsgs chan AlertMsg) (*IRCNotifier, erro
|
|||||||
ircConfig.Me.Name = config.IRCRealName
|
ircConfig.Me.Name = config.IRCRealName
|
||||||
ircConfig.Server = strings.Join(
|
ircConfig.Server = strings.Join(
|
||||||
[]string{config.IRCHost, strconv.Itoa(config.IRCPort)}, ":")
|
[]string{config.IRCHost, strconv.Itoa(config.IRCPort)}, ":")
|
||||||
|
ircConfig.Pass = config.IRCHostPass
|
||||||
ircConfig.SSL = config.IRCUseSSL
|
ircConfig.SSL = config.IRCUseSSL
|
||||||
ircConfig.SSLConfig = &tls.Config{
|
ircConfig.SSLConfig = &tls.Config{
|
||||||
ServerName: config.IRCHost,
|
ServerName: config.IRCHost,
|
||||||
|
40
irc_test.go
40
irc_test.go
@ -267,6 +267,46 @@ func TestPreJoinChannels(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServerPassword(t *testing.T) {
|
||||||
|
server, port := makeTestServer(t)
|
||||||
|
config := makeTestIRCConfig(port)
|
||||||
|
config.IRCHostPass = "hostsecret"
|
||||||
|
notifier, _ := makeTestNotifier(t, config)
|
||||||
|
|
||||||
|
var testStep sync.WaitGroup
|
||||||
|
|
||||||
|
joinHandler := func(conn *bufio.ReadWriter, line *irc.Line) error {
|
||||||
|
// #baz is configured as the last channel to pre-join
|
||||||
|
if line.Args[0] == "#baz" {
|
||||||
|
testStep.Done()
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
server.SetHandler("JOIN", joinHandler)
|
||||||
|
|
||||||
|
testStep.Add(1)
|
||||||
|
go notifier.Run()
|
||||||
|
|
||||||
|
testStep.Wait()
|
||||||
|
|
||||||
|
notifier.StopRunning <- true
|
||||||
|
server.Stop()
|
||||||
|
|
||||||
|
expectedCommands := []string{
|
||||||
|
"PASS hostsecret",
|
||||||
|
"NICK foo",
|
||||||
|
"USER foo 12 * :",
|
||||||
|
"JOIN #foo",
|
||||||
|
"JOIN #bar",
|
||||||
|
"JOIN #baz",
|
||||||
|
"QUIT :see ya",
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(expectedCommands, server.Log) {
|
||||||
|
t.Error("Did not send IRC server password")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSendAlertOnPreJoinedChannel(t *testing.T) {
|
func TestSendAlertOnPreJoinedChannel(t *testing.T) {
|
||||||
server, port := makeTestServer(t)
|
server, port := makeTestServer(t)
|
||||||
config := makeTestIRCConfig(port)
|
config := makeTestIRCConfig(port)
|
||||||
|
Loading…
Reference in New Issue
Block a user