Hi everybody, i was testing some scripting on my 3011 and i got a discord notification webhook working and want to share with the rest
# Func: Discord send message
:local DiscordSendMessage do={
/tool fetch url=($Token) http-method=post \
http-data=("content=" . $Text) mode=https keep-result=no
}
# Constants
:local webhookUrl "<WebHook>";
:local DeviceName [/system identity get name];
:local MessageText "$DeviceName:\n";
# 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 MessageText ($MessageText . "System is already up to date");
} else={
:set MessageText "$MessageText\F0\9F\9F\A2 New version $LatVer is available! \n\F0\9F\94\B4 Installed version $InstVer, channel $Chan.";
$DiscordSendMessage Token=$webhookUrl Text=$MessageText;
}
:log info $MessageText;
The code above checks for the latest routerOs update and sends a message to a discord webhook