Send hipchat message on startup (if configured). (#179)

+ If a valid hipchat configuration is provided, send a message when
  Red October has restarted.
+ If persistence is inactive, alert the channel that this is the case.
This commit is contained in:
Kyle Isom
2016-12-06 17:49:54 -08:00
committed by GitHub
parent 7c4413ab4a
commit a2cd47445f
2 changed files with 28 additions and 3 deletions

View File

@@ -39,10 +39,12 @@ type UI struct {
Static string `json:"static"`
}
// HipChat contains the settings for Hipchat integration.
// HipChat contains the settings for Hipchat integration. The ID is
// the name that should be used in the startup message.
type HipChat struct {
Host string `json:"host"`
Room string `json:"room"`
ID string `json:"id"`
APIKey string `json:"api_key"`
}

View File

@@ -18,6 +18,7 @@ import (
"github.com/cloudflare/redoctober/keycache"
"github.com/cloudflare/redoctober/order"
"github.com/cloudflare/redoctober/passvault"
"github.com/cloudflare/redoctober/persist"
)
var (
@@ -244,6 +245,11 @@ func Init(path string, config *config.Config) error {
err = fmt.Errorf("failed to load password vault %s: %s", path, err)
}
crypt, err = cryptor.New(&records, nil, config)
if err != nil {
return err
}
var hipchatClient hipchat.HipchatClient
hc := config.HipChat
if hc.Valid() {
@@ -258,11 +264,28 @@ func Init(path string, config *config.Config) error {
HcHost: hc.Host,
RoHost: config.UI.Root,
}
name := hc.ID
if name == "" {
name = "Red October"
}
message := name + " has restarted."
color := hipchat.GreenBackground
status := crypt.Status()
if status.State == persist.Inactive {
message += " @here: persistence is currently " + status.State + "; the restore admins need to restore the saved delegations."
color = hipchat.RedBackground
}
err = hipchatClient.Notify(message, color)
if err != nil {
return err
}
}
orders = order.NewOrderer(hipchatClient)
crypt, err = cryptor.New(&records, nil, config)
return err
return nil
}
// Create processes a create request.