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

47 lines
1.3 KiB
Text
Raw Normal View History

2022-02-21 06:57:29 +05:30
# Alert upon new Router OS Version
2022-02-12 14:03:41 +05:30
2022-02-19 19:40:24 +05:30
# requirement/s:
2022-02-19 19:51:41 +05:30
# policy: read, write, policy, test
2022-02-21 06:57:29 +05:30
:local adminEmail "admin@example.com"
:local startDelay "90s"
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
2022-02-21 06:57:29 +05:30
# :delay $startDelay
2022-02-19 19:40:24 +05:30
: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..." )
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={
2022-02-21 06:57:29 +05:30
:log info "A new update is available for Router OS and an email is probably sent to $adminEmail."
/tool e-mail send to="$adminEmail" \
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
}