Prepend hostname to notification message

If multiple instances of uptime-kuma are deployed to cross-check each other and/or in different environments (say ipv4+ipv6 and ipv6 only), and only one or some of the instances fire notificationsm, it is tricky to figure out which specific environment is experiencing the outage. Explicitly setting unique hostnames and prepending it to the message will help in these scenarios.

Signed-off-by: Sid Sun <sids@Sids-MacBook.local>
This commit is contained in:
Sid Sun 2025-05-09 08:43:10 +10:00
parent 86b3ef9c86
commit 0890660e01
3 changed files with 5 additions and 3 deletions

View file

@ -40,7 +40,7 @@ It is a temporary live demo, all data will be deleted after 10 minutes. Sponsore
### 🐳 Docker
```bash
docker run -d --restart=always -p 3001:3001 -v uptime-kuma:/app/data --name uptime-kuma louislam/uptime-kuma:1
docker run -d --restart=always -p 3001:3001 -v uptime-kuma:/app/data --hostname uptime-kuma --name uptime-kuma louislam/uptime-kuma:1
```
Uptime Kuma is now running on <http://0.0.0.0:3001>.
@ -52,7 +52,7 @@ Uptime Kuma is now running on <http://0.0.0.0:3001>.
> If you want to limit exposure to localhost (without exposing port for other users or to use a [reverse proxy](https://github.com/louislam/uptime-kuma/wiki/Reverse-Proxy)), you can expose the port like this:
>
> ```bash
> docker run -d --restart=always -p 127.0.0.1:3001:3001 -v uptime-kuma:/app/data --name uptime-kuma louislam/uptime-kuma:1
> docker run -d --restart=always -p 127.0.0.1:3001:3001 -v uptime-kuma:/app/data --hostname uptime-kuma --name uptime-kuma louislam/uptime-kuma:1
> ```
### 💪🏻 Non-Docker

View file

@ -1,5 +1,6 @@
services:
uptime-kuma:
hostname: uptime-kuma
image: louislam/uptime-kuma:1
volumes:
- ./data:/app/data

View file

@ -24,6 +24,7 @@ const { CookieJar } = require("tough-cookie");
const { HttpsCookieAgent } = require("http-cookie-agent/http");
const https = require("https");
const http = require("http");
const os = require('os');
const rootCertificates = rootCertificatesFingerprints();
@ -1288,7 +1289,7 @@ class Monitor extends BeanModel {
text = "🔴 Down";
}
let msg = `[${monitor.name}] [${text}] ${bean.msg}`;
let msg = `[${os.hostname()}] [${monitor.name}] [${text}] ${bean.msg}`;
for (let notification of notificationList) {
try {