orangeCatDeveloper opened a new pull request, #4331:
URL: https://github.com/apache/hertzbeat/pull/4331

   Part of #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. 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).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to