Merge pull request #2169 from louislam/fix-docker-monitor

Fix Docker container monitor not working in 1.18.1
pull/2173/head
Louis Lam 2 years ago committed by GitHub
commit c538983b87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -75,7 +75,7 @@ class DockerHost {
if (dockerHost.dockerType === "socket") {
options.socketPath = dockerHost.dockerDaemon;
} else if (dockerHost.dockerType === "tcp") {
options.baseURL = dockerHost.dockerDaemon;
options.baseURL = DockerHost.patchDockerURL(dockerHost.dockerDaemon);
}
let res = await axios.request(options);
@ -99,6 +99,18 @@ class DockerHost {
}
}
/**
* Since axios 0.27.X, it does not accept `tcp://` protocol.
* Change it to `http://` on the fly in order to fix it. (https://github.com/louislam/uptime-kuma/issues/2165)
*/
static patchDockerURL(url) {
if (typeof url === "string") {
// Replace the first occurrence only with g
return url.replace(/tcp:\/\//g, "http://");
}
return url;
}
}
module.exports = {

@ -17,6 +17,7 @@ const version = require("../../package.json").version;
const apicache = require("../modules/apicache");
const { UptimeKumaServer } = require("../uptime-kuma-server");
const { CacheableDnsHttpAgent } = require("../cacheable-dns-http-agent");
const { DockerHost } = require("../docker");
/**
* status:
@ -498,7 +499,7 @@ class Monitor extends BeanModel {
if (dockerHost._dockerType === "socket") {
options.socketPath = dockerHost._dockerDaemon;
} else if (dockerHost._dockerType === "tcp") {
options.baseURL = dockerHost._dockerDaemon;
options.baseURL = DockerHost.patchDockerURL(dockerHost._dockerDaemon);
}
log.debug(`[${this.name}] Axios Request`);

@ -56,7 +56,7 @@ module.exports.dockerSocketHandler = (socket) => {
let amount = await DockerHost.testDockerHost(dockerHost);
let msg;
if (amount > 1) {
if (amount >= 1) {
msg = "Connected Successfully. Amount of containers: " + amount;
} else {
msg = "Connected Successfully, but there are no containers?";

@ -30,7 +30,8 @@
{{ $t("Examples") }}:
<ul>
<li>/var/run/docker.sock</li>
<li>tcp://localhost:2375</li>
<li>http://localhost:2375</li>
<li>https://localhost:2376 (TLS)</li>
</ul>
</div>
</div>

Loading…
Cancel
Save