servers100
servers100
10.10.10.10
113.0.0.1
10.0.20.1
10.0.19.1
10.0.18.1
10.0.17.1
10.0.16.1
10.0.15.1
10.0.13.1
10.0.12.1
10.0.14.1
:do {
# LOG FILTER TO TELEGRAM BY AHMED MOUSELLY
# BEGIN SETUP Edit Here
:local myserver ([/system identity get name])
:local scheduleName "LogFilter"
:local bot "5778830696:AAF0SNevlZom-i9l7B3tDU4fY_bcGqcyQ4M"
:local ChatID "6397372473"
:local startBuf [:toarray [/log find message~" failure" || message~"loop" ||
message~"down" || message~"fcs" || message~"excessive"]]
# END SETUP
# warn if schedule does not exist
:if ([:len [/system scheduler find name="$scheduleName"]] = 0) do={
/log warning "[LogFilter] Alert : Schedule does not exist. Creating schedule ....";
/system scheduler add name=$scheduleName interval=60s start-date=Jul/05/2019 start-
time=startup on-event=LogFilter
/log warning "[LogFilter] Alert : Schedule created .";
}
# get last time
:local lastTime [/system scheduler get [find name="$scheduleName"] comment]
# for checking time of each log entry
:local currentTime
# log message
:local message;
# final output
:local output;
:local keepOutput false;
# if lastTime is empty, set keepOutput to true
:if ([:len $lastTime] = 0) do={
:set keepOutput true;
}
:local counter 0;
# loop through all log entries that have been found
:foreach i in=$startBuf do={
# loop through all removeThese array items
: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];
# LOG DATE
# depending on log date/time, the format may be different. 3 known formats
# format of jan/01/2002 00:00:00 which shows up at unknown date/time. Using as
default
:set currentTime [ /log get $i time ]
# format of 00:00:00 which shows up on current day's logs
:if ([:len $currentTime] = 8 ) do={
:set currentTime ([:pick [/system clock get date] 0 11]." ".$currentTime)
} else={
# format of jan/01 00:00:00 which shows up on previous day's logs
:if ([:len $currentTime] = 15 ) do={
:set currentTime ([:pick $currentTime 0 6]."/".[:pick [/system clock get date] 7
11]." ".[:pick $currentTime 7 15])
}
}
# if keepOutput is true, add this log entry to output
:if ($keepOutput = true) do={
:set output ($output.$currentTime." %0A%0A ".$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.$currentTimer." ".$message."\r\n")
}
}
}
:set counter ($counter + 1)
}
:if ([:len $output] > 0) do={
/system scheduler set [find name="$scheduleName"] comment=$currentTime
/tool fetch url="https://api.telegram.org/bot$bot/sendmessage?
chat_id=$ChatID&text=$myserver%0A%0A$output" keep-result=no;
}}
:local counter 0
# loop through all log entries that have been found
:foreach i in=$startBuf do={
# LOG DATE
# depending on log date/time, the format may be different. 3 known formats
# format of jan/01/2002 00:00:00 which shows up at unknown date/time. Using as
default
:set currentTime [ /log get $i time ]
# format of 00:00:00 which shows up on current day's logs
:if ([:len $currentTime] = 8 ) do={
:set currentTime ([:pick [/system clock get date] 0 11]." ".$currentTime)
} else={
# format of jan/01 00:00:00 which shows up on previous day's logs
:if ([:len $currentTime] = 15 ) do={
:set currentTime ([:pick $currentTime 0 6]."/".[:pick [/system clock get
date] 7 11]." ".[:pick $currentTime 7 15])
}
}
http-header-field="Content-Type: application/json"
/tool
{
:local username myuser
:local password mypass
:local ip 1.1.1.1
:local loginurl "https://$ip/api/auth"
:local statusurl "http://$ip/status.cgi"
##### mikrotik script to fetch the current signal strength from an lbe or af60
using cookie based authentication
/tool
{
:local username <user>
:local password <pass>
:local ip <lbeip>
:local loginurl "https://$ip/api/auth"
:local statusurl "https://$ip/status.cgi"
:local strData [fetch mode=https url=$loginurl http-method=post http-
data="username=$username&password=$password" output=user-with-headers as-value ];
:local headerData ([:toarray $strData ]->"http-headers");
:local headerData ($strData->"http-headers");
:local cookieData [:pick $headerData 4]
:local cookie [:pick $cookieData ([:find $cookieData " "]+1) [:find $cookieData
";"]]
:local header "content-type: application/json,Cookie: $cookie; ok=1" ;
:put $header
:set strData [fetch mode=https url=$statusurl http-method=get http-header-
field=$header output=user as-value ];
:set strData ($strData->"data");
:local startSignal [:pick $strData ([:find $strData "\"signal\":"]+9) [:len
$strData]]
:local signalStrenght [:pick $startSignal 0 [:find $startSignal ","]]
:put "Current signal strength = $signalStrenght"
}
# functions
:local "urlEncode" do={
:local "input" [:tostr $1];
:return $"ret";
}
:local "regExArr" {
# <p><a href="/graphs/">Main page</a>
{"re"=".*<a\\s+href=\"\\/graphs\\/\">.*";
"todo"={
{"find"="href=\"/graphs/"; "replace"=("href=\"".$"depth")};
{"find"="/\">"; "insert"=("/".$"indexHTML")}
}
};
{"re"=".*<a\\s+href='\\/graphs\\/'>.*";
"todo"={
{"find"="href='/graphs/"; "replace"=("href='".$"depth")};
{"find"="/'>"; "insert"=("/".$"indexHTML")}
}
};
{"re"=".*<a\\s+href=\\/graphs\\/>.*";
"todo"={
{"find"="href=/https/www.scribd.com/graphs/"; "replace"=("href=".$"depth")};
{"find"="/>"; "insert"=("/".$"indexHTML")}
}
};
:local "regExArrMainPage" {
# <li><a href='/graphs/iface/bridge/'>bridge</a>
{"re"="<li><a\\s+href=\"\\/graphs\\/(iface|queue)\\/.*\\/\">.*</a>";
"todo"={
{"find"="href='/"; "replace"=("href='".$"depth")};
{"find"="/\">"; "insert"=("/".$"indexHTML")};
{"find"="\">"; "margin"="<"; "types"={"/iface/";"/queue/"}}
}
};
{"re"="<li><a\\s+href='\\/graphs\\/(iface|queue)\\/.*\\/'>.*</a>";
"todo"={
{"find"="href='/"; "replace"=("href='".$"depth")};
{"find"="/'>"; "insert"=("/".$"indexHTML")};
{"find"="'>"; "margin"="<"; "types"={"/iface/";"/queue/"}}
}
};
{"re"="<li><a\\s+href=\\/graphs\\/(iface|queue)\\/.*\\/>.*</a>";
"todo"={
{"find"="href=/"; "replace"=("href=".$"depth")};
{"find"="/>"; "insert"=("/".$"indexHTML")};
{"find"="'>"; "margin"="<"; "types"={"/iface/";"/queue/"}}
}
}
}
:return $"resourcesURLs";
}
:local "graphPath";
:local "graphPathDST";
:local "resourcesURLs" [:toarray ""];
:local "ok" (true);
# Fetch main graphs page and build resources list based on main page URLs
:put "==> Fetching main page graphs... <==";
:set $"graphPathDST" ($"baseDST".$"outFolder");
/file remove [find name=$"graphPathDST"];
:foreach "file" in=$"rootFiles" do={
:if ($"ok") do={
:if ($"file"="") do={
:put (" ".$"baseURL"."graphs/");
:set $"resourcesURLs" [$"rebaseHTML" url=($"baseURL"."graphs/")
dstFile=($"graphPathDST".$"indexHTML") level=0];
:set $"ok" ($"resourcesURLs"!=false);
} else={
:put (" ".$"baseURL".$"file");
:do {
/tool fetch url=($"baseURL".[$"urlEncode" $"file"]) mode=http dst-
path=($"graphPathDST".$"file") output=file;
} on-error={ :set $"ok" (false); };
}
}
}
# Telegram Test
{
:global tgFunc
:global SymbolByUnicodeName
$tgFunc ("$[$SymbolByUnicodeName "calendar"] Telegram Test") ; # send OK
$tgFunc ("$[$SymbolByUnicodeName "calendar,memo"] Telegram Test") ; # Not OK
}
:do {
:global Symbols;
:local bot "5778830696:AAF0SNevlZom-i9l7B3tDU4fY_bcGqcyQ4M";
:local chatID "6397372473";
:set Symbols ("\E2\84\B9" . "\E2\8F\B0" . "\F0\9F\93\85" . "\F0\9F\97\83" . "\
F0\9F\94\8F" . "\F0\9F\94\97" . "\E2\9A\A0");
/tool fetch url="https://api.telegram.org/bot$bot/sendmessage\?
chat_id=$chatID&text=$Symbols" keep-result=no;} on-error={};
"chart-decreasing"="\F0\9F\93\89";
"chart-increasing"="\F0\9F\93\88";
"cloud"="\E2\98\81";
"cross-mark"="\E2\9D\8C";
"earth"="\F0\9F\8C\8D";
"fire"="\F0\9F\94\A5";
"floppy-disk"="\F0\9F\92\BE";
"high-voltage-sign"=;
"incoming-envelope"="\F0\9F\93\A8";
"information"="\E2\84\B9";
"large-orange-circle"="\F0\9F\9F\A0";
"large-red-circle"="\F0\9F\94\B4";
"link"="\F0\9F\94\97";
"lock-with-ink-pen"="\F0\9F\94\8F";
"memo"="\F0\9F\93\9D";
"mobile-phone"="\F0\9F\93\B1";
"pushpin"="\F0\9F\93\8C";
"scissors"="\E2\9C\82";
"sparkles"="\E2\9C\A8";
"speech-balloon"="\F0\9F\92\AC";
"up-arrow"="\E2\AC\86";
"warning-sign"="\E2\9A\A0";
"white-heavy-check-mark"="\E2\9C\85"]);
/tool fetch url="https://api.telegram.org/bot$bot/sendmessage\?
chat_id=$chatID&text=$Symbols" keep-result=no;} on-error={};