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

Code before:
                    if (this.dnsLastResult !== dnsMessage) {
                        R.exec("UPDATE `monitor` SET dns_last_result = ? WHERE id = ? ", [
                            dnsMessage,
                            this.id
                        ]);
                    }

                    bean.msg = dnsMessage;
                    bean.status = UP;
                } else if (this.type === "push") {      // Type: Push
                    const bufferTime = 1000 // 1s buffer to accommodate clock differences
                    // Fix #922, since previous heartbeat could be inserted by api, it should get from database
                    previousBeat = await Monitor.getPreviousHeartbeat(this.id);
                    const msSinceLastBeat = dayjs.utc().valueOf() - dayjs.utc(previousBeat.time).valueOf()
                    debug("msSinceLastBeat " + msSinceLastBeat);

                    if (msSinceLastBeat > beatInterval * 1000 + bufferTime) {
                        throw new Error("No heartbeat in the time window");
                    } else {
                        let timeout = beatInterval * 1000 - msSinceLastBeat
                        if (timeout < 0)
                            timeout = bufferTime
                        else
                            timeout += bufferTime
                        // No need to insert successful heartbeat for push type, so end here
                        retries = 0;
                        this.heartbeatInterval = setTimeout(beat, timeout);
                        return;
                    }

                } else if (this.type === "steam") {
                    const steamApiUrl = "https://api.steampowered.com/IGameServersService/GetServerList/v1/";
                    const steamAPIKey = await setting("steamAPIKey");
                    const filter = `addr\\${this.hostname}:${this.port}`;

                    if (!steamAPIKey) {
                        throw new Error("Steam API Key not found");
                    }

                    let res = await axios.get(steamApiUrl, {
                        timeout: this.interval * 1000 * 0.8,
                        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(),
                        }),
                        maxRedirects: this.maxredirects,
                        validateStatus: (status) => {

Review comment (suggestion):
```suggestion
                        if (timeout < 0) {
                            timeout = bufferTime
                        } else {
                            timeout += bufferTime
                        }
```

Code after:
                    if (this.type === "http") {
                        bean.status = UP;
                    } else {

                        let data = res.data;

                        // Convert to string for object/array
                        if (typeof data !== "string") {
                            data = JSON.stringify(data);
                        }

                        if (data.includes(this.keyword)) {
                            bean.msg += ", keyword is found";
                            bean.status = UP;
                        } else {
                            throw new Error(bean.msg + ", but keyword is not found");
                        }

                    }

                } else if (this.type === "port") {
                    bean.ping = await tcping(this.hostname, this.port);
                    bean.msg = "";
                    bean.status = UP;

                } else if (this.type === "ping") {
                    bean.ping = await ping(this.hostname);
                    bean.msg = "";
                    bean.status = UP;
                } else if (this.type === "dns") {
                    let startTime = dayjs().valueOf();
                    let dnsMessage = "";

                    let dnsRes = await dnsResolve(this.hostname, this.dns_resolve_server, this.port, this.dns_resolve_type);
                    bean.ping = dayjs().valueOf() - startTime;

                    if (this.dns_resolve_type === "A" || this.dns_resolve_type === "AAAA" || this.dns_resolve_type === "TXT") {
                        dnsMessage += "Records: ";
                        dnsMessage += dnsRes.join(" | ");
                    } else if (this.dns_resolve_type === "CNAME" || this.dns_resolve_type === "PTR") {
                        dnsMessage = dnsRes[0];
                    } else if (this.dns_resolve_type === "CAA") {
                        dnsMessage = dnsRes[0].issue;
                    } else if (this.dns_resolve_type === "MX") {
                        dnsRes.forEach(record => {
                            dnsMessage += `Hostname: ${record.exchange} - Priority: ${record.priority} | `;
                        });
                        dnsMessage = dnsMessage.slice(0, -2);
                    } else if (this.dns_resolve_type === "NS") {
                        dnsMessage += "Servers: ";
                        dnsMessage += dnsRes.join(" | ");