## Fox RouterOS Notification
:global SendSystemLog true;
:global SendPPPoELog true;
:global SendScriptLog true;
:global SendFirewallLog true;
:global SendDHCPLog true;
## Resolve Mail Server
:local MailServer "<smtp.xxx.com>"; # Need to customize
:local SendTo "<your-email-y@yyy.com>"; # Need to customize
:local MailTls "yes";
:local MailIp;
:onerror e {
:retry command={
:set MailIp [:resolve $MailServer ];
:delay 2s;
} delay=5 max=3;
} do={
# Failed to resolve mail server
:error ("Failed to resolve email server address...");
}
## End Resolve
## Shared Variables
:local DeviceName [/system identity get name ];
:local Uptime [/system resource get uptime ];
:local Time [/system clock get time ];
:local Date [/system clock get date ];
## End Shared variables
## System Mail
:if ($SendSystemLog) do={
:global SystemGlobalEndID;
:local SystemEmailText;
:local GetSystemIDs [/log find where buffer ~ "memory" && topics ~ "system" ];
:local LenSystemIDs [:len $GetSystemIDs ];
:if ($SystemGlobalEndID = nothing) do={:set SystemGlobalEndID ($GetSystemIDs -> 0)};
:local SystemStartID [:find $GetSystemIDs $SystemGlobalEndID ];
:local SystemEndID ($GetSystemIDs -> ($LenSystemIDs-1));
: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 message]\r>>> $[/log get number=$SystemIDMessage time] <<<\n";
}
:local Project "System Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local SystemBody "=====> Device $Project <=====\n$SystemEmailText";
/tool e-mail send server=$MailIp tls=$MailTls to=$SendTo subject=$Subject body=$SystemBody;
:set SystemGlobalEndID $SystemEndID;
:delay 5s;
}
}
## End System Mail
## PPPoE Mail
:if ($SendPPPoELog) do={
:global PPPoEGlobalEndID;
:local PPPoEEmailText;
:local GetPPPoEIDs [/log find where buffer ~ "memory" && topics ~ "pppoe" ];
:local LenPPPoEIDs [:len $GetPPPoEIDs ];
:if ($PPPoEGlobalEndID = nothing) do={:set PPPoEGlobalEndID ($GetPPPoEIDs -> 0)};
:local PPPoEStartID [:find $GetPPPoEIDs $PPPoEGlobalEndID ];
:local PPPoEEndID ($GetPPPoEIDs -> ($LenPPPoEIDs-1));
: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 message]\r>>> $[/log get number=$PPPoEIDMessage time] <<<\n";
}
:local Project "PPPoE Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local PPPoEBody "=====> Device $Project <=====\n$PPPoEEmailText";
/tool e-mail send server=$MailIp tls=$MailTls to=$SendTo subject=$Subject body=$PPPoEBody;
:set PPPoEGlobalEndID $PPPoEEndID;
:delay 5s;
}
}
## End PPPoE Mail
## Script Mail
:if ($SendScriptLog) do={
:global ScriptGlobalEndID;
:local ScriptEmailText;
:local GetScriptIDs [/log find where buffer ~ "memory" && topics ~ "script" ];
:local LenScriptIDs [:len $GetScriptIDs ];
:if ($ScriptGlobalEndID = nothing) do={:set ScriptGlobalEndID ($GetScriptIDs -> 0)};
:local ScriptStartID [:find $GetScriptIDs $ScriptGlobalEndID ];
:local ScriptEndID ($GetScriptIDs -> ($LenScriptIDs-1));
: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 message]\r>>> $[/log get number=$ScriptIDMessage time] <<<\n";
}
:local Project "Script Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local ScriptBody "=====> Device $Project <=====\n$ScriptEmailText";
/tool e-mail send server=$MailIp tls=$MailTls to=$SendTo subject=$Subject body=$ScriptBody;
:set ScriptGlobalEndID $ScriptEndID;
:delay 5s;
}
}
## End Script Mail
## Firewall Mail
:if ($SendFirewallLog) do={
:global FirewallGlobalEndID;
:local FirewallEmailText;
:local GetFirewallIDs [/log find where buffer ~ "memory" && topics ~ "firewall" ];
:local LenFirewallIDs [:len $GetFirewallIDs ];
:if ($FirewallGlobalEndID = nothing) do={:set FirewallGlobalEndID ($GetFirewallIDs -> 0)};
:local FirewallStartID [:find $GetFirewallIDs $FirewallGlobalEndID ];
:local FirewallEndID ($GetFirewallIDs -> ($LenFirewallIDs-1));
: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 message]\r>>> $[/log get number=$FirewallIDMessage time] <<<\n";
}
:local Project "Firewall Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local FirewallBody "=====> Device $Project <=====\n$FirewallEmailText";
/tool e-mail send server=$MailIp tls=$MailTls to=$SendTo subject=$Subject body=$FirewallBody;
:set FirewallGlobalEndID $FirewallEndID;
:delay 5s;
}
}
## End Firewall Mail
## DHCP Mail
:if ($SendDHCPLog) do={
:global DHCPGlobalEndID;
:local DHCPEmailText;
:local GetDHCPIDs [/log find where buffer ~ "memory" && topics ~ "dhcp" ];
:local LenDHCPIDs [:len $GetDHCPIDs ];
:if ($DHCPGlobalEndID = nothing) do={:set DHCPGlobalEndID ($GetDHCPIDs -> 0)};
:local DHCPStartID [:find $GetDHCPIDs $DHCPGlobalEndID ];
:local DHCPEndID ($GetDHCPIDs -> ($LenDHCPIDs-1));
: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 message]\r>>> $[/log get number=$DHCPIDMessage time] <<<\n";
}
:local Project "DHCPv4 Event";
:local Subject "$DeviceName $Project: [Uptime: $Uptime] [$Date $Time]";
:local DHCPBody "=====> Device $Project <=====\n$DHCPEmailText";
/tool e-mail send server=$MailIp tls=$MailTls to=$SendTo subject=$Subject body=$DHCPBody;
:set DHCPGlobalEndID $DHCPEndID;
:delay 5s;
}
}
## End DHCP Mail
## End Fox RouterOS Notification
版权归属:
Backspace
许可协议:
本文使用《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》协议授权
评论区