Community discussions

MikroTik App
 
joserf
just joined
Topic Author
Posts: 4
Joined: Mon Apr 28, 2014 5:51 pm

Telegram

Tue Sep 01, 2020 10:38 pm

Did anyone manage to send the back-up via telegram? I can only send an image via a link, I was unable to send a file.
 
ShayanPAL
just joined
Posts: 22
Joined: Thu Dec 19, 2019 12:20 pm

Re: Telegram

Tue Sep 01, 2020 11:27 pm

what do U mean
specify more with details
 
joserf
just joined
Topic Author
Posts: 4
Joined: Mon Apr 28, 2014 5:51 pm

Re: Telegram

Wed Sep 02, 2020 3:23 pm

I need to send the backup of the rb by Telegram
 
User avatar
eworm
Forum Veteran
Forum Veteran
Posts: 743
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Telegram

Wed Sep 02, 2020 4:06 pm

The Telegram Bot API documentation regarding sending files is here:
https://core.telegram.org/bots/api#sending-files

Not sure this works with fetch command... Probably not.
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
ShayanPAL
just joined
Posts: 22
Joined: Thu Dec 19, 2019 12:20 pm

Re: Telegram

Wed Sep 02, 2020 8:12 pm

you can also do this with via mail instead
 
usmans
Member Candidate
Member Candidate
Posts: 115
Joined: Sun Aug 29, 2010 11:54 pm

Re: Telegram

Sun Dec 06, 2020 4:51 am

Some screenshot of my telegram bot...
You do not have the required permissions to view the files attached to this post.
 
erkexzcx
Member Candidate
Member Candidate
Posts: 146
Joined: Mon Oct 07, 2019 11:42 pm

Re: Telegram

Sun Dec 06, 2020 1:26 pm

Answer is: No

I did not manage to send directly from Mikrotik, because "fetch" tool does not support sending files. I managed to send using Raspberry Pi:

Generate SSH keys on raspberry Pi and its upload public key to each router. Then pretty much use this bash script:
#!/bin/bash

ROUTER=$1
TITLE=$2

SSHUSER="admin"
SSHIDENTITY="~/.ssh/mikrotik"

TELEGRAMCHATID="1234567890"
TELEGRAMAPIKEY="0000000000:AAAAAAAAA-bbbbbbbbbbbbbbb-cccccccccc"


OUTPUT=$(ssh -i "$SSHIDENTITY" "$SSHUSER@$ROUTER" "/export")
RES=$?

if [[ $RES -eq 0 ]]; then
        TMPFILE="/dev/shm/export_${TITLE}_$(date +%Y%m%d)"
        echo "# Address: $ROUTER" > $TMPFILE
        echo "#" >> $TMPFILE
        echo -e "$OUTPUT" >> $TMPFILE

        curl -s -F "chat_id=$TELEGRAMCHATID" -F "document=@$TMPFILE" https://api.telegram.org/bot$TELEGRAMAPIKEY/sendDocument > /dev/null
        rm $TMPFILE
fi

Then in crontab:
# Backup Mikrotik routers
0 2 * * * /storage/tasks/others/mikrotik-backup.sh aaaaaaaaaaaa.sn.mynetname.net name1
0 2 * * * /storage/tasks/others/mikrotik-backup.sh aaaaaaaaaaaa.sn.mynetname.net name2
0 2 * * * /storage/tasks/others/mikrotik-backup.sh aaaaaaaaaaaa.sn.mynetname.net name3

EDIT: Don't like or don't have Raspberry Pi? Get the cheapest Linode instance then and host such script on it. 5 dollars per month for the cheapest instance AFAIK + you can do other stuff on it.

Who is online

Users browsing this forum: eworm and 49 guests