Splunk Search

How to create regex for different pattern of data

seksit
Explorer

Hi everyone

I'm new splunk, I'm try to extract fields called username, clientip.

But some row of data start with "Invalid user (username)" , some row has only (username).

How can I create regex for this pattern data?

Sorry for my english 🙂

Thanks

Tags (2)
0 Karma
1 Solution

somesoni2
Revered Legend

This works fine for me. (things before the rex are just to generate sample data)

| gentimes start=-1 | eval temp="Thu Sep 29 2015 00:00:00 mailsv1 sshd[5276]: Failed password for invalid user appserver from 100.890.03.34 port 3351 ssh2#Thu Sep 29 2015 00:00:00 mailsv1 sshd[5276]: Failed password for root from 100.890.03.34 port 3351 ssh2" | table temp | makemv temp delim="#" | mvexpand temp | rename temp as _raw 
| rex "^(?:[^\s\n]* ){10}(invalid user )*(?P<username>\w+) from (?P<clientip>[^ ]+)"

View solution in original post

seksit
Explorer

Thanks everyone who came to help me.

0 Karma

somesoni2
Revered Legend

This works fine for me. (things before the rex are just to generate sample data)

| gentimes start=-1 | eval temp="Thu Sep 29 2015 00:00:00 mailsv1 sshd[5276]: Failed password for invalid user appserver from 100.890.03.34 port 3351 ssh2#Thu Sep 29 2015 00:00:00 mailsv1 sshd[5276]: Failed password for root from 100.890.03.34 port 3351 ssh2" | table temp | makemv temp delim="#" | mvexpand temp | rename temp as _raw 
| rex "^(?:[^\s\n]* ){10}(invalid user )*(?P<username>\w+) from (?P<clientip>[^ ]+)"

seksit
Explorer

Hi somesoni2,

Now I can extract this pattern by using your regex. Thanks you for your your advice.

0 Karma

kennybms
New Member

Something like this should do:

.. rex field=_raw "Invalid user (?<InvalidUser>.*\").*\" ..
0 Karma

3stimpson
Engager

Can you provide a snippet of the data in text format, with both formats included?

update: sorry scratch below, I didn't see the jpg
Better yet you can use the IFX tool to extract on your own...
http://docs.splunk.com/Documentation/Splunk/6.3.0/Knowledge/ExtractfieldsinteractivelywithIFX

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...