Repository: louislam/uptime-kuma
File: server/notification-providers/flashduty.js (JavaScript)

Code before:
            }
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }

    /**
     * Check if result is successful, result code should be in range 2xx
     * @param {Object} result Axios response object
     * @throws {Error} The status code is not in range 2xx
     */
    checkResult(result) {
        if (result.status == null) {
            throw new Error("FlashDuty notification failed with invalid response!");
        }
        if (result.status < 200 || result.status >= 300) {
            throw new Error("FlashDuty notification failed with status code " + result.status);
        }
    }

    /**
     * Send the message
     * @param {BeanModel} notification Message title
     * @param {string} title Message title
     * @param {string} body Message
     * @param {Object} monitorInfo Monitor details (For Up/Down only)
     * @returns {string}
     */
    async postNotification(notification, title, body, monitorInfo) {
        let monitorUrl;
        if (monitorInfo.type === "port") {
            monitorUrl = monitorInfo.hostname;
            if (monitorInfo.port) {
                monitorUrl += ":" + monitorInfo.port;
            }
        } else if (monitorInfo.hostname != null) {
            monitorUrl = monitorInfo.hostname;
        } else {
            monitorUrl = monitorInfo.url;
        }
        const options = {
            method: "POST",
            url: notification.flashdutyIntegrationUrl,
            headers: { "Content-Type": "application/json" },
            data: {
                description: `[${title}] [${monitorInfo.name}] ${body}`,
                title,
                event_status: notification.flashdutyPriority || "Warning",
                alert_key: String(monitorInfo.id) || Math.random().toString(36).substring(7),
                labels: monitorInfo.tags.reduce((acc, item) => ({ ...acc,
                    [item.name]: item.value

Review comment (suggestion):
```suggestion
     * @param {Object} monitorInfo Monitor details
```

Code after:
            this.throwGeneralAxiosError(error);
        }
    }
    /**
     * Generate a monitor url from the monitors infomation
     * @param {Object} monitorInfo Monitor details
     * @returns {string|undefined}
     */

    genMonitorUrl(monitorInfo) {
        if (monitorInfo.type === "port" && monitorInfo.port) {
            return monitorInfo.hostname + ":" + monitorInfo.port;
        }
        if (monitorInfo.hostname != null) {
            return monitorInfo.hostname;
        }
        return monitorInfo.url;
    }

    /**
     * Send the message
     * @param {BeanModel} notification Message title
     * @param {string} title Message
     * @param {string} body Message
     * @param {Object} monitorInfo Monitor details
     * @param {string} eventStatus Monitor status (Info, Warning, Critical, Ok)
     * @returns {string}
     */
    async postNotification(notification, title, body, monitorInfo, eventStatus) {
        const options = {
            method: "POST",
            url: "https://api.flashcat.cloud/event/push/alert/standard?integration_key=" + notification.flashdutyIntegrationKey,
            headers: { "Content-Type": "application/json" },
            data: {
                description: `[${title}] [${monitorInfo.name}] ${body}`,
                title,
                event_status: eventStatus || "Info",
                alert_key: String(monitorInfo.id) || Math.random().toString(36).substring(7),
                labels: monitorInfo?.tags?.reduce((acc, item) => ({ ...acc,
                    [item.name]: item.value
                }), { resource: this.genMonitorUrl(monitorInfo) }),
            }
        };

        const baseURL = await setting("primaryBaseURL");
        if (baseURL && monitorInfo) {
            options.client = "Uptime Kuma";
            options.client_url = baseURL + getMonitorRelativeURL(monitorInfo.id);
        }

        let result = await axios.request(options);