noticer: 更详细的通知内容

结点失败通知加上通知人
pull/1/head
miraclesu 2017-04-21 15:28:01 +08:00
parent ecdb29fe02
commit f816c3934c
2 changed files with 17 additions and 1 deletions

View File

@ -550,12 +550,14 @@ func (j *Job) Notify(t time.Time, msg string) {
ts := t.Format(time.RFC3339) ts := t.Format(time.RFC3339)
body := "job: " + j.Key() + "\n" + body := "job: " + j.Key() + "\n" +
"job name: " + j.Name + "\n" +
"job cmd: " + j.Command + "\n" +
"node: " + j.runOn + "\n" + "node: " + j.runOn + "\n" +
"time: " + ts + "\n" + "time: " + ts + "\n" +
"err: " + msg "err: " + msg
m := Message{ m := Message{
Subject: "node[" + j.runOn + "] job[" + j.ID + "] time[" + ts + "] exec failed", Subject: "node[" + j.runOn + "] job[" + j.ShortName() + "] time[" + ts + "] exec failed",
Body: body, Body: body,
To: j.To, To: j.To,
} }
@ -683,3 +685,16 @@ func (j *Job) ValidRules() error {
} }
return nil return nil
} }
func (j *Job) ShortName() string {
if len(j.Name) <= 10 {
return j.Name
}
names := []rune(j.Name)
if len(names) <= 10 {
return j.Name
}
return string(names[:10]) + "..."
}

View File

@ -191,6 +191,7 @@ func monitorNodes(n Noticer) {
if ok { if ok {
n.Send(&Message{ n.Send(&Message{
Subject: "node[" + id + "] fault at time[" + time.Now().Format(time.RFC3339) + "]", Subject: "node[" + id + "] fault at time[" + time.Now().Format(time.RFC3339) + "]",
To: conf.Config.Mail.To,
}) })
} }
} }