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.
The Telegram message contains:
- device identifier;
- a message indicating the update version;
- link to the official website with a description of the changes;
- information about the current device version and the release tree.
Article in other languages:
?? – Scripts MikroTik: Verifique la actualización de RouterOS
?? – MikroTik Скрипты: Проверка обновления RouterOS
?? – Scripts MikroTik: vérifier la mise à jour de RouterOS
?? – MikroTik-Skripte: Auf RouterOS-Update prüfen
?? – MikroTik-scripts: Controleer op RouterOS-updates
Change device Identity
Change the device ID to better understand which device is sending the message.
[System] -> [Identity]
or
/system identity set name="WhiteHouseMikroTik"
Create a script for checking the RouterOS update
The following permissions are required for the script to Сheck the RouterOS update: read, write, policy, test.
[System] -> [Scripts] -> [+] -> [Name: CheckUpdate] -> [Policy: read, write, test, policy]
Script code:
# 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 <b> $DeviceName:</b> ";
# 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! <a href=\"https://mikrotik.com/download/changelogs\">Changelogs</a>. [Installed version $InstVer, chanell $Chan].";
$TGSendMessage Token=$TelegramBotToken ChatID=$TelegramChatID Text=$TelegramMessageText;
}
:log info $TelegramMessageText;
If no updates are found, the script prints a message to the log. So you can understand that the script is working successfully.
Add script launch to schedule
[System] -> [Schedule] -> [+] -> [Name:CheckUpdate] – > [Start Time: 07:00:00] -> [Interval: 1d 00:00:00] -> [Policy: read, write, policy, test]
Script code:
/system script run CheckUpdate
Now the update of any device will not be forgotten, each MikroTik device will be checked daily and remind you to update!
How to check RouterOS updates and send a message to Telegram was discussed in this article. I hope you can now control RouterOS versions on MikroTik devices. However, if you run into any problems while setting up, feel free to write in the comments. I will try to help.
✅ The script is checked: hAP ac lite [RouterBOARD 952Ui-5ac2nD], RouterOS 6.47.8 (stable).
Hi, i’m getting script to work but when runs it creates file with name “: b> System is already up to date&parse_mode=html&disable_web_page_preview=True”
Can u spot the error and help ?
# Constants
: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;
# START SEND TELEGRAM
:local MessageText “$TelegramMessageText”;
:local SendTelegramMessage [:parse [/system script get TGBotSendMessage source]];
$SendTelegramMessage MessageText=$MessageText;
# END SEND TELEGRAM
Hi! In the function TGBotSendMessage add parameter “keep-result=no”:
Example:
/tool fetch http-method=get url=$tgUrl keep-result=no;