📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

适用版本: 6.8-6.8

1. 错误异常的基本描述 #

invalid [hipchat] action for [watchId/actionId] action 是 Elasticsearch Watcher 中 HipChat action 的一个配置校验异常。该错误并非消息体 JSON 语法问题,而是 action 模板中使用了当前绑定的 HipChat 账户 profile 所不支持的功能字段,导致在校验阶段被直接拒绝。

常见现象 #

  • 创建或更新 watch 时,Elasticsearch 返回 400 Bad Request,响应体中包含 invalid [hipchat] action 错误信息。
  • Kibana 的 Watcher 管理界面中,对应 watch 的 action 保存失败,并提示 action 配置无效。
  • 集群日志中会出现 ElasticsearchParseException,明确指出是哪个账户不支持自定义 rooms 或用户私聊。
  • 该错误只在校验阶段抛出,不会造成集群崩溃或数据丢失,但会导致对应的告警通知无法生效。

典型报错信息 #

ElasticsearchParseException: invalid [hipchat] action for [my_watch/my_hipchat_action] action. [integration] hipchat account doesn't support custom rooms

ElasticsearchParseException: invalid [hipchat] action for [my_watch/my_hipchat_action] action. [notification] hipchat account doesn't support user private messages

2. 为什么会发生这个错误 #

Elasticsearch Watcher 的 HipChat action 支持多种账户 profile,不同 profile 的能力范围不同。在校验 action 模板时,源码会严格检查模板中使用的字段是否与账户 profile 的能力匹配:

@Override
public void validateParsedTemplate(String watchId, String actionId, HipChatMessage.Template template) throws SettingsException {
    if (template.rooms != null) {
        throw new ElasticsearchParseException("invalid [" + HipChatAction.TYPE + "] action for [" + watchId + "/" + actionId + "] " +
            "action. [" + name + "] hipchat account doesn't support custom rooms");
    }
    if (template.users != null) {
        throw new ElasticsearchParseException("invalid [" + HipChatAction.TYPE + "] action for [" + watchId + "/" + actionId + "] " +
            "action. [" + name + "] hipchat account doesn't support user private messages");
    }
}

常见原因包括:

  • 使用了 integration 类型的 HipChat 账户,却在 action 模板中指定了 rooms 字段(integration 账户不支持自定义 room)。
  • 使用了 notification 类型的 HipChat 账户,却在 action 模板中指定了 users 字段(notification 账户不支持向用户发送私聊消息)。
  • 从其他 watch 或环境复制粘贴了 action 配置,未注意目标账户 profile 的差异。
  • 在账户 profile 变更后,未同步更新已有 watch 的 action 模板。

3. 如何排查这个错误 #

建议按以下步骤定位问题:

  1. 从报错信息中提取 watchIdactionId,确认是哪个 watch 的哪个 action 出了问题。
  2. 查看该 action 的配置,确认其绑定的是哪个 HipChat 账户(account 字段)。
  3. 检查 action 模板中是否包含 roomsusers 字段。
  4. 查看 Elasticsearch 配置中该 HipChat 账户的 profile 设置,确认其类型和能力范围。
  5. 对比字段与账户能力:若账户 profile 不支持自定义 rooms,则必须去掉 rooms;若不支持私聊,则必须去掉 users

排查时需要注意的问题 #

  • HipChat 的 integration profile 只能向预配置的固定 room 发消息,不能在 action 中动态指定 room。
  • HipChat 的 notification profile 只能向 room 发消息,不支持 users 字段。
  • HipChat 的 user profile 才支持向指定用户发送私聊消息。
  • 如果不确定账户 profile 类型,可以通过 _cluster/settingselasticsearch.yml 中的 xpack.notification.hipchat.account.*.profile 配置来确认。

4. 如何解决这个错误 #

方案一:移除不支持的字段 #

如果账户 profile 不支持自定义 rooms,将 action 模板修改为不指定 rooms,使用账户默认配置的 room:

{
  "trigger": { "schedule": { "interval": "5m" } },
  "input": { "search": { "request": { "indices": ["logs"], "body": {} } } },
  "condition": { "compare": { "ctx.payload.hits.total": { "gt": 0 } } },
  "actions": {
    "send_hipchat": {
      "hipchat": {
        "account": "integration",
        "message": {
          "body": "发现异常日志,请及时处理。"
        }
      }
    }
  }
}

方案二:改用支持所需能力的账户 profile #

如果需要向多个 room 发消息或向用户私聊,请将 HipChat 账户配置为对应的 profile 类型,然后在 action 中引用该账户:

xpack.notification.hipchat:
  account:
    my_user_account:
      profile: user
      auth_token: "your_auth_token"
      host: "https://hipchat.example.com"

方案三:为不同场景创建不同的 HipChat 账户 #

为不同用途分别配置账户,避免能力交叉导致配置错误:

xpack.notification.hipchat:
  account:
    room_alerts:
      profile: integration
      auth_token: "token_for_rooms"
    user_alerts:
      profile: user
      auth_token: "token_for_users"

5. 预防建议 #

  • 在 watch 模板或自动化脚本中,将账户 profile 的能力约束写入注释或校验逻辑,避免生成不兼容的配置。
  • 不同用途的 HipChat 通知使用不同的 action 模板,不要在不同账户之间复用包含 roomsusers 的通用模板。
  • 在 CI/CD 流程中,对 watch 配置文件做静态检查,提前发现 profile 与字段不匹配的问题。
  • 建立 HipChat 账户 profile 的文档说明,记录每个账户支持的功能范围,方便团队成员查阅。

借助 INFINI 产品提升排障效率 #

  • INFINI Console 适合查看集群健康度、Watcher 执行状态、告警历史和错误趋势,帮助快速判断是配置问题还是运行时问题。
  • INFINI Gateway 可部署在 Elasticsearch 前面做请求观测和流量治理,捕获 Watcher 触发时的异常请求,辅助定位配置错误。

6. 小结 #

invalid [hipchat] action 错误的根本原因是 action 模板中使用了当前 HipChat 账户 profile 不支持的字段。解决方法是根据账户 profile 的能力范围,调整 action 模板中的 roomsusers 字段,或者切换到支持所需功能的账户 profile。通过规范账户配置、分离不同场景的模板以及引入静态检查,可以有效预防此类问题再次发生。

相关错误 #

附:日志上下文 #

下面保留当前页面中的源码或日志片段,便于继续结合异常调用栈定位问题:

@Override
public void validateParsedTemplate(String watchId, String actionId, HipChatMessage.Template template) throws SettingsException {
    if (template.rooms != null) {
        throw new ElasticsearchParseException("invalid [" + HipChatAction.TYPE + "] action for [" + watchId + "/" + actionId + "] " +
            "action. [" + name + "] hipchat account doesn't support custom rooms");
    }
    if (template.users != null) {
        throw new ElasticsearchParseException("invalid [" + HipChatAction.TYPE + "] action for [" + watchId + "/" + actionId + "] " +
            "action. [" + name + "] hipchat account doesn't support user private messages");
    }
}