pothi.mikrotik-scripts/scripts/alert-on-new-ros-version.rsc

50 lines
1.4 KiB
Text
Raw Normal View History

2022-02-12 14:03:41 +05:30
# Alert upon new version
2022-02-19 19:40:24 +05:30
# requirement/s:
2022-02-12 14:03:41 +05:30
:local adminEmailAddress "admin@example.com"
2022-02-19 19:40:24 +05:30
:local startDelay "100s"
2022-02-12 14:03:41 +05:30
# if you run this script at "startup",
# the following indicates the time for the internet to go "up"
2022-02-19 19:40:24 +05:30
# ToDo: Find it out dynamically
:delay $startDelay
:log info "Checking for new version of RouterOS..."
2022-02-12 14:03:41 +05:30
/system package update
check-for-updates once
2022-02-19 19:40:24 +05:30
:local versionStatus
:local deviceIdentity [/system identity get name]
2022-02-12 14:03:41 +05:30
:do {
2022-02-19 19:40:24 +05:30
:delay 3s
2022-02-12 14:03:41 +05:30
:set $versionStatus [get status]
# alternative way to get the above info
# :set $versionStatus ([print as-value]->"status")
} while=( $versionStatus = "finding out latest version..." )
# for debugging
# :put $versionStatus
# :put $adminEmailAddress
2022-02-19 19:40:24 +05:30
:local installedVersion [get installed-version]
:local latestVersion [get latest-version]
2022-02-12 14:03:41 +05:30
:if ( $versionStatus = "New version is available" ) do={
# alternative method
2022-02-19 19:40:24 +05:30
# :if ( installedVersion != $latestVersion ) do={
:log info "A new update is available for Router OS and an email is probably sent to $adminEmailAddress."
2022-02-12 14:03:41 +05:30
/tool e-mail send to="$adminEmailAddress" \
2022-02-19 19:40:24 +05:30
subject="[Mikrotik $deviceIdentity] Software Update is Available" \
body="A new update is available for your MikroTik device: \"$deviceIdentity\" ...
Installed Version: $installedVersion
Latest Version: $latestVersion
"
2022-02-12 14:03:41 +05:30
} else={
2022-02-19 19:40:24 +05:30
:log info "Router OS is already up to date."
2022-02-12 14:03:41 +05:30
}