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

Code before:
                    ])

                    let text;
                    if (bean.status === 1) {
                        text = "✅ Up"
                    } else {
                        text = "🔴 Down"
                    }

                    let msg = `[${this.name}] [${text}] ${bean.msg}`;

                    for(let notification of notificationList) {
                        try {
                            await Notification.send(JSON.parse(notification.config), msg, await this.toJSON(), bean.toJSON())
                        } catch (e) {
                            console.error("Cannot send notification to " + notification.name)
                        }
                    }
                }

            } else {
                bean.important = false;
            }


            monitor_status.set({
                monitor_name: this.name
            }, bean.status)

            if (bean.status === 1) {
                console.info(`Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${this.interval} seconds | Type: ${this.type}`)
            } else {
                console.warn(`Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Type: ${this.type}`)
            }

            monitor_response_time.set({
                monitor_name: this.name
            }, bean.ping)

            io.to(this.user_id).emit("heartbeat", bean.toJSON());

            await R.store(bean)
            Monitor.sendStats(io, this.id, this.user_id)

            previousBeat = bean;
        }

        beat();
        this.heartbeatInterval = setInterval(beat, this.interval * 1000);
    }


Review comment (suggestion):
```suggestion
            monitor_status.set({
```

Code after:
                } else if (this.type === "ping") {
                    bean.ping = await ping(this.hostname);
                    bean.msg = ""
                    bean.status = 1;
                }

            } catch (error) {
                bean.msg = error.message;
            }

            // Mark as important if status changed
            if (! previousBeat || previousBeat.status !== bean.status) {
                bean.important = true;

                // Do not send if first beat is UP
                if (previousBeat || bean.status !== 1) {
                    let notificationList = await R.getAll(`SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id `, [
                        this.id
                    ])

                    let text;
                    if (bean.status === 1) {
                        text = "✅ Up"
                    } else {
                        text = "🔴 Down"
                    }

                    let msg = `[${this.name}] [${text}] ${bean.msg}`;

                    for(let notification of notificationList) {
                        try {
                            await Notification.send(JSON.parse(notification.config), msg, await this.toJSON(), bean.toJSON())
                        } catch (e) {
                            console.error("Cannot send notification to " + notification.name)
                        }
                    }
                }

            } else {
                bean.important = false;
            }


            monitor_status.set(monitorLabelValues, bean.status)

            if (bean.status === 1) {
                console.info(`Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${this.interval} seconds | Type: ${this.type}`)
            } else {
                console.warn(`Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Type: ${this.type}`)
            }