From 5b074c834d32824a18896297ba662ea88f4115a5 Mon Sep 17 00:00:00 2001 From: Bothim_TV Date: Wed, 30 Oct 2024 20:48:47 +0100 Subject: [PATCH] * Added db migration * Made inputting the endpoint more user friendly & foolproof --- .../2024-10-30-2000-pterodactyl-apikey.js | 16 ++++++++++++++++ server/monitor-types/pterodactyl-node.js | 11 +++++++---- src/pages/EditMonitor.vue | 16 ++++++++-------- 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 db/knex_migrations/2024-10-30-2000-pterodactyl-apikey.js diff --git a/db/knex_migrations/2024-10-30-2000-pterodactyl-apikey.js b/db/knex_migrations/2024-10-30-2000-pterodactyl-apikey.js new file mode 100644 index 000000000..3c5d28f46 --- /dev/null +++ b/db/knex_migrations/2024-10-30-2000-pterodactyl-apikey.js @@ -0,0 +1,16 @@ +exports.up = function (knex) { + // Add new column monitor.api_key + return knex.schema + .alterTable("monitor", function (table) { + table.string("api_key", 255).notNullable(); + }); + +}; + +exports.down = function (knex) { + // Drop column monitor.api_key + return knex.schema + .alterTable("monitor", function (table) { + table.dropColumn("api_key"); + }); +}; diff --git a/server/monitor-types/pterodactyl-node.js b/server/monitor-types/pterodactyl-node.js index 2cc2eab4c..c154d3181 100644 --- a/server/monitor-types/pterodactyl-node.js +++ b/server/monitor-types/pterodactyl-node.js @@ -9,17 +9,20 @@ class PterodactylNode extends MonitorType { * @inheritdoc */ async check(monitor, heartbeat, server) { - - await axios.get(`${monitor.nodeHost}/api/system`, { + const pingStart = Date.now(); + const url = new URL(monitor.url); + url.port = monitor.port; + url.pathname = "/api/system"; + await axios.get(url.href, { headers: { Authorization: `Bearer ${monitor.apiKey}` } }) .then(async res => { if (res.status === 200) { - const data = await res.json(); - heartbeat.msg = `Node is up, Version ${data.version}`; + heartbeat.msg = `Node is up, Version ${res.data.version}`; heartbeat.status = UP; + heartbeat.ping = Date.now() - pingStart; } else { throw Error(`Node is down, Status ${res.status}`); } diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 240f5ef9f..eb8d13c75 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -116,7 +116,7 @@ -
+
@@ -285,7 +285,7 @@ -
+
+ +
+ + +
+
@@ -604,12 +610,6 @@
- -
- - -
-