-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathros_email_log_worker.conf
178 lines (137 loc) · 6.95 KB
/
ros_email_log_worker.conf
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
## Fox RouterOS Notification
:global SystemGlobalEndID;
:global PPPoEGlobalEndID;
:global ScriptGlobalEndID;
:global FirewallGlobalEndID;
:global DHCPGlobalEndID;
## Shared variables
:local DeviceName [/system identity get name ];
:local Time [/system clock get time ];
:local Date [/system clock get date ];
## Shared variables End
## Resolve Mail Server
:local MailServer "<smtp.xxx.com>"; # Need to customize
:local MailPort "465";
:local MailTls "yes";
:local SendFrom "<[email protected]>"; # Need to customize
:local SendTo "<[email protected]>"; # Need to customize
:local MailIp;
:set MailIp [:resolve $MailServer ];
:delay 1s;
## Resolve End
## System variables
:local SystemEmailText;
:local GetSystemIDs [/log find where buffer ~ "memory" && topics ~ "system" ];
:local LenSystemIDs [:len $GetSystemIDs ];
:if ($SystemGlobalEndID = nothing) do={:set SystemGlobalEndID ($GetSystemIDs -> ($LenSystemIDs-$LenSystemIDs))};
:local SystemStartID [:find $GetSystemIDs $SystemGlobalEndID ];
:local SystemEndID ($GetSystemIDs -> ($LenSystemIDs-1));
## System variables End
## PPPoE variables
:local PPPoEEmailText;
:local GetPPPoEIDs [/log find where buffer ~ "memory" && topics ~ "pppoe" ];
:local LenPPPoEIDs [:len $GetPPPoEIDs ];
:if ($PPPoEGlobalEndID = nothing) do={:set PPPoEGlobalEndID ($GetPPPoEIDs -> ($LenPPPoEIDs-$LenPPPoEIDs))};
:local PPPoEStartID [:find $GetPPPoEIDs $PPPoEGlobalEndID ];
:local PPPoEEndID ($GetPPPoEIDs -> ($LenPPPoEIDs-1));
## PPPoE variables End
## Script variables
:local ScriptEmailText;
:local GetScriptIDs [/log find where buffer ~ "memory" && topics ~ "script" ];
:local LenScriptIDs [:len $GetScriptIDs ];
:if ($ScriptGlobalEndID = nothing) do={:set ScriptGlobalEndID ($GetScriptIDs -> ($LenScriptIDs-$LenScriptIDs))};
:local ScriptStartID [:find $GetScriptIDs $ScriptGlobalEndID ];
:local ScriptEndID ($GetScriptIDs -> ($LenScriptIDs-1));
## Script variables End
## Firewall variables
:local FirewallEmailText;
:local GetFirewallIDs [/log find where buffer ~ "memory" && topics ~ "firewall" ];
:local LenFirewallIDs [:len $GetFirewallIDs ];
:if ($FirewallGlobalEndID = nothing) do={:set FirewallGlobalEndID ($GetFirewallIDs -> ($LenFirewallIDs-$LenFirewallIDs))};
:local FirewallStartID [:find $GetFirewallIDs $FirewallGlobalEndID ];
:local FirewallEndID ($GetFirewallIDs -> ($LenFirewallIDs-1));
## Firewall variables End
## DHCP variables
:local DHCPEmailText;
:local GetDHCPIDs [/log find where buffer ~ "memory" && topics ~ "dhcp" ];
:local LenDHCPIDs [:len $GetDHCPIDs ];
:if ($DHCPGlobalEndID = nothing) do={:set DHCPGlobalEndID ($GetDHCPIDs -> ($LenDHCPIDs-$LenDHCPIDs))};
:local DHCPStartID [:find $GetDHCPIDs $DHCPGlobalEndID ];
:local DHCPEndID ($GetDHCPIDs -> ($LenDHCPIDs-1));
## DHCP variables End
## System Mail
:if ($SystemEndID != $SystemGlobalEndID && [:tobool $SystemGlobalEndID ]) do={
:for SystemKeyArray from=($SystemStartID) to=($LenSystemIDs-1) do={
:local SystemIDMessage ($GetSystemIDs -> $SystemKeyArray);
:set SystemEmailText "$SystemEmailText \n $[/log get number=$SystemIDMessage time] - $[/log get number=$SystemIDMessage message] \n";
}
:local Uptime [/system resource get uptime ];
:local Project "System Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local SystemBody "=====> Device $Project <===== \n $SystemEmailText";
/tool e-mail send server=$MailIp port=$MailPort tls=$MailTls from=$SendFrom to=$SendTo subject=$Subject body=$SystemBody;
:delay 5s;
}
## System Mail End
## PPPoE Mail
:if ($PPPoEEndID != $PPPoEGlobalEndID && [:tobool $PPPoEGlobalEndID ]) do={
:for PPPoEKeyArray from=($PPPoEStartID) to=($LenPPPoEIDs-1) do={
:local PPPoEIDMessage ($GetPPPoEIDs -> $PPPoEKeyArray);
:set PPPoEEmailText "$PPPoEEmailText \n $[/log get number=$PPPoEIDMessage time] - $[/log get number=$PPPoEIDMessage message] \n";
}
:local Uptime [/system resource get uptime ];
:local Project "PPPoE Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local PPPoEBody "=====> Device $Project <===== \n $PPPoEEmailText";
/tool e-mail send server=$MailIp port=$MailPort tls=$MailTls from=$SendFrom to=$SendTo subject=$Subject body=$PPPoEBody;
:delay 10s;
}
## PPPoE Mail End
## Script Mail
:if ($ScriptEndID != $ScriptGlobalEndID && [:tobool $ScriptGlobalEndID ]) do={
:for ScriptKeyArray from=($ScriptStartID) to=($LenScriptIDs-1) do={
:local ScriptIDMessage ($GetScriptIDs -> $ScriptKeyArray);
:set ScriptEmailText "$ScriptEmailText \n $[/log get number=$ScriptIDMessage time] - $[/log get number=$ScriptIDMessage message] \n";
}
:local Uptime [/system resource get uptime ];
:local Project "Script Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local ScriptBody "=====> Device $Project <===== \n $ScriptEmailText";
/tool e-mail send server=$MailIp port=$MailPort tls=$MailTls from=$SendFrom to=$SendTo subject=$Subject body=$ScriptBody;
:delay 5s;
}
## Script Mail End
## Firewall Mail
:if ($FirewallEndID != $FirewallGlobalEndID && [:tobool $FirewallGlobalEndID ]) do={
:for FirewallKeyArray from=($FirewallStartID) to=($LenFirewallIDs-1) do={
:local FirewallIDMessage ($GetFirewallIDs -> $FirewallKeyArray);
:set FirewallEmailText "$FirewallEmailText \n $[/log get number=$FirewallIDMessage time] - $[/log get number=$FirewallIDMessage message] \n";
}
:local Uptime [/system resource get uptime ];
:local Project "Firewall Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local FirewallBody "=====> Device $Project <===== \n $FirewallEmailText";
/tool e-mail send server=$MailIp port=$MailPort tls=$MailTls from=$SendFrom to=$SendTo subject=$Subject body=$FirewallBody;
:delay 10s;
}
## Firewall Mail End
## DHCP Mail
:if ($DHCPEndID != $DHCPGlobalEndID && [:tobool $DHCPGlobalEndID ]) do={
:for DHCPKeyArray from=($DHCPStartID) to=($LenDHCPIDs-1) do={
:local DHCPIDMessage ($GetDHCPIDs -> $DHCPKeyArray);
:set DHCPEmailText "$DHCPEmailText \n $[/log get number=$DHCPIDMessage time] - $[/log get number=$DHCPIDMessage message] \n";
}
:local Uptime [/system resource get uptime ];
:local Project "DHCPv4 Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local DHCPBody "=====> Device $Project <===== \n $DHCPEmailText";
/tool e-mail send server=$MailIp port=$MailPort tls=$MailTls from=$SendFrom to=$SendTo subject=$Subject body=$DHCPBody;
:delay 5s;
}
## DHCP Mail End
:set SystemGlobalEndID $SystemEndID;
:set PPPoEGlobalEndID $PPPoEEndID;
:set ScriptGlobalEndID $ScriptEndID;
:set FirewallGlobalEndID $FirewallEndID;
:set DHCPGlobalEndID $DHCPEndID;
## Fox RouterOS Notification End