Community discussions

MikroTik App
 
User avatar
mxena
newbie
Topic Author
Posts: 48
Joined: Fri May 25, 2007 5:54 pm
Location: Catalonia
Contact:

Problem reading ethernet parameters via script

Fri Mar 23, 2012 6:03 pm

Dear all,

My goal is to create a script that checks if an ethernet is in full-duplex or linked at less rate and send an e-mail with the warning. I will post it when finished.

My first try was for reading running values from the ethernet:
:foreach i in=[/interface ethernet find running] do={
/interface ethernet monitor numbers=$i once do {
:if ($rate="100Mbps") do {
:put $status
:put $rate
#:put $auto-negotiation
#:put $full-duplex
}
}
}
My surprise is that I can read "status" and "rate" but I get a syntax error when I uncomment "auto-negotiation" and "full-duplex". Anyone knows why?

Thanks.
 
User avatar
c0d3rSh3ll
Long time Member
Long time Member
Posts: 557
Joined: Mon Jul 25, 2011 9:42 pm
Location: [admin@Chile] >

Re: Problem reading ethernet parameters via script

Fri Mar 23, 2012 9:55 pm

:foreach i in=[/interface ethernet find running] do={
/interface ethernet monitor numbers=$i once do {
:if ($rate="100Mbps") do {
:put $status
:put $rate
:put $"auto-negotiation"
:put $"full-duplex"
}
}
}
 
User avatar
mxena
newbie
Topic Author
Posts: 48
Joined: Fri May 25, 2007 5:54 pm
Location: Catalonia
Contact:

Re: Problem reading ethernet parameters via script

Sun Apr 01, 2012 10:35 pm

Thanks.
 
User avatar
mxena
newbie
Topic Author
Posts: 48
Joined: Fri May 25, 2007 5:54 pm
Location: Catalonia
Contact:

Re: Problem reading ethernet parameters via script

Tue Apr 03, 2012 5:55 pm

Here You have the full script.

For every ethernet set to auto-negotiation and running, the script checks the rate and full-duplex. If something is wrong send and e-mail. I have checked it in all situations: autoneg in 100Mbps and rate at 10Mbps, 1Gbps to 100Mbps and no full-duplex. And seems that it works.

I have placed it in all my aps and scheduled it every 3 hours. To disable it just unschedule the script or put the interface not to auto-negotiation.

In x86 plattforms all the ethernets appear as running spite there is no connection. In this case the script will alert about the unplugged interfaces. You can disable the unused ethernets or avoid using this script.

Thanks to c0d3rSh3ll for the help.
# For each ethernet connected and running
:foreach i in=[/interface ethernet find running] do={
#
# If configured at 100Mbps and auto-negotiation
# =============================================
:if ([/interface ethernet get $i speed]="100Mbps" and [/interface ethernet get $i auto-negotiation]=yes) do {
/interface ethernet monitor numbers=$i once do {
# If 10Mbps or without full-duplex send and e-mail
:if ($rate="10Mbps" or $"full-duplex"=false) do {
:put ("Ethernet with wrong auto-negotiation");
/tool e-mail send to="me@mycompany.com" subject=( "Ethernet with wrong auto-negotiation in " .  [/system identity get name] ) tls=yes;
:delay 10;
:log info ("Ethernet error emailed at " . [/sys cl get time] . " " . [/sys cl get date])
}
}
}
#
# If configured at 1Gbps and auto-negotiation
# ===========================================
:if ([/interface ethernet get $i speed]="1Gbps" and [/interface ethernet get $i auto-negotiation]=yes) do {
/interface ethernet monitor numbers=$i once do {
# If 100Mbps or without full-duplex send and e-mail
:if ($rate="10Mbps" or $rate="100Mbps" or $"full-duplex"=false) do {
:put ("Ethernet with wrong auto-negotiation");
/tool e-mail send to="me@mycompany.com" subject=( "Ethernet with wrong auto-negotiation in " .  [/system identity get name] ) tls=yes;
:delay 10;
:log info ("Ethernet error emailed at " . [/sys cl get time] . " " . [/sys cl get date])
}
}
}
}
 
User avatar
desertadmin
Member Candidate
Member Candidate
Posts: 232
Joined: Tue Jul 26, 2005 6:09 pm
Location: Las Vegas, New Mexico
Contact:

Re: Problem reading ethernet parameters via script

Tue Apr 17, 2012 11:00 am

Awesome script here is my version for just a 10/100 MT switch. We use the 493AHs at a lot of places. This script seems to help.
#Props to Mxena and  c0d3rSh3ll  revised by Desertadmin
:foreach i in=[/interface ethernet find running] do={
:if ([/interface ethernet get $i speed]="100Mbps" and [/interface ethernet get $i auto-negotiation]=yes) do {
/interface ethernet monitor numbers=$i once do {
# If 10Mbps or without full-duplex send and e-mail
:if ($rate="10Mbps" or $"full-duplex"=false) do {
:put ("Ethernet with wrong auto-negotiation");
/tool e-mail send to="ADMIN@ADDRESS.COM" subject=( "Ethernet trouble on " .  [/system identity get name] ) tls=yes body=("Interface: " . [/interface ethernet get $i name]);
:delay 10;
:log info ("Ethernet issue on ". [/interface ethernet get $i name]." emailed at " . [/sys cl get time] . " " . [/sys cl get date])
/interface ethernet set $i disable=yes;
:delay 2;
/interface ethernet set $i disable=no;
:delay 2;
/interface ethernet set $i auto-negotiation=yes;
:delay 2;
/interface ethernet set $i speed="100Mbps";
:delay 2;
/interface ethernet set $i full-duplex=yes;
}
}
}
}
:log info ("Script End @" . [/sys cl get time] . " " . [/sys cl get date])
-Sincerely,
DesertAdmin
 
User avatar
mxena
newbie
Topic Author
Posts: 48
Joined: Fri May 25, 2007 5:54 pm
Location: Catalonia
Contact:

Re: Problem reading ethernet parameters via script

Fri May 18, 2012 7:55 pm

Great! Detects the error and tryes to resolve it. Really nice.

Who is online

Users browsing this forum: mostfa228 and 52 guests