global-functions: introduce and use $DeviceInfo

This commit is contained in:
Christian Hesse 2019-09-12 13:45:44 +02:00
parent 23b38fa15a
commit 94581741f4
5 changed files with 41 additions and 47 deletions

View file

@ -8,6 +8,7 @@
:global SafeUpdateUrl; :global SafeUpdateUrl;
:global SentRouterosUpdateNotification; :global SentRouterosUpdateNotification;
:global DeviceInfo;
:global SendNotification; :global SendNotification;
:local DoUpdate do={ :local DoUpdate do={
@ -36,9 +37,6 @@
} }
:if ($Update->"installed-version" != $Update->"latest-version") do={ :if ($Update->"installed-version" != $Update->"latest-version") do={
:local BoardName [ / system resource get board-name ];
:local RouterBoard [ / system routerboard get ];
:if ([ :len $SafeUpdateUrl ] > 0) do={ :if ([ :len $SafeUpdateUrl ] > 0) do={
:local Result; :local Result;
:do { :do {
@ -74,13 +72,7 @@
$SendNotification ("RouterOS update") \ $SendNotification ("RouterOS update") \
("There is a RouterOS update available.\n\n" . \ ("There is a RouterOS update available.\n\n" . \
"Board name: " . $BoardName . "\n" . \ [ $DeviceInfo ] . "\n\n" . \
"Model: " . $RouterBoard->"model" . "\n" . \
"Serial number: " . $RouterBoard->"serial-number" . "\n" . \
"Hostname: " . $Identity . "\n" . \
"Channel: " . $Update->"channel" . "\n" . \
"Installed: " . $Update->"installed-version" . "\n" . \
"Available: " . $Update->"latest-version" . "\n\n" .\
"https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree") \ "https://mikrotik.com/download/changelogs/" . $Update->"channel" . "-release-tree") \
"" "true"; "" "true";
:set SentRouterosUpdateNotification ($Update->"latest-version"); :set SentRouterosUpdateNotification ($Update->"latest-version");

View file

@ -7,13 +7,9 @@
:global Identity; :global Identity;
:global BackupPassword; :global BackupPassword;
:global DeviceInfo;
:global SendNotification; :global SendNotification;
# get some system information
:local BoardName [ / system resource get board-name ];
:local RouterBoard [ / system routerboard get ];
:local Update [ / system package update get ];
:do { :do {
# we are not interested in output, but print without count-only is # we are not interested in output, but print without count-only is
# required to fetch information from cloud # required to fetch information from cloud
@ -29,12 +25,7 @@
$SendNotification "Cloud backup" \ $SendNotification "Cloud backup" \
("Uploaded backup for " . $Identity . " to cloud.\n\n" . \ ("Uploaded backup for " . $Identity . " to cloud.\n\n" . \
"Board name: " . $BoardName . "\n" . \ [ $DeviceInfo ] . "\n\n" . \
"Model: " . $RouterBoard->"model" . "\n" . \
"Serial number: " . $RouterBoard->"serial-number" . "\n" . \
"Hostname: " . $Identity . "\n" . \
"Channel: " . $Update->"channel" . "\n" . \
"RouterOS: " . $Update->"installed-version" . "\n\n" . \
"Name: " . $Cloud->"name" . "\n" . \ "Name: " . $Cloud->"name" . "\n" . \
"Size: " . $Cloud->"size" . "\n" . \ "Size: " . $Cloud->"size" . "\n" . \
"Download key: " . $Cloud->"secret-download-key") "" "true"; "Download key: " . $Cloud->"secret-download-key") "" "true";

View file

@ -13,6 +13,7 @@
:global BackupPassword; :global BackupPassword;
:global CharacterReplace; :global CharacterReplace;
:global DeviceInfo;
:if ($BackupSendBinary != true && \ :if ($BackupSendBinary != true && \
$BackupSendExport != true) do={ $BackupSendExport != true) do={
@ -26,11 +27,6 @@
:local ConfigFile "none"; :local ConfigFile "none";
:local Attach [ :toarray "" ]; :local Attach [ :toarray "" ];
# get some system information
:local BoardName [ / system resource get board-name ];
:local RouterBoard [ / system routerboard get ];
:local Update [ / system package update get ];
# binary backup # binary backup
:if ($BackupSendBinary = true) do={ :if ($BackupSendBinary = true) do={
/ system backup save encryption=aes-sha256 name=$FileName password=$BackupPassword; / system backup save encryption=aes-sha256 name=$FileName password=$BackupPassword;
@ -49,13 +45,8 @@
/ tool e-mail send to=$EmailBackupTo cc=$EmailBackupCc \ / tool e-mail send to=$EmailBackupTo cc=$EmailBackupCc \
subject=("[" . $Identity . "] Backup & Config") \ subject=("[" . $Identity . "] Backup & Config") \
body=("Backup and config export for " . $Identity . ".\n\n" . \ body=("Backup and config export for " . $Identity . ".\n\n" . \
"Board name: " . $BoardName . "\n" . \ [ $DeviceInfo ] . "\n\n" . \
"Model: " . $RouterBoard->"model" . "\n" . \ "Backup file: " . $BackupFile . "\n" . \
"Serial number: " . $RouterBoard->"serial-number" . "\n" . \ "Config file: " . $ConfigFile) \
"Hostname: " . $Identity . "\n" . \
"Channel: " . $Update->"channel" . "\n" . \
"RouterOS: " . $Update->"installed-version" . "\n\n" . \
"Backup file: " . $BackupFile . "\n" . \
"Config file: " . $ConfigFile) \
file=$Attach; file=$Attach;
} }

View file

@ -294,3 +294,32 @@
:delay ([ $GetRandom $1 ] . "s"); :delay ([ $GetRandom $1 ] . "s");
} }
# get readable device info
:global DeviceInfo do={
:global Identity;
:local BoardName [ / system resource get board-name ];
:local RouterBoard [ / system routerboard get ];
:local Update [ / system package update get ];
:local Info ( \
"Hostname: " . $Identity . "\n" . \
"Board name: " . $BoardName);
:if ($RouterBoard->"routerboard" = true) do={
:set Info ($Info . "\n" . \
"Model: " . $RouterBoard->"model" . "\n" . \
"Serial number: " . $RouterBoard->"serial-number");
}
:set Info ($Info . "\n" . \
"RouterOS:\n" . \
" Channel: " . $Update->"channel" . "\n" . \
" Installed: " . $Update->"installed-version");
:if ([ :typeof ($Update->"latest-version") ] != "nothing" && \
$Update->"installed-version" != $Update->"latest-version") do={
:set Info ($Info . "\n" . \
" Available: " . $Update->"latest-version");
}
:return $Info;
}

View file

@ -14,6 +14,7 @@
:global BackupPassword; :global BackupPassword;
:global CharacterReplace; :global CharacterReplace;
:global DeviceInfo;
:global SendNotification; :global SendNotification;
:if ($BackupSendBinary != true && \ :if ($BackupSendBinary != true && \
@ -27,11 +28,6 @@
:local BackupFile "none"; :local BackupFile "none";
:local ConfigFile "none"; :local ConfigFile "none";
# get some system information
:local BoardName [ / system resource get board-name ];
:local RouterBoard [ / system routerboard get ];
:local Update [ / system package update get ];
# binary backup # binary backup
:if ($BackupSendBinary = true) do={ :if ($BackupSendBinary = true) do={
/ system backup save encryption=aes-sha256 name=$FileName password=$BackupPassword; / system backup save encryption=aes-sha256 name=$FileName password=$BackupPassword;
@ -62,12 +58,7 @@
$SendNotification "Backup & Config Upload" \ $SendNotification "Backup & Config Upload" \
("Backup and config export for " . $Identity . ".\n\n" . \ ("Backup and config export for " . $Identity . ".\n\n" . \
"Board name: " . $BoardName . "\n" . \ [ $DeviceInfo ] . "\n\n" . \
"Model: " . $RouterBoard->"model" . "\n" . \ "Backup file: " . $BackupFile . "\n" . \
"Serial number: " . $RouterBoard->"serial-number" . "\n" . \ "Config file: " . $ConfigFile) "" "true";
"Hostname: " . $Identity . "\n" . \
"Channel: " . $Update->"channel" . "\n" . \
"RouterOS: " . $Update->"installed-version" . "\n\n" . \
"Backup uploaded: " . $BackupFile . "\n" . \
"Config uploaded: " . $ConfigFile) "" "true";
} }