Skip to content

Commit

Permalink
adds more dockerode values (no 'os'), customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveratgithub committed Dec 13, 2024
1 parent f47bf69 commit e21772c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 11 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Docker = require('dockerode');
const TelegramClient = require('./telegram');
const os = require('os');
const JSONStream = require('JSONStream');
const templates = require('./templates');

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -71,4 +79,4 @@ if (process.argv.includes("healthcheck")) {
healthcheck();
} else {
main().catch(handleError);
}
}
4 changes: 3 additions & 1 deletion templates.js
Original file line number Diff line number Diff line change
@@ -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 =>
`&#9654;&#65039; <b>${e.Actor.Attributes.name}</b> started\n${e.Actor.Attributes.image}`,

Expand Down Expand Up @@ -38,4 +41,3 @@ module.exports = {
'container_health_status: unhealthy': e =>
`&#9888; <b>${e.Actor.Attributes.name}</b> unhealthy!\n${e.Actor.Attributes.image}`,
};

0 comments on commit e21772c

Please sign in to comment.