from the Mikrotik site
https://www.mikrotik.com/testdocs/ros/2.8/appex/scripting1.php
This should get you going with what you want to do.
In this example, we will monitor IP address on the *ether1* interface,
and if it is changed, send an e-mail:
/system script add name="changed-address" source={
:if ([/system scheduler get check run-count]<=1) do={
/system script run start-once
}
:global temp
:global b
:set temp $a
:set b [ \
/ip address get \
[/ip address find=interface=ether1] \
address \
]
:if ($temp != $b) do={
/tool e-mail send \
to=exam...@example.com \
subject="The dynamic IP gets changed"
:set a $b
}
}
/system script add name="start-once" source={
:global a
:set a [ \
/ip address get \
[/ip address find interface=ether1] \
address \
]
}
/system scheduler add name=check interval=1m on-event=changed-address
On 3/7/2016 2:22 PM, Christopher Tyler wrote:
I'm in need of a little scripting assistance. I'm trying to write a router
script that gets the current link speed of all the interfaces on a router and
compare that against the previous value that was received from that same script.
Below is the script that I have so far. Right now it loops through all of the interfaces,
checks to see if there is an active Ethernet link, then it gets the current rate and
compares it to the string "1Gbps", if it's not 1Gbps it then puts a message in
the log for for that interface. What I can't figure out is how to store a variable as
part of the variable name so that I can compare it to the current value to see if the
link changed, which is what I really want to know. But I need that stored value in order
to check against it, rather than the string 1Gbps.
:global identity ([/system identity get name])
:foreach interface in=[/interface ethernet find] do={
/interface ethernet monitor numbers=$interface once do={
:if ("$status" = "link-ok") do {
:if ("$rate" != "1Gbps") do {
:log info message=($name . " is set to " . $rate)
}}}}
This will eventually send an email, I just have it logging right now to keep my
inbox from getting flooded. And before anyone says it. Yes, I know that the
built in logging can do this, but we have over 100 routers and figuring out
which one sent out a message is not an entirely non-time consuming task, and I
ultimately we would like a little more information in the email than what the
logging system provides.
Any assistance is greatly appreciated.
--
Scott Reed
Wireless Networking
Network Design, Installation and Administration
Mikrotik Advanced Certified
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.butchevans.com/pipermail/mikrotik/attachments/20160307/688307dc/attachment.html>
_______________________________________________
Mikrotik mailing list
Mikrotik@mail.butchevans.com
http://mail.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik RouterOS