mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Add Echobell provider
This commit is contained in:
@@ -86,7 +86,7 @@ func LoadNotifications(db *sql.DB) ([]models.Notification, error) {
|
||||
rows, err := db.Query(
|
||||
`SELECT id, enabled, type, "smtpHost", "smtpPort", "smtpFrom", "smtpUser", "smtpPass", "smtpSecure", "smtpTo",
|
||||
"telegramChatId", "telegramToken", "discordWebhook", "gotifyUrl", "gotifyToken", "ntfyUrl", "ntfyToken",
|
||||
"pushoverUrl", "pushoverToken", "pushoverUser"
|
||||
"pushoverUrl", "pushoverToken", "pushoverUser", "echobellUrl"
|
||||
FROM notification
|
||||
WHERE enabled = true`,
|
||||
)
|
||||
@@ -103,7 +103,7 @@ func LoadNotifications(db *sql.DB) ([]models.Notification, error) {
|
||||
&n.SMTPHost, &n.SMTPPort, &n.SMTPFrom, &n.SMTPUser, &n.SMTPPass, &n.SMTPSecure, &n.SMTPTo,
|
||||
&n.TelegramChatID, &n.TelegramToken, &n.DiscordWebhook,
|
||||
&n.GotifyUrl, &n.GotifyToken, &n.NtfyUrl, &n.NtfyToken,
|
||||
&n.PushoverUrl, &n.PushoverToken, &n.PushoverUser,
|
||||
&n.PushoverUrl, &n.PushoverToken, &n.PushoverUser, &n.EchobellURL,
|
||||
); err != nil {
|
||||
fmt.Printf("Error scanning notification: %v\n", err)
|
||||
continue
|
||||
|
||||
@@ -94,4 +94,5 @@ type Notification struct {
|
||||
PushoverUrl sql.NullString
|
||||
PushoverToken sql.NullString
|
||||
PushoverUser sql.NullString
|
||||
EchobellURL sql.NullString
|
||||
}
|
||||
|
||||
@@ -84,6 +84,10 @@ func (ns *NotificationSender) SendSpecificNotification(n models.Notification, me
|
||||
if n.PushoverUrl.Valid && n.PushoverToken.Valid && n.PushoverUser.Valid {
|
||||
ns.sendPushover(n, message)
|
||||
}
|
||||
case "echobell":
|
||||
if n.EchobellURL.Valid {
|
||||
ns.sendEchobell(n, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,3 +241,26 @@ func (ns *NotificationSender) sendPushover(n models.Notification, message string
|
||||
fmt.Printf("Pushover: ERROR status code: %d\n", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
func (ns *NotificationSender) sendEchobell(n models.Notification, message string) {
|
||||
jsonData := fmt.Sprintf(`{"message": "%s"}`, message)
|
||||
req, err := http.NewRequest("POST", n.EchobellURL.String, strings.NewReader(jsonData))
|
||||
if err != nil {
|
||||
fmt.Printf("Echobell: ERROR creating request: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
client := &http.Client{Timeout: 5 * time.Second}
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
fmt.Printf("Echobell: ERROR sending request: %v\n", err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
fmt.Printf("Echobell: ERROR status code: %d\n", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user