Forward OpenFalcon alarm messages to a WeCom application.
- Accepts the OpenFalcon sender payload:
tosandcontent. - Sends WeCom text messages through the application message API.
- Loads credentials from
config.confor environment variables. - Requires a request token before messages can be sent.
- Uses HTTP timeouts and explicit upstream error handling.
- Register a WeCom account.
- Get the
CorpIDfrom My Company -> Company Info. - Create an application from Apps -> Add App.
- Copy the application
AgentIdandSecret. - Make sure the receiver follows the WeCom account, otherwise messages may only be visible inside the WeCom app.
Create a local config file:
cp config.example.conf config.confEdit config.conf:
[http]
address = 0.0.0.0
port = 4567
[server]
auth_token = replace-with-a-long-random-token
[weixin]
CorpID = replace-with-your-corpid
AgentId = 1000001
Secret = replace-with-your-secretconfig.conf is ignored by Git and should not be committed.
Environment variables override the file values:
| Variable | Description |
|---|---|
CHAT_CONFIG |
Config file path. Defaults to config.conf. |
CHAT_HTTP_ADDRESS |
HTTP bind address. |
CHAT_HTTP_PORT |
HTTP bind port. |
CHAT_AUTH_TOKEN |
Request token for /send. |
WEIXIN_CORP_ID |
WeCom CorpID. |
WEIXIN_AGENT_ID |
WeCom application AgentId. |
WEIXIN_SECRET |
WeCom application Secret. |
go build -o main .
./control.sh start
./control.sh status
./control.sh stopFor foreground testing:
go run .Endpoint:
GET /send?token=<auth_token>&tos=<wecom_user>&content=<message>
POST /send
Parameters:
| Field | Required | Description |
|---|---|---|
token |
Yes | Request token. It can also be sent as X-Chat-Token or Authorization: Bearer <token>. |
tos |
Yes | WeCom user ID. |
content |
Yes | Text message content. |
Example:
curl 'http://127.0.0.1:4567/send?token=your-token&tos=zhangsan&content=test'JSON POST is also accepted:
curl -X POST 'http://127.0.0.1:4567/send?token=your-token' \
-H 'Content-Type: application/json' \
-d '{"tos":"zhangsan","content":"test"}'Set the IM endpoint to this service. The token can be embedded in the URL:
{
"api": {
"im": "http://127.0.0.1:4567/send?token=your-token",
"sms": "http://127.0.0.1:10086/sms",
"mail": "http://127.0.0.1:10086/mail",
"dashboard": "http://127.0.0.1:8081",
"plus_api": "http://127.0.0.1:8080",
"plus_api_token": "used-by-alarm-in-server-side-and-disabled-by-set-to-blank"
}
}OpenFalcon should send:
tos WeCom user ID
content Alarm content
go test ./...
go build ./...