leovp / telegram_notifications

System Notifications via Telegram
MIT License
7 stars 2 forks source link

Ubuntu not sending out smart alerts #1

Open hyperbart opened 4 years ago

hyperbart commented 4 years ago

First of all kudo's for this project. I had no monitoring, enabled your scripts for ZFS and hey presto 👍 .

However for smart it doesn't seem to work (or I did something wrong) or I'm not receiving anything although I have hooked up a disk that generates pending sectors/reallocated sectors.

Ubuntu 18.04.3 LTS Made a symlink to the script:

root@nas:~# ls -lah /etc/smartmontools/run.d/
total 16K
drwxr-xr-x 2 root root 4.0K Apr  1 12:31 .
drwxr-xr-x 4 root root 4.0K Nov 16 16:14 ..
-rwxr-xr-x 1 root root  231 Jul 30  2016 10mail
-rwxr-xr-x 1 root root  258 Jul 30  2016 10powersave-notify
lrwxrwxrwx 1 root root   50 Mar 21 18:51 10telegram -> /root/telegramsystemnotifications/telegram_text.sh

Script contains:

root@nas:~# cat /root/telegramsystemnotifications/telegram_text.sh
#!/bin/bash
CHAT_ID='xxxxxxxxx'
API_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

# Get the message from stdin, making the first line bold.
MESSAGE=$(cat -)

# Try to send a message; sleep a bit after each unsuccessful attempt.
until /usr/bin/curl -G \
    --data-urlencode "parse_mode=Markdown" \
    --data-urlencode "chat_id=${CHAT_ID}" \
    --data-urlencode "text=${MESSAGE}" \
    "https://api.telegram.org/bot${API_KEY}/sendMessage" >&/dev/null
do
    sleep 10
done

A simple echo to the symlink sends a message so that seems to work. (echo hello | /etc/smartmontools/run.d/10telegram)

leovp commented 4 years ago

How does smartd call these scripts in run.d? Maybe it doesn't write to stdout or writes in a strange way, or even passes the text as a parameter.