Manual:Tools/Netwatch: Difference between revisions
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
<div class=manual> | <div class=manual> | ||
==Summary== | |||
<p> | <p> | ||
Netwatch monitors state of hosts on the network. It does so by sending ICMP pings to the list of specified IP addresses. For each entry in netwatch table you can specify IP address, ping interval and console scripts. The main advantage of netwatch is it's ability to issue arbitrary console commands on host state changes. | Netwatch monitors state of hosts on the network. It does so by sending ICMP pings to the list of specified IP addresses. For each entry in netwatch table you can specify IP address, ping interval and console scripts. The main advantage of netwatch is it's ability to issue arbitrary console commands on host state changes. | ||
</p> | </p> | ||
==Properties== | |||
<p><b>Sub-menu:</b> <code>/tool netwatch</code></p> | <p><b>Sub-menu:</b> <code>/tool netwatch</code></p> | ||
Line 34: | Line 34: | ||
</table> | </table> | ||
==Status== | |||
<p> | <p> | ||
Command <code>/ip dhcp-client print</code> will show current status of netwatch and <b>read-only</b> properties listed in table below: | Command <code>/ip dhcp-client print</code> will show current status of netwatch and <b>read-only</b> properties listed in table below: | ||
Line 56: | Line 56: | ||
==Basic examples== | |||
<p> | <p> | ||
This example will run the scripts gw_1 or gw_2 which change the default gateway depending on the status of one of the gateways: | This example will run the scripts gw_1 or gw_2 which change the default gateway depending on the status of one of the gateways: | ||
Line 121: | Line 121: | ||
[[Category:Manual|N]] | [[Category:Manual|N]] | ||
[[Category:Tools|N]] |
Revision as of 10:16, 26 April 2010
Applies to RouterOS: v3, v4, v5
Summary
Netwatch monitors state of hosts on the network. It does so by sending ICMP pings to the list of specified IP addresses. For each entry in netwatch table you can specify IP address, ping interval and console scripts. The main advantage of netwatch is it's ability to issue arbitrary console commands on host state changes.
Properties
Sub-menu: /tool netwatch
Property | Description |
---|---|
down-script (string; Default: ) | Console script that is executed once when state of a host changes to down |
host (IP; 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 more responsive, but can create unnecessary traffic and consume system resources. |
up-script (string; Default: ) | Console script that is executed once when state of a host changes to up |
Status
Command /ip dhcp-client print
will show current status of netwatch and read-only properties listed in table below:
Property | Description |
---|---|
since (time) | Indicates when state of the host changed last time |
status (up | down | unknown) | Shows the current status of the host |
Basic examples
This example will run the scripts gw_1 or gw_2 which change the default gateway depending on the status of one of the gateways:
[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> print Flags: X - disabled # HOST TIMEOUT INTERVAL STATUS 0 10.0.0.217 997ms 10s up [admin@MikroTik] tool netwatch> print detail Flags: X - disabled 0 host=10.0.0.217 timeout=997ms interval=10s since=feb/27/2003 14:01:03 status=up up-script=gw_2 down-script=gw_1 [admin@MikroTik] tool netwatch>
Without scripts, netwatch can be used just as an information tool to see which links are up, or which specific hosts are running at the moment.
Let's look at the example above - it changes default route if gateway becomes unreachable. How it's done? There are two scripts. The script "gw_2" is executed once when status of host changes to up. In our case, it's equivalent to entering this console command:
[admin@MikroTik] > /ip route set [/ip route find dst 0.0.0.0] gateway 10.0.0.217
The /ip route find dst 0.0.0.0 command returns list of all routes whose dst-address value is 0.0.0.0. Usually, that is the default route. It is substituted as first argument to /ip route set command, which changes gateway of this route to 10.0.0.217
The script "gw_1" is executed once when status of host becomes down. It does the following:
[admin@MikroTik] > /ip route set [/ip route find dst 0.0.0.0] gateway 10.0.0.1
It changes the default gateway if 10.0.0.217 address has become unreachable.
Here is another example, that sends e-mail notification whenever the 10.0.0.215 host goes down:
[admin@MikroTik] system script> add name=e-down source={/tool e-mail send {... from="rieks@mt.lv" server="159.148.147.198" body="Router down" {... subject="Router at second floor is down" to="rieks@latnet.lv"} [admin@MikroTik] system script> add name=e-up source={/tool e-mail send {... from="rieks@mt.lv" server="159.148.147.198" body="Router up" {.. subject="Router at second floor is up" to="rieks@latnet.lv"} [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 detail Flags: X - disabled 0 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>
[ Top | Back to Content ]