-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (59 loc) · 1.81 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"flag"
"log"
"net/http"
"firebase.google.com/go/messaging"
"github.com/julienschmidt/httprouter"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
flagListen = flag.String("listen", ":9716", "[ip]:port to listen on for HTTP")
fcmClient *messaging.Client
webhookRequests = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "alertmanager_webhook_requests_total",
Help: "Total number of HTTP requests.",
},
[]string{"method", "handler", "status"},
)
templateErrors = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "alertmanager_webhook_template_errors_total",
Help: "Total number of errors executing message templates.",
},
[]string{"type"},
)
fcmMessages = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "alertmanager_webhook_fcm_messages_total",
Help: "Total number of messages seind to Firebase Cloud Messaging API.",
},
[]string{"handler", "topic"},
)
fcmErrors = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "alertmanager_webhook_fcm_errors_total",
Help: "Total number of errors talking to Firebase Cloud Messaging API.",
},
[]string{"handler", "topic"},
)
)
func main() {
var err error
flag.Parse()
fcmClient, err = NewMessaging()
if err != nil {
log.Fatalf("error getting Messaging client: %v\nDo you have GOOGLE_APPLICATION_CREDENTIALS set?\n", err)
}
router := httprouter.New()
router.SaveMatchedRoutePath = true
router.GET("/", indexHandler)
router.POST("/alert/:topic", alertHandler)
router.POST("/generic/:topic", genericHandler)
router.Handler("GET", "/metrics", promhttp.Handler())
log.Printf("Listening on: %s\n", *flagListen)
log.Fatal(http.ListenAndServe(*flagListen, router))
}