Splunk Search

Extract new fields from the existing field

fariapm1
Explorer

Hi,

I have this log line:
May 13 08:01:56 192.168.10.10 system_service: 192.168.10.10 05/13/2020:07:01:56 GMT : GUI CMD_EXECUTED : User test_user - Remote_ip 10.10.10.10 - Command "login login tenant_name=Owner,password=********,Secret=*****,challenge_response=*****,token=80410000cb49a9,client_port=-1,cert_verified=false,sessionid=********,session_timeout=0,permission=superuser" - Status "Done"

and I already have the Fields:
user: test_user
remote_ip: 10.10.10.10
command: "login login tenant_name=Owner,password=********,Secret=*****,challenge_response=*****,token=*****,client_port=-1,cert_verified=false,sessionid=********,session_timeout=0,permission=user"
status: "Done"

But I need to extract new fields from the existing field "command"
For now what I need is to create the field "event" with the fist word (Login and Logout)

Is there any way to Extract a field from an existing ? Or do I have to use the REX in Search?
I have this search, but the event field has no values

index=my_index (command=login* OR command=logout*)
| rex field=command "event:^(.*.Command)\s+\"(?P\w+)"
| table user,event, command,remote_ip, status, _time

| sort -_time

I've tested this regex expression and it return the value "login" from the log line above.

Any idea of what I'm doing wrong?

Regards,

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Your regex string was corrupted by the formatter, but it appears to be scanning the entire event (_raw) rather than just the command field. Try this rex command.

... | rex field=command "(?<event>\w+)" | ...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Your regex string was corrupted by the formatter, but it appears to be scanning the entire event (_raw) rather than just the command field. Try this rex command.

... | rex field=command "(?<event>\w+)" | ...
---
If this reply helps you, Karma would be appreciated.

fariapm1
Explorer

Bingo!!!

My Regex was for the full line and not for Command

Regards,
Pedro

0 Karma

harsmarvania57
Ultra Champion

Hi,

Please try below query

index=my_index (command=login* OR command=logout*)
| rex field=command "^\"(?<login_type>[\S]+)\s"
| table user, command, login_type ,remote_ip, status, _time

If you have whitespace in command field at start then try below query.

index=my_index (command=login* OR command=logout*)
| rex field=command "^\s\"(?<login_type>[\S]+)\s"
| table user, command, login_type ,remote_ip, status, _time
0 Karma

fariapm1
Explorer

Hi,

thanks for the reply.

On both searches, Fields "event" and "login_type" didn't return any value.

 user    event    login_type    remote_ip        status        _time
 user1                          192.168.10.10    Success        2020-05-13 08:07:06
 user1                          192.168.10.10    Success        2020-05-13 08:07:06
0 Karma

richgalloway
SplunkTrust
SplunkTrust

Please share your query.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...