From f84ae82983744ab50e7e2b9ac5d4a277b40b60e8 Mon Sep 17 00:00:00 2001 From: rmt/src <144435+rmtsrc@users.noreply.github.com> Date: Sat, 25 Jun 2022 17:22:53 +0100 Subject: [PATCH] feat: added Home Assistant notification integration --- .../notification-providers/home-assistant.js | 38 ++++++++++++++++++ server/notification.js | 2 + .../notifications/HomeAssistant.vue | 40 +++++++++++++++++++ src/components/notifications/index.js | 2 + src/languages/bg-BG.js | 1 + src/languages/cs-CZ.js | 1 + src/languages/da-DK.js | 1 + src/languages/de-DE.js | 1 + src/languages/en.js | 1 + src/languages/es-ES.js | 1 + src/languages/et-EE.js | 1 + src/languages/eu.js | 1 + src/languages/fa.js | 1 + src/languages/fr-FR.js | 1 + src/languages/hr-HR.js | 1 + src/languages/hu.js | 1 + src/languages/id-ID.js | 1 + src/languages/it-IT.js | 1 + src/languages/ja.js | 1 + src/languages/ko-KR.js | 1 + src/languages/nb-NO.js | 1 + src/languages/nl-NL.js | 1 + src/languages/pl.js | 1 + src/languages/pt-BR.js | 1 + src/languages/ru-RU.js | 1 + src/languages/sl-SI.js | 1 + src/languages/sr-latn.js | 1 + src/languages/sr.js | 1 + src/languages/sv-SE.js | 1 + src/languages/th-TH.js | 1 + src/languages/tr-TR.js | 1 + src/languages/uk-UA.js | 1 + src/languages/vi-VN.js | 1 + src/languages/zh-CN.js | 1 + src/languages/zh-HK.js | 1 + src/languages/zh-TW.js | 1 + 36 files changed, 114 insertions(+) create mode 100644 server/notification-providers/home-assistant.js create mode 100644 src/components/notifications/HomeAssistant.vue diff --git a/server/notification-providers/home-assistant.js b/server/notification-providers/home-assistant.js new file mode 100644 index 000000000..285989eeb --- /dev/null +++ b/server/notification-providers/home-assistant.js @@ -0,0 +1,38 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); + +const defaultNotificationService = "notify"; + +class HomeAssistant extends NotificationProvider { + name = "HomeAssistant"; + + async send(notification, message, monitor = null, heartbeat = null) { + const notificationService = notification?.notificationService || defaultNotificationService; + + try { + await axios.post( + `${notification.homeAssistantUrl}/api/services/notify/${notificationService}`, + { + title: "Uptime Kuma", + message, + ...(notificationService !== "persistent_notification" && { data: { + name: monitor?.name, + status: heartbeat?.status, + } }), + }, + { + headers: { + Authorization: `Bearer ${notification.longLivedAccessToken}`, + "Content-Type": "application/json", + }, + } + ); + + return "Sent Successfully."; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = HomeAssistant; diff --git a/server/notification.js b/server/notification.js index c457ed144..c86983fae 100644 --- a/server/notification.js +++ b/server/notification.js @@ -35,6 +35,7 @@ const Gorush = require("./notification-providers/gorush"); const Alerta = require("./notification-providers/alerta"); const OneBot = require("./notification-providers/onebot"); const PushDeer = require("./notification-providers/pushdeer"); +const HomeAssistant = require("./notification-providers/home-assistant"); class Notification { @@ -82,6 +83,7 @@ class Notification { new Alerta(), new OneBot(), new PushDeer(), + new HomeAssistant(), ]; for (let item of list) { diff --git a/src/components/notifications/HomeAssistant.vue b/src/components/notifications/HomeAssistant.vue new file mode 100644 index 000000000..67e370a15 --- /dev/null +++ b/src/components/notifications/HomeAssistant.vue @@ -0,0 +1,40 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 18c316a53..cd0acabb1 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -33,6 +33,7 @@ import Gorush from "./Gorush.vue"; import Alerta from "./Alerta.vue"; import OneBot from "./OneBot.vue"; import PushDeer from "./PushDeer.vue"; +import HomeAssistant from "./HomeAssistant.vue"; /** * Manage all notification form. @@ -75,6 +76,7 @@ const NotificationFormList = { "alerta": Alerta, "OneBot": OneBot, "PushDeer": PushDeer, + "HomeAssistant": HomeAssistant, }; export default NotificationFormList; diff --git a/src/languages/bg-BG.js b/src/languages/bg-BG.js index b2c185d9d..1a6d351a4 100644 --- a/src/languages/bg-BG.js +++ b/src/languages/bg-BG.js @@ -536,4 +536,5 @@ export default { Domain: "Домейн", Workstation: "Работна станция", disableCloudflaredNoAuthMsg: "Тъй като сте в режим \"No Auth mode\", парола не се изисква.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/cs-CZ.js b/src/languages/cs-CZ.js index 1ad47fd31..135c0d4c7 100644 --- a/src/languages/cs-CZ.js +++ b/src/languages/cs-CZ.js @@ -364,4 +364,5 @@ export default { smtpDkimHashAlgo: "Hashovací algoritmus (volitelné)", smtpDkimheaderFieldNames: "Podepisovat tyto hlavičky (volitelné)", smtpDkimskipFields: "Nepodepisovat tyto hlavičky (volitelné)", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/da-DK.js b/src/languages/da-DK.js index 83cd97bae..4b0f04d98 100644 --- a/src/languages/da-DK.js +++ b/src/languages/da-DK.js @@ -352,4 +352,5 @@ export default { serwersmsPhoneNumber: "Telefonnummer", serwersmsSenderName: "SMS Afsender Navn (registreret via kundeportal)", stackfield: "Stackfield", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/de-DE.js b/src/languages/de-DE.js index 3df13b945..107adca4d 100644 --- a/src/languages/de-DE.js +++ b/src/languages/de-DE.js @@ -455,4 +455,5 @@ export default { "Domain Names": "Domainnamen", signedInDisp: "Angemeldet als {0}", signedInDispDisabled: "Authentifizierung deaktiviert.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/en.js b/src/languages/en.js index 9aeedd9de..d80c3c8dc 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -536,4 +536,5 @@ export default { "Domain": "Domain", "Workstation": "Workstation", disableCloudflaredNoAuthMsg: "You are in No Auth mode, password is not require.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/es-ES.js b/src/languages/es-ES.js index 315382952..7b3af365c 100644 --- a/src/languages/es-ES.js +++ b/src/languages/es-ES.js @@ -206,4 +206,5 @@ export default { records: "registros", "One record": "Un registro", steamApiKeyDescription: "Para monitorear un servidor de juegos de Steam, necesita una clave Steam Web-API. Puede registrar su clave API aquí: ", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/et-EE.js b/src/languages/et-EE.js index f581a6994..448577a7a 100644 --- a/src/languages/et-EE.js +++ b/src/languages/et-EE.js @@ -206,4 +206,5 @@ export default { alertaApiKey: "API võti", alertaAlertState: "Häireseisund", alertaRecoverState: "Taasta algolek", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/eu.js b/src/languages/eu.js index c99f1eb70..00a7a5f6f 100644 --- a/src/languages/eu.js +++ b/src/languages/eu.js @@ -536,4 +536,5 @@ export default { Domain: "Domeinua", Workstation: "Lan gunea", disableCloudflaredNoAuthMsg: "Ez Auth moduan zaude, pasahitza ez da beharrezkoa.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/fa.js b/src/languages/fa.js index 528451920..fc7eec9ee 100644 --- a/src/languages/fa.js +++ b/src/languages/fa.js @@ -205,4 +205,5 @@ export default { pushbullet: "Pushbullet", line: "Line Messenger", mattermost: "Mattermost", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/fr-FR.js b/src/languages/fr-FR.js index 00abe8d39..d6e746354 100644 --- a/src/languages/fr-FR.js +++ b/src/languages/fr-FR.js @@ -309,4 +309,5 @@ export default { alertaApiKey: "Clé de l'API", alertaAlertState: "État de l'Alerte", alertaRecoverState: "État de récupération", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/hr-HR.js b/src/languages/hr-HR.js index bebd2c560..5bdc6983f 100644 --- a/src/languages/hr-HR.js +++ b/src/languages/hr-HR.js @@ -375,4 +375,5 @@ export default { alertaAlertState: "Stanje upozorenja", alertaRecoverState: "Stanje oporavka", deleteStatusPageMsg: "Sigurno želite obrisati ovu statusnu stranicu?", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/hu.js b/src/languages/hu.js index e6118c9e5..cb53ca8b4 100644 --- a/src/languages/hu.js +++ b/src/languages/hu.js @@ -373,4 +373,5 @@ export default { alertaAlertState: "Figyelmeztetési állapot", alertaRecoverState: "Visszaállási állapot", deleteStatusPageMsg: "Biztos, hogy törölni akarja a státusz oldalt?", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/id-ID.js b/src/languages/id-ID.js index 0a0653082..1e8499fd0 100644 --- a/src/languages/id-ID.js +++ b/src/languages/id-ID.js @@ -283,4 +283,5 @@ export default { promosmsPhoneNumber: "Nomor telepon (untuk penerima Polandia Anda dapat melewati kode area)", promosmsSMSSender: "Nama Pengirim SMS : Nama pra-registrasi atau salah satu bawaan: InfoSMS, Info SMS, MaxSMS, INFO, SMS", "Feishu WebHookUrl": "Feishu WebHookUrl", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/it-IT.js b/src/languages/it-IT.js index f5276183b..5b593c0b6 100644 --- a/src/languages/it-IT.js +++ b/src/languages/it-IT.js @@ -364,4 +364,5 @@ export default { smtpDkimheaderFieldNames: "Campi Intestazione da firmare (opzionale)", smtpDkimskipFields: "Campi Intestazione da non firmare (opzionale)", GoogleChat: "Google Chat (solo per Google Workspace)", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/ja.js b/src/languages/ja.js index 187ade0cd..c53a63343 100644 --- a/src/languages/ja.js +++ b/src/languages/ja.js @@ -198,4 +198,5 @@ export default { pushbullet: "Pushbullet", line: "Line Messenger", mattermost: "Mattermost", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/ko-KR.js b/src/languages/ko-KR.js index dbb02e658..50f6222a9 100644 --- a/src/languages/ko-KR.js +++ b/src/languages/ko-KR.js @@ -528,4 +528,5 @@ export default { "Go back to the previous page.": "이전 페이지로 돌아가기", "Coming Soon": "Coming Soon", wayToGetClickSendSMSToken: "{0}에서 API 사용자 이름과 키를 얻을 수 있어요.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/nb-NO.js b/src/languages/nb-NO.js index 96f71d979..6d54ec829 100644 --- a/src/languages/nb-NO.js +++ b/src/languages/nb-NO.js @@ -282,4 +282,5 @@ export default { promosmsTypeSpeed: "SMS SPEED - Høyest prioritet i systemet.Veldig rask på pålitelig, men dyrt (omtrent det dobbeltet av SMS FULL pris).", promosmsPhoneNumber: "Telefonnummber (for polske mottakere. Du trenger ikke områdekode.)", promosmsSMSSender: "SMS Avsendernavn : Forhåndsregistert navn eller en av standardnavnene: InfoSMS, SMS Info, MaxSMS, INFO, SMS", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/nl-NL.js b/src/languages/nl-NL.js index 3b6ebd836..f3f952676 100644 --- a/src/languages/nl-NL.js +++ b/src/languages/nl-NL.js @@ -462,4 +462,5 @@ export default { "Footer Text": "Footer Tekst", "Show Powered By": "Laat 'Mogeljik gemaakt door' zien", "Domain Names": "Domein Namen", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/pl.js b/src/languages/pl.js index 3e962746e..fe533bbaa 100644 --- a/src/languages/pl.js +++ b/src/languages/pl.js @@ -467,4 +467,5 @@ export default { "Domain Names": "Domeny", signedInDisp: "Zalogowany jako {0}", signedInDispDisabled: "Autoryzacja wyłączona.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/pt-BR.js b/src/languages/pt-BR.js index 7bc8d0fd7..4c03c4a6a 100644 --- a/src/languages/pt-BR.js +++ b/src/languages/pt-BR.js @@ -200,4 +200,5 @@ export default { pushbullet: "Pushbullet", line: "Line Messenger", mattermost: "Mattermost", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/ru-RU.js b/src/languages/ru-RU.js index 0aaf09681..cb7b70eea 100644 --- a/src/languages/ru-RU.js +++ b/src/languages/ru-RU.js @@ -400,4 +400,5 @@ export default { proxyDescription: "Прокси должны быть привязаны к монитору, чтобы работать.", enableProxyDescription: "Этот прокси не будет влиять на запросы монитора, пока не будет активирован. Вы можете контролировать временное отключение прокси для всех мониторов через статус активации.", setAsDefaultProxyDescription: "Этот прокси будет по умолчанию включен для новых мониторов. Вы всё ещё можете отдельно отключать прокси в каждом мониторе.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/sl-SI.js b/src/languages/sl-SI.js index 3c8497f05..1ad708288 100644 --- a/src/languages/sl-SI.js +++ b/src/languages/sl-SI.js @@ -354,4 +354,5 @@ export default { serwersmsPhoneNumber: "Telefonska številka", serwersmsSenderName: "Ime SMS pošiljatelja (registrirani prek portala za stranke)", "stackfield": "Stackfield", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/sr-latn.js b/src/languages/sr-latn.js index 32e074eea..1bc2bb637 100644 --- a/src/languages/sr-latn.js +++ b/src/languages/sr-latn.js @@ -201,4 +201,5 @@ export default { pushbullet: "Pushbullet", line: "Line Messenger", mattermost: "Mattermost", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/sr.js b/src/languages/sr.js index bd8e4dd31..d811ec554 100644 --- a/src/languages/sr.js +++ b/src/languages/sr.js @@ -201,4 +201,5 @@ export default { pushbullet: "Pushbullet", line: "Line Messenger", mattermost: "Mattermost", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/sv-SE.js b/src/languages/sv-SE.js index 1fc35be10..35c8d4b35 100644 --- a/src/languages/sv-SE.js +++ b/src/languages/sv-SE.js @@ -107,4 +107,5 @@ export default { "Repeat Password": "Upprepa Lösenord", respTime: "Svarstid (ms)", notAvailableShort: "Ej Tillg.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/th-TH.js b/src/languages/th-TH.js index a573206b5..1893e4428 100644 --- a/src/languages/th-TH.js +++ b/src/languages/th-TH.js @@ -518,4 +518,5 @@ export default { "Go back to the previous page.": "กลับไปที่หน้าก่อนหน้า", "Coming Soon": "เร็ว ๆ นี้", wayToGetClickSendSMSToken: "คุณสามารถรับ API Username และ API Key ได้จาก {0}", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/tr-TR.js b/src/languages/tr-TR.js index 215b5381d..7ae7e6477 100644 --- a/src/languages/tr-TR.js +++ b/src/languages/tr-TR.js @@ -527,4 +527,5 @@ export default { "do nothing": "hiçbir şey yapma", "auto acknowledged": "otomatik onaylama", "auto resolve": "otomatik çözümleme", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/uk-UA.js b/src/languages/uk-UA.js index 51802a39c..fe3da3e36 100644 --- a/src/languages/uk-UA.js +++ b/src/languages/uk-UA.js @@ -392,4 +392,5 @@ export default { alertaAlertState: "Стан алерту", alertaRecoverState: "Стан відновлення", deleteStatusPageMsg: "Дійсно хочете видалити цю сторінку статусів?", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/vi-VN.js b/src/languages/vi-VN.js index 505776f07..38d3d9701 100644 --- a/src/languages/vi-VN.js +++ b/src/languages/vi-VN.js @@ -466,4 +466,5 @@ export default { "Domain Names": "Domain Names", signedInDisp: "Signed in as {0}", signedInDispDisabled: "Auth Disabled.", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/zh-CN.js b/src/languages/zh-CN.js index 67077f389..8ae84b3e2 100644 --- a/src/languages/zh-CN.js +++ b/src/languages/zh-CN.js @@ -540,4 +540,5 @@ export default { "ntfy Topic": "ntfy 主题", "Domain": "域名", "Workstation": "工作站", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/zh-HK.js b/src/languages/zh-HK.js index a55f4fb65..ac9069be8 100644 --- a/src/languages/zh-HK.js +++ b/src/languages/zh-HK.js @@ -380,4 +380,5 @@ export default { proxyDescription: "必須將代理伺服器指派給監測器才能運作。", enableProxyDescription: "此代理伺服器在啟用前不會在監測器上生效,您可以藉由控制啟用狀態來暫時對所有的監測器停用代理伺服器。", setAsDefaultProxyDescription: "預設情況下,新監測器將啟用此代理伺服器。您仍可分別停用各監測器的代理伺服器。", + HomeAssistant: "Home Assistant", }; diff --git a/src/languages/zh-TW.js b/src/languages/zh-TW.js index ace32e17b..f3ceefd5f 100644 --- a/src/languages/zh-TW.js +++ b/src/languages/zh-TW.js @@ -465,4 +465,5 @@ export default { "Footer Text": "頁尾文字", "Show Powered By": "顯示技術支援文字", "Domain Names": "網域名稱", + HomeAssistant: "Home Assistant", };