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

Code before:
    }

    /**
     * Get list of notification providers for a given monitor
     * @param {Monitor} monitor Monitor to get notification providers for
     * @returns {Promise<LooseObject<any>[]>}
     */
    static async getNotificationList(monitor) {
        let notificationList = await R.getAll("SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id ", [
            monitor.id,
        ]);
        return notificationList;
    }

    /**
     * Send notification about a certificate
     * @param {Object} tlsInfoObject Information about certificate
     */
    async sendCertNotification(tlsInfoObject) {
        if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
            const notificationList = await Monitor.getNotificationList(this);

            log.debug("monitor", "call sendCertNotificationByTargetDays");
            await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 21, notificationList);
            await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 14, notificationList);
            await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, 7, notificationList);
        }
    }

    /**
     * Send a certificate notification when certificate expires in less
     * than target days
     * @param {number} daysRemaining Number of days remaining on certifcate
     * @param {number} targetDays Number of days to alert after
     * @param {LooseObject<any>[]} notificationList List of notification providers
     * @returns {Promise<void>}
     */
    async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {

        if (daysRemaining > targetDays) {
            log.debug("monitor", `No need to send cert notification. ${daysRemaining} > ${targetDays}`);
            return;
        }

        if (notificationList.length > 0) {

            let row = await R.getRow("SELECT * FROM notification_sent_history WHERE type = ? AND monitor_id = ? AND days = ?", [
                "certificate",
                this.id,
                targetDays,
            ]);

Review comment (suggestion):
Just tried clean install of 1.17.0-beta, it seems that the default values is not working.

![image](https://user-images.githubusercontent.com/1336778/173487635-a43583f8-60bd-43f0-b88f-9c3d2487ef78.png)


Code after:
    }

    /**
     * Get list of notification providers for a given monitor
     * @param {Monitor} monitor Monitor to get notification providers for
     * @returns {Promise<LooseObject<any>[]>}
     */
    static async getNotificationList(monitor) {
        let notificationList = await R.getAll("SELECT notification.* FROM notification, monitor_notification WHERE monitor_id = ? AND monitor_notification.notification_id = notification.id ", [
            monitor.id,
        ]);
        return notificationList;
    }

    /**
     * Send notification about a certificate
     * @param {Object} tlsInfoObject Information about certificate
     */
    async sendCertNotification(tlsInfoObject) {
        if (tlsInfoObject && tlsInfoObject.certInfo && tlsInfoObject.certInfo.daysRemaining) {
            const notificationList = await Monitor.getNotificationList(this);

            let notifyDays = await setting("tlsExpiryNotifyDays");
            if (notifyDays == null || !Array.isArray(notifyDays)) {
                // Reset Default
                setSetting("tlsExpiryNotifyDays", [ 7, 14, 21 ], "general");
                notifyDays = [ 7, 14, 21 ];
            }

            if (notifyDays != null && Array.isArray(notifyDays)) {
                for (const day of notifyDays) {
                    log.debug("monitor", "call sendCertNotificationByTargetDays", day);
                    await this.sendCertNotificationByTargetDays(tlsInfoObject.certInfo.daysRemaining, day, notificationList);
                }
            }
        }
    }

    /**
     * Send a certificate notification when certificate expires in less
     * than target days
     * @param {number} daysRemaining Number of days remaining on certifcate
     * @param {number} targetDays Number of days to alert after
     * @param {LooseObject<any>[]} notificationList List of notification providers
     * @returns {Promise<void>}
     */
    async sendCertNotificationByTargetDays(daysRemaining, targetDays, notificationList) {

        if (daysRemaining > targetDays) {
            log.debug("monitor", `No need to send cert notification. ${daysRemaining} > ${targetDays}`);
            return;