Monday, August 31, 2020

Mikrotik Send SMS

Mikrotik router send notifications of various information in the form of SMS to the admin related to the events of the network. And to send this SMS, mikrotik router has to be connected to the mobile network. We can easily do this connection using a USB modem. However, not all USB modems are supported by  mikrotik router. Mikrotik company has published a list of all the modems that will support, on their own website. The link is given below:-

https://wiki.mikrotik.com/wiki/Manual:Peripherals

However, many modems are available that are supported by the mikrotik router, not mentioned in this list. How to connect a modem to a router is discussed in detail in the link below.

https://mo-nirul.blogspot.com/2020/07/mikrotik-connect-usb-modem.html

After the modem is successfully connected to the router, we can send a message with the help of some script. These scripts will run when it will meet some criteria.

For example, we will monitor our gateway link using mikrotik's netwatch tool. 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

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:-



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