Page 1 of 1

send log entry to external website

Posted: Tue Jan 04, 2022 11:17 am
by informant
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)

Re: send log entry to external website

Posted: Tue Jan 04, 2022 11:37 am
by normis
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

Re: send log entry to external website

Posted: Tue Jan 04, 2022 11:48 am
by informant
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?

Re: send log entry to external website

Posted: Tue Jan 04, 2022 11:53 am
by normis
You can open the URL with "Fetch" tool, and trigger it based on script such as this:
viewtopic.php?t=158680#p823395

Re: send log entry to external website

Posted: Tue Jan 04, 2022 12:05 pm
by Jotne
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.

Re: send log entry to external website

Posted: Tue Jan 04, 2022 12:07 pm
by normis
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

Re: send log entry to external website

Posted: Tue Jan 04, 2022 12:08 pm
by informant
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

Re: send log entry to external website

Posted: Tue Jan 04, 2022 12:47 pm
by Jotne
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.

Re: send log entry to external website

Posted: Tue Jan 04, 2022 2:30 pm
by informant
hi can i send it live if new entry comes send url?

Re: send log entry to external website

Posted: Tue Jan 04, 2022 2:39 pm
by jvanhambelgium
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

Re: send log entry to external website

Posted: Tue Jan 04, 2022 2:46 pm
by informant
do mikrotik not have an eventhandler? for exsample newlogentry() or other?

Re: send log entry to external website

Posted: Tue Jan 04, 2022 3:08 pm
by normis
Yes there is, it's called logging to syslog server :)

Re: send log entry to external website

Posted: Tue Jan 04, 2022 3:21 pm
by informant
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}

Re: send log entry to external website

Posted: Tue Jan 04, 2022 4:22 pm
by Amm0
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.

Re: send log entry to external website

Posted: Tue Jan 04, 2022 4:31 pm
by jvanhambelgium
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.

Re: send log entry to external website

Posted: Tue Jan 04, 2022 4:55 pm
by informant
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