Community discussions

MikroTik App
 
solar77
Long time Member
Long time Member
Topic Author
Posts: 586
Joined: Thu Feb 04, 2016 11:42 am
Location: Scotland

check non-active PPPoE users

Mon Mar 01, 2021 5:57 pm

trying to get a script to display non-active pppoe users. so far I've got
foreach pppuser in=[/ppp secret find ] do={
: local pppname [/ppp secret get $pppuser name]
:local ip [/ppp active get value-name=address [find name=$pppname]]

##; log warning $pppname
}
this will stop as soon as it find the first user that is not active.
I tried to use something like inside the foreach loop:
if ($ip!=true)
 do={:log warning "user Offline "}
but cannot get this to work. appreciate any help!

yes i know we should use a radius server. once I find the time to add it I will.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3343
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: check non-active PPPoE users

Mon Mar 01, 2021 7:08 pm

The secret can be used for PPPoE, L2TP, ++ and Any.
So its not easy to differentiate between what user is what. To see user who is online you can just look at active connection and PPPoE service.

Using Splunk you can graph the online users. Script would be ok if you only have PPPoE users.
 
solar77
Long time Member
Long time Member
Topic Author
Posts: 586
Joined: Thu Feb 04, 2016 11:42 am
Location: Scotland

Re: check non-active PPPoE users

Mon Mar 01, 2021 7:16 pm

thanks Jotne,

sorry I should have given more details.
it's PPPoE only. we do have a radius server but the short story is this router has not been added. believe me the script took me nearly 3 hours so far, if adding it to the radius is less time consuming I will do it.
I only need the scrip to run , when I logged into the Mikrotik and want to check which PPPoE user is NOT active.
there are 500+ users so I don't want to jump between secrets and active to find out which handful of routers are not active.
hence the reason for the script.

I did think outside the box, like kick everyone offline and watch the log off time but I would prefer not to do this if I can avoid it.
 
solar77
Long time Member
Long time Member
Topic Author
Posts: 586
Joined: Thu Feb 04, 2016 11:42 am
Location: Scotland

Re: check non-active PPPoE users

Mon Mar 01, 2021 7:55 pm

my current work around, is to go through the active list, get the username, use this username to find secret, then add a comment "online "on the secret,
then I can print out all secret that comment!=online

very messy but thats the best I've got so far.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3343
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: check non-active PPPoE users

Mon Mar 01, 2021 10:28 pm

This should give you a start.

Problem is that when you try to get status from a user that is not found in /ppp active, the command will fail and break the script.
To overcome this we do use on-error that will run when user is not online and command above fails.

This gives all user status
:local status
:foreach pppuser in=[/ppp secret find ] do={
	:local pppname [/ppp secret get $pppuser name]
	:do {
		:local tmp [/ppp active get [find where name="$pppname"]]
		:set status "online"
	} on-error={
		:set status "offline"
	}
	:put "$pppname is $status"
}
If you only like to list offline users.
:foreach pppuser in=[/ppp secret find ] do={
	:local pppname [/ppp secret get $pppuser name]
	:do {
		:local tmp [/ppp active get [find where name="$pppname"]]
	} on-error={
		:put $pppname
	}
}
To send it to the log:
:foreach pppuser in=[/ppp secret find ] do={
	:local pppname [/ppp secret get $pppuser name]
	:do {
		:local tmp [/ppp active get [find where name="$pppname"]]
	} on-error={
		:log warning "$pppname user is offline"
	}
}

Who is online

Users browsing this forum: No registered users and 7 guests