-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCAPsMAN_CAP_Package_Auto_Install.rsc
62 lines (40 loc) · 2.03 KB
/
CAPsMAN_CAP_Package_Auto_Install.rsc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# RouterOS Fucntion
# Copyright (c) Grzegorz Budny
# Version 1.0
# Last update: 2/8/2020
# Upgrades all CAPs attached to CAPsMAN. Log actions in system log and in the file. Sends email notification upon completion
:global CapAutoUpgrade do={
:local capIdentity;
:local capVersion;
:local today [/system clock get date];
:local time [/system clock get time];
:local systemName [/system identity get value-name=name];
:local capsNumber [/caps-man remote-cap print count-only];
:local packagePath [/caps-man manager get package-path];
:local fileName ($today."_".$systemName."_CAP_Upgrade.log");
:if ([:len [/file find name=$fileName]] <= 0) do={
:log warning"...:::Log file not found, creating file:::...";
/file print file=$fileName;
}
:if ([:len [/file find name=$fileName]] > 0) do={
:log info "...:::Log file found:::...";
}
:if ($packagePath != "") do={
:log info "...:::Package path defined. Starting CAPs upgrade:::..."
/file set $fileName contents=([get $fileName contents].("New upgrade task started ".$today." at ".$time);
:for $i from=0 to=($capsNumber - 1) step=1 do={
:set $capIdentity [/ caps-man remote-cap get value-name=identity number=$i];
/caps-man remote-cap upgrade numbers=$i;
:log info ("Upgrading ".$capIdentity."...");
/file set $fileName contents=([get $fileName contents].($i.") Upgraded ".$capIdentity."\n"));
:set $capIdentity;
}
/tool e-mail send server=$smtpServer port=$smtpPort from=($systemName.$domain) \
to=$recipient subject=("Remote CAPs upgrade run on ".$systemName) \
body=($systemName." upgraded remote CAPs. \n Attached upgrade log file.") file=$fileName;
}\
else={
:log warning "...:::Upgrade path not specified. Firmware image is missing!:::..."
}
}
$CapAutoUpgrade smtpServer=smtpIP port=smtpPort [email protected] [email protected]