Repository: louislam/uptime-kuma
File: server/model/monitor.js (JavaScript)

Code before:
            if (isImportant) {
                bean.important = true;

                log.debug("monitor", `[${this.name}] sendNotification`);
                await Monitor.sendNotification(isFirstBeat, this, bean);

                // Set last notified time to now
                bean.lastNotifiedTime = R.isoDateTime(dayjs.utc());

                // Clear Status Page Cache
                log.debug("monitor", `[${this.name}] apicache clear`);
                apicache.clear();

            } else {
                bean.important = false;

                if (bean.status === DOWN && this.resendInterval > 0) {
                    // divide by 1000 to convert from milliseconds to seconds and divide by 60 to convert from seconds to minutes
                    let timeSinceLastNotified = (dayjs.utc().valueOf() - (bean.lastNotifiedTime == null ? 0 : dayjs.utc(bean.lastNotifiedTime).valueOf())) / 1000 / 60;
                    if (timeSinceLastNotified >= this.resendInterval) {
                        // Send notification again, because we are still DOWN
                        log.debug("monitor", `[${this.name}] sendNotification again: lastNotifiedTime: ${bean.lastNotifiedTime} | current time: ${R.isoDateTime(dayjs.utc())}`);
                        await Monitor.sendNotification(isFirstBeat, this, bean);

                        // Set last notified time to now
                        bean.lastNotifiedTime = R.isoDateTime(dayjs.utc());
                    }
                }
            }

            if (bean.status === UP) {
                log.info("monitor", `Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${beatInterval} seconds | Type: ${this.type}`);
            } else if (bean.status === PENDING) {
                if (this.retryInterval > 0) {
                    beatInterval = this.retryInterval;
                }
                log.warn("monitor", `Monitor #${this.id} '${this.name}': Pending: ${bean.msg} | Max retries: ${this.maxretries} | Retry: ${retries} | Retry Interval: ${beatInterval} seconds | Type: ${this.type}`);
            } else {
                log.warn("monitor", `Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Interval: ${beatInterval} seconds | Type: ${this.type}`);
            }

            log.debug("monitor", `[${this.name}] Send to socket`);
            io.to(this.user_id).emit("heartbeat", bean.toJSON());
            Monitor.sendStats(io, this.id, this.user_id);

            log.debug("monitor", `[${this.name}] Store`);
            await R.store(bean);

            log.debug("monitor", `[${this.name}] prometheus.update`);
            prometheus.update(bean, tlsInfo);


Review comment (bug):
Can you make a variable for `lastNotifiedTime` and debug log to have a consistent timestamp?
```suggestion
                        const currentTime = R.isoDateTime(dayjs.utc());
                        log.debug("monitor", `[${this.name}] sendNotification again: lastNotifiedTime: ${bean.lastNotifiedTime} | current time: ${currentTime}`);
                        await Monitor.sendNotification(isFirstBeat, this, bean);

                        // Set last notified time to now
                        bean.lastNotifiedTime = currentTime;
```

Code after:

                        try {
                            bean.ping = await ping(this.hostname);
                        } catch (_) { }
                    } else {
                        throw new Error("Server not found on Steam");
                    }
                } else if (this.type === "docker") {
                    log.debug(`[${this.name}] Prepare Options for Axios`);

                    const dockerHost = await R.load("docker_host", this.docker_host);

                    const options = {
                        url: `/containers/${this.docker_container}/json`,
                        headers: {
                            "Accept": "*/*",
                            "User-Agent": "Uptime-Kuma/" + version,
                        },
                        httpsAgent: new https.Agent({
                            maxCachedSessions: 0,      // Use Custom agent to disable session reuse (https://github.com/nodejs/node/issues/3940)
                            rejectUnauthorized: ! this.getIgnoreTls(),
                        }),
                    };

                    if (dockerHost._dockerType === "socket") {
                        options.socketPath = dockerHost._dockerDaemon;
                    } else if (dockerHost._dockerType === "tcp") {
                        options.baseURL = dockerHost._dockerDaemon;
                    }

                    log.debug(`[${this.name}] Axios Request`);
                    let res = await axios.request(options);
                    if (res.data.State.Running) {
                        bean.status = UP;
                        bean.msg = "";
                    }
                } else if (this.type === "mqtt") {
                    bean.msg = await mqttAsync(this.hostname, this.mqttTopic, this.mqttSuccessMessage, {
                        port: this.port,
                        username: this.mqttUsername,
                        password: this.mqttPassword,
                        interval: this.interval,
                    });
                    bean.status = UP;
                } else if (this.type === "sqlserver") {
                    let startTime = dayjs().valueOf();

                    await mssqlQuery(this.databaseConnectionString, this.databaseQuery);

                    bean.msg = "";
                    bean.status = UP;