mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-10-01 01:25:45 -04:00
Fixing linting & adding documentation
This commit is contained in:
parent
0d098b0958
commit
e356d5f623
@ -122,6 +122,11 @@ async function sendInfo(socket) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send list of docker hosts to client
|
||||||
|
* @param {Socket} socket Socket.io socket instance
|
||||||
|
* @returns {Promise<Bean[]>}
|
||||||
|
*/
|
||||||
async function sendDockerHostList(socket) {
|
async function sendDockerHostList(socket) {
|
||||||
const timeLogger = new TimeLogger();
|
const timeLogger = new TimeLogger();
|
||||||
|
|
||||||
|
@ -4,6 +4,13 @@ const version = require("../package.json").version;
|
|||||||
const https = require("https");
|
const https = require("https");
|
||||||
|
|
||||||
class DockerHost {
|
class DockerHost {
|
||||||
|
/**
|
||||||
|
* Save a docker host
|
||||||
|
* @param {Object} dockerHost Docker host to save
|
||||||
|
* @param {?number} dockerHostID ID of the docker host to update
|
||||||
|
* @param {number} userID ID of the user who adds the docker host
|
||||||
|
* @returns {Promise<Bean>}
|
||||||
|
*/
|
||||||
static async save(dockerHost, dockerHostID, userID) {
|
static async save(dockerHost, dockerHostID, userID) {
|
||||||
let bean;
|
let bean;
|
||||||
|
|
||||||
@ -28,6 +35,12 @@ class DockerHost {
|
|||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a Docker host
|
||||||
|
* @param {number} dockerHostID ID of the Docker host to delete
|
||||||
|
* @param {number} userID ID of the user who created the Docker host
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
static async delete(dockerHostID, userID) {
|
static async delete(dockerHostID, userID) {
|
||||||
let bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
|
let bean = await R.findOne("docker_host", " id = ? AND user_id = ? ", [ dockerHostID, userID ]);
|
||||||
|
|
||||||
@ -38,6 +51,11 @@ class DockerHost {
|
|||||||
await R.trash(bean);
|
await R.trash(bean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the amount of containers on the Docker host
|
||||||
|
* @param {Object} dockerHost Docker host to check for
|
||||||
|
* @returns {number} Total amount of containers on the host
|
||||||
|
*/
|
||||||
static async getAmountContainer(dockerHost) {
|
static async getAmountContainer(dockerHost) {
|
||||||
const options = {
|
const options = {
|
||||||
url: "/containers/json?all=true",
|
url: "/containers/json?all=true",
|
||||||
@ -64,4 +82,4 @@ class DockerHost {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
DockerHost,
|
DockerHost,
|
||||||
}
|
};
|
||||||
|
@ -12,7 +12,7 @@ class DockerHost extends BeanModel {
|
|||||||
daemon: this._dockerDaemon,
|
daemon: this._dockerDaemon,
|
||||||
type: this._dockerType,
|
type: this._dockerType,
|
||||||
name: this._name,
|
name: this._name,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +470,7 @@ class Monitor extends BeanModel {
|
|||||||
} else if (this.type === "docker") {
|
} else if (this.type === "docker") {
|
||||||
log.debug(`[${this.name}] Prepare Options for Axios`);
|
log.debug(`[${this.name}] Prepare Options for Axios`);
|
||||||
|
|
||||||
const docker_host = await R.load("docker_host", this.docker_host);
|
const dockerHost = await R.load("docker_host", this.docker_host);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
url: `/containers/${this.docker_container}/json`,
|
url: `/containers/${this.docker_container}/json`,
|
||||||
@ -484,10 +484,10 @@ class Monitor extends BeanModel {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (docker_host._dockerType === "socket") {
|
if (dockerHost._dockerType === "socket") {
|
||||||
options.socketPath = docker_host._dockerDaemon;
|
options.socketPath = dockerHost._dockerDaemon;
|
||||||
} else if (docker_host._dockerType === "tcp") {
|
} else if (dockerHost._dockerType === "tcp") {
|
||||||
options.baseURL = docker_host._dockerDaemon;
|
options.baseURL = dockerHost._dockerDaemon;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(`[${this.name}] Axios Request`);
|
log.debug(`[${this.name}] Axios Request`);
|
||||||
|
@ -2,6 +2,10 @@ const { sendDockerHostList } = require("../client");
|
|||||||
const { checkLogin } = require("../util-server");
|
const { checkLogin } = require("../util-server");
|
||||||
const { DockerHost } = require("../docker");
|
const { DockerHost } = require("../docker");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handlers for docker hosts
|
||||||
|
* @param {Socket} socket Socket.io instance
|
||||||
|
*/
|
||||||
module.exports.dockerSocketHandler = (socket) => {
|
module.exports.dockerSocketHandler = (socket) => {
|
||||||
socket.on("addDockerHost", async (dockerHost, dockerHostID, callback) => {
|
socket.on("addDockerHost", async (dockerHost, dockerHostID, callback) => {
|
||||||
try {
|
try {
|
||||||
@ -20,7 +24,7 @@ module.exports.dockerSocketHandler = (socket) => {
|
|||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: e.message,
|
msg: e.message,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -40,7 +44,7 @@ module.exports.dockerSocketHandler = (socket) => {
|
|||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: e.message,
|
msg: e.message,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ module.exports.dockerSocketHandler = (socket) => {
|
|||||||
callback({
|
callback({
|
||||||
ok: false,
|
ok: false,
|
||||||
msg: e.message,
|
msg: e.message,
|
||||||
})
|
});
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
@ -144,7 +144,7 @@ export default {
|
|||||||
|
|
||||||
socket.on("dockerHostList", (data) => {
|
socket.on("dockerHostList", (data) => {
|
||||||
this.dockerHostList = data;
|
this.dockerHostList = data;
|
||||||
})
|
});
|
||||||
|
|
||||||
socket.on("heartbeat", (data) => {
|
socket.on("heartbeat", (data) => {
|
||||||
if (! (data.monitorID in this.heartbeatList)) {
|
if (! (data.monitorID in this.heartbeatList)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user