Community discussions

MikroTik App
 
fredericpi
just joined
Topic Author
Posts: 18
Joined: Mon Jan 30, 2023 6:38 pm

log info comment

Tue Feb 28, 2023 5:38 pm

Hello,

Without abusing your kindness, do you know how to recover a comment from a secret transformed into a variable for a log info?
Something like:
:log info "$secretComment is connected"

I’m desperately looking for a way to extract the comments from a L2TP secret to be able to see it in my logs, I've been searching for hours and days buc can't manage to get the coments to show up...
Thanks in advance for your help.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: log info comment

Tue Feb 28, 2023 6:36 pm

I've been searching for hours and days but can't manage to get the coments to show up...
Why do you do not ask on forum before?


If the l2tp-secret for example is this:
/ppp l2tp-secret
add address=1.5.4.6/32 comment=bau secret=miao

for retrieve the comment must be doed in this way:
:put [/ppp l2tp-secret get [find where secret="miao"] comment]

so is this:
:log info "$[/ppp l2tp-secret get [find where secret="miao"] comment] is connected"

or this:
{
:global retrCommFrmL2tpSecret do={:return [/ppp l2tp-secret get [find where secret=$1] comment]}
:local secretComment [$retrCommFrmL2tpSecret  "miao"]
:log info "$secretComment is connected"
}
 
fredericpi
just joined
Topic Author
Posts: 18
Joined: Mon Jan 30, 2023 6:38 pm

Re: log info comment

Tue Feb 28, 2023 7:27 pm

Thank you very much for your kindness and it's true that I tried to look before bothering everyone, it also allows you to learn but there I can't.

I may have misspoken I just want to extract how when a l2tp link disconnects where connects using the script in profile. I put a capture to better understand, I already use some variables to create logs which works well but I just miss adding the comment field in my logs.
You do not have the required permissions to view the files attached to this post.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: log info comment

Tue Feb 28, 2023 9:21 pm

Just checked, this, and not all the scripton picture, work after the 2nd disconnection.
On first disconnection do not work because is on cache the previous script, no matter if you hava changed it.

Try only with this:
:global retrCommFrmL2tpSecret do={:return [/ppp l2tp-secret get [find where secret=$1] comment]}
:local secretComment [$retrCommFrmL2tpSecret $user]
:log info "$secretComment is disconnected"
 
fredericpi
just joined
Topic Author
Posts: 18
Joined: Mon Jan 30, 2023 6:38 pm

Re: log info comment

Wed Mar 01, 2023 6:30 pm

I'm sorry but I tried and it didn't work for me.
I put you the complete code that I use the first part works but not yours.
the comment that I will recover and on a secret create in PPP and not L2TP secret I think it may differ I tried to modify but it does not work I do not understand
:local localAddr $"local-address"
:local remoteAddr $"remote-address"
:local callerId $"caller-id"
:local calledId $"called-id"
:local interfaceName [/interface get $interface name]
:local calledRealm "PI-VRF-4G"
:log info "$user (srcIp=$callerId, dstIp=$calledId) connected: was given $remoteAddr IP (GW $localAddr) and assigned to $interfaceName interface in VRF $calledRealm"
:global retrCommFrmL2tpSecret do={:return [/ppp secret get [find where secret=$1] comment]}
:local secretComment [$retrCommFrmL2tpSecret $user]
:log info "$secretComment is disconnected"
 
fredericpi
just joined
Topic Author
Posts: 18
Joined: Mon Jan 30, 2023 6:38 pm

Re: log info comment

Wed Mar 01, 2023 7:44 pm

I tried this with a variable I defined (which is correct) and the return is good.
:local secretComment [/ppp secret get [find where secret=test] comment]
:log info "$secretComment is disconnected"
I tried with a dynamic $user variable and there it doesn't work anymore I tried several possibilities:
:local secretComment [/ppp secret get [find where secret=$user] comment]
:log info "$secretComment is disconnected"
or
:local secretComment do={:return [/ppp secret get [find where secret=$user] comment]}
:log info "$secretComment is disconnected"
or
:local secretComment do={:put [/ppp secret get [find where secret=$user] comment]}
:log info "$secretComment is disconnected"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: log info comment

Wed Mar 01, 2023 7:48 pm

From your OP: ...comments from a L2TP secret... not "comment from a secret"

sabotaged code

:global retrCommFrmL2tpSecret do={:return [/ppp secret get [find where secret=$1] comment]}

Why you change arbitrarly the code????
I clearly write "/ppp l2tp-secret" and on example "If the l2tp-secret for example is this:" /ppp l2tp-secret [...] comment=bau [...]

If you want the comment on the secret itself:
:local secretComment [/ppp secret get $user comment]
:log info "$secretComment is disconnected"
 
fredericpi
just joined
Topic Author
Posts: 18
Joined: Mon Jan 30, 2023 6:38 pm

Re: log info comment

Wed Mar 01, 2023 9:35 pm

I'm sorry I misspoke it's true that I use secrets most of the time for L2TP services English is not my mother tongue so I made some syntax errors..

I tried with the different techniques that you had given me to find a code that responded and I shared my research I am trying at the same time to learn and understand the scripting mechanism of the Mikrotik programming language. I thank you for your help. I will try the code you gave me.

On the other hand, I don't understand the use of: global and the $1.
I'm trying a bit too hard to understand...

I'll get back to you tomorrow after my tests so that it can be used for others.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: log info comment

Wed Mar 01, 2023 11:32 pm

:global name do={ ... }
create a function called name for be used later,
and $1 is the first parameter you pass to the function.
On the last script is not present because for what you really want is useless.
 
fredericpi
just joined
Topic Author
Posts: 18
Joined: Mon Jan 30, 2023 6:38 pm

Re: log info comment

Thu Mar 02, 2023 5:03 pm

ok thank you very much I did some tests it works perfectly for me thank you for your help.
:local secretComment [/ppp secret get $user comment]
:log warning "$secretComment ($user) est connecté"
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: log info comment

Thu Mar 02, 2023 5:16 pm

For avoid problems (RouterOS do not support non-7bit-ASCII):
:local secretComment [/ppp secret get $user comment]
:log warning "$secretComment ($user) est connect\E9"

Who is online

Users browsing this forum: No registered users and 17 guests