Support ntfy tags
This commit is contained in:
parent
9043ccfb5e
commit
2818ba9885
3 changed files with 34 additions and 0 deletions
11
config.go
11
config.go
|
@ -29,6 +29,7 @@ type labels struct {
|
|||
|
||||
type labelConfig struct {
|
||||
Priority string
|
||||
Tags []string
|
||||
}
|
||||
|
||||
func readConfig(path string) (*config, error) {
|
||||
|
@ -101,6 +102,16 @@ func readConfig(path string) (*config, error) {
|
|||
}
|
||||
}
|
||||
|
||||
d = labelDir.Children.Get("tags")
|
||||
if d != nil {
|
||||
var tags string
|
||||
if err := d.ParseParams(&tags); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
labelConfig.Tags = strings.Split(tags, ",")
|
||||
}
|
||||
|
||||
labels[fmt.Sprintf("%s:%s", labelName, name)] = *labelConfig
|
||||
}
|
||||
}
|
||||
|
|
11
functions.go
Normal file
11
functions.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
func sliceContains(s []string, e string) bool {
|
||||
for _, v := range s {
|
||||
if e == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
12
main.go
12
main.go
|
@ -100,6 +100,7 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) {
|
|||
req.Header.Set("X-Title", title)
|
||||
|
||||
var priority string
|
||||
var tags []string
|
||||
for _, labelName := range rcv.cfg.labels.Order {
|
||||
val, ok := event.CommonLabels[labelName]
|
||||
if !ok {
|
||||
|
@ -114,12 +115,23 @@ func (rcv *receiver) handleWebhooks(w http.ResponseWriter, r *http.Request) {
|
|||
if priority == "" {
|
||||
priority = labelConfig.Priority
|
||||
}
|
||||
|
||||
for _, val := range labelConfig.Tags {
|
||||
if !sliceContains(tags, val) {
|
||||
tags = append(tags, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if priority != "" {
|
||||
req.Header.Set("X-Priority", priority)
|
||||
}
|
||||
|
||||
tagString := strings.Join(tags, ",")
|
||||
if tagString != "" {
|
||||
req.Header.Set("X-Tags", tagString)
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
rcv.logger.Error(err)
|
||||
|
|
Loading…
Reference in a new issue