mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-18 23:34:04 +02:00
Merge 38037f5673
into 2fd4e1cc72
This commit is contained in:
commit
03d520f47f
3 changed files with 57 additions and 16 deletions
|
@ -20,7 +20,6 @@ const version = require("../../package.json").version;
|
||||||
const apicache = require("../modules/apicache");
|
const apicache = require("../modules/apicache");
|
||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
const { DockerHost } = require("../docker");
|
const { DockerHost } = require("../docker");
|
||||||
const Gamedig = require("gamedig");
|
|
||||||
const jwt = require("jsonwebtoken");
|
const jwt = require("jsonwebtoken");
|
||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
const { UptimeCalculator } = require("../uptime-calculator");
|
const { UptimeCalculator } = require("../uptime-calculator");
|
||||||
|
@ -702,21 +701,6 @@ class Monitor extends BeanModel {
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Server not found on Steam");
|
throw new Error("Server not found on Steam");
|
||||||
}
|
}
|
||||||
} else if (this.type === "gamedig") {
|
|
||||||
try {
|
|
||||||
const state = await Gamedig.query({
|
|
||||||
type: this.game,
|
|
||||||
host: this.hostname,
|
|
||||||
port: this.port,
|
|
||||||
givenPortOnly: this.getGameDigGivenPortOnly(),
|
|
||||||
});
|
|
||||||
|
|
||||||
bean.msg = state.name;
|
|
||||||
bean.status = UP;
|
|
||||||
bean.ping = state.ping;
|
|
||||||
} catch (e) {
|
|
||||||
throw new Error(e.message);
|
|
||||||
}
|
|
||||||
} else if (this.type === "docker") {
|
} else if (this.type === "docker") {
|
||||||
log.debug("monitor", `[${this.name}] Prepare Options for Axios`);
|
log.debug("monitor", `[${this.name}] Prepare Options for Axios`);
|
||||||
|
|
||||||
|
|
55
server/monitor-types/gamedig.js
Normal file
55
server/monitor-types/gamedig.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
const { MonitorType } = require("./monitor-type");
|
||||||
|
const { UP, DOWN } = require("../../src/util");
|
||||||
|
const Gamedig = require("gamedig");
|
||||||
|
const dns = require("dns").promises;
|
||||||
|
const net = require("net");
|
||||||
|
|
||||||
|
class GameDigMonitorType extends MonitorType {
|
||||||
|
name = "gamedig";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async check(monitor, heartbeat, server) {
|
||||||
|
heartbeat.status = DOWN;
|
||||||
|
|
||||||
|
let host = monitor.hostname;
|
||||||
|
if (net.isIP(host) === 0) {
|
||||||
|
host = await this.resolveHostname(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const state = await Gamedig.query({
|
||||||
|
type: monitor.game,
|
||||||
|
host: host,
|
||||||
|
port: monitor.port,
|
||||||
|
givenPortOnly: Boolean(monitor.gamedigGivenPortOnly),
|
||||||
|
});
|
||||||
|
|
||||||
|
heartbeat.msg = state.name;
|
||||||
|
heartbeat.status = UP;
|
||||||
|
heartbeat.ping = state.ping;
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a domain name to its IPv4 address.
|
||||||
|
* @param {string} hostname - The domain name to resolve (e.g., "example.dyndns.org").
|
||||||
|
* @returns {Promise<string>} - The resolved IP address.
|
||||||
|
* @throws Will throw an error if the DNS resolution fails.
|
||||||
|
*/
|
||||||
|
async resolveHostname(hostname) {
|
||||||
|
try {
|
||||||
|
const result = await dns.lookup(hostname);
|
||||||
|
return result.address;
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`DNS resolution failed for ${hostname}: ${err.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
GameDigMonitorType,
|
||||||
|
};
|
|
@ -118,6 +118,7 @@ class UptimeKumaServer {
|
||||||
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
|
UptimeKumaServer.monitorTypeList["snmp"] = new SNMPMonitorType();
|
||||||
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
|
UptimeKumaServer.monitorTypeList["mongodb"] = new MongodbMonitorType();
|
||||||
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
|
UptimeKumaServer.monitorTypeList["rabbitmq"] = new RabbitMqMonitorType();
|
||||||
|
UptimeKumaServer.monitorTypeList["gamedig"] = new GameDigMonitorType();
|
||||||
UptimeKumaServer.monitorTypeList["manual"] = new ManualMonitorType();
|
UptimeKumaServer.monitorTypeList["manual"] = new ManualMonitorType();
|
||||||
|
|
||||||
// Allow all CORS origins (polling) in development
|
// Allow all CORS origins (polling) in development
|
||||||
|
@ -559,5 +560,6 @@ const { GroupMonitorType } = require("./monitor-types/group");
|
||||||
const { SNMPMonitorType } = require("./monitor-types/snmp");
|
const { SNMPMonitorType } = require("./monitor-types/snmp");
|
||||||
const { MongodbMonitorType } = require("./monitor-types/mongodb");
|
const { MongodbMonitorType } = require("./monitor-types/mongodb");
|
||||||
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
|
const { RabbitMqMonitorType } = require("./monitor-types/rabbitmq");
|
||||||
|
const { GameDigMonitorType } = require("./monitor-types/gamedig");
|
||||||
const { ManualMonitorType } = require("./monitor-types/manual");
|
const { ManualMonitorType } = require("./monitor-types/manual");
|
||||||
const Monitor = require("./model/monitor");
|
const Monitor = require("./model/monitor");
|
||||||
|
|
Loading…
Add table
Reference in a new issue