###Step by step
- Install smartmontools with
sudo apt-get install smartmontools
- Create a new telegram bot via the botfather (see https://core.telegram.org/bots#3-how-do-i-create-a-bot).
You will need the token of the bot from
botfather. - Initiate a chat with your new bot.
- Send a GET to
https://api.telegram.org/bot{YOUR_TOKEN}/getUpdates. You will need the chat id of your chat with the bot.
- On your machine open the file
/etc/default/smartmontoolsand uncomment the linestart_smartd=yes. - In the file
/etc/smartd.confuse the first example that might be uncommented already and change it toDEVICESCAN -d removable -n standby -m root -M test -M exec /usr/share/smartmontools/smartd-runner - Create a bash file in the folder
/etc/smartmontools/run.dcalled10telegram-notify. - Fill in this content (replace token and chat id):
#!/bin/bash -e
chatid="YOUR_CHAT_ID"
error=$(cat $1)
apikey="YOUR_BOT_TOKEN"
curl -G --data-urlencode "chat_id=${chatid}" --data-urlencode "text=${error}" https://api.telegram.org/bot${apikey}/sendMessage- Make the file executable with
chmod +x FILENAME
- Start the daemon with
sudo smartd. You should be receiving a test message in the chat with your bot. If not, you can investigate the error withsudo cat /var/log/syslog. - Remove the
-M testfrom your/etc/smartd.conffile, so that the line looks like this now:DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner. - Done.
One suggestion - replace:
with