从CLI发送电报消息的小实用程序。
cli2telegram的Python项目详细描述
CLI2电报
从CLI发送电报消息的小实用程序。在
这可以用来
- 将Telegram用作ZFS事件守护程序(zed)的通知后端
特点
- [x] 从参数或STDIN读取消息
- [x] (可选)配置文件
- [x] 在指定的时间内重试发送邮件
示例
# From arguments cli2telegram "This is a message" cli2telegram "Header""This is a multiline message."# From STDINecho My Message | cli2telegram printf"Header\nThis is a multiline message."| cli2telegram # Config via parametersprintf"Message"| cli2telegram -b "123456789:ABCDEFG" -c "123456789"
安装
要使用此实用程序,请使用以下方法安装:
^{pr2}$或者-如果不想全局安装-使用venv-install:
venv-install cli2telegram cli2telegram
或者您的定制venv管理器。在
配置
文件
要发送消息,您必须提供bot令牌和chat id。
cli2telegram使用container-app-conf,因此您可以使用YAML、TOML或ENV来设置它们。由于zed
将以根用户身份运行脚本,如果要使用配置文件,则必须将其放入f.ex中。/root/.config/zed2telegram.toml
:
[cli2telegram.telegram]chat_id="12345678"bot_token="123456789:ABCDEFGH1234567890AB-1234567890ABC"[cli2telegram.retry]enabled="True"timeout="10s"give_up_after="4h"
参数
如果您不想使用参数创建文件,请执行以下操作:
-b
-电报机器人令牌-c
-电报聊天ID
ZFS事件守护程序(ZED)
为了使zed
调用cli2telegram,我们将欺骗它并使它将cli2telegram用作电子邮件客户端。在
将/etc/zfs/zed.d/zed.rc
编辑为根:
sudo nano -w /etc/zfs/zed.d/zed.rc
以及
- 取消注释
ZED_EMAIL_ADDR
,该值无关紧要,因为我们使用自己的电子邮件脚本,但是必须设置一个值,使ZED发送“emails” - 将
ZED_EMAIL_PROG
设置为脚本的路径f.ex./usr/bin/cli2telegram
- 需要注意的是,如果命令需要参数来运行,zed似乎不起作用
ZED_EMAIL_ADDR="root"
[...]
ZED_EMAIL_PROG="/usr/bin/cli2telegram"
[...]
# If you want to receive email no matter the state of your pool, you’ll want to set:
ZED_NOTIFY_VERBOSE=1
[...]
贡献
GitHub是用于社会化编码的:如果你想写代码,我会通过forks的pull请求来鼓励贡献 此存储库的。为bug和新特性创建GitHub罚单,并对您感兴趣的特性进行评论。在
许可证
cli2telegram by Markus Ressel Copyright (C) 2018 Markus Ressel This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
- 项目
标签: