mirror of
https://github.com/cooperspencer/gickup
synced 2025-05-01 00:37:55 +02:00
added apprise
This commit is contained in:
parent
69ddf8b24a
commit
110d608cc0
12
main.go
12
main.go
@ -27,6 +27,7 @@ import (
|
||||
"github.com/cooperspencer/gickup/gogs"
|
||||
"github.com/cooperspencer/gickup/local"
|
||||
"github.com/cooperspencer/gickup/logger"
|
||||
"github.com/cooperspencer/gickup/metrics/apprise"
|
||||
"github.com/cooperspencer/gickup/metrics/gotify"
|
||||
"github.com/cooperspencer/gickup/metrics/heartbeat"
|
||||
"github.com/cooperspencer/gickup/metrics/ntfy"
|
||||
@ -97,7 +98,7 @@ func readConfigFile(configfile string) []*types.Conf {
|
||||
|
||||
if !reflect.ValueOf(c).IsZero() {
|
||||
if len(conf) > 0 {
|
||||
if len(c.Metrics.PushConfigs.Gotify) == 0 && len(c.Metrics.PushConfigs.Ntfy) == 0 {
|
||||
if len(c.Metrics.PushConfigs.Gotify) == 0 && len(c.Metrics.PushConfigs.Ntfy) == 0 && len(c.Metrics.PushConfigs.Apprise) == 0 {
|
||||
c.Metrics.PushConfigs = conf[0].Metrics.PushConfigs
|
||||
}
|
||||
}
|
||||
@ -870,6 +871,15 @@ func runBackup(conf *types.Conf, num int) {
|
||||
}
|
||||
}
|
||||
|
||||
if len(conf.Metrics.PushConfigs.Apprise) > 0 {
|
||||
for _, pusher := range conf.Metrics.PushConfigs.Apprise {
|
||||
err := apprise.Notify(fmt.Sprintf("backup took %v", duration), *pusher)
|
||||
if err != nil {
|
||||
log.Warn().Str("push", "apprise").Err(err).Msg("couldn't send message")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.Info().
|
||||
Str("duration", duration.String()).
|
||||
Msg("Backup run complete")
|
||||
|
40
metrics/apprise/apprise.go
Normal file
40
metrics/apprise/apprise.go
Normal file
@ -0,0 +1,40 @@
|
||||
package apprise
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/cooperspencer/gickup/types"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
Body string `json:"body"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Urls []string `json:"urls",omitempty`
|
||||
}
|
||||
|
||||
func Notify(msg string, config types.AppriseConfig) error {
|
||||
|
||||
payload := Request{
|
||||
Body: msg,
|
||||
Urls: config.Urls,
|
||||
Tags: config.Tags,
|
||||
}
|
||||
|
||||
jsonData, _ := json.Marshal(payload)
|
||||
|
||||
url := config.Url + "/notify/"
|
||||
|
||||
if config.Config != "" {
|
||||
url += config.Config
|
||||
}
|
||||
|
||||
resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
@ -82,6 +82,14 @@ type PushConfig struct {
|
||||
Url string `yaml:"url"`
|
||||
}
|
||||
|
||||
// AppriseConfig TODO
|
||||
type AppriseConfig struct {
|
||||
Url string `yaml:"url"`
|
||||
Tags []string `yaml:"tags"`
|
||||
Config string `yaml:"tags"`
|
||||
Urls []string `yaml:"notification_urls"`
|
||||
}
|
||||
|
||||
func (p *PushConfig) ResolveToken() {
|
||||
if p.Password != "" {
|
||||
p.Password = resolve(p.Password)
|
||||
@ -102,8 +110,9 @@ func resolve(value string) string {
|
||||
|
||||
// PushConfigs TODO.
|
||||
type PushConfigs struct {
|
||||
Ntfy []*PushConfig `yaml:"ntfy"`
|
||||
Gotify []*PushConfig `yaml:"gotify"`
|
||||
Ntfy []*PushConfig `yaml:"ntfy"`
|
||||
Gotify []*PushConfig `yaml:"gotify"`
|
||||
Apprise []*AppriseConfig `yaml:"apprise"`
|
||||
}
|
||||
|
||||
// Metrics TODO.
|
||||
|
Loading…
Reference in New Issue
Block a user