diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 67d6ed301e..c24eafcf52 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -48,10 +48,9 @@ type Config struct { Uploader struct { Token string `yaml:"token"` } `yaml:"uploader"` - Pushover struct { - User string `yaml:"user"` - Token string `yaml:"token"` - } `yaml:"pushover"` + Webhook struct { + Endpoint string `yaml:"endpoint"` + } `yaml:"webhook"` } // ValidateAndInit validates config and sets the Google credentials in diff --git a/internal/pkg/monitoring/latest_probe.go b/internal/pkg/monitoring/latest_probe.go index 7f71deff71..b233444e65 100644 --- a/internal/pkg/monitoring/latest_probe.go +++ b/internal/pkg/monitoring/latest_probe.go @@ -1,10 +1,11 @@ package monitoring import ( + "bytes" + "encoding/json" "fmt" "io/ioutil" "net/http" - "net/url" "time" "github.com/Jeffail/gabs/v2" @@ -41,25 +42,26 @@ func LatestProbe(cfg config.Config) error { } if time.Since(t).Hours() > 24 { - URL := "https://api.pushover.net/1/messages.json" - - values := url.Values{} - values.Add("token", cfg.Pushover.Token) - values.Add("user", cfg.Pushover.User) - values.Add("title", "Play Data Warning") - values.Add("message", fmt.Sprintf("%.0f hours since last play", time.Since(t).Hours())) + datab := map[string]string{ + "Title": "Play Data Warning", + "Body": fmt.Sprintf("%.0f hours since last play", time.Since(t).Hours()), + "URL": "", + } - res, err := http.PostForm(URL, values) + b, err := json.Marshal(datab) if err != nil { - return err + return fmt.Errorf("failed to marshal webhook body: %w", err) } - data, err := ioutil.ReadAll(res.Body) - res.Body.Close() + client := &http.Client{} + req, err := http.NewRequest("POST", cfg.Webhook.Endpoint, bytes.NewBuffer(b)) + + req.Header.Add("Content-Type", "application/json; charset=utf-8") + + _, err = client.Do(req) if err != nil { - return err + return fmt.Errorf("failed to send webhook: %w", err) } - fmt.Println(string(data)) } return nil