@Override
    public void doAlarm(List<AlarmMessage> alarmMessages) throws Exception {
        Map<String, PagerDutySettings> settingsMap = alarmRulesWatcher.getPagerDutySettings();
        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.getIntegrationKeys()) || CollectionUtils.isEmpty(
                messages)) {
                continue;
            }
            for (final var integrationKey : setting.getIntegrationKeys()) {
                for (final var alarmMessage : messages) {
                    try {
                        post(
                            URI.create(PAGER_DUTY_EVENTS_API_V2_URL),
                            getMessageBody(alarmMessage, integrationKey, setting.getTextTemplate()), Map.of()
                        );
                    } catch (Exception e) {
                        log.error("Failed to send alarm message to PagerDuty: {}", integrationKey, e);
                    }
                }
            }
        }
    }
@Test
    @Disabled
    public void testWithRealAccount() throws Exception {
        // replace this with your actual integration key(s) and run this test manually
        List<String> integrationKeys = Arrays.asList(
                "dummy-integration-key"
        );

        Rules rules = new Rules();
        PagerDutySettings setting1 = new PagerDutySettings("setting1", AlarmHooksType.pagerduty, true);
        setting1.setIntegrationKeys(integrationKeys);
        setting1.setTextTemplate("Apache SkyWalking Alarm: \\n %s.");
        PagerDutySettings setting2 = new PagerDutySettings("setting2", AlarmHooksType.pagerduty, false);
        setting2.setIntegrationKeys(integrationKeys);
        setting2.setTextTemplate("Apache SkyWalking Alarm: \\n %s.");
        rules.getPagerDutySettingsMap().put(setting1.getFormattedName(), setting1);
        rules.getPagerDutySettingsMap().put(setting2.getFormattedName(), setting2);
        PagerDutyHookCallback pagerDutyHookCallback = new PagerDutyHookCallback(
            new AlarmRulesWatcher(rules, null)
        );
        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);

        pagerDutyHookCallback.doAlarm(alarmMessages);

        // please check your pagerduty account to see if the alarm is sent
    }