I’d like have to know if there is a script that check if ethernet interface is correctly at the right speed (f.e. 1Gb).
If it was wrong (f.e. 100Mb) shoulda try disable and enable that interface 3 times, if all three times doesn’t fix the issue, send an email
SO, i give you an example:
2 RB1100 connect each on ether 1, LAN SPEED 1000Mb. → EVERYTHING IS OK
NOW
ISSUE (NOT ALWAYS) that LAN at 100MB
TODAY SOLUTION
i manually disable and enable that interface… (8 on 10 times it fix the problem)
–
BEST SOLUTION: script that check if the LAN is at 1000Mb, if is 100Mb disable and enable interface, for 3 times… if it doesn’t works, send an email
Now that I have more time to answer, what I would do is setup a script that has two arrays in it… One telling the script which ethernet interfaces to check and the second telling the script what speed each interface should be at…
Then loop through the list of interfaces… check the speed that it is supposed to be at… if it is wrong cycle it… until either it is the correct speed OR you cycled it some number of times (say 8 or whatever you want) and give up…
Had a spare minute… THIS IS NOT TESTED… but should be pretty close…
Basically you set ethernetSpeeds to an array… where the key is the ethernet name… and the value is the targeted speed.
cycleNumber specifies how many times to try before it gives up, downtime specifies how long to keep the interface down, sleepBetween specifies how long to wait before the script checks again, and sendEmail is a boolean to send an email if the script hits the cycleNumber and is still not at the target speed.
But (and I know it’s not an error in your script) here in my testing environment, the speed reading always return “100Mbps”, no mater if the interface is at 10Mbps or 1Gbps.
Have you heard something about this ? It appears to be an routerOS FW issue, since there is no errors in your logic. I am using 6.36.2
Hmmm… can you give me access to the devices?.. I just want to see what data I can get off the interfaces. That’s really odd though? Email me efaden@gmail and I can try to figure out the right command to pull the data.
Efaden: sorry for answering just today, but the past few days we were working on a ceragon link and I barely had time to sit near a computer…
About the interface rate, I researched here and there and found a solution, which was use the “/interface ethernet monitor” command.
I worked in your code, added some code by my own, and the result:
The script checks if the interface speed matches the target speed for that interface
If yes, the script ends;
if not, it logs the event and start the reset procedure, logging every attempt;
If any attempt succeds, it logs it and stop trying;
if all the attempts failed, it also logs it and sends an email
Please, feel free to look into my code and if you have any improvements (I’m not as good as you are!) please suggest it for us !
PS: I’m brazilian, and maybe I forgot the translation of some variable or function from portuguese to english… the code are reviewed, but i’ts late here…
:local "ethernetSpeeds" { "eth_uplink_HP"="100Mbps" ; "ether2"="1Gbps" }
:local cycleNumber 3
:local downtime 2
:local sleepBetween 5
:local trying false;
#Define variables for sending email
:local mailServerName "PUT_YOUR_MAIL_SERVER_NAME_HERE";
:local mailServerIp [:resolve $mailServerName];
:local mailServerPort PUT_YOUR_MAIL_SERVER_PORT_HERE;
:local mailFrom "PUT_MAIL_FROM_HERE";
:local mailTo "PUT_MAIL_TO_HERE";
:local mailSubject "WRITE_YOUR_MAIL_SUBJECT_HERE";
:local mailUser "PUT_YOUR_MAIL_USER_HERE";
:local mailPass "PUT_YOUR_MAIL_PASSWORD_HERE";
:local mailBody "PUT_MAIL_BODY_HERE";
# define sendMail function
:global sendMail do={
/tool e-mail send server=$mailServerIp port=$mailServerPort from=$mailFrom to=$mailTo subject=$mailSubject body=$mailBody user=$mailUser password=$mailPass;
}
:foreach ethName,targetSpeed in=$ethernetSpeeds do={
/interface ethernet {
monitor $ethName once do { :set $currentSpeed $rate }
:local loopCounter 0
:if ($currentSpeed != $targetSpeed) do { :log info "Port $ethName current speed: $currentSpeed, target = $targetSpeed: [FAILURE]" }
:while (($currentSpeed != $targetSpeed) && ($loopCounter < $cycleNumber)) do={
:if (!trying) do { :log info "Starting interface reset procedure >>> " }
set $ethName disabled=yes
:delay $downtime
set $ethName disabled=no
:set $loopCounter ($loopCounter + 1)
:delay $sleepBetween
monitor $ethName once do { :set $currentSpeed $rate }
:if ($currentSpeed = $targetSpeed) do { :log info "Interface target speed restored." } else {
:log info "Attempt $loopCounter of $cycleNumber failed.";
:set $trying true;
:if ($loopCounter = $cycleNumber) do {
:log info "Trying to send email alert...";
$sendMail;
}
}
}
}
}
Out of interest, on 6.42.3 when I run that port speed query, I get the same - every Interface is 100Mbps except for sfp1 (CRS-125-24G-1S-2HnD) which is 1Gbps - and all interfaces are configured as “Auto” with all speeds advertised.
What’s even weirder is if I run it even with some ports set to “1Gbps Full” and not on Auto, I still get the reported speed being 100Mbps on all ether ports.