Tool: Using Splunk to analyse MikroTik logs 3.3 (Graphing everything) 💾 🛠 💻 📊

great guide
I need some first time help

I have done “almost” everything you said

this is what I have done in the login

/system logging action
set 3 remote=192.168.1.0
/system logging
add action=remote prefix=MikroTik topics=account
add action=remote prefix=MikroTik topics=critical

for now I want to see all the login attempts made to my router

I can see in the “MikroTik Admin user login” all the login (good and bad)
so I guess this working , now? right

I have also added the script - but I can’t see any data on router voltage\temp
the script in running without any problems - so why I don’t see in the the Splunk?

I can’t see any other data also in no page - everything is No results found. (even on router uptime, temp\voltage )
why is it?
the accounting is working

/ip accounting
set enabled=yes threshold=2560

do I need to enable something in the firewall so the server can read this data or something ?
**also why do I need to enable the accounting? , the data is send out from the router and not from the Splunk to the router - or I missunderstand soemthing?
Thanks ,

Remember with this:

add action=remote prefix=MikroTik topics=account
add action=remote prefix=MikroTik topics=critical

You only get all account and critical logs and nothing else from the internal logs.

That is what I do use:

/system logging add action=logserver prefix=MikroTik topics=dhcp
/system logging add action=logserver prefix=MikroTik topics=!debug,!packet,!snmp
/system logging add action=logserver prefix=MikroTik topics=hotspot

This gets all dhcp logs including debug dhcp packets.
This gets all hotspot logs including debug hotspot packets.
With the !, get all other logs that are not debug, packet and snmp.

Voltage and temperature are only on devices that do supports it.
Accounting is used to get all the packet flow from the router to Splunk.
Accounting is gone in v7, so there netflow has to be used. Not implemented in my solution, yet.

OK
I just saw you answer
I thought that on the RBM33G there is temp\voltage , but now I see there isn’t any

 :put [/system health get cpu-temperature ]

I can see the device now , I looked somewhere else

so if I want to see only spesific things I can only make logs for them ?
is there any where a WiKi or some explain about what each page can show and how he read it ?
for example -
this is what I get in the Device list

18.14.45.136	Test_Router	A2FFFFF71F31	RBM33G	RBM33G	6.48.2 (stable)	1

is there any way to change the first IP to some local variable to be sent?

You can send anything to logs, in for example this form.

:log info message="This is a test"

Then in splunk you should be able to see this by search for:

"This is a test"

great
I will try to see now what can I do with this

thank you !

*** I will ask if I will have more questions

more quetsions:
for my testing I only want to be able to see the MikroTik Admin user login block\OK
I have setup a loggin like this:

/system logging action
add name=Splunk remote=12.15.15.14 target=remote
/system logging
add disabled=yes topics=ovpn,debug
add action=DavidServer disabled=yes topics=warning
add action=Splunk prefix=MikroTik topics=account
add action=Splunk prefix=MikroTik topics=critical

when I put a wrong password I can see in the router logs “error login failure for user admin from 8.19.166.6 via winbox”
and on the splunk page I can see the line:

_time	host	user	system	user_ip	eventtype	host_name
2021-06-20 12:56:50	9.13.10.118	admin	winbox	 8.19.166.6	adm_user_login_failure	9.13.10.118

2 questions (help)
why I can’t see the name I setup in the identity for this router in the host name \ host user system?

is there any way to make the login send more information ? for example the MAC of the ethernet and put it in the host name?
I’m asing because my devices use dynamic IP - so the router IP give me nothing.

Thanks ,

Everything is already logged in menu Overview → MikroTik Admin user login.
There you see both logged inn and blocked user.

You have changed from the default log action setup and do loose a lot of information since you do only log some.
Change back to what is posted inn first post and you get all back.

This one logs all except: !debug,!packet,!snmp

/system logging add action=logserver prefix=MikroTik topics=!debug,!packet,!snmp

1st up, amazing effort, love this, so easy to setup and use, thank you.

I have a question though …

A lot of my nodes are LTE based devices, so they tend to change IP address quite frequently and as a result of that if i want to look at traffic utlisiation for the device, i need to collate all the stats from the various IPs.

Is there any way to aggregate the data at hostname level opposed to IP ?

Thanks

The app do use IP as hostname and do sort everything after that, so when IP changes, it will see it as a new device.

What can be done is to tag all packed with an id so that all router can be identified even after IP change.

Example, change from:

/system logging add action=logserver prefix=MikroTik topics=dhcp
/system logging add action=logserver prefix=MikroTik topics=!debug,!packet,!snmp
/system logging add action=logserver prefix=MikroTik topics=hotspot

To:

add action=logserver prefix="MikroTik: sys=22" topics=dhcp
add action=logserver prefix="MikroTik: sys=22" topics=!debug,!packet
add action=logserver prefix="MikroTik: sys=22" topics=hotspot

Use different number or name for the sys to distinguish each ruter.
Take care not use to long ID, since it eats of the max packet size.

Then you need to adapt the Splunk app to use sys instead of host
Its some work to do, but it will give you separate logs for each router based by the sys name.

another question
I notice that my all my device are sending data to another syslog system
so I have connected to the log file of it and sendting the data to the Splunk
it’s working - I get the data - but not as mikrotik (just as regular udp syslog )
is there anything I can change in the setting of the Splunk-Mikrotik to read that data?

this is what I’m getting on the splunk :

SEVERE 05/07 06:24:06 wrong message: 3.13.12.118 <27>Jul  5 09:24:06 Router script error: error - contact MikroTik support and send a supout file (2)

can I change the reading somehow so it will enter the splunk as Mikrotik ?

Thanks ,

If I understand you, you do not get the “MikroTik” prefix?

system,info,account > MikroTik> : sys=22: user hidden logged out from 1.2.3.4 via winbox

The whole app with field extraction etc are based on this tag, so If that changes or are removed, lots of the stuff inn the app must be rewritten.
Possible, but you need to try to figure it out.

Thank you so much Jotne this is an amazing tool you put together!
I am new to Mikrotik, just got the router 2 weeks ago.
I am wondering how you guys get the hostname to show in the screenshots? I have the IP address instead?

My Splunk host (=VM) just resolves these.
If you have a rather “static” small home-network, just add them to /etc/hosts or something on the Splunk host so your internal entries are resolved too.
If you run a Pihole or other DNS internal just let Splunk use that one and add the entries over there.

Some scripts run only once every day, so if you wait one day, it should be ok.

PS post image on the forum using Attachements below the post instead of posting a link.

Thank you editing the /etc/hosts does provide immediate name resolution.

I need to do some digging though: on the splunk host I seem to be experiencing local DNS issues:

me@docker01:~/scripts$ host 192.168.88.24
Host 24.88.168.192.in-addr.arpa. not found: 3(NXDOMAIN)
me@docker01:~/scripts$ ping DESKTOP-MESF01
ping: DESKTOP-MESF01: Temporary failure in name resolution
me@docker01:~/scripts$ ping DESKTOP-MESF01.local
PING DESKTOP-MESF01.local (192.168.88.24) 56(84) bytes of data.

Ah ok, you run Splunk in a container.
DNS resolving in a container is slightly different so I read. Perhaps you could try info below ?
On linux systems, DNS resolution happens using /etc/resolv.conf file, check this file inside your container, if it has invalid DNS, then your container won’t be able to resolve hostnames.

Docker uses a property set in /etc/docker/daemon.json file(on host) for populating entries in /etc/resolv.conf inside container.
update the value of this property in /etc/docker/daemon.json file in host machine:

{
“dns”: [“8.8.8.8”]
}
Note: This change requires restarting docker to take effect, also existing containers have to be removed and created again.

Restarting Docker:

sudo systemctl restart docker
removing containers:

sudo docker stop <container-name/id>
sudo docker rm <container-name/id>

oh I should have mentioned that the command line output I shared were directly from the docker host that runs the docker container. The DNS issues materialize on the physical machine and for some reasons name resolution only happen with the .local domain.

Anyway - I did not figure it out yet, but I am happy with the /etc/hosts solution. I actually find it better than DNS resolution because I can give more friendly name to my devices.

For those who are contemplating running splunk in docker, here is my script:

docker stop splunk-server 
docker rm splunk-server 
docker run -d \
-p 8000:8000 \
--name splunk-server \
-v /data/syslog/udp:/data/syslog/udp \
-v /data/syslog/tcp:/data/syslog/tcp \
-v /data/splunk/etc:/opt/splunk/etc \
-v /data/splunk/var:/opt/splunk/var \
-v /etc/localtime:/etc/localtime:ro \
-v /etc/hosts:/etc/hosts:ro \
-v ~/conf/input.conf:${SPLUNK_HOME}/etc/apps/MikroTik/default/input.conf \
-e SPLUNK_START_ARGS='--accept-license' \
-e SPLUNK_PASSWORD='XXXXXXXXXXX' \
--restart always \
splunk/splunk:latest

Script version 4.4

4.4 Removed on-error from wifi

4.4 Removed on-error from board info

Some small changes to error handling, no need for upgrade.

Splunk for MikroTik updated to v3.3

New file found under section 1g) at the first post

This version contains lots of tweaks and fixes, and some new KV store

To upgrade, delete the folder /splunk/etc/app/Mikrotik
Then install the unpacked spl (use winrar/winzip) file, install app from
"Manage app" -> "Install app from file"

To get the most out of this version, upgrade the script (not needed) on the router to latest version. (3.9+)

3.3 (13.08.2021)

New KV store (used to store info about Devices and DHCP info

Changed from table to fields in base search for all dashboard to speed up searches.

Added more DNS extraction

Updated script to 4.4 (Added firmware info)

Added frimware info "MikroTik Device List"

Fixed lookup "MikroTik Wifi strength"

Added new DoH dashboard "MikroTik DoH information"

Change table format "MikroTik Interface Changes"

Fixed typo in eventtype "MikroTik VPN Connections"

Added user local ip "MikroTik VPN Connections"

Fixed missing search in 2b, duplicate entry in user-name, added 1b login info "MikroTik VPN Connections"

Fixed to not show false logged in user "MikroTik VPN Connections"

Fixed html formatting in "Mikrotik DHCP to Static"

Fixed missing City in "Mikrotik Firewall Rules"

Moved "Mikrotik uPnP" to Connections menu

Added table view to "Mikrotik uPnP"

Thanks for the update Jotne.
I seems I've lost data on the "Overview" > "Device List" is not populating (as in "no result found")
All other tabs seems to work find, data is still coming in normally.
I'm running it on a RB3011 / 6.47.x release

If I look in the output on the console while the script is running, I'm only seeing this line : " script=version ver=4.4" where I normally would need to see more like

:log info message="s**cript=sysinfo version="$version**" board-name="$board" model="$model" serial=$serial identity="$identity" factory-firmware="$ffirmware" current-firmware="$cfirmware" upgrade-firmware="$ufirmware""



The previous script had this section

Collect system information

----------------------------------

:local model
:local serial
if ($SystemInformation and $run) do={
:local version ([/system resource get version])
:local board ([/system resource get board-name])
:do {
:set model ([/system routerboard get model])
:set serial ([/system routerboard get serial-number])
} on-error={
:set model na
:set serial na
}
:local identity ([/system identity get name])
:log info message="script=sysinfo version="$version" board-name="$board" model="$model" serial=$serial identity="$identity""
}

While you new script has this one

\

Collect system information

----------------------------------

:local model na
:local serial na
:local ffirmware na
:local cfirmware na
:local ufirmware na
:if ($SystemInformation and $run) do={
:local version ([/system resource get version])
:local board ([/system resource get board-name])
:if ([/system routerboard get routerboard]) do={
/system routerboard
:set model ([get model])
:set serial ([get serial-number])
:set ffirmware ([get factory-firmware])
:set cfirmware ([get current-firmware])
:set ufirmware ([get upgrade-firmware])
}
:local identity ([/system identity get name])
:log info message="script=sysinfo version="$version" board-name="$board" model="$model" serial=$serial identity="$identity" factory-firmware="$ffirmware" current-firmware="$cfirmware" upgrade-firmware="$ufirmware""
}