Tuesday, September 1, 2020

Mikrotik Netwatch Configuration

Netwatch tool, that monitors the status of a network or a link. At a certain point in time, this tool perform ping to a predefined network or a link. If for some reason this tool does not receive ping response from that link or network, it sends a notification in the form of email or SMS to the system admin or user. Whenever there is a change in the status of the link, a notification will be sent. Netwatch tool sends this notification with the help of some scripts. Whenever there is a change in the status of the link, the script related to that status will be started.

We will discuss the whole matter with the help of an example.

For example, we will monitor our gateway link. The IP of our gateway is 8.8.8.8. Whenever our gateway link will go down, we will get a notification in the form of SMS. In the same way, when the link will go up, the notification will come in the form of SMS.

To do this we will create two different scripts. One script will work if the link goes down and the other will work if the link goes up. And this link status will be checked by the "netwatch" tool.

The script for link down is: -

tool sms send message="link down" phone-number=your_mobile_number channel=your_channel_number port=Your_port

For example:-

tool sms send message="link down" phone-number=123456 channel=3 port=usb3


The script for link up is: -

tool sms send message="link up" phone-number=your_mobile_number channel=your_channel_number port=Your_port

For example:-

tool sms send message="link up" phone-number=123456 channel=3 port=usb3


In the same way, we can configure netwatch to send email notification. In that case, the script will be as follows:-


The script for link down is: -

tool e-mail send from="your_Email_Address" server=Your_imap_server user=your_user password=your_password subject="your_notification_message" to="recepient_address"

For example:-

tool e-mail send from="script@gmail.com" server=imap.gmail.com user=user_name password=your_password subject="link down" to="12345678"


The script for link up is: -

tool e-mail send from="your_Email_Address" server=Your_imap_server user=your_user password=your_password subject="your_notification_message" to="recepient_address"

For example:-

tool e-mail send from="script@gmail.com" server=imap.gmail.com user=user_name password=your_password subject="link up" to="12345678"


Below, the whole process is shown graphically: -

Connect your mikrotik via winbox. Then go to "Netwatch" from "Tools".



Now click on add (+) sign to create a new entry.


Now, our host address will be 8.8.8.8 (as per our example). Router will check this link by "1" minute interval. If the router doesn't get any response under 1000 millisecond, then the link will be considered as down.


Now, we are going to add "Up" script and "Down" script. If the link goes down, then down script will be executed and the same time, when the link will get back then the up script will be executed.
To add "Down" script, we have to navigate "Down" tab. And there we will write the script to send sms to mobile phone.


Now, to add "Up" script go to "Up" tab.


Finally then, click on "Apply" and then "Ok". The entry will be look like this:-


If we want we can use email notification. For that, just replace the sms script with the email script. If you want you can use both script. 

Screenshot for down script:-



Screenshot for up script:-


From now on, if the link status goes down, then it will execute "Down" script and when the link get back, then it will execute "Up" script.

Done.

No comments:

Post a Comment