-
Notifications
You must be signed in to change notification settings - Fork 26
/
RouterOS_Log_To_Alert.rsc
37 lines (26 loc) · 1.17 KB
/
RouterOS_Log_To_Alert.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
# RouterOS Function
# Copyright (c) Grzegorz Budny
# Version 1.0
# Last update: 2/8/2020
# Generates mail alarm based on log message match
:global LogToAlert do={
:local logMessage $message;
:local logFoundCount;
:local logArray;
:local alarmText;
:local logCount [/log print count-only where message~$logMessage];
:local systemName [/system identity get value-name=name];
:if ($logCount > 0) do={
:set $logArray [/log find where message~$logMessage];
:toarray value=$logArray;
:set logFoundCount [:len value=$logArray];
:log print file=$fileName where .id=($logArray->($logFoundCount-1));
:set alarmText [/log print where .id=($logArray->($logFoundCount-1))];
:log warning "$systemName triggered mail alarm";
/tool e-mail send server=$smtpServer port=$smtpPort from=($systemName.$domain) \
to=$recipient subject=($systemName." triggered an alarm!") body="Enclosed detected alarm log message" \
file=$fileName;
}
}
$LogToAlert message="message" fileName="fileName" smtpServer=smtpServer smtpPort=smtpPort domain="@example.com" \
recipient="[email protected]";