Skip to content

Commit d421d12

Browse files
committed
Add Apprise notification support to configuration and notification handling
1 parent 4c2e177 commit d421d12

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.73.31
1+
0.73.32

etc/wigo.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ OnProbeChange = false
118118
HttpEnabled = 0 # -> 0: disabled, 1: enabled
119119
HttpUrl = ""
120120

121+
# Apprise https://github.com/caronc/apprise
122+
AppriseEnabled = 0 # -> 0: disabled, 1: enabled
123+
ApprisePath = "/usr/local/bin/apprise" # Path to the Apprise binary, you need to install it first
124+
# List of Apprise URLs to send notifications to, see https://github.com/caronc/apprise/wiki/Notify_urls
125+
AppriseUrls = []
126+
121127
# EMAIL
122128
EmailEnabled = 0 # -> 0: disabled, 1: enabled, 2: only if http failed
123129
EmailSmtpServer = "smtp.domain.tld:25"

src/wigo.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ func threadRemoteChecks(remoteWigos []wigo.AdvancedRemoteWigoConfig) {
281281
func threadCallbacks(chanCallbacks chan wigo.INotification) {
282282
httpEnabled := wigo.GetLocalWigo().GetConfig().Notifications.HttpEnabled
283283
mailEnabled := wigo.GetLocalWigo().GetConfig().Notifications.EmailEnabled
284+
appriseEnabled := wigo.GetLocalWigo().GetConfig().Notifications.AppriseEnabled
284285

285286
for {
286287
notification := <-chanCallbacks
@@ -304,6 +305,10 @@ func threadCallbacks(chanCallbacks chan wigo.INotification) {
304305
if mailEnabled == 1 {
305306
wigo.SendMail(notification.GetSummary(), notification.GetMessage())
306307
}
308+
309+
if appriseEnabled != 0 {
310+
wigo.SendApprise(notification.GetSummary(), notification.GetMessage())
311+
}
307312
}()
308313
}
309314
}

src/wigo/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func NewConfig(configFile string) (this *Config) {
109109
this.Notifications.EmailFromName = ""
110110
this.Notifications.EmailRecipients = nil
111111

112+
this.Notifications.AppriseEnabled = 0
113+
this.Notifications.ApprisePath = "/usr/local/bin/apprise"
114+
this.Notifications.AppriseUrls = nil
115+
112116
// OpenTSDB
113117
this.OpenTSDB.Enabled = false
114118
this.OpenTSDB.Address = nil
@@ -239,6 +243,10 @@ type NotificationConfig struct {
239243
EmailRecipients []string
240244
EmailFromName string
241245
EmailFromAddress string
246+
247+
AppriseEnabled int
248+
ApprisePath string
249+
AppriseUrls []string
242250
}
243251

244252
type AdvancedRemoteWigoConfig struct {

src/wigo/notification.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wigo
22

33
import (
44
"bytes"
5+
"context"
56
"crypto/tls"
67
"encoding/json"
78
"fmt"
@@ -11,6 +12,7 @@ import (
1112
"net/mail"
1213
"net/smtp"
1314
"net/url"
15+
"os/exec"
1416
"time"
1517
)
1618

@@ -257,3 +259,60 @@ func CallbackHttp(json string) (e error) {
257259

258260
return nil
259261
}
262+
263+
func SendApprise(summary string, message string) {
264+
265+
log.Printf("We're gonna launch apprise notif...")
266+
267+
config := GetLocalWigo().GetConfig().Notifications
268+
269+
// Check if Apprise is enabled
270+
if config.AppriseEnabled == 0 {
271+
return
272+
}
273+
274+
// Check if URLs are configured
275+
if len(config.AppriseUrls) == 0 {
276+
log.Printf("Apprise is enabled but no URLs are configured")
277+
return
278+
}
279+
280+
apprisePath := config.ApprisePath
281+
282+
// Ensure summary is not empty (Apprise requires it)
283+
appriseSummary := summary
284+
if appriseSummary == "" {
285+
appriseSummary = message
286+
if appriseSummary == "" {
287+
appriseSummary = "Wigo notification"
288+
}
289+
}
290+
291+
// Send to each URL in a separate goroutine
292+
for _, url := range config.AppriseUrls {
293+
go func(appriseUrl string) {
294+
// Create context with timeout (10 seconds)
295+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
296+
defer cancel()
297+
298+
// Create command: apprise -v -t "title" -b "body" url
299+
cmd := exec.CommandContext(ctx, apprisePath, "-v", "-t", message, "-b", appriseSummary, appriseUrl)
300+
301+
// Execute command
302+
output, err := cmd.CombinedOutput()
303+
if err != nil {
304+
log.Printf("Error sending apprise notification to %s : %s", appriseUrl, err)
305+
if len(output) > 0 {
306+
log.Printf("Apprise verbose output for %s : %s", appriseUrl, string(output))
307+
}
308+
return
309+
}
310+
311+
// Log verbose output even on success for debugging
312+
if len(output) > 0 {
313+
log.Printf("Apprise verbose output for %s : %s", appriseUrl, string(output))
314+
}
315+
log.Printf(" - Sent to apprise url : %s", appriseUrl)
316+
}(url)
317+
}
318+
}

0 commit comments

Comments
 (0)