Improve node warning message

pull/98/merge
Doflatango 2018-03-13 16:06:43 +08:00
parent 75c9a83b13
commit 75b49bddae
2 changed files with 13 additions and 11 deletions

View File

@ -92,6 +92,11 @@ func GetNodesBy(query interface{}) (nodes []*Node, err error) {
return
}
func GetNodesByID(id string) (node *Node, err error) {
err = mgoDB.FindId(Coll_Node, id, &node)
return
}
func RemoveNode(query interface{}) error {
return mgoDB.WithC(Coll_Node, func(c *mgo.Collection) error {
return c.Remove(query)

View File

@ -169,28 +169,25 @@ func StartNoticer(n Noticer) {
}
func monitorNodes(n Noticer) {
var (
err error
ok bool
id string
)
rch := WatchNode()
for wresp := range rch {
for _, ev := range wresp.Events {
switch {
case ev.Type == client.EventTypeDelete:
id = GetIDFromKey(string(ev.Kv.Key))
ok, err = ISNodeAlive(id)
id := GetIDFromKey(string(ev.Kv.Key))
log.Errorf("cronnode DELETE event detected, node UUID: %s", id)
node, err := GetNodesByID(id)
if err != nil {
log.Warnf("query node[%s] err: %s", id, err.Error())
log.Warnf("failed to fetch node[%s] from mongodb: %s", id, err.Error())
continue
}
if ok {
if node.Alived {
n.Send(&Message{
Subject: "Node[" + id + "] break away cluster, this happed at " + time.Now().Format(time.RFC3339),
Body: "Node breaked away cluster, this might happed when node crash or network problems.",
Subject: fmt.Sprintf("Node[%s] break away cluster at %s", node.Hostname, time.Now().Format(time.RFC3339)),
Body: fmt.Sprintf("Node breaked away cluster, this might happened when node crash or network problems.\nUUID: %s\nHostname: %s\nIP: %s\n", id, node.Hostname, node.IP),
To: conf.Config.Mail.To,
})
}