Syed Jahanzaib Personal Blog to Share Knowledge !

September 17, 2015

Monitoring multiple WAN links in PCC using BLACK-HOLE route approach !

Filed under: Mikrotik Related — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 12:18 PM

bh

Scenario:

Dual pppoe-client wan links are configured in mikrotik with PCC load balancing.

Task:

To monitor both (ow more) wan links via some fixed routes and email in case any goes down or take other action as required.

Solution:

You must be aware that to achieve any task, there are multiple ways to do so, Select whatever is best and whatever works for you (offcourse without affecting any other functionality). I tried various solutions to monitor pppoe-wan clients, but most of them didn’t worked as I wanted. So I used blackhole route approach and it worked 100%.

Example:

[This example is just for demonstration purpose only. In the real production environment you MUST use multiple host monitoring , because it is very possible that if you monitor single host, and for some reason ISP blocks it, or the owner of the host close it for maintenance then what happens? YES you will get false alarm even if the internet is working fine. To avoid such false alarms ,You must use multiple host to monitor each wan link I wrote multiple wan monitor script in some previous post, search it.)

For WAN-1 link we will monitor 4.2.2.1  [DNS Server]
For WAN-2 link we will monitor 208.67.222.123 [Open DNS server IP]

 

/ip route
add comment="WAN-1  /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=1 dst-address=4.2.2.1/32 gateway=pppoe-out1 scope=30 target-scope=10

add comment="WAN-2  /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=1 dst-address=208.67.222.123/32 gateway=pppoe-out2 scope=30 target-scope=10

PROBLEM:

The problem is that as soon as one WAN (pppoe-out1 disconnects for any reason like line dead etc, the PING will then look in main table and whatever route it found (example pppoe-out2) it will pass the traffic from that available wan link, and this is BAD for our monitoring script because we wanted to FORCE specific route to always pass via specific link only.

For this reason we will duplicate above routes, BUT this time we will use type ‘blackhole‘ and create higher distance value so that when default route FOR SPECIFIC MONITORED HOST goes down, then next route with higher distance value will be enabled automatically and will send packets to black-hole resulting in timeout which we will be using in net watch monitoring scripts.

 

add comment="WAN-1  blackhole /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=2 dst-address=4.2.2.1/32 type=blackhole

add comment="WAN-2  blackhole /  FORCED ROUTE FOR LINK MONITORING / ZAIB" disabled=no distance=2 dst-address=208.67.222.123/32 type=blackhole

So as soon as WAN1 goes down, the ping to 4.2.2.1 will go to BLACKHOLE / timeout dueto above rules. same for wan2.

 


Example script to monitor wan link and email or take other action

Complete script to monitor wan1 is as follows. Just for reference purposes.


# Syed Jahanzaib / aacable @ hotmail.com
# https://aacable.wordpress.com
# WAN Monitor script (for single host) and email if down/up
# Kindly configure tools/Email first to send email alert
# Modified on : 26-NOV-2015 added KANNEL sms support, on request of mr anotnino ITALY

:local i 0;
:local F 0;
:local date;
:local time;
:set date [/system clock get date];
:set time [/system clock get time];

:global DSL1netstatus;
:global DSL1netLastChange;

:local adminmail1 "YOUR MAIL ADDRESS"
:local gmailid "YOURGMAILID@gmail.com"
:local gmailpass "YOURGMAILPASS"

# If you have KANNEL , you can modify below

:local KANNEHOST "192.168.100.1"
:local KANNELID "kannel"
:local KANNELPASS "kannel"
:local cell1 "03333021909"

# Donot use spaces in following, instead use plus sign to accomodate space
:local COMPANY "MY_ISP_ZAIB"
:local UPSMS "$COMPANY+INFO:+WAN-1+is+UP+now+at+$date+$time"
:local DOWNSMS "$COMPANY+ALERT:+WAN-1+is+DOWN+now+at+$date+$time"


# Check WAN1 GATEWAY to be monitored (Currently we are monitoring internet host)
:global wan1host1 4.2.2.1

# Gmail SMTP Address
:global gmailsmtp
:set gmailsmtp [:resolve "smtp.gmail.com"];

# Ping Internet Host 10 times,
:for i from=1 to=10 do={
if ([/ping $wan1host1 count=1]=0) do={:set F ($F + 1)}
:delay 1;
};

# If no response (10 out of 10 Ping fails for each item, Times out, then LOG down status and take action
:if (($F=10)) do={
:if (($DSL1netstatus="UP")) do={
:set DSL1netstatus "DOWN";

# Also add status in global variables to be used as tracking
:set date [/system clock get date];
:set time [/system clock get time];
:set DSL1netLastChange ($time . " " . $date);


##################################################
####### FOR DOWN STATUS, CHANGE THE RULES ########
##################################################
# If the link is down, then LOG info and warning in Mikrotik LOG window [Zaib]
:log error "WAN1 Gateway Not Responding. Please Check DSL1 Connectivity..."


# "Emailing the DOWN status. . . "
/tool e-mail send to="$adminmail1" password=$gmailpass subject="$[/system clock get date] $[/system clock get time] -- ALERT: PTCL DSL-1 is DOWN" from=$gmailid server=$gmailsmtp tls=yes body="$[/system clock get date] $[/system clock get time] : ALERT: PTCL DSL-1 is DOWN"

# IF USB MODEM IS CONNECTED WITH LOCAL RB THEN USE FOLLOWING
#/tool sms send port=usb3 phone-number=$cell4  message="INFO: xxxxx Network DSL-1 is DOWN ... / by Jz."  channel=0

# IF YOU HAVE SMS GATEWAY LIKE KANNEL USE FOLLOWING
# Send DOWN SMS
#/tool fetch url="http://$KANNELHOST:13013/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$cell1&text=$DOWNSMS"


##################################################
####### FOR UP STATUS, CHANGE THE RULES ########
##################################################
# If ping is ok 5/5 reply received, then LOG UP and take action as required

} else={:set DSL1netstatus "DOWN";}
} else={
:if (($DSL1netstatus="DOWN")) do={
:set DSL1netstatus "UP";
# If link is UP, then LOG info and warning in Mikrotik LOG window [Zaib]
log warning "WAN1 Gateway RESTORED ..."

# "Emailing the UP  status. . . "
/tool e-mail send to="$adminmail1" password=$gmailpass subject="$[/system clock get date] $[/system clock get time] -- INFO: PTCL DSL-1 is UP Now." from=$gmailid server=$gmailsmtp tls=yes body="$[/system clock get date] $[/system clock get time] : ALERT: PTCL DSL-1 is UP Now."

# IF USB MODEM IS CONNECTED WITH LOCAL RB THEN USE FOLLOWING
#/tool sms send port=usb3 phone-number=$cell4  message="INFO: xxxxx Network DSL-1 is UP ... / by Jz."  channel=0

# IF YOU HAVE SMS GAETWAY LIKE KANNEL USE FOLLOWING
# Send UP SMS
#/tool fetch url="http://$KANNELHOST:13013/cgi-bin/sendsms?username=$KANNELID&password=$KANNELPASS&to=$cell1&text=$UPSMS"


:set date [/system clock get date];
:set time [/system clock get time];
:set DSL1netLastChange ($time . " " . $date);

} else={:set DSL1netstatus "UP";}
}

 

EMAIL ALERT

 

alerts

SMS ALERT

sms_alert

LOG

WAN_DOWN_ALERTS_LOGS

 

You can perform other customized actions on DOWN or UP  too 🙂

 

Regard’s
SYED JAHANZAIB

6 Comments »

  1. Reblogged this on SUMONCHAI .

    Comment by LAO — September 17, 2015 @ 1:26 PM

  2. The problem is that as soon as one WAN (pppoe-out1 disconnects for any reason like line dead etc,
    Or PING goes down from pppoe-out1….than auto RUN to Reboot Script VDSL Modem
    we want vdsl router goes reboot…………any problems solved……..!
    Plz….Sir write Script Allah aap ko jaza e khair dey………

    Comment by Salman — December 29, 2015 @ 6:08 AM

    • Sir….aap k iss article me redial pppoe ka script hai jo black ip honey ki sorat main to work kata hai …..Lekin modem hang honey per usey manually reboot karna parhta hai…1 sey 2 times in a day……

      Comment by Salman — January 8, 2016 @ 10:58 PM

  3. Bhai how to define ………..distance wan1-wa2-wan3
    you mention both wan distance 2 in this article

    Comment by Salman — January 2, 2016 @ 9:55 PM

  4. Sir….aap k Blackhole article me redial pppoe ka script hai jo black ip honey ki sorat main to work kata hai …..Lekin modem hang honey per usey manually reboot karna parhta hai…1 sey 2 times in a day……
    Kindly….write the reboot script for vdsl modem
    Allah aap ko jaza e khair de…..!

    Comment by Salman — January 8, 2016 @ 11:03 PM


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: