From fbfa5a33ed2fb44b33d8b85359ddd3654630b73a Mon Sep 17 00:00:00 2001 From: Matthew Nickson Date: Sat, 11 Jun 2022 17:23:12 +0100 Subject: [PATCH 01/50] Added Clickable hostname on status page. #1221 This should fully implement #1221 by modifying the API and adding two new properties to the result. The `sendUrl` property denotes if the URL is sent and `url` is included when required. Client side checks have been implemented in order to only show a link when the URL is vaugely correct. I.e not "" or "https://". This prevents the link from being included if the monitor type is not HTTP without having to publicly expose the monitor type. The exposure of the URL is configuarable for each monitor on each status page by clicking on the link icon. Signed-off-by: Matthew Nickson --- db/patch-add-clickable-status-page-link.sql | 5 ++ server/database.js | 1 + server/model/group.js | 2 +- server/model/monitor.js | 6 +++ .../status-page-socket-handler.js | 1 + src/components/PublicGroupList.vue | 48 ++++++++++++++++++- src/icon.js | 1 + 7 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 db/patch-add-clickable-status-page-link.sql diff --git a/db/patch-add-clickable-status-page-link.sql b/db/patch-add-clickable-status-page-link.sql new file mode 100644 index 00000000..bacd669b --- /dev/null +++ b/db/patch-add-clickable-status-page-link.sql @@ -0,0 +1,5 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; +ALTER TABLE monitor_group + ADD send_url BOOLEAN DEFAULT 0 NOT NULL; +COMMIT; diff --git a/server/database.js b/server/database.js index b17e7f4e..8c93fed6 100644 --- a/server/database.js +++ b/server/database.js @@ -58,6 +58,7 @@ class Database { "patch-monitor-expiry-notification.sql": true, "patch-status-page-footer-css.sql": true, "patch-added-mqtt-monitor.sql": true, + "patch-add-clickable-status-page-link.sql": true, }; /** diff --git a/server/model/group.js b/server/model/group.js index 599b758b..3f3b3b12 100644 --- a/server/model/group.js +++ b/server/model/group.js @@ -31,7 +31,7 @@ class Group extends BeanModel { */ async getMonitorList() { return R.convertToBeans("monitor", await R.getAll(` - SELECT monitor.* FROM monitor, monitor_group + SELECT monitor.*, monitor_group.send_url FROM monitor, monitor_group WHERE monitor.id = monitor_group.monitor_id AND group_id = ? ORDER BY monitor_group.weight diff --git a/server/model/monitor.js b/server/model/monitor.js index 643d34a6..b46c0e32 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -34,7 +34,13 @@ class Monitor extends BeanModel { let obj = { id: this.id, name: this.name, + sendUrl: this.sendUrl, }; + + if (this.sendUrl) { + obj.url = this.url; + } + if (showTags) { obj.tags = await this.getTags(); } diff --git a/server/socket-handlers/status-page-socket-handler.js b/server/socket-handlers/status-page-socket-handler.js index 0a0dc686..80017e7d 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -202,6 +202,7 @@ module.exports.statusPageSocketHandler = (socket) => { relationBean.weight = monitorOrder++; relationBean.group_id = groupBean.id; relationBean.monitor_id = monitor.id; + relationBean.send_url = monitor.sendUrl; await R.store(relationBean); } diff --git a/src/components/PublicGroupList.vue b/src/components/PublicGroupList.vue index df94eec9..cbd8aeff 100644 --- a/src/components/PublicGroupList.vue +++ b/src/components/PublicGroupList.vue @@ -39,7 +39,21 @@ - {{ monitor.element.name }} + + {{ monitor.element.name }} + +

{{ monitor.element.name }}

+
@@ -101,6 +115,27 @@ export default { removeMonitor(groupIndex, index) { this.$root.publicGroupList[groupIndex].monitorList.splice(index, 1); }, + + /** + * Toggle the value of sendUrl + * @param {number} groupIndex Index of group monitor is member of + * @param {number} index Index of monitor within group + */ + toggleLink(groupIndex, index) { + this.$root.publicGroupList[groupIndex].monitorList[index].sendUrl = !this.$root.publicGroupList[groupIndex].monitorList[index].sendUrl; + }, + + /** + * Should a link to the monitor be shown? + * Attempts to guess if a link should be shown based upon if + * sendUrl is set and if the URL is default or not. + * @param {Object} monitor Monitor to check + * @returns {boolean} + */ + showLink(monitor) { + return monitor.element.sendUrl && monitor.element.url && monitor.element.url !== "https://"; + + }, } }; @@ -119,6 +154,17 @@ export default { min-height: 46px; } +.item-name { + padding-left: 5px; + padding-right: 5px; + margin: 0; + display: inline-block; +} + +.link-active { + color: #4caf50; +} + .flip-list-move { transition: transform 0.5s; } diff --git a/src/icon.js b/src/icon.js index d83034fa..23513bcc 100644 --- a/src/icon.js +++ b/src/icon.js @@ -81,6 +81,7 @@ library.add( faUndo, faPlusCircle, faAngleDown, + faLink, ); export { FontAwesomeIcon }; From 5f6347d277695f8af5a68b186b373809f7a03272 Mon Sep 17 00:00:00 2001 From: Daeho Ro Date: Sun, 12 Jun 2022 04:02:44 +0900 Subject: [PATCH 02/50] pull request for adding alertnow notification --- server/notification-providers/alertnow.js | 50 ++++++++++ server/notification.js | 68 ++++++------- src/components/notifications/AlertNow.vue | 13 +++ src/components/notifications/index.js | 112 +++++++++++----------- 4 files changed, 155 insertions(+), 88 deletions(-) create mode 100644 server/notification-providers/alertnow.js create mode 100644 src/components/notifications/AlertNow.vue diff --git a/server/notification-providers/alertnow.js b/server/notification-providers/alertnow.js new file mode 100644 index 00000000..d778b01d --- /dev/null +++ b/server/notification-providers/alertnow.js @@ -0,0 +1,50 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { setting } = require("../util-server"); +const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util"); + +class AlertNow extends NotificationProvider { + + name = "AlertNow"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + try { + let textMsg = ""; + let status = "open"; + let eventType = "ERROR"; + let eventId = new Date().toISOString().slice(0, 10).replace(/-/g, ""); + + if (heartbeatJSON && heartbeatJSON.status === UP) { + textMsg = `[${heartbeatJSON.name}] ✅ Application is back online`; + status = "close"; + eventType = "INFO"; + eventId += `_${heartbeatJSON.name.replace(/\s/g, "")}`; + } else if (heartbeatJSON && heartbeatJSON.status === DOWN) { + textMsg = `[${heartbeatJSON.name}] 🔴 Application went down`; + } + + textMsg += ` - ${msg}`; + + const baseURL = await setting("primaryBaseURL"); + if (baseURL && monitorJSON) { + textMsg += ` >> ${baseURL + getMonitorRelativeURL(monitorJSON.id)}`; + } + + const data = { + "summary": textMsg, + "status": status, + "event_type": eventType, + "event_id": eventId, + }; + + await axios.post(notification.alertNowWebhookURL, data); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + + } +} + +module.exports = AlertNow; diff --git a/server/notification.js b/server/notification.js index c457ed14..a3b3a70b 100644 --- a/server/notification.js +++ b/server/notification.js @@ -1,40 +1,41 @@ const { R } = require("redbean-node"); +const { log } = require("../src/util"); +const Alerta = require("./notification-providers/alerta"); +const AlertNow = require("./notification-providers/alertnow"); +const AliyunSms = require("./notification-providers/aliyun-sms"); const Apprise = require("./notification-providers/apprise"); +const Bark = require("./notification-providers/bark"); +const ClickSendSMS = require("./notification-providers/clicksendsms"); +const DingDing = require("./notification-providers/dingding"); const Discord = require("./notification-providers/discord"); +const Feishu = require("./notification-providers/feishu"); +const GoogleChat = require("./notification-providers/google-chat"); +const Gorush = require("./notification-providers/gorush"); const Gotify = require("./notification-providers/gotify"); -const Ntfy = require("./notification-providers/ntfy"); const Line = require("./notification-providers/line"); const LunaSea = require("./notification-providers/lunasea"); -const Mattermost = require("./notification-providers/mattermost"); const Matrix = require("./notification-providers/matrix"); +const Mattermost = require("./notification-providers/mattermost"); +const Ntfy = require("./notification-providers/ntfy"); const Octopush = require("./notification-providers/octopush"); +const OneBot = require("./notification-providers/onebot"); +const PagerDuty = require("./notification-providers/pagerduty"); const PromoSMS = require("./notification-providers/promosms"); -const ClickSendSMS = require("./notification-providers/clicksendsms"); const Pushbullet = require("./notification-providers/pushbullet"); +const PushDeer = require("./notification-providers/pushdeer"); const Pushover = require("./notification-providers/pushover"); const Pushy = require("./notification-providers/pushy"); -const TechulusPush = require("./notification-providers/techulus-push"); const RocketChat = require("./notification-providers/rocket-chat"); +const SerwerSMS = require("./notification-providers/serwersms"); const Signal = require("./notification-providers/signal"); const Slack = require("./notification-providers/slack"); const SMTP = require("./notification-providers/smtp"); +const Stackfield = require("./notification-providers/stackfield"); const Teams = require("./notification-providers/teams"); +const TechulusPush = require("./notification-providers/techulus-push"); const Telegram = require("./notification-providers/telegram"); const Webhook = require("./notification-providers/webhook"); -const Feishu = require("./notification-providers/feishu"); -const AliyunSms = require("./notification-providers/aliyun-sms"); -const DingDing = require("./notification-providers/dingding"); -const Bark = require("./notification-providers/bark"); -const { log } = require("../src/util"); -const SerwerSMS = require("./notification-providers/serwersms"); -const Stackfield = require("./notification-providers/stackfield"); const WeCom = require("./notification-providers/wecom"); -const GoogleChat = require("./notification-providers/google-chat"); -const PagerDuty = require("./notification-providers/pagerduty"); -const Gorush = require("./notification-providers/gorush"); -const Alerta = require("./notification-providers/alerta"); -const OneBot = require("./notification-providers/onebot"); -const PushDeer = require("./notification-providers/pushdeer"); class Notification { @@ -47,41 +48,42 @@ class Notification { this.providerList = {}; const list = [ - new Apprise(), + new Alerta(), + new AlertNow(), new AliyunSms(), + new Apprise(), + new Bark(), + new ClickSendSMS(), new DingDing(), new Discord(), - new Teams(), + new Feishu(), + new GoogleChat(), + new Gorush(), new Gotify(), - new Ntfy(), new Line(), new LunaSea(), - new Feishu(), - new Mattermost(), new Matrix(), + new Mattermost(), + new Ntfy(), new Octopush(), + new OneBot(), + new PagerDuty(), new PromoSMS(), - new ClickSendSMS(), new Pushbullet(), + new PushDeer(), new Pushover(), new Pushy(), - new TechulusPush(), new RocketChat(), + new SerwerSMS(), new Signal(), new Slack(), new SMTP(), + new Stackfield(), + new Teams(), + new TechulusPush(), new Telegram(), new Webhook(), - new Bark(), - new SerwerSMS(), - new Stackfield(), new WeCom(), - new GoogleChat(), - new PagerDuty(), - new Gorush(), - new Alerta(), - new OneBot(), - new PushDeer(), ]; for (let item of list) { diff --git a/src/components/notifications/AlertNow.vue b/src/components/notifications/AlertNow.vue new file mode 100644 index 00000000..93acc959 --- /dev/null +++ b/src/components/notifications/AlertNow.vue @@ -0,0 +1,13 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 18c316a5..e5cbe8ce 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -1,38 +1,39 @@ -import STMP from "./SMTP.vue"; -import Telegram from "./Telegram.vue"; +import Alerta from "./Alerta.vue"; +import AlertNow from "./AlertNow.vue"; +import AliyunSMS from "./AliyunSms.vue"; +import Apprise from "./Apprise.vue"; +import Bark from "./Bark.vue"; +import ClickSendSMS from "./ClickSendSMS.vue"; +import DingDing from "./DingDing.vue"; import Discord from "./Discord.vue"; -import Webhook from "./Webhook.vue"; -import Signal from "./Signal.vue"; +import Feishu from "./Feishu.vue"; +import GoogleChat from "./GoogleChat.vue"; +import Gorush from "./Gorush.vue"; import Gotify from "./Gotify.vue"; +import Line from "./Line.vue"; +import LunaSea from "./LunaSea.vue"; +import Matrix from "./Matrix.vue"; +import Mattermost from "./Mattermost.vue"; import Ntfy from "./Ntfy.vue"; -import Slack from "./Slack.vue"; -import RocketChat from "./RocketChat.vue"; -import Teams from "./Teams.vue"; +import Octopush from "./Octopush.vue"; +import OneBot from "./OneBot.vue"; +import PagerDuty from "./PagerDuty.vue"; +import PromoSMS from "./PromoSMS.vue"; +import Pushbullet from "./Pushbullet.vue"; +import PushDeer from "./PushDeer.vue"; import Pushover from "./Pushover.vue"; import Pushy from "./Pushy.vue"; -import TechulusPush from "./TechulusPush.vue"; -import Octopush from "./Octopush.vue"; -import PromoSMS from "./PromoSMS.vue"; -import ClickSendSMS from "./ClickSendSMS.vue"; -import LunaSea from "./LunaSea.vue"; -import Feishu from "./Feishu.vue"; -import Apprise from "./Apprise.vue"; -import Pushbullet from "./Pushbullet.vue"; -import Line from "./Line.vue"; -import Mattermost from "./Mattermost.vue"; -import Matrix from "./Matrix.vue"; -import AliyunSMS from "./AliyunSms.vue"; -import DingDing from "./DingDing.vue"; -import Bark from "./Bark.vue"; +import RocketChat from "./RocketChat.vue"; import SerwerSMS from "./SerwerSMS.vue"; +import Signal from "./Signal.vue"; +import Slack from "./Slack.vue"; import Stackfield from "./Stackfield.vue"; +import STMP from "./SMTP.vue"; +import Teams from "./Teams.vue"; +import TechulusPush from "./TechulusPush.vue"; +import Telegram from "./Telegram.vue"; +import Webhook from "./Webhook.vue"; import WeCom from "./WeCom.vue"; -import GoogleChat from "./GoogleChat.vue"; -import PagerDuty from "./PagerDuty.vue"; -import Gorush from "./Gorush.vue"; -import Alerta from "./Alerta.vue"; -import OneBot from "./OneBot.vue"; -import PushDeer from "./PushDeer.vue"; /** * Manage all notification form. @@ -40,41 +41,42 @@ import PushDeer from "./PushDeer.vue"; * @type { Record } */ const NotificationFormList = { - "telegram": Telegram, - "webhook": Webhook, - "smtp": STMP, - "discord": Discord, - "teams": Teams, - "signal": Signal, - "gotify": Gotify, - "ntfy": Ntfy, - "slack": Slack, - "rocket.chat": RocketChat, - "pushover": Pushover, - "pushy": Pushy, - "PushByTechulus": TechulusPush, - "octopush": Octopush, - "promosms": PromoSMS, - "clicksendsms": ClickSendSMS, - "lunasea": LunaSea, - "Feishu": Feishu, + "alerta": Alerta, + "AlertNow": AlertNow, "AliyunSMS": AliyunSMS, "apprise": Apprise, - "pushbullet": Pushbullet, - "line": Line, - "mattermost": Mattermost, - "matrix": Matrix, - "DingDing": DingDing, "Bark": Bark, - "serwersms": SerwerSMS, - "stackfield": Stackfield, - "WeCom": WeCom, + "clicksendsms": ClickSendSMS, + "DingDing": DingDing, + "discord": Discord, + "Feishu": Feishu, "GoogleChat": GoogleChat, - "PagerDuty": PagerDuty, "gorush": Gorush, - "alerta": Alerta, + "gotify": Gotify, + "line": Line, + "lunasea": LunaSea, + "matrix": Matrix, + "mattermost": Mattermost, + "ntfy": Ntfy, + "octopush": Octopush, "OneBot": OneBot, + "PagerDuty": PagerDuty, + "promosms": PromoSMS, + "pushbullet": Pushbullet, + "PushByTechulus": TechulusPush, "PushDeer": PushDeer, + "pushover": Pushover, + "pushy": Pushy, + "rocket.chat": RocketChat, + "serwersms": SerwerSMS, + "signal": Signal, + "slack": Slack, + "smtp": STMP, + "stackfield": Stackfield, + "teams": Teams, + "telegram": Telegram, + "webhook": Webhook, + "WeCom": WeCom, }; export default NotificationFormList; From 945288f0c01c45b771d81da711768d8987754baa Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Wed, 15 Jun 2022 12:12:47 -0500 Subject: [PATCH 03/50] Added postgres monitor --- package-lock.json | 215 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + server/model/monitor.js | 10 +- server/util-server.js | 28 +++++ src/pages/EditMonitor.vue | 22 ++-- 5 files changed, 268 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 87342813..d213b883 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,6 +52,7 @@ "nodemailer": "~6.6.5", "notp": "~2.0.3", "password-hash": "~1.2.2", + "pg": "^8.7.3", "postcss-rtlcss": "~3.4.1", "postcss-scss": "~4.0.3", "prismjs": "^1.27.0", @@ -5335,6 +5336,14 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, + "node_modules/buffer-writer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", + "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==", + "engines": { + "node": ">=4" + } + }, "node_modules/builtins": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/builtins/-/builtins-5.0.0.tgz", @@ -14437,6 +14446,11 @@ "node": ">=8" } }, + "node_modules/packet-reader": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz", + "integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" + }, "node_modules/pacote": { "version": "13.0.5", "resolved": "https://registry.npmjs.org/pacote/-/pacote-13.0.5.tgz", @@ -14689,11 +14703,88 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "optional": true }, + "node_modules/pg": { + "version": "8.7.3", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.7.3.tgz", + "integrity": "sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==", + "dependencies": { + "buffer-writer": "2.0.0", + "packet-reader": "1.0.0", + "pg-connection-string": "^2.5.0", + "pg-pool": "^3.5.1", + "pg-protocol": "^1.5.0", + "pg-types": "^2.1.0", + "pgpass": "1.x" + }, + "engines": { + "node": ">= 8.0.0" + }, + "peerDependencies": { + "pg-native": ">=2.0.0" + }, + "peerDependenciesMeta": { + "pg-native": { + "optional": true + } + } + }, "node_modules/pg-connection-string": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz", "integrity": "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==" }, + "node_modules/pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/pg-pool": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.1.tgz", + "integrity": "sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==", + "peerDependencies": { + "pg": ">=8.0" + } + }, + "node_modules/pg-protocol": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.5.0.tgz", + "integrity": "sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ==" + }, + "node_modules/pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "dependencies": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "dependencies": { + "split2": "^4.1.0" + } + }, + "node_modules/pgpass/node_modules/split2": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz", + "integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -14927,6 +15018,41 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", "dev": true }, + "node_modules/postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", + "engines": { + "node": ">=4" + } + }, + "node_modules/postgres-bytea": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", + "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "dependencies": { + "xtend": "^4.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -22865,6 +22991,11 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, + "buffer-writer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", + "integrity": "sha512-a7ZpuTZU1TRtnwyCNW3I5dc0wWNC3VR9S++Ewyk2HHZdrO3CQJqSpd+95Us590V6AL7JqUAH2IwZ/398PmNFgw==" + }, "builtins": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/builtins/-/builtins-5.0.0.tgz", @@ -29671,6 +29802,11 @@ "semver": "^6.2.0" } }, + "packet-reader": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/packet-reader/-/packet-reader-1.0.0.tgz", + "integrity": "sha512-HAKu/fG3HpHFO0AA8WE8q2g+gBJaZ9MG7fcKk+IJPLTGAD6Psw4443l+9DGRbOIh3/aXr7Phy0TjilYivJo5XQ==" + }, "pacote": { "version": "13.0.5", "resolved": "https://registry.npmjs.org/pacote/-/pacote-13.0.5.tgz", @@ -29867,11 +30003,67 @@ "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", "optional": true }, + "pg": { + "version": "8.7.3", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.7.3.tgz", + "integrity": "sha512-HPmH4GH4H3AOprDJOazoIcpI49XFsHCe8xlrjHkWiapdbHK+HLtbm/GQzXYAZwmPju/kzKhjaSfMACG+8cgJcw==", + "requires": { + "buffer-writer": "2.0.0", + "packet-reader": "1.0.0", + "pg-connection-string": "^2.5.0", + "pg-pool": "^3.5.1", + "pg-protocol": "^1.5.0", + "pg-types": "^2.1.0", + "pgpass": "1.x" + } + }, "pg-connection-string": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.5.0.tgz", "integrity": "sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==" }, + "pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" + }, + "pg-pool": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.5.1.tgz", + "integrity": "sha512-6iCR0wVrro6OOHFsyavV+i6KYL4lVNyYAB9RD18w66xSzN+d8b66HiwuP30Gp1SH5O9T82fckkzsRjlrhD0ioQ==" + }, + "pg-protocol": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.5.0.tgz", + "integrity": "sha512-muRttij7H8TqRNu/DxrAJQITO4Ac7RmX3Klyr/9mJEOBeIpgnF8f9jAfRz5d3XwQZl5qBjF9gLsUtMPJE0vezQ==" + }, + "pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "requires": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + } + }, + "pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "requires": { + "split2": "^4.1.0" + }, + "dependencies": { + "split2": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.1.0.tgz", + "integrity": "sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==" + } + } + }, "picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -30035,6 +30227,29 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", "dev": true }, + "postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==" + }, + "postgres-bytea": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", + "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==" + }, + "postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==" + }, + "postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "requires": { + "xtend": "^4.0.0" + } + }, "prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/package.json b/package.json index efb3e7c1..781e07b1 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "nodemailer": "~6.6.5", "notp": "~2.0.3", "password-hash": "~1.2.2", + "pg": "^8.7.3", "postcss-rtlcss": "~3.4.1", "postcss-scss": "~4.0.3", "prismjs": "^1.27.0", diff --git a/server/model/monitor.js b/server/model/monitor.js index 3e026fb6..9f1bbea5 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -7,7 +7,7 @@ dayjs.extend(timezone); const axios = require("axios"); const { Prometheus } = require("../prometheus"); const { log, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util"); -const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, mqttAsync, setSetting, httpNtlm } = require("../util-server"); +const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting, mssqlQuery, postgresQuery, mqttAsync, setSetting, httpNtlm } = require("../util-server"); const { R } = require("redbean-node"); const { BeanModel } = require("redbean-node/dist/bean-model"); const { Notification } = require("../notification"); @@ -477,6 +477,14 @@ class Monitor extends BeanModel { await mssqlQuery(this.databaseConnectionString, this.databaseQuery); + bean.msg = ""; + bean.status = UP; + bean.ping = dayjs().valueOf() - startTime; + } else if (this.type === "postgres") { + let startTime = dayjs().valueOf(); + + await postgresQuery(this.databaseConnectionString, this.databaseQuery); + bean.msg = ""; bean.status = UP; bean.ping = dayjs().valueOf() - startTime; diff --git a/server/util-server.js b/server/util-server.js index 87f9151d..34139383 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -11,6 +11,7 @@ const mqtt = require("mqtt"); const chroma = require("chroma-js"); const { badgeConstants } = require("./config"); const mssql = require("mssql"); +const { Client } = require("pg"); const { NtlmClient } = require("axios-ntlm"); // From ping-lite @@ -254,6 +255,33 @@ exports.mssqlQuery = function (connectionString, query) { }); }; +/** + * Run a query on Postgres + * @param {string} connectionString The database connection string + * @param {string} query The query to validate the database with + * @returns {Promise<(string[]|Object[]|Object)>} + */ +exports.postgresQuery = function (connectionString, query) { + + return new Promise((resolve, reject) => { + + const client = new Client({ connectionString }); + + client.connect(); + + client.query(query) + .then(res => { + resolve(res); + }) + .catch(err => { + reject(err); + }) + .finally(() => { + client.end(); + }); + }); +}; + /** * Retrieve value of setting based on key * @param {string} key Key of setting to retrieve diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 83ffcfd8..cc100bac 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -45,6 +45,9 @@ +
@@ -168,15 +171,21 @@ - -
From e1f766756f067f043bfc6a43c3f24e2c9c19f76a Mon Sep 17 00:00:00 2001 From: "sur.la.route" Date: Wed, 15 Jun 2022 20:14:26 -0500 Subject: [PATCH 06/50] Removed blank line Co-authored-by: Matthew Nickson --- server/util-server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/util-server.js b/server/util-server.js index dc403cbd..89777bce 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -263,7 +263,6 @@ exports.mssqlQuery = function (connectionString, query) { * @returns {Promise<(string[]|Object[]|Object)>} */ exports.postgresQuery = function (connectionString, query) { - return new Promise((resolve, reject) => { const config = postgresConParse(connectionString); From 47e82ed83ad980b16374ecd1010ccf4b4f9ae9bd Mon Sep 17 00:00:00 2001 From: "sur.la.route" Date: Wed, 15 Jun 2022 20:14:36 -0500 Subject: [PATCH 07/50] Removed blank line Co-authored-by: Matthew Nickson --- server/util-server.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/util-server.js b/server/util-server.js index 89777bce..0ac13c68 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -264,7 +264,6 @@ exports.mssqlQuery = function (connectionString, query) { */ exports.postgresQuery = function (connectionString, query) { return new Promise((resolve, reject) => { - const config = postgresConParse(connectionString); if (config.password === "") { From c4e2d67d17319cc438be7174aaea3f7f6f560077 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 17 Jun 2022 10:11:53 +0300 Subject: [PATCH 08/50] fix: hide mobile header when not logged in --- src/layouts/Layout.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/Layout.vue b/src/layouts/Layout.vue index aea58bf1..57519f55 100644 --- a/src/layouts/Layout.vue +++ b/src/layouts/Layout.vue @@ -77,7 +77,7 @@
-