File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import "encoding/json"
4+
5+ type rawPromAlert struct {
6+ Annotations struct {
7+ Description string `json:"description"`
8+ Summary string `json:"summary"`
9+ } `json:"annotations"`
10+ EndsAt string `json:"endsAt"`
11+ GeneratorURL string `json:"generatorURL"`
12+ Labels map [string ]string `json:"labels"`
13+ StartsAt string `json:"startsAt"`
14+ Status string `json:"status"`
15+ }
16+
17+ func isRawPromAlert (b []byte ) bool {
18+ alertTest := make ([]rawPromAlert , 0 )
19+ err := json .Unmarshal (b , & alertTest )
20+ if err == nil {
21+ if len (alertTest ) != 0 {
22+ if alertTest [0 ].Status == "" {
23+ // Ok it's more than likely then
24+ return true
25+ }
26+ }
27+ }
28+ return false
29+ }
Original file line number Diff line number Diff line change @@ -109,6 +109,34 @@ func main() {
109109 amo := alertManOut {}
110110 err = json .Unmarshal (b , & amo )
111111 if err != nil {
112+ if isRawPromAlert (b ) {
113+ badString := `This program is suppose to be fed by alertmanager.` + "\n " +
114+ `It is not a replacement for alertmanager, it is a ` + "\n " +
115+ `webhook target for it. Please read the README.md ` + "\n " +
116+ `for guidance on how to configure it for alertmanager` + "\n " +
117+ `or https://prometheus.io/docs/alerting/latest/configuration/#webhook_config`
118+
119+ log .Print (`/!\ -- You have misconfigured this software -- /!\` )
120+ log .Print (`--- -- -- ---` )
121+ log .Print (badString )
122+
123+ DO := discordOut {
124+ Content : "" ,
125+ Embeds : []discordEmbed {
126+ {
127+ Title : "You have misconfigured this software" ,
128+ Description : badString ,
129+ Color : ColorGrey ,
130+ Fields : []discordEmbedField {},
131+ },
132+ },
133+ }
134+
135+ DOD , _ := json .Marshal (DO )
136+ http .Post (* whURL , "application/json" , bytes .NewReader (DOD ))
137+ return
138+ }
139+
112140 if len (b ) > 1024 {
113141 log .Printf ("Failed to unpack inbound alert request - %s..." , string (b [:1023 ]))
114142
You can’t perform that action at this time.
0 commit comments