Mikrotik - шлем уведомление о входе на роутер на почту
Создаем сервер, через который mikrotik будет слать сообщения:
Тут разрешаем
https://myaccount.google.com/lesssecureapps
В микротике:
snmp set enabled=yes
[admin@MikroTik] > /tool e-mail
[admin@MikroTik] /tool e-mail> set address=smtp.gmail.com
[admin@MikroTik] /tool e-mail> set port=587
[admin@MikroTik] /tool e-mail> set from=virtualcoin.videos@gmail.com
[admin@MikroTik] /tool e-mail> set user=virtualcoin.videos@gmail.com
[admin@MikroTik] /tool e-mail> set password=pass
Проверка
send to=test@gmail.com subject="Mikrotik test" body="email test" start-tls=yes
Добавляем скрипт
:local scheduleName "on_login"
:local emailAddress "test@gmail.com"
:local startBuf [:toarray [/log find message~"logged in" || message~"login failure"]]
:if ([:len [/system scheduler find name="$scheduleName"]] = 0) do={
/log warning "[LOGMON] ERROR: Schedule does not exist. Create schedule and edit script to match name"
}
:local lastTime [/system scheduler get [find name="$scheduleName"] comment]
:local currentTime
:local message
:local output
:local keepOutput false
:if ([:len $lastTime] = 0) do={
:set keepOutput true
}
:local counter 0
:foreach i in=$startBuf do={
:local keepLog true
:foreach j in=$removeThese do={
# if this log entry contains any of them, it will be ignored
:if ([/log get $i message] ~ "$j") do={
:set keepLog false
}
}
:if ($keepLog = true) do={
:set message [/log get $i message]
:set currentTime [ /log get $i time ]
:if ([:len $currentTime] = 8 ) do={
:set currentTime ([:pick [/system clock get date] 0 11]." ".$currentTime)
} else={
:if ([:len $currentTime] = 15 ) do={
:set currentTime ([:pick $currentTime 0 6]."/".[:pick [/system clock get date] 7 11]." ".[:pick $currentTime 7 15])
}
}
:if ($keepOutput = true) do={
:set output ($output.$currentTime." ".$message."\r\n")
}
:if ($currentTime = $lastTime) do={
:set keepOutput true
:set output ""
}
}
:if ($counter = ([:len $startBuf]-1)) do={
:if ($keepOutput = false) do={
:if ([:len $message] > 0) do={
:set output ($output.$currentTime." ".$message."\r\n")
}
}
}
:set counter ($counter + 1)
}
if ([:len $output] > 0) do={
/system scheduler set [find name="$scheduleName"] comment=$currentTime
/tool e-mail send to=$emailAddress subject="MikroTik alert $currentTime" body="$output" start-tls=yes
/log info "[LOGMON] New logs found, send email"
}
Добавляем Shedule
Name:
on_login
Event:
system script run notification
Комментарии
Отправить комментарий