You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.9 KiB
81 lines
2.9 KiB
2 years ago
|
:global lastKnownROSVersion
|
||
|
|
||
|
:local rcpt "admin@example.org"
|
||
|
|
||
|
|
||
|
:local id [/system identity get name]
|
||
|
:local ts [/system clock get time]
|
||
|
:local ds [/system clock get date]
|
||
|
|
||
|
:set ts ([:pick $ts 0 2]."-".[:pick $ts 3 5]."-".[:pick $ts 6 8])
|
||
|
:set ds ([:pick $ds 4 6]."-".[:pick $ds 0 3]."-".[:pick $ds 7 11])
|
||
|
|
||
|
:local installedVersion [/system package update get installed-version]
|
||
|
:local latestVersion $installedVersion
|
||
|
:local updateChannel [/system package update get channel]
|
||
|
:local changelogLink ("https://mikrotik.com/download/changelogs/".$updateChannel."-release-tree")
|
||
|
|
||
|
:local subj ("MT update notification from ".$id." - ".$ds." ".$ts)
|
||
|
:local body ("This is a scheduled update notification from MT device \"".$id."\". \r\nDate: ".$ds." \r\nTime: ".$ts." \r\n\r\n")
|
||
|
:local send false
|
||
|
:local fail false
|
||
|
|
||
|
|
||
|
:if ([:len [/tool e-mail get address]] = 0 or [:len [/tool e-mail get from]] = 0) do={
|
||
|
:log error "Email configuration is missing"
|
||
|
:error "Email configuration is missing"
|
||
|
} else={
|
||
|
:do {
|
||
|
:log info "Checking for RouterOS updates..."
|
||
|
|
||
|
/system package update check-for-updates
|
||
|
:set latestVersion [/system package update get latest-version]
|
||
|
|
||
|
:if ([:len $latestVersion] = 0) do={
|
||
|
:log error "Failed to retrieve latest RouterOS version information, sending an email"
|
||
|
:set subj ($subj.": failed to get version info")
|
||
|
:set body ($body."Failed to retrieve latest RouterOS version information")
|
||
|
:set send true
|
||
|
} else={
|
||
|
:local versionDescription ($latestVersion." in ".$updateChannel." channel")
|
||
|
|
||
|
:if ($installedVersion != $latestVersion and $lastKnownROSVersion != $latestVersion) do={
|
||
|
:log info ("Found new version ".$versionDescription.", sending an email")
|
||
|
:set subj ($subj.": new version ".$versionDescription)
|
||
|
:set body ($body."A new RouterOS version is avaliable - ".$versionDescription." (currently running ".$installedVersion."). \r\nRead full changelog here: ".$changelogLink)
|
||
|
:set send true
|
||
|
} else={
|
||
|
:if ($installedVersion != $latestVersion) do={
|
||
|
:log info ("Found new version ".$versionDescription.", notification already sent")
|
||
|
} else={
|
||
|
:log info ("No new RouterOS updates (latest version is ".$versionDescription.")")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
:set lastKnownROSVersion $latestVersion
|
||
|
}
|
||
|
|
||
|
:if ($send = true) do={
|
||
|
:do {/tool e-mail send to=$rcpt subject=$subj body=$body} on-error={
|
||
|
:log warning "Failed to send email message. Retrying in 30s..."
|
||
|
:delay 30s
|
||
|
|
||
|
:do {/tool e-mail send to=$rcpt subject=$subj body=$body} on-error={
|
||
|
:log error "Failed to send email message (2nd attempt)"
|
||
|
:set fail true
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
} on-error={
|
||
|
:log warning "Caught an exception when checking for updates"
|
||
|
:set fail true
|
||
|
}
|
||
|
|
||
|
:if ($fail = false) do={
|
||
|
:log info "Update notification script completed"
|
||
|
} else={
|
||
|
:log error "Update notification script completed with errors"
|
||
|
:error "Update notification script completed with errors"
|
||
|
}
|
||
|
}
|