smartd Disk Failure Alerts to Telegram Without a Bot Token

smartd Disk Failure Alerts to Telegram Without a Bot Token

push.tg

smartd, the daemon from smartmontools, watches your disks' SMART data and warns you when a drive starts failing. By default it sends that warning by email, which means setting up a mail server first. It can also run any program instead, so one small script with curl is enough to get the warning in Telegram. No BotFather, no bot token, no chat ID.

Step 1: get your endpoint (30 seconds)

Open @trafficRobot in Telegram and press Start. You get an address like k3x9q@push.tg. Your endpoint is the part before the @: https://push.tg/k3x9q. Every example below uses k3x9q, so swap in your own key.

There's no bot to create, no chat_id to look up and no token to keep safe. Add @trafficRobot to a group and the group gets its own address, so everyone on call sees the messages.

Step 2: the alert script

Save this as /usr/local/bin/pushtg-smartd and make it executable (sudo chmod +x /usr/local/bin/pushtg-smartd):

#!/bin/sh
curl -s -o /dev/null -m 10 --data-urlencode "data=smartd on $(hostname): $SMARTD_FAILTYPE on $SMARTD_DEVICESTRING
$SMARTD_MESSAGE" https://push.tg/k3x9q

smartd sets these environment variables before it runs the script: SMARTD_FAILTYPE (for example Health, CurrentPendingSector, Temperature or EmailTest), SMARTD_DEVICESTRING (the disk, like /dev/sda [SAT]) and SMARTD_MESSAGE (a one-sentence summary). --data-urlencode "data=..." puts the text in the form field push.tg reads and keeps it in one piece if it contains & or =.

-o /dev/null and -m 10 matter here. smartd treats any output from the script as an error and logs it, and it waits for the script to finish, so the script should stay quiet and never hang.

Step 3: point smartd at it

Edit /etc/smartd.conf (some distributions keep it at /etc/smartmontools/smartd.conf). Most installs have a single DEVICESCAN line. Add the options to that line, because smartd ignores every line after DEVICESCAN:

DEVICESCAN -a -m <nomailer> -M exec /usr/local/bin/pushtg-smartd

-m <nomailer> tells smartd there is no email address: it just runs the program. -M exec names the program. If your line already has other options, such as -n standby or a -s self-test schedule, keep them and replace only the -m and -M exec parts.

By default you get one message per problem type. Add -M daily to get a daily reminder while the problem lasts, or -M diminishing for reminders that get further apart.

Then tell smartd to re-read its config:

sudo killall -HUP smartd

Step 4: test it

smartd can send a test warning without touching your config. Run one check on a single disk with -M test:

echo '/dev/sda -m <nomailer> -M exec /usr/local/bin/pushtg-smartd -M test' | sudo smartd -c - -q onecheck

You should get a Telegram message with EmailTest as the type. If nothing arrives, run the curl by hand to rule out the network:

curl -d "test from $(hostname)" https://push.tg/k3x9q

Prefer smartd's own email?

Your push.tg address is also a real email address. If the server can already send mail, -m k3x9q@push.tg on the DEVICESCAN line sends smartd's normal warning email to the same Telegram chat. The script route above just means you don't need a mail server.

Each Telegram chat or group gets its own push.tg address, so disk warnings can go to a group the whole team watches.

Check that the message really arrived. push.tg answers HTTP 200 even when the key is wrong; the body then says {"error":"no such user"}. Send one test by hand and look at Telegram before you trust it:

Official references: smartd.conf(5) (sections -m, -M exec and DEVICESCAN), smartd(8) (-q onecheck and the HUP signal).

Open @trafficRobot · push.tg

More copy-paste guides

Report Page