Scripting Host and Complementary ToolsDocument revision 2.6 (Wed Nov 24 12:48:55 GMT 2004)This document applies to V2.8
Table of Contents
Table of ContentsSummarySpecificationsRelated Documents
Console Command SyntaxDescriptionNotesExample
Expression GroupingDescriptionNotesExample
VariablesDescriptionNotesExample
Command Substitution and Return ValuesDescriptionExample
OperatorsDescriptionCommand DescriptionNotesExample
Data typesDescription
Internal Console Expressions (ICE)DescriptionCommand Description
Special ActionsDescriptionNotesExample
Additional FeaturesDescription
ScriptsDescriptionProperty DescriptionCommand DescriptionNotesExample
Page 1 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
Task ManagementDescriptionProperty DescriptionExample
Script EditorDescriptionCommand DescriptionNotesExample
System SchedulerSpecificationsDescriptionProperty DescriptionNotesExample
Network Watching ToolSpecificationsDescriptionProperty DescriptionExample
Traffic MonitorSpecificationsDescriptionProperty DescriptionExample
SigwatchSpecificationsDescriptionProperty DescriptionNotesExample
General Information
Summary
Specifications
Packages required: system
Page 2 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
License required: level1Home menu level: /system scriptStandards and Technologies: NoneHardware usage: Not significant
Related Documents
•
Console Command Syntax
Description
• prefix :putpath /ping 10.0.0.1
• path
• path_args/ip firewall rule <name>
• action actions
• action_args/ping <ip address>
• params[=values]
Notes
path_argsaction_args prefix path action params :put (1
+ 2) ":pu" . "t") 3
Example
/ping 10.0.0.1 count=5
prefix /
action ping
action_args 10.0.0.1
params[=values] count=5
.. ip firewall rule input
path .. ip firewall rule
Page 3 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
path_args input
:for i from=1 to=10 do={:put $i}
prefix :
action for
action_args i
params[=values] from=1 to=10 do={:put $i}
/interface monitor-traffic ether1,ether2,ipip1
prefix /
path interface
action monitor-traffic
action_args ether1,ether2,ipip1
Expression Grouping
Description
Notes
admin@MikroTik] ip address> /user {{... /ip route{... print{... }Flags: X - disabled0 ;;; system default user
name="admin" group=full address=0.0.0.0/0
1 name="x" group=write address=0.0.0.0/0
2 name="y" group=read address=0.0.0.0/0
[admin@MikroTik] ip route>
/ip routeprint /user print
Example
user
Page 4 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
[admin@MikroTik] ip address> /user {{... add name=x password=y group=write{... add name=y password=z group=read{... print{... }Flags: X - disabled
0 ;;; system default username="admin" group=full address=0.0.0.0/0
1 name="x" group=write address=0.0.0.0/0
2 name="y" group=read address=0.0.0.0/0
[admin@MikroTik] ip address>
Variables
Description
• global - defined by action global, global variables can be accessed by all scripts and consolelogins on the same router. Variables are not kept across reboots.
• local - defined by action local, local variables are not shared with any other script, otherinstance of the same script or other console logins. Its value is lost when script finishes.
• loop index variables - defined within for and foreach statements, these variables are used onlyin do block of commands and are removed after command completes.
• monitor action - some monitor commands that have do part can also introduce variables.
set
Notes
Example
[admin@MikroTik] ip route> /[admin@MikroTik] > :global g1[admin@MikroTik] > :set g1 "this is global variable"[admin@MikroTik] > :put $g1this is global variable[admin@MikroTik] >
Command Substitution and Return Values
Page 5 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
Description
find /pingtime incr decr
add
Example
find
[admin@MikroTik] > /interface[admin@MikroTik] interface> find type=ether[admin@MikroTik] interface>[admin@MikroTik] interface> :put [find type=ether]*1,*2[admin@MikroTik] interface>
[admin@MikroTik] interface> enable [find type=ether][admin@MikroTik] interface>
Operators
Description
Command Description
- - unary minus. Inverts given number value.
- - binary minus. Substracts two numbers, two time values, two IP addresses or an IP address and anumber
! - logical NOT. Unary operator, which inverts given boolean value
/ - division. Binary operator. Divides one number by another (gives number) or a time value by anumber (gives time value).
. - concatenation. Binary operator, concatenates two string or append one list to another or appendsan element to a list.
^ - bitwise XOR. The argumens and the result are both IP addresses
~ - bit inversion. Unary operator, which inverts bits in IP address
* - multiplication. Binary operator, which can multiply two numbers or a time value by a number.
Page 6 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
& - bitwise AND The argumens and the result are both IP addresses
&& - logical AND. Binary operator. The argumens and the result are both logical values
+ - binary plus. Adds two numbers, two time values or a number and an IP address.
< - less. Binary operator which compares two numbers, two time values or two IP addresses.Returns boolean value
<< - left shift. Binary operator, which shifts IP address by a given amount of bits. The firstargument is an IP address, the second is an integer and the result is an IP address.
<= - less or equal. Binary operator which compares two numbers, two time values or two IPaddresses. Returns boolean value
> - greater. Binary operator which compares two numbers, two time values or two IP addresses.Returns boolean value
>= - greater or equal. Binary operator which compares two numbers, two time values or two IPaddresses. Returns boolean value
>> - right shift. Binary operator, which shifts IP address by a given amount of bits. The firstargument is an IP address, the second is an integer and the result is an IP address.
| - bitwise OR. The argumens and the result are both IP addresses
|| - logical OR. Binary operator. The argumens and the result are both logical values
Notes
Example
[admin@MikroTik] ip firewall rule forward> :put (10+1-6*2=11-12=2+(-3)=-1)false[admin@MikroTik] ip firewall rule forward> :put (10+1-6*2=11-12=(2+(-3)=-1))true[admin@MikroTik] ip firewall rule forward
[admin@MikroTik] interface> :put (!true)false[admin@MikroTik] interface> :put (!(2>3))true[admin@MikroTik] interface>
[admin@MikroTik] interface> :put (-1<0)true[admin@MikroTik] > :put (--1)1
[admin@MikroTik] interface> :put (~255.255.0.0)0.0.255.255[admin@MikroTik] interface>
Page 7 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
[admin@MikroTik] interface> :put (3s + 5s)8s[admin@MikroTik] interface> :put (10.0.0.15 + 0.0.10.0)ERROR: cannot add ip address to ip address[admin@MikroTik] interface> :put (10.0.0.15 + 10)10.0.0.25[admin@MikroTik] interface>
[admin@MikroTik] interface> :put (15 - 10)5[admin@MikroTik] interface> :put (10.0.0.15 - 10.0.0.3)12[admin@MikroTik] interface> :put (10.0.0.15 - 12)10.0.0.3[admin@MikroTik] interface> :put (15h - 2s)14h59m58s[admin@MikroTik] interface>
[admin@MikroTik] interface> :put (12s * 4)48s[admin@MikroTik] interface> :put (-5 * -2)10[admin@MikroTik] interface>
[admin@MikroTik] interface> :put (10s / 3)3s333.333ms[admin@MikroTik] interface> :put (5 / 2)2[admin@MikroTik] interface>
[admin@MikroTik] interface> :put (10.0.2.3<=2.0.3.10)false[admin@MikroTik] interface> :put (100000s>27h)true[admin@MikroTik] interface> :put (60s,1d!=1m,3600s)false[admin@MikroTik] interface> :put (bridge=routing)false[admin@MikroTik] interface> :put (yes=false)false[admin@MikroTik] interface> :put (true=aye)ERROR: cannot compare if truth value is equal to string[admin@MikroTik] interface>
[admin@MikroTik] interface> :put ((yes && yes) || (yes && no))true[admin@MikroTik] interface> :put ((no || no) && (no || yes))false[admin@MikroTik] interface>
[admin@MikroTik] interface> :put (10.16.0.134 & ~255.255.255.0)0.0.0.134[admin@MikroTik] interface>
Page 8 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
[admin@MikroTik] interface> :put (~((0.0.0.1 << 7) - 1))255.255.255.128[admin@MikroTik] interface>
[admin@MikroTik] interface> :put (1 . 3)13[admin@MikroTik] interface> :put (1,2 . 3)1,2,3[admin@MikroTik] interface> :put (1 . 3,4)13,4[admin@MikroTik] interface> :put (1,2 . 3,4)1,2,3,4[admin@MikroTik] interface> :put ((1 . 3) + 1)ERROR: cannot add string to integer number[admin@MikroTik] interface>
Data types
Description
•
•
•
•
•
•
•
0x
true false yes true no false
*
• d, day, days - one day, id est 24 hours
Page 9 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
• h, hour, hours - one hour
• m, min - one minute
• s - one second
• ms - one millisecond, id est 0.001 second
Internal Console Expressions (ICE)
Description
Command Description
beep - this action forces the built-in beeper to beep a signal for length seconds at frequency Hz.[admin@MikroTik] > :beep length=2s frequency=10000
[admin@MikroTik] >
delay - this action does nothing for a given amount of time. It takes one argument, an amount oftime to wait, which defaults to one second.
do - this action takes one argument, which holds the console commands that must be executed. It issimilar to the do statement of other commands. It has also two parameters, while and if. If noparameters are given, do just executes its payload once, which does not make much use. However ifyou specify a condition as a value for the while argument, it will be evaluated after executingcommands, and if it will return true, do statement is executed again and again until false. If youspecify a condition for the if argument, it is evaluated only once before doing anything else, and if itis false, nothing is done.[admin@MikroTik] > {:global i; :set i 10; :do{:put $i; :decr i;} \\... while (($i < 10) && ($i > 0)); :unset i;}10987654321[admin@MikroTik] >
environment print - this action prints information about variables. All global variables in thesystem are listed under the heading Global Variables. All variables that are introduced in this script(local variables introduced by :local or created by :for or :foreach statements, global variablesintroduced by :global, in short, all variables that can be used within the current script) are listedunder the heading Local Variables.[admin@MikroTik] > :environment printGlobal Variablesg1=this is global variable
Page 10 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
Local Variablesg1=this is global variablel1=this is local variablecounter=2[admin@MikroTik] >
for - this action takes one argument, the name of the loop variable. It has also four parameters,from, to, step and do. First two parameters indicate the borders for the loop counter. The intervalincludes these two values as well. The third one specifies the step of decrement (or increment).And, finally, the do statement holds console commands to repeat.[admin@MikroTik] > :for i from=1 to=100 step=37 do={:put ($i . " - " . 1000/$i)}1 - 100038 - 2675 - 13[admin@MikroTik] >
foreach - this action takes one argument, the name of the loop variable. It has also two parameters,in and do. The in argument is treated as a list with each value assigned to the loop variable, and dostatement executed for this value. If in value is not a list then do statement is executed only once. incase in value is empty, do statement is not executed at all. This way it is optimized to work withfind command, which returns lists of internal numbers, and may return an empty list or just oneinternal number. This example prints all ethernet interfaces, each followed by all addresses that areassigned to it:[admin@MikroTik] > :foreach i in=[/interface find type=ether ] do={{... :put [/interface get $i name]{... :foreach j in=[/ip address find interface=$i] do={{{... :put [/ip address get $j address]{{... }{... }ether1ether210.0.0.65/24[admin@MikroTik] >
if - this action takes one argument, a logical condition, id est an expression which must return aboolean value. It has also two parameters, do and else. If the logical condition is evaluated to truethen the part after the do parameter is executed, otherwise the else part takes place. Note, that elsepart is optional.[admin@MikroTik] > :if (yes) do={:put yes} else={:put no}true[admin@MikroTik] > :if ([/ping 10.0.0.1 count=1] = 0) do {:put "gw unreachable"}10.0.0.1 pong timeout1 packets transmitted, 0 packets received, 100% packet lossgw unreachable[admin@MikroTik] >
log - this action adds an entry to the system logs. It has two parameters, message which contains thestring needed to be added and facility which, in turn, specifies by which logging facility themessage should be logged. The facility parameter defaults to System-Info[admin@MikroTik] > :log facility=Firewall-Log message="Very Good \\... Thing happened. We have received our first packet!"[admin@MikroTik] >
put - this action takes one argument, which it echoes to console.
resolve - this action takes one argument, a DNS name and resolves it to the IP address of the host.You have to configure DNS settings on the router (/ip dns submenu) prior to using this action.[admin@MikroTik] ip route> /ip dns set primary-dns=159.148.60.2[admin@MikroTik] ip route> :put [:resolve www.example.com]192.0.34.166
Page 11 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
time - this action calculates the amount of time needed to execute given console commands. It takesone argument, which holds console commands the time action should be applied to. The commandsare executed once and the total amount of time taken is returned.[admin@MikroTik] > :put [:time {:delay}]1s34.31ms[admin@MikroTik] >
while - this action takes one argument, a logical condition, id est an expression which must return aboolean value. It has also one parameter, do. The logical condition is evaluated every time beforeexecuting do statement.[admin@MikroTik] > {:global i; :set i 0; :while ($i < 10) \\... do={:put $i; :incr i;}; :unset i;}0123456789[admin@MikroTik] >
Special Actions
Description
Monitor
monitor monitordo /system scripts
Get
printprint get get
Notes
do
get print
get
Example
Page 12 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
monitor
[admin@MikroTik] interface> monitor-traffic ether2 once do={:environment print}received-packets-per-second: 0
received-bits-per-second: 0bpssent-packets-per-second: 0
sent-bits-per-second: 0bps
Global Variablesi=1Local Variablessent-bits-per-second=0received-packets-per-second=0received-bits-per-second=0sent-packets-per-second=0[admin@MikroTik] interface>
Additional Features
Description
\a bell (alarm), character code 7\b backspace, character code 8\f form feed, character code 12\n newline, character code 10\r carriage return, character code 13\t tabulation, character code 9\v vertical tabulation, character code 11\_ space, character code 32
Note
Scripts
Home menu level: /system script
Description
•
•
•
Page 13 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
Property Description
last-started (time) - date and time when the script has been last invoked. The argument is shownonly if the run-count!=0.
owner (name; default: admin) - the name of the user who created the script
policy (multiple choice: ftp | local | policy | read | reboot | ssh | telnet | test | web | write; default:reboot,read,write,policy,test) - the list of the policies applicable:
• ftp - user can log on remotely via ftp and send and retrieve files from the router
• local - user can log on locally via console
• policy - manage user policies, add and remove user
• read - user can retrieve the configuration
• reboot - user can reboot the router
• ssh - user can log on remotely via secure shell
• telnet - user can log on remotely via telnet
• test - user can run ping, traceroute, bandwidth test
• web - user can log on remotely via http
• write - user can retrieve and change the configuration
run-count (integer; default: 0) - script usage counter. This counter is incremented each time thescript is executed. The counter will reset after reboot.
source (text; default: "") - the script source code itself
Command Description
run (name) - executes a given script
Notes
/user groupssh,local,telnet,read,write,policy,test,web
Example
[admin@MikroTik] system script> add name=log-test source={:log \\... message="Hello World!"}[admin@MikroTik] system script> print0 name="log-test" source=":log message="Hello World!"" owner="admin"
policy=reboot,read,write,policy,test last-started=dec/06/1999 20:07:37run-count=1
[admin@MikroTik] system script>
Task Management
Page 14 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
Home menu level: /system script job
Description
Property Description
name (read-only: name) - the name of the script to be referenced when invoking it
owner (text) - the name of the user who created the script
source (read-only: text) - the script source code itself
Example
[admin@MikroTik] system script> job print# SCRIPT OWNER STARTED0 DelayeD admin dec/27/2003 11:17:33
[admin@MikroTik] system script>
[admin@MikroTik] system script> job remove 0[admin@MikroTik] system script> job print
[admin@MikroTik] system script>
Script Editor
Command name: /system script edit
Description
Keyboard Shortcuts
• Delete - deletes character at cursor position
• Ctrl+h, backspase - deletes character before cursor. Unindents line
• Tab - indents line
• Ctrl+b, LeftArrow - moves cursor left
• Ctrl+f, RightArrow - moves cursor right
• Ctrl+p, UpArrow - moves cursor up
• Ctrl+n, DownArrow - moves cursor down
• Ctrl+a, Home - moves cursor to the beginning of line or script
• Ctrl+e, End - moves cursor to the end of line or script
• Ctrl+y - inserts contents of buffer at cursor position
• Ctrl+k - deletes characters from cursor position to the end of line
• Ctrl+u - undoes last action
Page 15 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
• Ctrl+o - exits editor accepting changes
• Ctrl+x - exits editor discarding changes
Command Description
edit (name) - opens the script specified by the name argument in full-screen editor
Notes
backspace, delete Ctrl+kCtrl+y
Example
System Scheduler
Specifications
Packages required: systemLicense required: level1Home menu level: /system schedulerStandards and Technologies: noneHardware usage: Not significant
Description
Property Description
interval (time; default: 0s) - interval between two script executions, if time interval is set to zero,the script is only executed at its start time, otherwise it is executed repeatedly at the time interval isspecified
name (name) - name of the task
on-event (name) - name of the script to execute. It must be presented at /system script
run-count (read-only: integer) - to monitor script usage, this counter is incremented each time thescript is executed
start-date (date) - date of the first script execution
Page 16 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
start-time (time) - time of the first script execution
Notes
run-count
move
Example
log-test
[admin@MikroTik] system script> add name=log-test source=:log message=test[admin@MikroTik] system script> print
0 name="log-test" source=":log messgae=test" owner=admin run-count=0[admin@MikroTik] system script> .. scheduler[admin@MikroTik] system scheduler> add name=run-1h interval=1hon-event=log-test[admin@MikroTik] system scheduler> print
Flags: X - disabled# NAME ON-EVENT START-DATE START-TIME INTERVAL RUN-COUNT0 run-1h log-test mar/30/2004 06:11:35 1h 0
[admin@MikroTik] system scheduler>
[admin@MikroTik] queue simple> add name=Cust0 interface=ether1 \\... dst-address=192.168.0.0/24 limit-at=64000[admin@MikroTik] queue simple> printFlags: X - disabled, I - invalid
0 name="Cust0" target-address=0.0.0.0/0 dst-address=192.168.0.0/24interface=ether1 limit-at=64000 queue=default priority=8 bounded=yes
[admin@MikroTik] queue simple> /system script[admin@MikroTik] system script> add name=start_limit source={/queue simple set \\... Cust0 limit-at=64000}[admin@MikroTik] system script> add name=stop_limit source={/queue simple set \\... Cust0 limit-at=128000}[admin@MikroTik] system script> print
0 name="start_limit" source="/queue simple set Cust0 limit-at=64000"owner=admin run-count=0
1 name="stop_limit" source="/queue simple set Cust0 limit-at=128000"owner=admin run-count=0
[admin@MikroTik] system script> .. scheduler[admin@MikroTik] system scheduler> add interval=24h name="set-64k" \\... start-time=9:00:00 on-event=start_limit[admin@MikroTik] system scheduler> add interval=24h name="set-128k" \\... start-time=17:00:00 on-event=stop_limit[admin@MikroTik] system scheduler> printFlags: X - disabled
# NAME ON-EVENT START-DATE START-TIME INTERVAL RUN-COUNT0 set-64k start... oct/30/2008 09:00:00 1d 01 set-128k stop_... oct/30/2008 17:00:00 1d 0
[admin@MikroTik] system scheduler>
Page 17 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
[admin@MikroTik] system script> add name=e-backup source={/system backup{... save name=email; /tool e-mail send to="[email protected]" subject=([/system{... identity get name] . " Backup") file=email.backup}[admin@MikroTik] system script> print0 name="e-backup" source="/system backup save name=ema... owner=admin
run-count=0
[admin@MikroTik] system script> .. scheduler[admin@MikroTik] system scheduler> add interval=7d name="email-backup" \\... on-event=e-backup[admin@MikroTik] system scheduler> printFlags: X - disabled# NAME ON-EVENT START-DATE START-TIME INTERVAL RUN-COUNT0 email-... e-backup oct/30/2008 15:19:28 7d 1
[admin@MikroTik] system scheduler>
/tool e-mail
[admin@MikroTik] tool e-mail> set server=159.148.147.198 [email protected][admin@MikroTik] tool e-mail> print
server: 159.148.147.198from: [email protected]
[admin@MikroTik] tool e-mail>
[admin@MikroTik] system script> add name=enable-x source={/system scheduler{... enable x}[admin@MikroTik] system script> add name=disable-x source={/system scheduler{... disable x}[admin@MikroTik] system script> add name=log-x source={:log message=x}[admin@MikroTik] system script> .. scheduler[admin@MikroTik] system scheduler> add name=x-up start-time=00:00:00 \\... interval=24h on-event=enable-x[admin@MikroTik] system scheduler> add name=x-down start-time=12:00:00\... interval=24h on-event=disable-x[admin@MikroTik] system scheduler> add name=x start-time=00:00:00 interval=1h \\... on-event=log-x[admin@MikroTik] system scheduler> printFlags: X - disabled# NAME ON-EVENT START-DATE START-TIME INTERVAL RUN-COUNT0 x-up enable-x oct/30/2008 00:00:00 1d 01 x-down disab... oct/30/2008 12:00:00 1d 02 x log-x oct/30/2008 00:00:00 1h 0
[admin@MikroTik] system scheduler>
Network Watching Tool
Specifications
Packages required: advanced-toolsLicense required: level1Home menu level: /tool netwatchStandards and Technologies: noneHardware usage: Not significant
Description
Page 18 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
Property Description
down-script (name) - a console script that is executed once when state of a host changes fromunknown or up to down
host (IP address; default: 0.0.0.0) - IP address of host that should be monitored
interval (time; default: 1s) - the time between pings. Lowering this will make state changes moreresponsive, but can create unnecessary traffic and consume system resources
since (read-only: time) - indicates when state of the host changed last time
status (read-only: up | down | unknown) - shows the current status of the host• up - the host is up
• down - the host is down
• unknown - after any properties of this list entry were changed, or the item is enabled ordisabled
timeout (time; default: 1s) - timeout for each ping. If no reply from a host is received during thistime, the host is considered unreachable (down)
up-script (name) - a console script that is executed once when state of a host changes fromunknown or down to up
Example
[admin@MikroTik] system script> add name=gw_1 source={/ip route set{... [/ip route find dst 0.0.0.0] gateway 10.0.0.1}[admin@MikroTik] system script> add name=gw_2 source={/ip route set{.. [/ip route find dst 0.0.0.0] gateway 10.0.0.217}[admin@MikroTik] system script> /tool netwatch[admin@MikroTik] tool netwatch> add host=10.0.0.217 interval=10s timeout=998ms \\... up-script=gw_2 down-script=gw_1[admin@MikroTik] tool netwatch> printFlags: X - disabled
# HOST TIMEOUT INTERVAL STATUS0 10.0.0.217 997ms 10s up
[admin@MikroTik] tool netwatch> print detailFlags: X - disabled
0 host=10.0.0.217 timeout=997ms interval=10s since=feb/27/2003 14:01:03status=up up-script=gw_2 down-script=gw_1
[admin@MikroTik] tool netwatch>
up
[admin@MikroTik] > /ip route set [/ip route find dst 0.0.0.0] gateway 10.0.0.217
/ip route find dst 0.0.0.0 dst-address 0.0.0.0/ip route set
Page 19 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
down
[admin@MikroTik] > /ip route set [/ip route find dst 0.0.0.0] gateway 10.0.0.1
[admin@MikroTik] system script> add name=e-down source={/tool e-mail send{... from="[email protected]" server="159.148.147.198" body="Router down"{... subject="Router at second floor is down" to="[email protected]"}[admin@MikroTik] system script> add name=e-up source={/tool e-mail send{... from="[email protected]" server="159.148.147.198" body="Router up"{.. subject="Router at second floor is up" to="[email protected]"}[admin@MikroTik] system script>[admin@MikroTik] system script> /tool netwatch[admin@MikroTik] system netwatch> add host=10.0.0.215 timeout=999ms \\... interval=20s up-script=e-up down-script=e-down[admin@MikroTik] tool netwatch> print detailFlags: X - disabled0 host=10.0.0.215 timeout=998ms interval=20s since=feb/27/2003 14:15:36
status=up up-script=e-up down-script=e-down
[admin@MikroTik] tool netwatch>
Traffic Monitor
Specifications
Packages required: advanced-toolsLicense required: level1Home menu level: /tool traffic-monitorStandards and Technologies: noneHardware usage: Not significant
Description
Property Description
interface (name) - interface to monitor
name (name) - name of the traffic monitor item
on-event (name) - script source. Must be present under /system script
threshold (integer; default: 0) - traffic threshold
traffic (transmitted | received; default: transmitted) - type of traffic to monitor• transmitted - transmitted traffic
• received - received traffic
Page 20 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
trigger (above | always | below; default: above) - condition on which to execute the script• above - the script will be run each time the traffic exceeds the threshold
• always - triggers scripts on both - above and below condition
• below - triggers script in the opposite condition, when traffic reaches a value that is lower thanthe threshold
Example
[admin@MikroTik] system script> add name=eth-up source={/interface enable ether2}[admin@MikroTik] system script> add name=eth-down source={/interface disable{... ether2}[admin@MikroTik] system script> /tool traffic-monitor[admin@MikroTik] tool traffic-monitor> add name=turn_on interface=ether1 \\... on-event=eth-up threshold=15000 trigger=above traffic=received[admin@MikroTik] tool traffic-monitor> add name=turn_off interface=ether1 \\... on-event=eth-down threshold=12000 trigger=below traffic=received[admin@MikroTik] tool traffic-monitor> printFlags: X - disabled, I - invalid
# NAME INTERFACE TRAFFIC TRIGGER THRESHOLD ON-EVENT0 turn_on ether1 received above 15000 eth-up1 turn_off ether1 received below 12000 eth-down
[admin@MikroTik] tool traffic-monitor>
Sigwatch
Specifications
Packages required: advanced-toolsLicense required: level1Home menu level: /tool sigwatchStandards and Technologies: noneHardware usage: Not significant
Description
Property Description
count (read-only: integer) - how many times the event for this item was triggered. Count is reset onreboot and on most item configuration changes
log (yes | no; default: no) - whether to add a message in form of name-of-sigwatch-item: signalchanged [to high | to low] to System-Info facility whenever this sigwatch item is triggered
name (name) - name of the sigwatch item
on-condition (on | off | change; default: on) - on what condition to trigger action of this item• on - trigger when state of pin changes to high
• off - trigger when state of pin changes to low
• change - trigger whenever state of pin changes. If state of pin changes rapidly, there might be
Page 21 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
triggered only one action for several state changes
port (name) - serial port name to monitor
script (name) - script to execute when this item is trigered
signal (dtr | rts | cts | dcd | ri | dsr; default: rts) - name of signal of number of pin (for standard9-pin connector) to monitor
• dtr - Data Terminal Ready (pin #4)
• rts - Request To Send (pin #7)
• cts - Clear To Send (pin #8)
• dcd - Data Carrier Detect (pin #1)
• ri - Ring Indicator (pin #9)
• dsr - Data Set Ready (pin #6)
state (read-only: text) - last remembered state of monitored signal
Notes
/system script
Example
serial1
[[email protected]] tool sigwatch> prFlags: X - disabled# NAME PORT SIGNAL ON-CONDITION LOG0 test serial1 cts change no
[admin@MikroTik] tool sigwatch>
print detail interval=1sstate on off
[admin@MikroTik] tool sigwatch> print detailFlags: X - disabled0 name="test" port=serial1 signal=cts on-condition=change log=no script=""
count=1 state=on
[admin@MikroTik] tool sigwatch> print detailFlags: X - disabled0 name="test" port=serial1 signal=cts on-condition=change log=no script=""
count=1 state=on
[admin@MikroTik] tool sigwatch> print detailFlags: X - disabled0 name="test" port=serial1 signal=cts on-condition=change log=no script=""
count=2 state=off
[admin@MikroTik] tool sigwatch> print detailFlags: X - disabled0 name="test" port=serial1 signal=cts on-condition=change log=no script=""
count=2 state=off
[admin@MikroTik] tool sigwatch>
port signal
Page 22 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.
[admin@MikroTik] port> print stats0 name="serial0" line-state=dtr,rts
1 name="serial1" line-state=dtr,rts[admin@MikroTik] port>
[admin@MikroTik] port> print stats0 name="serial0" line-state=dtr,rts
1 name="serial1" line-state=dtr,rts,cts[admin@MikroTik] port>
dtr rts cts
on-condition off
[[email protected]] tool sigwatch> pr detailFlags: X - disabled
0 name="cts_rest" port=serial1 signal=cts on-condition=off log=noscript=/system shutdown count=0 state=on
[[email protected]] tool sigwatch>
Page 23 of 23Copyright 1999-2006, MikroTik. All rights reserved. Mikrotik, RouterOS and RouterBOARD are trademarks of Mikrotikls SIA.
Other trademarks and registred trademarks mentioned herein are properties of their respective owners.