diff --git a/db/patch-add-docker-columns.sql b/db/patch-add-docker-columns.sql new file mode 100644 index 000000000..fdde41705 --- /dev/null +++ b/db/patch-add-docker-columns.sql @@ -0,0 +1,10 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE monitor + ADD docker_daemon VARCHAR(255); + +ALTER TABLE monitor + ADD docker_container VARCHAR(255); + +COMMIT; diff --git a/server/database.js b/server/database.js index afcace705..536acd198 100644 --- a/server/database.js +++ b/server/database.js @@ -53,6 +53,7 @@ class Database { "patch-2fa-invalidate-used-token.sql": true, "patch-notification_sent_history.sql": true, "patch-monitor-basic-auth.sql": true, + "patch-add-docker-columns.sql": true } /** diff --git a/server/model/monitor.js b/server/model/monitor.js index c4441d63e..5683352f5 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -77,6 +77,8 @@ class Monitor extends BeanModel { dns_resolve_server: this.dns_resolve_server, dns_last_result: this.dns_last_result, pushToken: this.pushToken, + docker_container: this.docker_container, + docker_daemon: this.docker_daemon, notificationIDList, tags: tags, }; @@ -347,6 +349,27 @@ class Monitor extends BeanModel { throw new Error("Server not found on Steam"); } + } else if (this.type === "docker") { + debug(`[${this.name}] Prepare Options for axios`); + + const options = { + url: `/containers/${this.docker_container}/json`, + headers: { + "Accept": "*/*", + "User-Agent": "Uptime-Kuma/" + version, + }, + socketPath: this.docker_daemon, + httpsAgent: new https.Agent({ + maxCachedSessions: 0, // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940) + rejectUnauthorized: ! this.getIgnoreTls(), + }), + }; + + debug(`[${this.name}] Axios Request`); + let res = await axios.request(options); + if (res.data.State.Running) { + bean.status = UP; + } } else { bean.msg = "Unknown Monitor Type"; bean.status = PENDING; diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 4b6a920c8..8b02a75f9 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -32,6 +32,9 @@ + @@ -115,6 +118,20 @@ + + +
+ + +
+ + + +
+ + +
+
@@ -439,6 +456,8 @@ export default { accepted_statuscodes: ["200-299"], dns_resolve_type: "A", dns_resolve_server: "1.1.1.1", + docker_container: "", + docker_daemon: "/var/run/docker.sock" }; for (let i = 0; i < this.$root.notificationList.length; i++) {