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:
1. The script checks if the interface speed matches the target speed for that interface
2. If yes, the script ends;
3. if not, it logs the event and start the reset procedure, logging every attempt;
4. If any attempt succeds, it logs it and stop trying;
4. 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;
}
}
}
}
}