From 4a84d4fdff31df15046390511eb67e891290ac8f Mon Sep 17 00:00:00 2001 From: Craig Peterson Date: Tue, 25 Aug 2015 15:07:49 -0600 Subject: [PATCH] Slogging all the things. --- cmd/bosun/conf/conf.go | 4 ++-- cmd/bosun/conf/notify.go | 18 +++++++++--------- cmd/bosun/sched/check.go | 1 + cmd/bosun/sched/notify.go | 15 +++++++-------- cmd/bosun/sched/sched.go | 6 +++--- cmd/bosun/sched/template.go | 3 +-- cmd/bosun/web/web.go | 14 +++++++------- cmd/scollector/main.go | 6 +++--- 8 files changed, 33 insertions(+), 34 deletions(-) diff --git a/cmd/bosun/conf/conf.go b/cmd/bosun/conf/conf.go index 27244c8d12..a5af4ef0f0 100644 --- a/cmd/bosun/conf/conf.go +++ b/cmd/bosun/conf/conf.go @@ -5,7 +5,6 @@ import ( "fmt" htemplate "html/template" "io/ioutil" - "log" "net" "net/http" "net/mail" @@ -24,6 +23,7 @@ import ( eparse "bosun.org/cmd/bosun/expr/parse" "bosun.org/graphite" "bosun.org/opentsdb" + "bosun.org/slog" ) type Conf struct { @@ -963,7 +963,7 @@ func (c *Conf) loadNotification(s *parse.SectionNode) { "json": func(v interface{}) string { b, err := json.Marshal(v) if err != nil { - log.Println(err) + slog.Errorln(err) } return string(b) }, diff --git a/cmd/bosun/conf/notify.go b/cmd/bosun/conf/notify.go index 318a786be7..0176f91ee3 100644 --- a/cmd/bosun/conf/notify.go +++ b/cmd/bosun/conf/notify.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/tls" "errors" - "log" "net/http" "net/mail" "net/smtp" @@ -13,6 +12,7 @@ import ( "bosun.org/_third_party/github.com/jordan-wright/email" "bosun.org/collect" "bosun.org/metadata" + "bosun.org/slog" "bosun.org/util" ) @@ -41,14 +41,14 @@ func (n *Notification) Notify(subject, body string, emailsubject, emailbody []by } func (n *Notification) DoPrint(subject string) { - log.Println(subject) + slog.Infoln(subject) } func (n *Notification) DoPost(subject []byte) { if n.Body != nil { buf := new(bytes.Buffer) if err := n.Body.Execute(buf, string(subject)); err != nil { - log.Println(err) + slog.Errorln(err) return } subject = buf.Bytes() @@ -58,22 +58,22 @@ func (n *Notification) DoPost(subject []byte) { defer resp.Body.Close() } if err != nil { - log.Println(err) + slog.Error(err) return } if resp.StatusCode >= 300 { - log.Println("bad response on notification post:", resp.Status) + slog.Errorln("bad response on notification post:", resp.Status) } } func (n *Notification) DoGet() { resp, err := http.Get(n.Get.String()) if err != nil { - log.Println(err) + slog.Error(err) return } if resp.StatusCode >= 300 { - log.Println("bad response on notification get:", resp.Status) + slog.Error("bad response on notification get:", resp.Status) } } @@ -97,11 +97,11 @@ func (n *Notification) DoEmail(subject, body []byte, c *Conf, ak string, attachm e.Headers.Add("X-Bosun-Server", util.Hostname) if err := Send(e, c.SMTPHost, c.SMTPUsername, c.SMTPPassword); err != nil { collect.Add("email.sent_failed", nil, 1) - log.Printf("failed to send alert %v to %v %v\n", ak, e.To, err) + slog.Errorf("failed to send alert %v to %v %v\n", ak, e.To, err) return } collect.Add("email.sent", nil, 1) - log.Printf("relayed alert %v to %v sucessfully\n", ak, e.To) + slog.Infof("relayed alert %v to %v sucessfully\n", ak, e.To) } // Send an email using the given host and SMTP auth (optional), returns any diff --git a/cmd/bosun/sched/check.go b/cmd/bosun/sched/check.go index dfcb808700..192e34f0d1 100644 --- a/cmd/bosun/sched/check.go +++ b/cmd/bosun/sched/check.go @@ -440,6 +440,7 @@ func (s *Schedule) CheckAlert(T miniprofiler.Timer, r *RunHistory, a *conf.Alert } unevalCount, unknownCount := markDependenciesUnevaluated(r.Events, deps, a.Name) if err != nil { + slog.Errorf("Error checking alert %s: %s", a.Name, err.Error()) removeUnknownEvents(r.Events, a.Name) } collect.Put("check.duration", opentsdb.TagSet{"name": a.Name}, time.Since(start).Seconds()) diff --git a/cmd/bosun/sched/notify.go b/cmd/bosun/sched/notify.go index 9aea79e8f7..53b941eeb4 100644 --- a/cmd/bosun/sched/notify.go +++ b/cmd/bosun/sched/notify.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" htemplate "html/template" - "log" "strings" ttemplate "text/template" "time" @@ -47,7 +46,7 @@ func (s *Schedule) CheckNotifications() time.Duration { s.Notifications = nil for ak, ns := range notifications { if _, present := silenced[ak]; present { - log.Println("silencing", ak) + slog.Infoln("silencing", ak) continue } for name, t := range ns { @@ -94,7 +93,7 @@ func (s *Schedule) CheckNotifications() time.Duration { func (s *Schedule) sendNotifications(silenced map[expr.AlertKey]Silence) { if s.Conf.Quiet { - log.Println("quiet mode prevented", len(s.pendingNotifications), "notifications") + slog.Infoln("quiet mode prevented", len(s.pendingNotifications), "notifications") return } for n, states := range s.pendingNotifications { @@ -103,12 +102,12 @@ func (s *Schedule) sendNotifications(silenced map[expr.AlertKey]Silence) { _, silenced := silenced[ak] if st.Last().Status == StUnknown { if silenced { - log.Println("silencing unknown", ak) + slog.Infoln("silencing unknown", ak) continue } s.pendingUnknowns[n] = append(s.pendingUnknowns[n], st) } else if silenced { - log.Println("silencing", ak) + slog.Infoln("silencing", ak) } else { s.notify(st, n) } @@ -191,7 +190,7 @@ func (s *Schedule) utnotify(groups map[string]expr.AlertKeys, n *conf.Notificati groups, s.Conf.UnknownThreshold, }); err != nil { - log.Println(err) + slog.Errorln(err) } n.Notify(subject, body.String(), []byte(subject), body.Bytes(), s.Conf, "unknown_treshold") } @@ -220,12 +219,12 @@ func (s *Schedule) unotify(name string, group expr.AlertKeys, n *conf.Notificati data := s.unknownData(now, name, group) if t.Body != nil { if err := t.Body.Execute(body, &data); err != nil { - log.Println("unknown template error:", err) + slog.Infoln("unknown template error:", err) } } if t.Subject != nil { if err := t.Subject.Execute(subject, &data); err != nil { - log.Println("unknown template error:", err) + slog.Infoln("unknown template error:", err) } } n.Notify(subject.String(), body.String(), subject.Bytes(), body.Bytes(), s.Conf, name) diff --git a/cmd/bosun/sched/sched.go b/cmd/bosun/sched/sched.go index 1c06d8856a..e9bae59f38 100644 --- a/cmd/bosun/sched/sched.go +++ b/cmd/bosun/sched/sched.go @@ -4,7 +4,6 @@ import ( "encoding/gob" "encoding/json" "fmt" - "log" "net" "sort" "sync" @@ -22,6 +21,7 @@ import ( "bosun.org/collect" "bosun.org/metadata" "bosun.org/opentsdb" + "bosun.org/slog" ) func init() { @@ -522,7 +522,7 @@ func pingHost(host string) { timeout = 0 } if err := p.Run(); err != nil { - log.Print(err) + slog.Errorln(err) } collect.Put("ping.timeout", tags, timeout) } @@ -686,7 +686,7 @@ func (s *Schedule) Action(user, message string, t ActionType, ak expr.AlertKey) // Would like to also track the alert group, but I believe this is impossible because any character // that could be used as a delimiter could also be a valid tag key or tag value character if err := collect.Add("actions", opentsdb.TagSet{"user": user, "alert": ak.Name(), "type": t.String()}, 1); err != nil { - log.Println(err) + slog.Errorln(err) } return nil } diff --git a/cmd/bosun/sched/template.go b/cmd/bosun/sched/template.go index 65697b5ed6..33aba2a81f 100644 --- a/cmd/bosun/sched/template.go +++ b/cmd/bosun/sched/template.go @@ -7,7 +7,6 @@ import ( "fmt" "html/template" "io/ioutil" - "log" "math" "net/http" "net/url" @@ -127,7 +126,7 @@ func (s *Schedule) ExecuteBody(rh *RunHistory, a *conf.Alert, st *State, isEmail if inline, err := inliner.Inline(buf.String()); err == nil { buf = bytes.NewBufferString(inline) } else { - log.Println(err) + slog.Errorln(err) } return buf.Bytes(), c.Attachments, nil } diff --git a/cmd/bosun/web/web.go b/cmd/bosun/web/web.go index c7c5c345e9..630f3a7e33 100644 --- a/cmd/bosun/web/web.go +++ b/cmd/bosun/web/web.go @@ -8,7 +8,6 @@ import ( "html/template" "io" "io/ioutil" - "log" "net/http" "net/http/httputil" "net/url" @@ -24,6 +23,7 @@ import ( "bosun.org/collect" "bosun.org/metadata" "bosun.org/opentsdb" + "bosun.org/slog" "bosun.org/version" ) @@ -57,7 +57,7 @@ func init() { func Listen(listenAddr string, devMode bool, tsdbHost string) error { if devMode { - log.Println("using local web assets") + slog.Infoln("using local web assets") } webFS := FS(devMode) @@ -65,7 +65,7 @@ func Listen(listenAddr string, devMode bool, tsdbHost string) error { str := FSMustString(devMode, "/templates/index.html") templates, err := template.New("").Parse(str) if err != nil { - log.Fatal(err) + slog.Fatal(err) } return templates } @@ -117,8 +117,8 @@ func Listen(listenAddr string, devMode bool, tsdbHost string) error { http.Handle("/partials/", fs) http.Handle("/static/", http.StripPrefix("/static/", fs)) http.Handle("/favicon.ico", fs) - log.Println("bosun web listening on:", listenAddr) - log.Println("tsdb host:", tsdbHost) + slog.Infoln("bosun web listening on:", listenAddr) + slog.Infoln("tsdb host:", tsdbHost) return http.ListenAndServe(listenAddr, nil) } @@ -195,7 +195,7 @@ func indexTSDB(r *http.Request, body []byte) { func IndexTSDB(w http.ResponseWriter, r *http.Request) { body, err := ioutil.ReadAll(r.Body) if err != nil { - log.Println(err) + slog.Error(err) } indexTSDB(r, body) } @@ -237,7 +237,7 @@ func JSON(h func(miniprofiler.Timer, http.ResponseWriter, *http.Request) (interf } buf := new(bytes.Buffer) if err := json.NewEncoder(buf).Encode(d); err != nil { - log.Println(err) + slog.Error(err) serveError(w, err) return } diff --git a/cmd/scollector/main.go b/cmd/scollector/main.go index 90bc857eb9..b389b140a6 100644 --- a/cmd/scollector/main.go +++ b/cmd/scollector/main.go @@ -476,13 +476,13 @@ func toToml(fname string) { f, err := os.Create(fname) if err != nil { - log.Fatal(err) + slog.Fatal(err) } if err := toml.NewEncoder(f).Encode(&c); err != nil { - log.Fatal(err) + slog.Fatal(err) } if _, err := extra.WriteTo(f); err != nil { - log.Fatal(err) + slog.Fatal(err) } f.Close() }