diff --git a/main.go b/main.go index 4a324fcec..9b350564d 100644 --- a/main.go +++ b/main.go @@ -202,8 +202,8 @@ func main() { } go ruleManager.Run() - // Queue depth will need to be exposed - notificationHandler := notification.NewNotificationHandler(*alertmanagerUrl, notifications) + prometheusUrl := web.MustBuildServerUrl() + notificationHandler := notification.NewNotificationHandler(*alertmanagerUrl, prometheusUrl, notifications) go notificationHandler.Run() flags := map[string]string{} diff --git a/notification/notification.go b/notification/notification.go index 3f8873fe6..021e19a36 100644 --- a/notification/notification.go +++ b/notification/notification.go @@ -42,6 +42,8 @@ var ( type NotificationHandler struct { // The URL of the alert manager to send notifications to. alertmanagerUrl string + // The URL of this Prometheus instance to include in notifications. + prometheusUrl string // Buffer of notifications that have not yet been sent. pendingNotifications <-chan rules.NotificationReqs // HTTP client with custom timeout settings. @@ -49,11 +51,12 @@ type NotificationHandler struct { } // Construct a new NotificationHandler. -func NewNotificationHandler(alertmanagerUrl string, notificationReqs <-chan rules.NotificationReqs) *NotificationHandler { +func NewNotificationHandler(alertmanagerUrl string, prometheusUrl string, notificationReqs <-chan rules.NotificationReqs) *NotificationHandler { return &NotificationHandler{ alertmanagerUrl: alertmanagerUrl, pendingNotifications: notificationReqs, httpClient: utility.NewDeadlineClient(*deadline), + prometheusUrl: prometheusUrl, } } @@ -68,8 +71,10 @@ func (n *NotificationHandler) sendNotifications(reqs rules.NotificationReqs) err rules.AlertNameLabel: clientmodel.LabelValue(req.Rule.Name()), }), "Payload": map[string]interface{}{ - "Value": req.ActiveAlert.Value, - "ActiveSince": req.ActiveAlert.ActiveSince, + "Value": req.ActiveAlert.Value, + "ActiveSince": req.ActiveAlert.ActiveSince, + "GeneratorUrl": n.prometheusUrl, + "AlertingRule": req.Rule.String(), }, }) } diff --git a/web/web.go b/web/web.go index f09830489..cd8bd5abb 100644 --- a/web/web.go +++ b/web/web.go @@ -18,8 +18,10 @@ import ( "fmt" "html/template" "log" + "net" "net/http" "net/http/pprof" + "os" "code.google.com/p/gorest" @@ -64,7 +66,7 @@ func (w WebService) ServeForever() error { exp.HandleFunc("/graph", graphHandler) exp.Handle("/api/", compressionHandler{handler: gorest.Handle()}) - exp.Handle("/metrics.json", prometheus.DefaultHandler) + exp.Handle("/metrics", prometheus.DefaultHandler) if *useLocalAssets { exp.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static")))) } else { @@ -137,3 +139,15 @@ func executeTemplate(w http.ResponseWriter, name string, data interface{}) { log.Printf("Error executing template: %s", err) } } + +func MustBuildServerUrl() string { + _, port, err := net.SplitHostPort(*listenAddress) + if err != nil { + panic(err) + } + hostname, err := os.Hostname() + if err != nil { + panic(err) + } + return fmt.Sprintf("http://%s:%s", hostname, port) +}