diff --git a/db/patch-add-apikey-monitor.sql b/db/patch-add-apikey-monitor.sql deleted file mode 100644 index 1a30bdf3..00000000 --- a/db/patch-add-apikey-monitor.sql +++ /dev/null @@ -1,7 +0,0 @@ --- You should not modify if this have pushed to Github, unless it does serious wrong with the db. -BEGIN TRANSACTION; - -ALTER TABLE monitor - ADD apikey VARCHAR(64) default '' not null; - -COMMIT; diff --git a/server/database.js b/server/database.js index 14819101..1030ffdd 100644 --- a/server/database.js +++ b/server/database.js @@ -46,7 +46,6 @@ class Database { "patch-improve-performance.sql": true, "patch-2fa.sql": true, "patch-add-retry-interval-monitor.sql": true, - "patch-add-apikey-monitor.sql": true, "patch-incident-table.sql": true, "patch-group-table.sql": true, "patch-monitor-push_token.sql": true, @@ -54,7 +53,7 @@ class Database { } /** - * The finally version should be 10 after merged tag feature + * The final version should be 10 after merged tag feature * @deprecated Use patchList for any new feature */ static latestVersion = 10; diff --git a/server/model/monitor.js b/server/model/monitor.js index 589c198e..6d699258 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 { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util"); -const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom } = require("../util-server"); +const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting } = require("../util-server"); const { R } = require("redbean-node"); const { BeanModel } = require("redbean-node/dist/bean-model"); const { Notification } = require("../notification"); @@ -292,26 +292,22 @@ class Monitor extends BeanModel { }, params: { filter: filter, - key: this.apikey, + key: await setting("steamAPIKey"), } }); - bean.msg = `${res.status} - ${res.statusText}`; - bean.ping = await ping(this.hostname); - - let data = res.data; + if (res.data.response && res.data.response.servers && res.data.response.servers.length > 0) { + bean.status = UP; + bean.msg = res.data.response.servers[0].name; - // Convert to string for object/array - if (typeof data !== "string") { - data = JSON.stringify(data); - } + try { + bean.ping = await ping(this.hostname); + } catch (_) { } - if (data.includes(`${this.hostname}:${this.port}`)) { - bean.msg += ", server is found"; - bean.status = UP; } else { - throw new Error(bean.msg + ", but server is not found"); + throw new Error("Server not found on Steam"); } + } else { bean.msg = "Unknown Monitor Type"; bean.status = PENDING; diff --git a/src/languages/en.js b/src/languages/en.js index 53bda1bd..4542d72b 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -304,5 +304,5 @@ export default { records: "records", "One record": "One record", "Showing {from} to {to} of {count} records": "Showing {from} to {to} of {count} records", - steamApiKeyDescription: "For monitoring a Steam Gameserver you need a steam Web-API key. You can register your api key here: https://steamcommunity.com/dev", + steamApiKeyDescription: "For monitoring a Steam Gameserver you need a steam Web-API key. You can register your api key here: ", }; diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index dfeef93f..2a53be7c 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -67,18 +67,20 @@ - -
+ +
- -
+ + +
+