@Override
    public void doAlarm(List<AlarmMessage> alarmMessages) throws Exception {
        Map<String, WebhookSettings> settingsMap = alarmRulesWatcher.getWebHooks();
        if (settingsMap == null || settingsMap.isEmpty()) {
            return;
        }

        Map<String, List<AlarmMessage>> groupedMessages = groupMessagesByHook(alarmMessages);
        for (Map.Entry<String, List<AlarmMessage>> entry : groupedMessages.entrySet()) {
            var hookName = entry.getKey();
            var messages = entry.getValue();
            var setting = settingsMap.get(hookName);
            if (setting == null || CollectionUtils.isEmpty(setting.getUrls()) || CollectionUtils.isEmpty(
                messages)) {
                continue;
            }
            for (final var url : setting.getUrls()) {
                try {
                    post(URI.create(url), gson.toJson(messages), Map.of());
                } catch (Exception e) {
                    log.error("Failed to send alarm message to Webhook: {}", url, e);
                }
            }
        }
    }
@Test
    public void testWebhook() throws Exception {
        List<String> remoteEndpoints = new ArrayList<>();
        remoteEndpoints.add("http://127.0.0.1:" + SERVER.httpPort() + "/webhook/receiveAlarm");
        Rules rules = new Rules();
        WebhookSettings setting1 = new WebhookSettings("setting1", AlarmHooksType.webhook, true);
        setting1.setUrls(remoteEndpoints);
        WebhookSettings setting2 = new WebhookSettings("setting2", AlarmHooksType.webhook, false);
        setting2.setUrls(remoteEndpoints);
        rules.getWebhookSettingsMap().put(setting1.getFormattedName(), setting1);
        rules.getWebhookSettingsMap().put(setting2.getFormattedName(), setting2);
        AlarmRulesWatcher alarmRulesWatcher = new AlarmRulesWatcher(rules, null);
        WebhookCallback webhookCallback = new WebhookCallback(alarmRulesWatcher);
        List<AlarmMessage> alarmMessages = new ArrayList<>(2);
        AlarmMessage alarmMessage = new AlarmMessage();
        alarmMessage.setScopeId(DefaultScopeDefine.SERVICE);
        alarmMessage.setRuleName("service_resp_time_rule");
        alarmMessage.setAlarmMessage("alarmMessage with [DefaultScopeDefine.All]");
        alarmMessage.getHooks().add(setting1.getFormattedName());
        alarmMessages.add(alarmMessage);
        AlarmMessage anotherAlarmMessage = new AlarmMessage();
        anotherAlarmMessage.setRuleName("service_resp_time_rule_2");
        anotherAlarmMessage.setScopeId(DefaultScopeDefine.ENDPOINT);
        anotherAlarmMessage.setAlarmMessage("anotherAlarmMessage with [DefaultScopeDefine.Endpoint]");
        anotherAlarmMessage.getHooks().add(setting2.getFormattedName());
        alarmMessages.add(anotherAlarmMessage);
        webhookCallback.doAlarm(alarmMessages);

        Assertions.assertTrue(IS_SUCCESS.get());
        Assertions.assertEquals(2, COUNTER.get());
    }