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]
For WAN-2 link we will monitor 208.67.222.123 [Open DNS server IP]
1
2
3
4
| /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.
1
2
3
| 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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| # Syed Jahanzaib / aacable @ hotmail.com # WAN Monitor script (for single host) and email if down/up # Kindly configure tools/Email first to send email alert :local i 0; :local F 0; :local date; :local time; :global DSL1netstatus; :global DSL1netLastChange; :local cell1 "03333021909" :local adminmail1 "YOUR MAIL ADDRESS" :local gmailid "YOURGMAILID@gmail.com" :local gmailpass "YOURGMAILPASS" # 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 5 times, :for i from=1 to=10 do={ if ([/ping $wan1host1 count=1]=0) do={:set F ($F + 1)} :delay 1; }; # If no response (5=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" #/tool sms send port=usb3 phone-number=$cell4 message="INFO: xxxxx Network DSL-1 is DOWN ... / by Jz." channel=0 ################################################## ####### 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." #/tool sms send port=usb3 phone-number=$cell4 message="INFO: xxxxx Network DSL-1 is UP ... / by Jz." channel=0 :set date [/system clock get date]; :set time [/system clock get time]; :set DSL1netLastChange ($time . " " . $date); } else={:set DSL1netstatus "UP";} } |
EMAIL ALERT
SMS ALERT
LOG
You can perform other customized actions on DOWN or UP too
0 comments:
Post a Comment