Community discussions

 
User avatar
Splash
Member Candidate
Member Candidate
Topic Author
Posts: 151
Joined: Fri Oct 16, 2015 10:09 am
Location: Johannesburg, South Africa

Script: PPPOE Interface Monitoring Script

Wed Feb 24, 2016 10:25 am

Hello,

I wrote this script to help users determine when 1 or more of their PPPOE connections have failed. It is capable of monitoring 1 or more connections, for example a router running multiple ADSL Lines. I chose not to bother with email notifications as it wouldnt be helpful if the device only has 1 internet connection. One could add support for SMS as an option.

The script will log a message as well as control the user-led if it detects a problem. If no PPPOE links are up, the user-led will be off, If all PPPOE links are up, the user-led will be on, and if some are up and some are down it will blink.

Start with creating a user-led entry:
/system leds add leds=user-led type=off
# This script monitors the status of all pppoe connections, and reports their status through the user-led LED and logging.
# It automatically discovers all available pppoe interfaces.
# SynBurst 2016
# Version 1.5

# CONFIGURATION SETTINGS
# 1=ON; 0=OFF
# DEBUG = ALL OUTPUT
# ERROR = ONLY ERRORS

:local debug 0;
:local error 1;
:local prefix PPPOE;

#----STOP HERE----#

:local pppoeinfdown 0;
:local pppoeinfup 0;

:if ($debug = 1) do={:log info "[$prefix] Checking PPPOE Interface(s) Status"; }

:foreach i in=[/interface pppoe-client find] do={ 
     	/interface pppoe-client monitor $i once do={
     	:local name [/interface pppoe-client get $i name];

     	:if ($status = "connected") do={ 
			:set pppoeinfup (pppoeinfup +1); 
			:if ($debug = 1) do={ 
				:log info "[$prefix]$pppoecount $name - $status"; 
			} 
	}

     	:if ($status != "connected" ) do={ 
			:set pppoeinfdown (pppoeinfdown +1); 
			:if (($error = 1)  ||  ($debug = 1)) do={ 
				:log info "[$prefix]$pppoecount $name - $status"; 
			} 
	} 
     }
}

#NOW CHECK IF ITS ALL UP?
:local pppoetotal ($pppoeinfup + $pppoeinfdown);
:if ($debug = 1) do={ :log info "[$prefix] Total Interfaces Found = $pppoetotal"; }

:if ($pppoeinfup = 0) do={ 
	/system leds set [find leds=user-led] type=off; 
	:if (($error = 1)  ||  ($debug = 1)) do={ 
		:log error "[$prefix] ALL PPPOE Interfaces DISCONNECTED"; 
		} 
	}

:if ($pppoeinfdown = 0) do={ 
	/system leds set [find leds=user-led] type=on; 
	:if ($debug = 1) do={ 
		:log info "[$prefix] ALL PPPOE Interfaces OK"; 
		} 
	}

:if (($pppoeinfup > 0) && ($pppoeinfdown > 0) && ($pppoeinfdown < $pppoetotal)) do={ 
	:if (($error = 1)  ||  ($debug = 1)) do={ 
		:log warn "[$prefix] $pppoeinfdown PPPOE Interfaces DISCONNECTED"; 
		}

	:for i from=1 to=25 step=1 do={
		/system leds set [find leds=user-led] type=off; 
		:delay 1000ms;
		/system leds set [find leds=user-led] type=on; 
		:delay 1000ms;
	}
/system leds set [find leds=user-led] type=off; 
}

#The END

MTCNA, MTCRE, MTCINE, MTCTCE, MTCIPv6E, MTCUME

Who is online

Users browsing this forum: No registered users and 9 guests