{"id":559,"date":"2017-04-12T16:07:10","date_gmt":"2017-04-12T12:07:10","guid":{"rendered":"http:\/\/blog.5flor.ru\/?p=559"},"modified":"2017-04-12T16:07:10","modified_gmt":"2017-04-12T12:07:10","slug":"%d0%9e%d0%bf%d0%be%d0%b2%d0%b5%d1%89%d0%b5%d0%bd%d0%b8%d0%b5-%d0%b0%d0%b4%d0%bc%d0%b8%d0%bd%d0%b8%d1%81%d1%82%d1%80%d0%b0%d1%82%d0%be%d1%80%d0%b0-%d0%be-%d0%b2%d1%85%d0%be%d0%b4%d0%b5-%d0%b2-mikrotik","status":"publish","type":"post","link":"https:\/\/blog.5flor.ru\/?p=559","title":{"rendered":"\u041e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043e \u0432\u0445\u043e\u0434\u0435 \u0432 Mikrotik"},"content":{"rendered":"<h3 class=\"post-title entry-title\">\u041e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043e \u0432\u0445\u043e\u0434\u0435 \u0432 Mikrotik.<\/h3>\n<div class=\"post-header\"><\/div>\n<div id=\"post-body-2423652667239979545\" class=\"post-body entry-content\">\n<div dir=\"ltr\">\u00a0 \u0421\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u041e\u043d \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043b\u043e\u0433\u0438 Mikrotik, \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u041d\u041e\u0412\u042b\u0425 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u0445\u043e\u0434\u0430 (\u0443\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0433\u043e) \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e &#8212; \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442 e-mail \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443. \u0421\u0430\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e-\u0431\u044b \u043e\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u043b &#171;\u043b\u0435\u0433\u0438\u0442\u0438\u043c\u043d\u044b\u0435&#187; \u0432\u0445\u043e\u0434\u044b \u0441 \u043d\u0430\u0448\u0438\u0445 IP, \u0430 \u043e\u0442\u0441\u044b\u043b\u0430\u043b \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432\u0445\u043e\u0434\u044b \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442\u0441\u044f \u0441 \u0447\u0443\u0436\u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432. \u0421\u043a\u0440\u0438\u043f\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432\u0441\u0435\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0441\u0442\u0430\u0440\u0442\u0430, \u0438 \u043f\u043e\u0442\u043e\u043c \u0432\u0441\u0435 \u043d\u0430\u0439\u0434\u0435\u043d\u044b\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0448\u043b\u0435\u0442 \u043d\u0430 \u0435-\u043c\u0435\u0439\u043b. \u041f\u0440\u043e\u0432\u0435\u0440\u0435\u043d \u043d\u0430\u00a06.37rc5.<br \/>\n<a name=\"more\"><\/a>\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0443 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b.<\/p>\n<blockquote><p>\u00a0 # BEGIN SETUP<br \/>\n# \u0438\u043c\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0432 scheduler<br \/>\n:local scheduleName &#171;on_login&#187;<br \/>\n# \u043c\u044b\u043b\u043e \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0442\u0447\u0435\u0442<br \/>\n:local emailAddress &#171;test@gmail.com&#187;<br \/>\n# \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043b\u043e\u0433\u0435 \u043f\u043e \u043c\u0430\u0441\u043a\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u043e\u0442\u0447\u0435\u0442<br \/>\n:local startBuf [:toarray [\/log find message~&#187;logged in&#187; || message~&#187;login failure&#187;]]<br \/>\n# \u0441\u043b\u043e\u0432\u0430-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0421\u044e\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0438 &#171;\u043b\u0435\u0433\u0438\u0442\u0438\u043c\u043d\u044b\u0435&#187; IP, \u0438\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0435\u0440\u0432\u0438\u0441\u044b \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f.<br \/>\n:local removeThese {&#171;telnet&#187;;&#187;192.168.88.27&#8243;}<br \/>\n# smtp \u0441\u0435\u0440\u0432\u0435\u0440<br \/>\n:local smtpserv [:resolve &#171;smtp.yandex.ru&#187;];<br \/>\n# \u043c\u044b\u043b\u043e \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u0441\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f<br \/>\n:local email &#171;mikrotik@yandex.ru&#187;;<br \/>\n# \u043f\u0430\u0440\u043e\u043b\u044c \u043a \u043c\u044b\u043b\u0443<br \/>\n:local pass SuperPass;<br \/>\n# END SETUP<br \/>\n# \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0435, \u0435\u0441\u043b\u0438 \u043d\u0435\u0442 &#8212; \u0432\u044b\u0434\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443 \u0432 \u043b\u043e\u0433<br \/>\n:if ([:len [\/system scheduler find name=&#187;$scheduleName&#187;]] = 0) do={<br \/>\n\/log warning &#171;[LOGMON] ERROR: Schedule does not exist. Create schedule and edit script to match name&#187;<br \/>\n}<br \/>\n# \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<br \/>\n:local lastTime [\/system scheduler get [find name=&#187;$scheduleName&#187;] comment]<br \/>\n# for checking time of each log entry<br \/>\n:local currentTime<br \/>\n# log message<br \/>\n:local message<\/p>\n<p># \u0432\u0432\u043e\u0434\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e output<br \/>\n:local output<br \/>\n:local keepOutput false<br \/>\n# if lastTime is empty, set keepOutput to true<br \/>\n:if ([:len $lastTime] = 0) do={<br \/>\n:set keepOutput true<br \/>\n}<\/p>\n<p>:local counter 0<br \/>\n# loop through all log entries that have been found<br \/>\n:foreach i in=$startBuf do={<\/p>\n<p># loop through all removeThese array items<br \/>\n:local keepLog true<br \/>\n:foreach j in=$removeThese do={<br \/>\n# \u00a0 if this log entry contains any of them, it will be ignored<br \/>\n:if ([\/log get $i message] ~ &#171;$j&#187;) do={<br \/>\n:set keepLog false<br \/>\n}<br \/>\n}<br \/>\n:if ($keepLog = true) do={<\/p>\n<p>:set message [\/log get $i message]<br \/>\n# \u00a0 LOG DATE<br \/>\n# \u00a0 depending on log date\/time, the format may be different. 3 known formats<br \/>\n# \u00a0 format of jan\/01\/2002 00:00:00 which shows up at unknown date\/time. Using as default<br \/>\n:set currentTime [ \/log get $i time ]<br \/>\n# \u00a0 format of 00:00:00 which shows up on current day&#8217;s logs<br \/>\n:if ([:len $currentTime] = 8 ) do={<br \/>\n:set currentTime ([:pick [\/system clock get date] 0 11].&#187; &#171;.$currentTime)<br \/>\n} else={<br \/>\n# \u00a0 \u00a0 format of jan\/01 00:00:00 which shows up on previous day&#8217;s logs<br \/>\n:if ([:len $currentTime] = 15 ) do={<br \/>\n:set currentTime ([:pick $currentTime 0 6].&#187;\/&#187;.[:pick [\/system clock get date] 7 11].&#187; &#171;.[:pick $currentTime 7 15])<br \/>\n}<br \/>\n}<\/p>\n<p># \u00a0 if keepOutput is true, add this log entry to output<br \/>\n:if ($keepOutput = true) do={<br \/>\n:set output ($output.$currentTime.&#187; &#171;.$message.&#187;\\r\\n&#187;)<br \/>\n}<br \/>\n# \u00a0 if currentTime = lastTime, set keepOutput so any further logs found will be added to output<br \/>\n# \u00a0 reset output in the case we have multiple identical date\/time entries in a row as the last matching logs<br \/>\n# \u00a0 otherwise, it would stop at the first found matching log, thus all following logs would be output<br \/>\n:if ($currentTime = $lastTime) do={<br \/>\n:set keepOutput true<br \/>\n:set output &#171;&#187;<br \/>\n}<br \/>\n}<br \/>\n# \u00a0 if this is last log entry<br \/>\n:if ($counter = ([:len $startBuf]-1)) do={<br \/>\n# \u00a0 If keepOutput is still false after loop, this means lastTime has a value, but a matching currentTime was never found.<br \/>\n# \u00a0 This can happen if 1) The router was rebooted and matching logs stored in memory were wiped, or 2) An item is added<br \/>\n# \u00a0 to the removeThese array that then ignores the last log that determined the lastTime variable.<br \/>\n# \u00a0 This resets the comment to nothing. The next run will be like the first time, and you will get all matching logs<br \/>\n:if ($keepOutput = false) do={<br \/>\n# \u00a0 \u00a0 if previous log was found, this will be our new lastTime entry<br \/>\n:if ([:len $message] &gt; 0) do={<br \/>\n:set output ($output.$currentTime.&#187; &#171;.$message.&#187;\\r\\n&#187;)<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n:set counter ($counter + 1)<br \/>\n}<br \/>\n# If we have output, save new date\/time, and send email<br \/>\nif ([:len $output] &gt; 0) do={<br \/>\n\/system scheduler set [find name=&#187;$scheduleName&#187;] comment=$currentTime<br \/>\n\/tool e-mail send server=$smtpserv port=587 user=$email password=$pass start-tls=yes to=&#187;$emailAddress&#187; from=$email subject=&#187;MikroTik alert $currentTime&#187; body=&#187;$output&#187;<br \/>\n\/log info &#171;[LOGMON] New logs found, send email&#187;<br \/>\n}<\/p><\/blockquote>\n<p>\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<div class=\"separator\"><a href=\"https:\/\/2.bp.blogspot.com\/--3deCxNkpN4\/V5Uji_DH-XI\/AAAAAAAAAhM\/uKfPftMk9tUzFVMQMUvu3KJ9x8qUEHgFQCLcB\/s1600\/Screenshot_4.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/2.bp.blogspot.com\/--3deCxNkpN4\/V5Uji_DH-XI\/AAAAAAAAAhM\/uKfPftMk9tUzFVMQMUvu3KJ9x8qUEHgFQCLcB\/s640\/Screenshot_4.jpg\" width=\"640\" height=\"160\" border=\"0\" \/><\/a><\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043e \u0432\u0445\u043e\u0434\u0435 \u0432 Mikrotik. \u00a0 \u0421\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u043d \u0434\u043b\u044f \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430. \u041e\u043d \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043b\u043e\u0433\u0438 Mikrotik, \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u041d\u041e\u0412\u042b\u0425 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432\u0445\u043e\u0434\u0430 (\u0443\u0434\u0430\u0447\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u043d\u0435\u0443\u0434\u0430\u0447\u043d\u043e\u0433\u043e) \u043d\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e &#8212; \u043e\u0442\u0441\u044b\u043b\u0430\u0435\u0442 e-mail \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443. \u0421\u0430\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e-\u0431\u044b &hellip; <a href=\"https:\/\/blog.5flor.ru\/?p=559\">\u0427\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u0435\u0435 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-559","post","type-post","status-publish","format-standard","hentry","category-mikrotik"],"_links":{"self":[{"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=\/wp\/v2\/posts\/559"}],"collection":[{"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=559"}],"version-history":[{"count":0,"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=\/wp\/v2\/posts\/559\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=559"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=559"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.5flor.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=559"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}