Заметки системного администратора

Скрипт измерения скорости между микротиками, с отправкой алертов на почту.

 

 Переменные:

testSpeed - максимальная скорость теста в мегабитах.
testAlert - минимальная скорость до алерта в мегабитах
duration - время тестирования каждого канала, в секундах
testuser - пользователь удаленного микротика с правами test (bandwishtest)
testpass - пароль пользователя удаленного микротика с правами test (bandwishtest)
sender - email отправителя
mailreciever - email получателя
mailServer - адрес mail сервера

 

:local testSpeed 30;
:local testAlert 20;
:local duration 60;

:local filials {
{ "description"="test1"; "ip"=192.168.1.2 };
{ "description"="test2"; "ip"=192.168.2.2 };
{ "description"="test3"; "ip"=192.168.3.2 };
};

:local testuser testusername;
:local testpass testP@ssword;
:local mailreciever rАдрес электронной почты защищен от спам-ботов. Для просмотра адреса в вашем браузере должен быть включен Javascript.;
:local sender sАдрес электронной почты защищен от спам-ботов. Для просмотра адреса в вашем браузере должен быть включен Javascript.;
:local mailServer mailServer.address;
:local message "";
:local subject "";
:local email "";
:local currentDate ([/system clock get date]." ".[/system clock get time]);
:local rxSpeed 0;
:local txSpeed 0;
:set subject (">>> Bandwidth report on ".$currentDate);
:log warning ($subject);
:foreach filial in=$filials do={
:do {
/tool bandwidth-test address=[:put ( $filial->"ip" );] duration=[:put ("$duration"."s")] protocol=tcp user=$testuser password=$testpass direction=both local-tx-speed=[:put ("$testSpeed"."M")] remote-tx-speed=[:put ("$testSpeed"."M")] do={ :set rxSpeed [$"rx-total-average"]; :set txSpeed [$"tx-total-average"]; }
:set rxSpeed ($rxSpeed/1048576);
:set txSpeed ($txSpeed/1048576);
:set message ($message("Speed to ".[:put ( $filial->"description" );].", IP: ".[:put ( $filial->"ip" );]." Rx: ".$rxSpeed." mbps".", Tx: ".$txSpeed." mbps"));
:if ($rxSpeed < $testAlert || $txSpeed < $testAlert) do={ :log error ($message); :set email ($email.("\r\n- $message")) } else={ :log warning ($message);}
} on-error={ :log warning (">>> Script error. Not found any IP"); }
}
:if ($email != "") do={/tool e-mail send to=$mailreciever subject="Speed Alert" body="Speedtest alerts on $currentDate:\r\nSpeed lower then $testAlert mbps\r\n$email" server=$mailServer from=$sender}
:log warning (">>> Test completed");