Skip to content

Commit

Permalink
Update Controllers of FlashDuty To PrometheusAlert
Browse files Browse the repository at this point in the history
  • Loading branch information
cyancow committed Jul 17, 2023
1 parent 374a61d commit 9421dc9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions controllers/FlashDuty.go
Original file line number Diff line number Diff line change
@@ -1 +1,48 @@
package controllers

import (
"github.com/astaxie/beego"
"net"
"strings"
"time"
)

type FlashDuty struct {
beego.Controller
}

type PrometheusAlertInput struct {
Version string `json:"version"`
GroupKey string `json:"groupKey"` // key identifying the group of alerts (e.g. to deduplicate)
Status string `json:"status"`
Receiver string `json:"receiver"`
GroupLabels map[string]string `json:"groupLabels"`
CommonLabels map[string]string `json:"commonLabels"`
CommonAnnotations map[string]string `json:"commonAnnotations"`
ExternalURL string `json:"externalURL"` // backlink to the Alertmanager.
Alerts []Alert `json:"alerts" binding:"required"`
}

type Alert struct {
Status string `json:"status"`
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
StartsAt time.Time `json:"startsAt"`
EndsAt time.Time `json:"endsAt"`
GeneratorURL string `json:"generatorURL"`
Fingerprint string `json:"fingerprint"`
}

// PrometheusAlertPush 接受http请求

func parseIpFromAddr(addr string) string {
strs := strings.Split(addr, ":")
if len(strs) == 2 {
ip := net.ParseIP(strs[0])
if ip != nil {
return ip.String()
}
}

return ""
}

0 comments on commit 9421dc9

Please sign in to comment.