Community discussions

MikroTik App
 
informant
newbie
Topic Author
Posts: 28
Joined: Wed Jul 22, 2015 10:33 am

send log entry to external website

Tue Jan 04, 2022 11:17 am

hi all, i would send a log entry to a external website, how can i do it with a script? can help anyhere? regards

script example:

if(pppoe user logged in)
open url(https://url.de/user=pppoeusername&ipv4= ... &time=time)

if(pppoe user logged out)
open url(https://url.de/user=pppoeusername&date=date&time=time)
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26368
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: send log entry to external website

Tue Jan 04, 2022 11:37 am

You can configure that ppp related logs are sent to remote syslog server, as per the documentation:
https://wiki.mikrotik.com/wiki/Manual:S ... og#Actions

You will need a syslog server for this
 
informant
newbie
Topic Author
Posts: 28
Joined: Wed Jul 22, 2015 10:33 am

Re: send log entry to external website

Tue Jan 04, 2022 11:48 am

hi, i wouldn´t use a syslog server i would use my own php server to code own on this, i need only a script to send this information or log entry line to my server url....
how can i do this?
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26368
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: send log entry to external website

Tue Jan 04, 2022 11:53 am

You can open the URL with "Fetch" tool, and trigger it based on script such as this:
viewtopic.php?t=158680#p823395
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: send log entry to external website

Tue Jan 04, 2022 12:05 pm

Why not syslog? Its created for that purpose: sending logs to other systems.
See my Splunk prosjekt in my signature for how to sending syslog and monitor your solution.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26368
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: send log entry to external website

Tue Jan 04, 2022 12:07 pm

Yes, otherwise, anyone can start messing with your logs :) this is a weird solution
Just make a syslog server and use your php page to display what you want
 
informant
newbie
Topic Author
Posts: 28
Joined: Wed Jul 22, 2015 10:33 am

Re: send log entry to external website

Tue Jan 04, 2022 12:08 pm

ok fine but iam a php coder and need help here. i have following at moment
:local ppptime [system clock get time]
:local pppdate [system clock get date]
:local startBuf [:toarray [/log find message~"logged in" && topics~"pppoe"]]
:if ([/log find message~"logged in" && topics~"pppoe"]) {
	/tool fetch keep-result=no url="https://myurl.de/?pppuser=???&ipv4=???&ipv6=???&ppptime=$ppptime&pppdate=$pppdate&status=connect"
}

:if ([/log find message~"logged out" && topics~"pppoe"]) {
	/tool fetch keep-result=no url="https://myurl.de/?pppuser=???&ppptime=$ppptime&pppdate=$pppdate&status=disconnect"
}
username, ipv4 and ipv6 failed. how can i get this out of log line entry? and do i must create a job for this or how i can start this well i need fetch every loggedin and loggedout but 1st time loggedin
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: send log entry to external website

Tue Jan 04, 2022 12:47 pm

If you look at my script here, you see how to search last 5 min to get some from the log. Run a script every 5 min.
viewtopic.php?p=743875#p743875

The Splunk page (signature link), there are a view to see status in graphics all PPPoE logged inn/out + much more. 100% free.
 
informant
newbie
Topic Author
Posts: 28
Joined: Wed Jul 22, 2015 10:33 am

Re: send log entry to external website

Tue Jan 04, 2022 2:30 pm

hi can i send it live if new entry comes send url?
 
User avatar
jvanhambelgium
Forum Veteran
Forum Veteran
Posts: 989
Joined: Thu Jul 14, 2016 9:29 pm
Location: Belgium

Re: send log entry to external website

Tue Jan 04, 2022 2:39 pm

hi can i send it live if new entry comes send url?
Nope, it is always a scheduled approach. You let the script run every X time (30sec / 1min / 5min) and process results.
So "near live" I guess
 
informant
newbie
Topic Author
Posts: 28
Joined: Wed Jul 22, 2015 10:33 am

Re: send log entry to external website

Tue Jan 04, 2022 2:46 pm

do mikrotik not have an eventhandler? for exsample newlogentry() or other?
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26368
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: send log entry to external website

Tue Jan 04, 2022 3:08 pm

Yes there is, it's called logging to syslog server :)
 
informant
newbie
Topic Author
Posts: 28
Joined: Wed Jul 22, 2015 10:33 am

Re: send log entry to external website

Tue Jan 04, 2022 3:21 pm

ok but not for scripting, i wouldnt install a syslog server only to get log entry in php, thats old and not directly well we dont need 3rd party on our programming. we code directly all. but only with working api and handler its works. 3rd party is not a option. :( or do you have a idea to use a syslog server only with sql and php? if yes we can uye but not windows syslog or others. thats not acceptable...
best way was a eventhandler thats starts if a filter was activated for exsample OnNewLogEntry() { and here my code to send log line to external url}
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3422
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: send log entry to external website

Tue Jan 04, 2022 4:22 pm

i wouldnt install a syslog server only to get log entry in php, thats old and not directly well we dont need 3rd party on our programming. we code directly all.
Isn't PHP kinda old too ;). And, I guess nothing would stop PHP from listen on the syslog port and parsing the data. If DIY solution is desired. Mikrotik does have hooks for stuff like DHCP, Netwatch, etc. that are well suited to using /tool/fetch to PHP in realtime – wish there were more "hooks" in ROS but there isn't. But nothing stops a scheduler script as poll quite often to push the data your PHP every few seconds I you want. The REST API could install one via PHP if desired.

But most people use some logging middleware that collects the logs, and then that's what provides an API to something like PHP to proved a view. And importantly these systems, index the logs and make them query-able by some SQL-like language thus readably usable by something like PHP (or NodeJS, Python, or whatever). Typically these tools have graphical or "low code" designers that are quite powerful to build complex UI that can remove the need for any code at all.

Anyway, most people don't use syslog directly – it's parsed and indexed typically. This because you typically don't want multiple external code to be fetching the same log data, and typically queries against a large log aren't that quick without indexing. While Splunk is great and free at low volume, but quite expensive at higher volume. The "ELK stack" is OSS, which proximates Splunk (and thus @Jotne scripts might be a great example) but is free. For a quick overview of ELK (which is three OSS project ElasticSearch, Logstach, Kabana) see: https://www.guru99.com/elk-stack-tutorial.html. If you had PHP, you replace the Kabana part of ELK with your own PHP.
 
User avatar
jvanhambelgium
Forum Veteran
Forum Veteran
Posts: 989
Joined: Thu Jul 14, 2016 9:29 pm
Location: Belgium

Re: send log entry to external website

Tue Jan 04, 2022 4:31 pm

ok but not for scripting, i wouldnt install a syslog server only to get log entry in php, thats old and not directly well we dont need 3rd party on our programming. we code directly all. but only with working api and handler its works. 3rd party is not a option. :( or do you have a idea to use a syslog server only with sql and php? if yes we can uye but not windows syslog or others. thats not acceptable...
best way was a eventhandler thats starts if a filter was activated for exsample OnNewLogEntry() { and here my code to send log line to external url}
AAA / Radius Accounting not an option ?
I guess the Mikrotik device will be using AAA/Radius for authenticating/accounting on these PPPoE incoming users ?
Can't you run a (Linux) freeradius and work from there. You can configure the Mikrotik to send out Radius-Accounting packets (start/stop) when users login etc.
 
informant
newbie
Topic Author
Posts: 28
Joined: Wed Jul 22, 2015 10:33 am

Re: send log entry to external website

Tue Jan 04, 2022 4:55 pm

hi freeradius we have but its very many entrys to use one ppp user, well you must add for every user over 10 entrys for working , we have not found a way to use for all same dns 1 + dns 2, same gateeay timeout session limits ... only we must add all for every users. also we use ppp user direct in mikrotik ccr but we need in database entryas of ips well ipv6 is dynamic and we must save user with date time and ipv6 if they used it.
if anyther have good technical to help in freeradius please wrote me :) thanks

Who is online

Users browsing this forum: clorichel and 22 guests