aaa
This commit is contained in:
parent
c8602461c9
commit
ad8b83ac61
2 changed files with 15 additions and 16 deletions
|
|
@ -66,7 +66,7 @@ func LoadConfig() *Config {
|
||||||
if prefix != "nsec" {
|
if prefix != "nsec" {
|
||||||
log.Fatalf("not an nsec, got %s", prefix)
|
log.Fatalf("not an nsec, got %s", prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
pk := nostr.GetPublicKey(sk)
|
pk := nostr.GetPublicKey(sk)
|
||||||
npub := nip19.EncodeNpub(pk)
|
npub := nip19.EncodeNpub(pk)
|
||||||
log.Printf("Loading private key from file %s. Will send alerts from %s", nsecfile, npub)
|
log.Printf("Loading private key from file %s. Will send alerts from %s", nsecfile, npub)
|
||||||
|
|
|
||||||
29
parser.go
29
parser.go
|
|
@ -1,9 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Alert struct {
|
type Alert struct {
|
||||||
|
|
@ -26,30 +25,30 @@ type Payload struct {
|
||||||
Receiver string `json:"receiver"`
|
Receiver string `json:"receiver"`
|
||||||
Status string `json:"firing"`
|
Status string `json:"firing"`
|
||||||
ExternalURL string `json:"externalURL"`
|
ExternalURL string `json:"externalURL"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
GroupKey string `json:"groupKey"`
|
GroupKey string `json:"groupKey"`
|
||||||
TruncatedAlerts int `json:"truncatedAlerts"`
|
TruncatedAlerts int `json:"truncatedAlerts"`
|
||||||
OrgID int `json:"orgId"`
|
OrgID int `json:"orgId"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
State string `json"state"`
|
State string `json"state"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Alerts []Alert `json:"alerts"`
|
Alerts []Alert `json:"alerts"`
|
||||||
GroupLabels map[string]any `json:"groupLabels"`
|
GroupLabels map[string]any `json:"groupLabels"`
|
||||||
CommonLabels map[string]any `json:"groupLabels"`
|
CommonLabels map[string]any `json:"groupLabels"`
|
||||||
CommonAnnotations map[string]any `json:"commonAnnotations"`
|
CommonAnnotations map[string]any `json:"commonAnnotations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func check(e error) {
|
|
||||||
if e != nil {
|
|
||||||
panic(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func ParseAlert(payload []byte) (string) {
|
||||||
data, err := os.ReadFile("./alert.json")
|
var data Payload
|
||||||
check(err)
|
p1 := json.Unmarshal(payload, &data)
|
||||||
var payload Payload
|
|
||||||
p1 := json.Unmarshal([]byte(data), &payload)
|
|
||||||
check(p1)
|
check(p1)
|
||||||
fmt.Printf("Full payload: %+v\n", payload)
|
|
||||||
|
var o strings.Builder
|
||||||
|
|
||||||
|
o.WriteString(data.Title)
|
||||||
|
o.WriteString("status: " + data.Status)
|
||||||
|
o.WriteString("state: " + data.State)
|
||||||
|
o.WriteString(data.Message)
|
||||||
|
return o.String()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue