sidebar:networks:mikrotik:telegram

Мы лепили его из того что было но пока не слепили)

https://api.telegram.org/bot{ваш токен}/getUpdates

Делаем уведомление в два действия:

Подставляем имя бота в скрипте на строке :local TelegramBotToken « 123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ »;

Указываем ID чата или канала в строке :local TelegramChatID «1234567890 »;

# Func: Telegram send message
:local TGSendMessage do={
    :local tgUrl "https://api.telegram.org/bot$Token/sendMessage?chat_id=$ChatID&text=$Text&parse_mode=html";
    /tool fetch http-method=get url=$tgUrl keep-result=no;
}

# Constants
:global RebootStatus;
:local TelegramBotToken "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ";
:local TelegramChatID "1234567890";
:local DeviceName [/system identity get name];

:local TelegramMessageText "\F0\9F\9F\A2 <b>$DeviceName:</b> start after Power Off.";

# Program
:if ($RebootStatus != true)  do={
    $TGSendMessage Token=$TelegramBotToken ChatID=$TelegramChatID Text=$TelegramMessageText;
    :set RebootStatus true;
    :log info "Script CheckPowerOn send Telegram message."
}

Создаем скрипт в разделе system - scripts и не забываем поставить галку Don't Require Permissions

Создаем правило запуска в планировщике.

Указываем: Имя, Дату, Время и интервал запуска скрипта, мне достаточно проверки раз в 20 минут

download.txt
:log info "Start WANstat script"
:global routername "ИМЯ";
:global sendToTele "https://api.telegram.org/123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZ/sendmessage\?chat_id=-123456789&text=" ;
:global rxbyte [/interface get [find name=ether1] rx-byte];
:global simplGbrxreport ($rxbyte / 1073741824);
:global lowGbrxreport ((($rxbyte - ($simplGbrxreport * 1073741824)) * 1000000000) / 1048576);
:global Gbrxreport ("$[$simplGbrxreport]".",".[:pick "$[$lowGbrxreport]" 0 3] );
:global txbyte [/interface get [find name=ether1] tx-byte];
:global simplGbtxreport ($txbyte / 1073741824);
:global lowGbtxreport ((($txbyte - ($simplGbtxreport * 1073741824)) * 1000000000) / 1048576);
:global Gbtxreport ("$[$simplGbtxreport]".",".[:pick "$[$lowGbtxreport]" 0 3] );
:global tempC [/system health get temperature];
:global volt [/system health get voltage];
:global simplvolt ($volt / 10);
:global lowvolt ((($volt - ($simplvolt * 10)) * 10) / 1);
:global involt ("$[$simplvolt]".",".[:pick "$[$lowvolt]" 0 3] );
:global uptime [/system resource get uptime]
:global cpuZ [/system resource get cpu-load]
:global vers [/system resource get version]
:global memt [/system resource get total-memory]
:global memtotal ($memt / 1048576)
:global memo [/system resource get free-memory]
:global memoMB ($memo / 1048576)
/tool fetch url="$sendToTele $routername%0AVersion: $vers%0AUptime: $uptime%0AVoltage: $involt V%0ATemperature: $tempC C%0ACPU load: $cpuZ %%0AMemory Free / Total: $memoMB / $memtotal MB%0ADownload: $Gbrxreport GB%0AUpload: $Gbtxreport GB "  keep-result=no
:log info "WANstat script finished"

Для wifi

:global mac "XX:XX:XX:XX:XX:XX"
:global OldChek
:global chek 
if ([/interface wireless registration-table find mac-address=$mac] != "") do={set chek true} else={set chek false}

if (($chek != $OldChek) and ($chek = true)) do={
/tool fetch url="https://api.telegram.org/botXXXXXXXXX:YYYYYYYYYYYYYY/sendmessage?chat_id=ZZZZZZZZZZZZ&text=UP"
} 

if (($chek != $OldChek) and ($chek = false)) do={
/tool fetch url="https://api.telegram.org/botXXXXXXXXX:YYYYYYYYYYYYYY/sendmessage?chat_id=ZZZZZZZZZZZZ&text=DOWN"
} 

set OldChek $chek

для lan

:global mac "XX:XX:XX:XX:XX:XX"
:global OldChek
:global chek 
if ([/ip dhcp-server lease find mac-address=$mac] != "") do={set chek true} else={set chek false}

if (($chek != $OldChek) and ($chek = true)) do={
/tool fetch url="https://api.telegram.org/botXXXXXXXXX:YYYYYYYYYYYYYY/sendmessage?chat_id=ZZZZZZZZZZZZ&text=UP"
} 

if (($chek != $OldChek) and ($chek = false)) do={
/tool fetch url="https://api.telegram.org/botXXXXXXXXX:YYYYYYYYYYYYYY/sendmessage?chat_id=ZZZZZZZZZZZZ&text=DOWN"
} 

set OldChek $chek
  • sidebar/networks/mikrotik/telegram.txt
  • Последнее изменение: 2024/06/14 14:32
  • dred