Community discussions

MikroTik App
 
dakotabcn
newbie
Topic Author
Posts: 49
Joined: Thu Apr 21, 2016 11:16 pm

script send logs with l2tp connections no work

Fri Feb 04, 2022 4:11 pm

Hi all
Until recently this script that I put below worked fine but since I put 6.49 it has stopped working
The script was implemented in its day to send every night a list with the L2TP connections that happened during the day and the active connections at the time of sending the log
For some unknown reason it has stopped working and it is important that it works again
Apart from this we have now implemented SSTP connections or soon we hope to implement when we migrate to 7.1 wireguard or openvpn, how can we modify this script so that it logs all VPN connections?


###/log print file=ppplog.0.txt

:global voldvlist
:global l2tplist "L2TP interfaces \n \n"
:global vlist
:global int


:set l2tplist "$l2tplist SERVERS: \n" ;
:foreach int in=[/interface l2tp-server find] do={
:set l2tplist "$l2tplist L2TP: $[/interface l2tp-server get $int name] : $[/interface l2tp-server get $int running] \n" ;
:if ( [/interface l2tp-server get $int running] = true ) do={
:log error "L2TP: $[/interface l2tp-server get $int name] : true" ;
}
}

:set l2tplist "$l2tplist \n \n CLIENTS: \n" ;
:foreach int in=[/interface l2tp-client find] do={
:set l2tplist "$l2tplist L2TP: $[/interface l2tp-client get $int name] : $[/interface l2tp-client get $int running] \n" ;
:if ( [/interface l2tp-client get $int running] = true ) do={
:log error "L2TP: $[/interface l2tp-client get $int name] : true" ;
}
}
:set vlist "** Active VPN list ** \n \n \n $l2tplist"

:if ( $oldvlist != $vlist) do={
/tool e-mail send body="$vlist" subject="VPN" to="email1@server.com" file=ppplog.0.txt
:set voldvlist $vlist
:log error "VPN MCHard status list sent"
/tool e-mail send body="$vlist" subject="VPN" to="email2@server.com" file=ppplog.0.txt
:set voldvlist $vlist
:log error "VPN NewBlock status list sent"
:delay 30s
### /file remove ppplog.0.txt

} else={
:log error "VPN no change"
}


in the body of the email it puts this

** Active VPN list **


L2TP interfaces

SERVERS:
L2TP: <l2tp-User1VPN> : true


CLIENTS:


And an attached file with a text similar to this:

Jan/20/2022 01:55:47 l2tp,info first L2TP UDP packet received from 89.141.146.96
Jan/20/2022 01:55:47 l2tp,ppp,info,account User1VPN logged in, 192.168.xxx.3 from
Jan/20/2022 01:55:47 l2tp,ppp,info <l2tp-User1VPN>: authenticated
Jan/20/2022 01:55:47 l2tp,ppp,info <l2tp-User1VPN>: connected
Jan/20/2022 02:49:02 l2tp,info first L2TP UDP packet received from 146.88.240.4
Jan/20/2022 06:04:49 l2tp,info first L2TP UDP packet received from 81.184.153.91
Jan/20/2022 06:04:49 l2tp,ppp,info,account User2VPN logged in, 192.168.xxx.6 from
Jan/20/2022 06:04:49 l2tp,ppp,info <l2tp-User2VPN>: authenticated
Jan/20/2022 06:04:49 l2tp,ppp,info <l2tp-User2VPN>: connected
Jan/20/2022 07:49:54 l2tp,ppp,info <l2tp-User2VPN>: terminating...
Jan/20/2022 07:49:54 l2tp,ppp,info,account User2VPN logged out, 6306 15483745 193332136 271268 304635 from
Jan/20/2022 07:49:54 l2tp,ppp,info <l2tp-User2VPN>: disconnected
Jan/20/2022 09:09:35 l2tp,info first L2TP UDP packet received from 79.153.191.168
Jan/20/2022 09:09:35 l2tp,ppp,info,account McHard logged in, 192.168.xxxx.1 from
Jan/20/2022 09:09:35 l2tp,ppp,info <l2tp-User3>: authenticated
Jan/20/2022 09:09:35 l2tp,ppp,info <l2tp-User3>: connected

and t
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3295
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: script send logs with l2tp connections no work

Fri Feb 04, 2022 5:55 pm

I can not see any obvious reason for the script has stopped.
But please use code tags when post data </> button above the post.
I have reformatted the post and removed unneeded ; at the end of lines to make it easier to read.
###/log print file=ppplog.0.txt

:global voldvlist
:global l2tplist "L2TP interfaces \n \n"
:global vlist
:global int

:set l2tplist "$l2tplist SERVERS: \n"
:foreach int in=[/interface l2tp-server find] do={
	:set l2tplist "$l2tplist L2TP: $[/interface l2tp-server get $int name] : $[/interface l2tp-server get $int running] \n"
	:if ( [/interface l2tp-server get $int running] = true ) do={
		:log error "L2TP: $[/interface l2tp-server get $int name] : true"
	}
}

:set l2tplist "$l2tplist \n \n CLIENTS: \n"
:foreach int in=[/interface l2tp-client find] do={
	:set l2tplist "$l2tplist L2TP: $[/interface l2tp-client get $int name] : $[/interface l2tp-client get $int running] \n"
	:if ( [/interface l2tp-client get $int running] = true ) do={
		:log error "L2TP: $[/interface l2tp-client get $int name] : true"
	}
}
:set vlist "** Active VPN list ** \n \n \n $l2tplist"

:if ( $oldvlist != $vlist) do={
	/tool e-mail send body="$vlist" subject="VPN" to="email1@server.com" file=ppplog.0.txt
	:set voldvlist $vlist
	:log error "VPN MCHard status list sent"
	/tool e-mail send body="$vlist" subject="VPN" to="email2@server.com" file=ppplog.0.txt
	:set voldvlist $vlist
	:log error "VPN NewBlock status list sent"
	:delay 30s
	### /file remove ppplog.0.txt

} else={
	:log error "VPN no change"
}
PS
The Splunk tool that are in my signature do log all VPN both graphical and in table format. (and its free)

Who is online

Users browsing this forum: No registered users and 9 guests