Skip to main content

Small utility to send Telegram messages from the CLI.

Project description

cli2telegram

Small utility to send Telegram messages from the CLI.

This can be used to

  • use Telegram as a notification backend for the ZFS Event Daemon (zed)

Features

  • Read messages from argument or STDIN
  • (Optional) Configuration file
  • Retry sending messages for a specified amount of time

Examples

# From arguments
cli2telegram "This is a message"

cli2telegram "Header" "This is a multiline message."

# From STDIN
echo My Message | cli2telegram

printf "Header\nThis is a multiline message." | cli2telegram

# Config via parameters
printf "Message" | cli2telegram -b "123456789:ABCDEFG" -c "123456789"

Install

To use this utility install it either using:

pip install cli2telegram

or - if you don't want to install it globally - using venv-install:

venv-install cli2telegram cli2telegram

or your custom venv manager of choice.

Configuration

File

To be able to send you messages you have to provide a bot token and a chat id. cli2telegram uses container-app-conf so you can use YAML, TOML, or ENV to set those. Since zed will run your scripts as root, if you want to use a config file you have to put it in 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"

Parameters

If you do not want to create a configuration file you can pass them using parameters:

  • -b - Telegram Bot Token
  • -c - Telegram Chat ID

ZFS Event Daemon (ZED)

To make zed call cli2telegram we will trick it and make it use cli2telegram as an E-Mail client.

Edit /etc/zfs/zed.d/zed.rc as root:

sudo nano -w /etc/zfs/zed.d/zed.rc

and

  • uncomment ZED_EMAIL_ADDR, the value does not matter since we use our own email script, but it is necessary to set a value to make ZED send 'emails'
  • set ZED_EMAIL_PROG to the path of the script, f.ex. /usr/bin/cli2telegram
    • it is important to note that zed does not seem to work if your command needs arguments to run

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

[...]

Contributing

GitHub is for social coding: if you want to write code, I encourage contributions through pull requests from forks of this repository. Create GitHub tickets for bugs and new features and comment on the ones that you are interested in.

License

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/>.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cli2telegram-1.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

cli2telegram-1.0.0-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file cli2telegram-1.0.0.tar.gz.

File metadata

  • Download URL: cli2telegram-1.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for cli2telegram-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5c8f6eda908f6b0979b11163e2ee7338cc072556005570b71e02c35a81574d12
MD5 59ad2023c8d7d6839a5fe69e8a1f78ac
BLAKE2b-256 93ddb2e5d0041b2e7318365b74ee7b4eb0c7ff1ab420e02902748e71010f6cea

See more details on using hashes here.

File details

Details for the file cli2telegram-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: cli2telegram-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.8.0

File hashes

Hashes for cli2telegram-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ae5e8faac7ca594e158f6cb4aa4847861a1016760f54f5725a77b2a913ca0a1
MD5 e465e35630f84e051052b10d1f7d5167
BLAKE2b-256 4891f373d7f3fdcdeaded6ec7afc33ffd1496f9da28bfa929b8dae3397fc437e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page