diff --git a/dockerfile b/dockerfile index 8674b9993..3dabf513e 100644 --- a/dockerfile +++ b/dockerfile @@ -1,25 +1,30 @@ -# DON'T UPDATE TO alpine3.13, 1.14, see #41. -FROM node:14-alpine3.12 AS release +FROM node:14-bullseye-slim AS release WORKDIR /app +# install dependencies +RUN apt update && apt --yes install python3 python3-pip python3-dev git g++ make iputils-ping +RUN ln -s /usr/bin/python3 /usr/bin/python + # split the sqlite install here, so that it can caches the arm prebuilt -RUN apk add --no-cache --virtual .build-deps make g++ python3 python3-dev git && \ - ln -s /usr/bin/python3 /usr/bin/python && \ - npm install mapbox/node-sqlite3#593c9d && \ - apk del .build-deps && \ - rm -f /usr/bin/python +RUN npm install mapbox/node-sqlite3#593c9d # Install apprise -RUN apk add --no-cache python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib +RUN apt --yes install python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib RUN pip3 --no-cache-dir install apprise && \ - rm -rf /root/.cache + rm -rf /root/.cache + +# additional package should be added here, since we don't want to re-compile the arm prebuilt again + +# add sqlite3 cli for debugging in the future +RUN apt --yes install sqlite3 + COPY . . RUN npm install --legacy-peer-deps && npm run build && npm prune EXPOSE 3001 VOLUME ["/app/data"] -HEALTHCHECK --interval=60s --timeout=30s --start-period=300s CMD node extra/healthcheck.js +HEALTHCHECK --interval=600s --timeout=130s --start-period=300s CMD node extra/healthcheck.js CMD ["node", "server/server.js"] FROM release AS nightly diff --git a/dockerfile-alpine b/dockerfile-alpine new file mode 100644 index 000000000..1dd6b6b53 --- /dev/null +++ b/dockerfile-alpine @@ -0,0 +1,26 @@ +# DON'T UPDATE TO alpine3.13, 1.14, see #41. +FROM node:14-alpine3.12 AS release +WORKDIR /app + +# split the sqlite install here, so that it can caches the arm prebuilt +RUN apk add --no-cache --virtual .build-deps make g++ python3 python3-dev git && \ + ln -s /usr/bin/python3 /usr/bin/python && \ + npm install mapbox/node-sqlite3#593c9d && \ + apk del .build-deps && \ + rm -f /usr/bin/python + +# Install apprise +RUN apk add --no-cache python3 py3-cryptography py3-pip py3-six py3-yaml py3-click py3-markdown py3-requests py3-requests-oauthlib +RUN pip3 --no-cache-dir install apprise && \ + rm -rf /root/.cache + +COPY . . +RUN npm install --legacy-peer-deps && npm run build && npm prune + +EXPOSE 3001 +VOLUME ["/app/data"] +HEALTHCHECK --interval=600s --timeout=130s --start-period=300s CMD node extra/healthcheck.js +CMD ["node", "server/server.js"] + +FROM release AS nightly +RUN npm run mark-as-nightly diff --git a/dockerfile-debian b/dockerfile-debian deleted file mode 100644 index 7e0f79890..000000000 --- a/dockerfile-debian +++ /dev/null @@ -1,28 +0,0 @@ -# DON'T UPDATE TO alpine3.13, 1.14, see #41. -FROM node:14-bullseye AS release -WORKDIR /app - -RUN apt update -RUN apt --yes install python3 python3-pip python3-dev git g++ make -RUN ln -s /usr/bin/python3 /usr/bin/python - -# split the sqlite install here, so that it can caches the arm prebuilt -RUN npm install mapbox/node-sqlite3#593c9d - -# Install apprise -RUN apt --yes install python3 python3-pip python3-cryptography python3-six python3-yaml python3-click python3-markdown python3-requests python3-requests-oauthlib -RUN pip3 --no-cache-dir install apprise && \ - rm -rf /root/.cache - -RUN apt --yes install iputils-ping - -COPY . . -RUN npm install --legacy-peer-deps && npm run build && npm prune - -EXPOSE 3001 -VOLUME ["/app/data"] -HEALTHCHECK --interval=60s --timeout=30s --start-period=300s CMD node extra/healthcheck.js -CMD ["node", "server/server.js"] - -FROM release AS nightly -RUN npm run mark-as-nightly diff --git a/extra/healthcheck.js b/extra/healthcheck.js index c0b33b6ec..6dfdb23f0 100644 --- a/extra/healthcheck.js +++ b/extra/healthcheck.js @@ -1,19 +1,31 @@ -let http = require("http"); +process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; + +let client; + +if (process.env.SSL_KEY && process.env.SSL_CERT) { + client = require("https"); +} else { + client = require("http"); +} + let options = { - host: "localhost", - port: "3001", - timeout: 2000, + host: process.env.HOST || "127.0.0.1", + port: parseInt(process.env.PORT) || 3001, + timeout: 120 * 100, }; -let request = http.request(options, (res) => { - console.log(`STATUS: ${res.statusCode}`); - if (res.statusCode == 200) { + +let request = client.request(options, (res) => { + console.log(`Health Check OK [Res Code: ${res.statusCode}]`); + if (res.statusCode === 200) { process.exit(0); } else { process.exit(1); } }); + request.on("error", function (err) { - console.log("ERROR"); + console.error("Health Check ERROR"); process.exit(1); }); + request.end(); diff --git a/package.json b/package.json index 8bb962904..c04be03f4 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "build": "vite build", "vite-preview-dist": "vite preview --host", "build-docker": "npm run build-docker-alpine && npm run build-docker-debian", - "build-docker-alpine": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:1.5.3 -t louislam/uptime-kuma:alpine -t louislam/uptime-kuma:1-alpine -t louislam/uptime-kuma:1.5.3-alpine --target release . --push", - "build-docker-debian": "docker buildx build -f dockerfile-debian --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:debian -t louislam/uptime-kuma:1-debian -t louislam/uptime-kuma:1.5.3-debian --target release . --push", + "build-docker-alpine": "docker buildx build -f dockerfile-alpine --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:alpine -t louislam/uptime-kuma:1-alpine -t louislam/uptime-kuma:1.5.3-alpine --target release . --push", + "build-docker-debian": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma -t louislam/uptime-kuma:1 -t louislam/uptime-kuma:1.5.3 -t louislam/uptime-kuma:debian -t louislam/uptime-kuma:1-debian -t louislam/uptime-kuma:1.5.3-debian --target release . --push", "build-docker-nightly": "docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t louislam/uptime-kuma:nightly --target nightly . --push", "build-docker-nightly-amd64": "docker buildx build --platform linux/amd64 -t louislam/uptime-kuma:nightly-amd64 --target nightly . --push --progress plain", "setup": "git checkout 1.5.3 && npm install --legacy-peer-deps && node node_modules/esbuild/install.js && npm run build && npm prune", diff --git a/server/notification.js b/server/notification.js index 472012af7..f78401d9b 100644 --- a/server/notification.js +++ b/server/notification.js @@ -4,6 +4,8 @@ const FormData = require("form-data"); const nodemailer = require("nodemailer"); const child_process = require("child_process"); +const { UP, DOWN } = require("../src/util"); + class Notification { /** @@ -80,7 +82,7 @@ class Notification { } } else if (notification.type === "smtp") { - return await Notification.smtp(notification, msg) + return await Notification.smtp(notification, msg, heartbeatJSON) } else if (notification.type === "discord") { try { @@ -109,7 +111,7 @@ class Notification { } // If heartbeatJSON is not null, we go into the normal alerting loop. - if (heartbeatJSON["status"] == 0) { + if (heartbeatJSON["status"] == DOWN) { let discorddowndata = { username: discordDisplayName, embeds: [{ @@ -139,7 +141,7 @@ class Notification { await axios.post(notification.discordWebhookUrl, discorddowndata) return okMsg; - } else if (heartbeatJSON["status"] == 1) { + } else if (heartbeatJSON["status"] == UP) { let discordupdata = { username: discordDisplayName, embeds: [{ @@ -343,7 +345,7 @@ class Notification { const mattermostIconEmoji = notification.mattermosticonemo; const mattermostIconUrl = notification.mattermosticonurl; - if (heartbeatJSON["status"] == 0) { + if (heartbeatJSON["status"] == DOWN) { let mattermostdowndata = { username: mattermostUserName, text: "Uptime Kuma Alert", @@ -387,7 +389,7 @@ class Notification { mattermostdowndata ); return okMsg; - } else if (heartbeatJSON["status"] == 1) { + } else if (heartbeatJSON["status"] == UP) { let mattermostupdata = { username: mattermostUserName, text: "Uptime Kuma Alert", @@ -489,19 +491,19 @@ class Notification { return okMsg; } - if (heartbeatJSON["status"] == 0) { + if (heartbeatJSON["status"] == DOWN) { let downdata = { - "title": "UptimeKuma Alert:" + monitorJSON["name"], - "body": "[🔴 Down]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"], + "title": "UptimeKuma Alert: " + monitorJSON["name"], + "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], } await axios.post(lunaseadevice, downdata) return okMsg; } - if (heartbeatJSON["status"] == 1) { + if (heartbeatJSON["status"] == UP) { let updata = { - "title": "UptimeKuma Alert:" + monitorJSON["name"], - "body": "[✅ Up]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"], + "title": "UptimeKuma Alert: " + monitorJSON["name"], + "body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], } await axios.post(lunaseadevice, updata) return okMsg; @@ -527,18 +529,18 @@ class Notification { "body": "Testing Successful.", } await axios.post(pushbulletUrl, testdata, config) - } else if (heartbeatJSON["status"] == 0) { + } else if (heartbeatJSON["status"] == DOWN) { let downdata = { "type": "note", - "title": "UptimeKuma Alert:" + monitorJSON["name"], - "body": "[🔴 Down]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"], + "title": "UptimeKuma Alert: " + monitorJSON["name"], + "body": "[🔴 Down] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], } await axios.post(pushbulletUrl, downdata, config) - } else if (heartbeatJSON["status"] == 1) { + } else if (heartbeatJSON["status"] == UP) { let updata = { "type": "note", - "title": "UptimeKuma Alert:" + monitorJSON["name"], - "body": "[✅ Up]" + heartbeatJSON["msg"] + "\nTime (UTC):" + heartbeatJSON["time"], + "title": "UptimeKuma Alert: " + monitorJSON["name"], + "body": "[✅ Up] " + heartbeatJSON["msg"] + "\nTime (UTC): " + heartbeatJSON["time"], } await axios.post(pushbulletUrl, updata, config) } @@ -566,7 +568,7 @@ class Notification { ] } await axios.post(lineAPIUrl, testMessage, config) - } else if (heartbeatJSON["status"] == 0) { + } else if (heartbeatJSON["status"] == DOWN) { let downMessage = { "to": notification.lineUserID, "messages": [ @@ -577,7 +579,7 @@ class Notification { ] } await axios.post(lineAPIUrl, downMessage, config) - } else if (heartbeatJSON["status"] == 1) { + } else if (heartbeatJSON["status"] == UP) { let upMessage = { "to": notification.lineUserID, "messages": [ @@ -634,7 +636,7 @@ class Notification { await R.trash(bean) } - static async smtp(notification, msg) { + static async smtp(notification, msg, heartbeatJSON = null) { const config = { host: notification.smtpHost, @@ -652,12 +654,17 @@ class Notification { let transporter = nodemailer.createTransport(config); + let bodyTextContent = msg; + if(heartbeatJSON) { + bodyTextContent = `${msg}\nTime (UTC): ${heartbeatJSON["time"]}`; + } + // send mail with defined transport object await transporter.sendMail({ from: `"Uptime Kuma" <${notification.smtpFrom}>`, to: notification.smtpTo, subject: msg, - text: msg, + text: bodyTextContent, }); return "Sent Successfully."; diff --git a/src/components/HiddenInput.vue b/src/components/HiddenInput.vue new file mode 100644 index 000000000..7ec9f2e49 --- /dev/null +++ b/src/components/HiddenInput.vue @@ -0,0 +1,102 @@ + + + diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 2fdb8fe18..080fb859e 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -40,7 +40,7 @@