summaryrefslogtreecommitdiff
path: root/ntfy
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-04-21 21:14:58 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2024-04-21 21:14:58 -0700
commit9d96d1a9422b30dd6caa42cca2a561970735f160 (patch)
tree3a548002293bf8a79514134437f718484a10193b /ntfy
parentbef72712c271e7628342521985d68f418dcf0343 (diff)
downloadbackup-notify-9d96d1a9422b30dd6caa42cca2a561970735f160.tar.gz
backup-notify-9d96d1a9422b30dd6caa42cca2a561970735f160.zip
notify when we don't receive a thing in the last 24 hours
Diffstat (limited to 'ntfy')
-rw-r--r--ntfy/publisher.go16
-rw-r--r--ntfy/watcher.go6
2 files changed, 19 insertions, 3 deletions
diff --git a/ntfy/publisher.go b/ntfy/publisher.go
new file mode 100644
index 0000000..68f8e49
--- /dev/null
+++ b/ntfy/publisher.go
@@ -0,0 +1,16 @@
+package ntfy
+
+import (
+ "net/http"
+ "strings"
+)
+
+func SendMessage(message string, endpoint string, topics []string) error {
+ for _, topic := range topics {
+ _, err := http.Post(endpoint+"/"+topic, "text/plain", strings.NewReader(message))
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
diff --git a/ntfy/watcher.go b/ntfy/watcher.go
index af4dd55..759c35b 100644
--- a/ntfy/watcher.go
+++ b/ntfy/watcher.go
@@ -30,7 +30,7 @@ func (w *NtfyWatcher) Watch() chan Message {
retryTime := 5 * time.Second
retries := retryCount
- retry := func() {
+ sleepAndDecrementRetry := func() {
log.Println("waiting 5 seconds before reconnecting. retries left:", retries, "topic:", topic, "endpoint:", w.Endpoint)
time.Sleep(retryTime)
retries--
@@ -45,7 +45,7 @@ func (w *NtfyWatcher) Watch() chan Message {
resp, err := http.Get(endpoint)
if err != nil {
log.Println("error connecting to endpoint:", err)
- retry()
+ sleepAndDecrementRetry()
continue
}
@@ -60,7 +60,7 @@ func (w *NtfyWatcher) Watch() chan Message {
if err := scanner.Err(); err != nil {
log.Println("error reading response body:", err)
- retry()
+ sleepAndDecrementRetry()
}
}
}()