Skip to content

[fix] never send null template variables to Aliyun SMS - #4331

Open
orangeCatDeveloper wants to merge 1 commit into
apache:masterfrom
orangeCatDeveloper:fix/4319-alibaba-sms-null-param
Open

[fix] never send null template variables to Aliyun SMS#4331
orangeCatDeveloper wants to merge 1 commit into
apache:masterfrom
orangeCatDeveloper:fix/4319-alibaba-sms-null-param

Conversation

@orangeCatDeveloper

@orangeCatDeveloper orangeCatDeveloper commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Fixes #4319

Sending a test SMS through Alibaba Cloud always fails with Aliyun's "模板变量JSON格式错误 或 JSON变量属性与模板占位符不一致" error, regardless of configuration — and the docs make it worse by showing a template example in the wrong placeholder syntax.

Root cause: the hardcoded test alert built by sendTestMsg carries no instance label and no groupKey, while AlibabaSmsClientImpl assumes real-alert shape and falls through to templateParam.put("instance", null). Aliyun rejects any request whose template-variable JSON contains a null/blank value, so the test path was broken for every user.

Three layers:

  • AlibabaSmsClientImpl: param building extracted into buildTemplateParam, every variable falls back to non-blank text (instance → groupKey → "unknown"; content → summary → description → any annotation → "alert triggered"). Null can no longer reach the JSON, for test and real alerts alike; also removes an NPE when commonAnnotations is null.
  • sendTestMsg: the shared test alert now carries an instance label — all five SMS providers read it.
  • Docs (en/zh): the Aliyun template example used backticks; corrected to Aliyun's ${...} syntax with a note that the template must declare exactly these three variables.

Boundary: per-rule SMS templates (question 1 in the issue) is a feature request, not covered here — suggested as a separate issue in the discussion. No Aliyun account was available for a live send (custom templates require review), so evidence stops at the outbound JSON — which is what Aliyun validates.

Before / after (the exact TemplateParam sent to Aliyun for the test alert):

before: {"instance":null,"priority":"unknown","content":"Please check the CPU usage of the server"}
        -> rejected: template variable JSON error / placeholder mismatch (the issue error)

after:  {"instance":"127.0.0.1","priority":"unknown","content":"Please check the CPU usage of the server"}

Verified: 3 new unit tests (no-null for test-alert shape, no-null for empty alert, real values pass through untouched); full alerter suite 468/468; end-to-end smoke of the shared send-test-msg path via the email channel against a local SMTP server (message rendered and delivered).

@github-actions github-actions Bot added doc Improvements or additions to documentation backend labels Aug 17, 2026
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/4319-alibaba-sms-null-param branch from e4e72ef to b64a76d Compare August 17, 2026 17:27
The send-test-msg alert carries no instance label and no groupKey, so
the Alibaba client serialized {"instance":null,...} and Aliyun rejected
every test send with a template-variable error. Fall back to non-blank
text for all three variables, add the instance label to the shared test
alert, and fix the doc template examples to Aliyun's ${...} syntax.
@orangeCatDeveloper
orangeCatDeveloper force-pushed the fix/4319-alibaba-sms-null-param branch from b64a76d to 2628bf8 Compare August 18, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend doc Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Question] <title>默认部署后,阿里云短信发送失败

1 participant