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.
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.
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
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"
}
}