Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New monitor type: pterodactyl node #5288

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions db/knex_migrations/2024-10-30-2000-pterodactyl-apikey.js
Original file line number Diff line number Diff line change
@@ -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");
});
};
37 changes: 37 additions & 0 deletions server/monitor-types/pterodactyl-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { MonitorType } = require("./monitor-type");
const { UP } = require("../../src/util");
const axios = require("axios");

class PterodactylNode extends MonitorType {
name = "pterodactyl-node";

/**
* @inheritdoc
*/
async check(monitor, heartbeat, server) {
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) {
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}`);
}
});

}

}

module.exports = {
PterodactylNode,
};
2 changes: 2 additions & 0 deletions server/uptime-kuma-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class UptimeKumaServer {
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
UptimeKumaServer.monitorTypeList["pterodactyl-node"] = new PterodactylNode();

// Allow all CORS origins (polling) in development
let cors = undefined;
Expand Down Expand Up @@ -554,4 +555,5 @@ const { MqttMonitorType } = require("./monitor-types/mqtt");
const { SNMPMonitorType } = require("./monitor-types/snmp");
const { MongodbMonitorType } = require("./monitor-types/mongodb");
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
const { PterodactylNode } = require("./monitor-types/pterodactyl-node");
const Monitor = require("./model/monitor");
16 changes: 13 additions & 3 deletions src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
<option v-if="!$root.info.isContainer" value="tailscale-ping">
Tailscale Ping
</option>
<option value="pterodactyl-node">
Pterodactyl Node
</option>
</optgroup>
</select>
<i18n-t v-if="monitor.type === 'rabbitmq'" keypath="rabbitmqHelpText" tag="div" class="form-text">
Expand All @@ -113,7 +116,7 @@
</div>

<!-- URL -->
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' " class="my-3">
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' || monitor.type === 'real-browser' || monitor.type === 'pterodactyl-node'" class="my-3">
<label for="url" class="form-label">{{ $t("URL") }}</label>
<input id="url" v-model="monitor.url" type="url" class="form-control" pattern="https?://.+" required data-testid="url-input">
</div>
Expand Down Expand Up @@ -297,7 +300,7 @@

<!-- Port -->
<!-- For TCP Port / Steam / MQTT / Radius Type / SNMP -->
<div v-if="monitor.type === 'port' || monitor.type === 'steam' || monitor.type === 'gamedig' || monitor.type === 'mqtt' || monitor.type === 'radius' || monitor.type === 'snmp'" class="my-3">
<div v-if="monitor.type === 'port' || monitor.type === 'steam' || monitor.type === 'gamedig' || monitor.type === 'mqtt' || monitor.type === 'radius' || monitor.type === 'snmp' || monitor.type === 'pterodactyl-node'" class="my-3">
<label for="port" class="form-label">{{ $t("Port") }}</label>
<input id="port" v-model="monitor.port" type="number" class="form-control" required min="0" max="65535" step="1">
</div>
Expand Down Expand Up @@ -573,6 +576,12 @@
class="my-3"
/>

<!-- ApiKey: Pterodactyl node only -->
<div v-if="monitor.type === 'pterodactyl-node'" class="my-3">
<label for="apiKey" class="form-label">{{ $t("API Key") }}</label>
<HiddenInput id="apiKey" v-model="monitor.apiKey" type="password" required></HiddenInput>
</div>

<!-- Interval -->
<div class="my-3">
<label for="interval" class="form-label">{{ $t("Heartbeat Interval") }} ({{ $t("checkEverySecond", [ monitor.interval ]) }})</label>
Expand Down Expand Up @@ -1111,7 +1120,8 @@ const monitorDefaults = {
rabbitmqNodes: [],
rabbitmqUsername: "",
rabbitmqPassword: "",
conditions: []
conditions: [],
apiKey: "",
};

export default {
Expand Down
Loading