Hello everyone, this is a small work of me as an independent developer, and another service for sending notifications to WeChat. There are actually a lot of such services. I must be embarrassed to introduce them because they have new features.
Server can not only send notifications to WeChat, but also use WeChat to interact with the server. It looks like this:
Well, let's introduce the basic functions first.
Proactively send notifications
Sending messages to yourself is the most commonly used function.
Pull to the end of the article and scan the code to follow the service account, or search for the service account "LetServerRun" on WeChat to follow.token
command in the service account to view your user token.
Using the user token, you can use the API to send a warning message to the official account:
curl "https://api.letserver.run/message/info?token=YOUR-TOKEN&msg=hello"
This GET interface is for debugging and light-weight usage scenarios. If used in the program, there are a series and SDK.
Reverse control server
Server is to use WeChat to control the server to do simple things. Just like the picture in the beginning.
Don't worry, you don't need to provide the ssh key. For security, what the command can do is completely defined by you.
The principle of implementation is that the commands you send in the service account will be stored in the cloud.
The agent initiates a request to the cloud to check once every minute, and if there is a command, it pulls it back to execute it.
After the execution is complete, the result of success or failure can be returned, and you will see it on the WeChat service account.
Where does the Agent come from? There are several options:
- The most free: call our API to write by yourself
- Easy point: call the SDK and write by yourself
- Just enough: just use some of our open source solutions
Here we first use a open source general agent to get started.
It can help you execute specific commands on the server. Later, we can integrate the Agent through API or SDK, or write it ourselves according to our needs.
Assuming your server is Debian/Ubuntu, if it is something else, please refer to install the general agent
If you are a root user, please remove sudo
# 注册仓库
curl -1sLf \
'https://dl.cloudsmith.io/public/hackfan/skadi/setup.deb.sh' \
| sudo -E bash
# 更新
apt update
# 安装
apt install skadi
After installation, because there is no Token, it does not start automatically.
Where did the token come from? Enter the command in the service number: agent add name (the name is for you to give it a simple name, and you will use it to send commands every time in the future)
Then write the obtained Token into the configuration file, as shown below.
You can also edit /etc/skadi/skadi.yml
write it yourself.
# 写入 Token
sudo skadi AGENT-TOKEN
# 启动服务
sudo systemctl start
Only the first time you need to manually start the service after configuring the token, the server restarts it will rely on systemd to start it itself.
Then you can try out this Agent.
Enter 1609b51913f873 name help in the see the help of the Agent.
This official general agent function is defined by the configuration file /etc/skadi/skadi.yml
Then you can input name date,
name lsroot,
name free -m,
name Hi Fool,
Go for a trial. Then, you can complete simple actions such as restarting the service and checking the status by changing the configuration file.
If you just want to check it now, you can also check the code repository version
More features
Because it only provides a stage at present, and more functions are being continuously explored, we will continue to update the cookbook in the document:
- Notify WeChat in the CI service, and even send tasks directly to the Agent for continuous deployment
- Agents send tasks in a chain to complete the work
- Integrate into the business system as a simple console, such as clearing the cache, banning users, etc., and it's done on WeChat.
- as a 1609b51913fa19 delay queue
- Control the computer at home
- Control router or NAS
- More usages are waiting for you to develop your brain holes~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。