Check RouterOS Update and Notification to eMail or Telegram - MikroTik Script RouterOS
MikroTik script that starts checking for an update for RouterOS. If a system update is found, it sends a message to Telegram, otherwise it writes a log about the absence of updates.
🔔 For the script to work, you must have a Telegram bot Token and a chat ID or a personal ID. Creating a Telegram bot and getting the required IDs is not the topic of this article.
# Func: Telegram send message
:local TGSendMessage do={
:local tgUrl "https://api.telegram.org/bot$Token/sendMessage?chat_id=$ChatID&text=$Text&parse_mode=html&disable_web_page_preview=True";
/tool fetch http-method=get url=$tgUrl keep-result=no;
}
# Constants
:local TelegramBotToken "987654321:AAFJIVTAWodBwzGX2CLne6-PK4RFNSy-8OY";
:local TelegramChatID "987654321";
:local DeviceName [/system identity get name];
:local TelegramMessageText "\F0\9F\9F\A2 $DeviceName: ";
# Check Update
:local MyVar [/system package update check-for-updates as-value];
:local Chan ($MyVar -> "channel");
:local InstVer ($MyVar -> "installed-version");
:local LatVer ($MyVar -> "latest-version");
:if ($InstVer = $LatVer) do={
:set TelegramMessageText ($TelegramMessageText . "System is already up to date");
} else={
:set TelegramMessageText "$TelegramMessageText New version $LatVer is available! Changelogs. [Installed version $InstVer, chanell $Chan].";
$TGSendMessage Token=$TelegramBotToken ChatID=$TelegramChatID Text=$TelegramMessageText;
}
:log info $TelegramMessageText;
Credit: https://mhelp.pro/mikrotik-scripts-check-routeros-update/