mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 07:56:57 +00:00
Add Echobell provider
This commit is contained in:
parent
1a395783b0
commit
1fccc59c01
@ -86,7 +86,7 @@ func LoadNotifications(db *sql.DB) ([]models.Notification, error) {
|
|||||||
rows, err := db.Query(
|
rows, err := db.Query(
|
||||||
`SELECT id, enabled, type, "smtpHost", "smtpPort", "smtpFrom", "smtpUser", "smtpPass", "smtpSecure", "smtpTo",
|
`SELECT id, enabled, type, "smtpHost", "smtpPort", "smtpFrom", "smtpUser", "smtpPass", "smtpSecure", "smtpTo",
|
||||||
"telegramChatId", "telegramToken", "discordWebhook", "gotifyUrl", "gotifyToken", "ntfyUrl", "ntfyToken",
|
"telegramChatId", "telegramToken", "discordWebhook", "gotifyUrl", "gotifyToken", "ntfyUrl", "ntfyToken",
|
||||||
"pushoverUrl", "pushoverToken", "pushoverUser"
|
"pushoverUrl", "pushoverToken", "pushoverUser", "echobellUrl"
|
||||||
FROM notification
|
FROM notification
|
||||||
WHERE enabled = true`,
|
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.SMTPHost, &n.SMTPPort, &n.SMTPFrom, &n.SMTPUser, &n.SMTPPass, &n.SMTPSecure, &n.SMTPTo,
|
||||||
&n.TelegramChatID, &n.TelegramToken, &n.DiscordWebhook,
|
&n.TelegramChatID, &n.TelegramToken, &n.DiscordWebhook,
|
||||||
&n.GotifyUrl, &n.GotifyToken, &n.NtfyUrl, &n.NtfyToken,
|
&n.GotifyUrl, &n.GotifyToken, &n.NtfyUrl, &n.NtfyToken,
|
||||||
&n.PushoverUrl, &n.PushoverToken, &n.PushoverUser,
|
&n.PushoverUrl, &n.PushoverToken, &n.PushoverUser, &n.EchobellURL,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
fmt.Printf("Error scanning notification: %v\n", err)
|
fmt.Printf("Error scanning notification: %v\n", err)
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -94,4 +94,5 @@ type Notification struct {
|
|||||||
PushoverUrl sql.NullString
|
PushoverUrl sql.NullString
|
||||||
PushoverToken sql.NullString
|
PushoverToken sql.NullString
|
||||||
PushoverUser 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 {
|
if n.PushoverUrl.Valid && n.PushoverToken.Valid && n.PushoverUser.Valid {
|
||||||
ns.sendPushover(n, message)
|
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)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -22,13 +22,12 @@ interface AddRequest {
|
|||||||
pushoverToken?: string;
|
pushoverToken?: string;
|
||||||
pushoverUser?: string;
|
pushoverUser?: string;
|
||||||
echobellURL?: string;
|
echobellURL?: string;
|
||||||
echobellData?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const body: AddRequest = await request.json();
|
const body: AddRequest = await request.json();
|
||||||
const { type, name, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, smtpFrom, smtpTo, telegramToken, telegramChatId, discordWebhook, gotifyUrl, gotifyToken, ntfyUrl, ntfyToken, pushoverUrl, pushoverToken, pushoverUser, echobellURL, echobellData } = body;
|
const { type, name, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, smtpFrom, smtpTo, telegramToken, telegramChatId, discordWebhook, gotifyUrl, gotifyToken, ntfyUrl, ntfyToken, pushoverUrl, pushoverToken, pushoverUser, echobellURL } = body;
|
||||||
|
|
||||||
const notification = await prisma.notification.create({
|
const notification = await prisma.notification.create({
|
||||||
data: {
|
data: {
|
||||||
@ -51,8 +50,7 @@ export async function POST(request: NextRequest) {
|
|||||||
pushoverUrl: pushoverUrl,
|
pushoverUrl: pushoverUrl,
|
||||||
pushoverToken: pushoverToken,
|
pushoverToken: pushoverToken,
|
||||||
pushoverUser: pushoverUser,
|
pushoverUser: pushoverUser,
|
||||||
echobellURL: echobellURL,
|
echobellURL: echobellURL
|
||||||
echobellData: echobellData,
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,6 @@ export default function Settings() {
|
|||||||
const [pushoverToken, setPushoverToken] = useState<string>("")
|
const [pushoverToken, setPushoverToken] = useState<string>("")
|
||||||
const [pushoverUser, setPushoverUser] = useState<string>("")
|
const [pushoverUser, setPushoverUser] = useState<string>("")
|
||||||
const [echobellURL, setEchobellURL] = useState<string>("")
|
const [echobellURL, setEchobellURL] = useState<string>("")
|
||||||
const [echobellData, setEchobellData] = useState<string>("")
|
|
||||||
const [language, setLanguage] = useState<string>("english")
|
const [language, setLanguage] = useState<string>("english")
|
||||||
const [notifications, setNotifications] = useState<any[]>([])
|
const [notifications, setNotifications] = useState<any[]>([])
|
||||||
|
|
||||||
@ -193,7 +192,6 @@ export default function Settings() {
|
|||||||
pushoverToken: pushoverToken,
|
pushoverToken: pushoverToken,
|
||||||
pushoverUser: pushoverUser,
|
pushoverUser: pushoverUser,
|
||||||
echobellURL: echobellURL,
|
echobellURL: echobellURL,
|
||||||
echobellData: echobellData,
|
|
||||||
})
|
})
|
||||||
getNotifications()
|
getNotifications()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@ -701,17 +699,7 @@ export default function Settings() {
|
|||||||
onChange={(e) => setEchobellURL(e.target.value)}
|
onChange={(e) => setEchobellURL(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="grid w-full items-center gap-1.5">
|
<span className="text-xs text-muted-foreground">Add in Echobell the "message" field.</span>
|
||||||
<Label>{t('Settings.Notifications.AddNotification.Echobell.Data')}</Label>
|
|
||||||
<Textarea
|
|
||||||
placeholder={`e.g.:
|
|
||||||
"title": "Server Status",
|
|
||||||
"message": "Server is online"
|
|
||||||
`}
|
|
||||||
onChange={(e: React.ChangeEvent<HTMLTextAreaElement>) => setEchobellData(e.target.value)}
|
|
||||||
rows={4}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@ -384,8 +384,7 @@
|
|||||||
},
|
},
|
||||||
"Echobell": {
|
"Echobell": {
|
||||||
"Title": "Echobell",
|
"Title": "Echobell",
|
||||||
"Url": "Echobell-URL",
|
"Url": "Echobell-URL"
|
||||||
"Data": "Echobell-Data"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CustomizeText": {
|
"CustomizeText": {
|
||||||
|
|||||||
@ -384,8 +384,7 @@
|
|||||||
},
|
},
|
||||||
"Echobell": {
|
"Echobell": {
|
||||||
"Title": "Echobell",
|
"Title": "Echobell",
|
||||||
"Url": "Echobell URL",
|
"Url": "Echobell URL"
|
||||||
"Data": "Echobell Data"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"CustomizeText": {
|
"CustomizeText": {
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `echobellData` on the `notification` table. All the data in the column will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "notification" DROP COLUMN "echobellData";
|
||||||
@ -105,7 +105,6 @@ model notification {
|
|||||||
pushoverToken String?
|
pushoverToken String?
|
||||||
pushoverUser String?
|
pushoverUser String?
|
||||||
echobellURL String?
|
echobellURL String?
|
||||||
echobellData String?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model test_notification {
|
model test_notification {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user