这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/bosun/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
htemplate "html/template"
"io/ioutil"
"log"
"net"
"net/http"
"net/mail"
Expand All @@ -24,6 +23,7 @@ import (
eparse "bosun.org/cmd/bosun/expr/parse"
"bosun.org/graphite"
"bosun.org/opentsdb"
"bosun.org/slog"
)

type Conf struct {
Expand Down Expand Up @@ -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)
},
Expand Down
18 changes: 9 additions & 9 deletions cmd/bosun/conf/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"crypto/tls"
"errors"
"log"
"net/http"
"net/mail"
"net/smtp"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/bosun/sched/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
15 changes: 7 additions & 8 deletions cmd/bosun/sched/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
htemplate "html/template"
"log"
"strings"
ttemplate "text/template"
"time"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions cmd/bosun/sched/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/gob"
"encoding/json"
"fmt"
"log"
"net"
"sort"
"sync"
Expand All @@ -22,6 +21,7 @@ import (
"bosun.org/collect"
"bosun.org/metadata"
"bosun.org/opentsdb"
"bosun.org/slog"
)

func init() {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/bosun/sched/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"html/template"
"io/ioutil"
"log"
"math"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/bosun/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"html/template"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"net/url"
Expand All @@ -24,6 +23,7 @@ import (
"bosun.org/collect"
"bosun.org/metadata"
"bosun.org/opentsdb"
"bosun.org/slog"
"bosun.org/version"
)

Expand Down Expand Up @@ -57,15 +57,15 @@ 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)

indexTemplate = func() *template.Template {
str := FSMustString(devMode, "/templates/index.html")
templates, err := template.New("").Parse(str)
if err != nil {
log.Fatal(err)
slog.Fatal(err)
}
return templates
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/scollector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}