From e21772c0c07422cc44ba037afbdece859ac1b223 Mon Sep 17 00:00:00 2001 From: oliveratgithub Date: Fri, 13 Dec 2024 08:45:22 +0100 Subject: [PATCH] adds more dockerode values (no 'os'), customizable --- app.js | 14 +++++++++++--- templates.js | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 5ad56d2..3d205dc 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,5 @@ const Docker = require('dockerode'); const TelegramClient = require('./telegram'); -const os = require('os'); const JSONStream = require('JSONStream'); const templates = require('./templates'); @@ -31,7 +30,16 @@ async function sendEventStream() { async function sendVersion() { const version = await docker.version(); - let text = `Connected to docker on ${os.hostname()} (v${version.Version})`; + const info = await docker.info(); + let text = templates.connection_message({ + hostname: info.Name, + os: info.OperatingSystem, + type: info.OSType, + architecture: info.Architecture, + cpu: info.NCPU, + memory: (info.MemTotal / (1024 * 1024)).toFixed(2) + 'MB', + version: version.Version + }); console.log(text, "\n"); await telegram.send(text); } @@ -71,4 +79,4 @@ if (process.argv.includes("healthcheck")) { healthcheck(); } else { main().catch(handleError); -} \ No newline at end of file +} diff --git a/templates.js b/templates.js index 202872d..5ef290a 100755 --- a/templates.js +++ b/templates.js @@ -1,4 +1,7 @@ module.exports = { + connection_message: ({hostname, version, os, type, architecture, cpu, memory}) => + `Connected to docker v${version} on ${hostname}\nOS: ${type}/${architecture} (${os}), ${cpu} CPU, ${memory} RAM`, + container_start: e => `▶️ ${e.Actor.Attributes.name} started\n${e.Actor.Attributes.image}`, @@ -38,4 +41,3 @@ module.exports = { 'container_health_status: unhealthy': e => `⚠ ${e.Actor.Attributes.name} unhealthy!\n${e.Actor.Attributes.image}`, }; -