Dashboards & Visualizations

Help In writing Regex for a dashboard

mayank101
New Member

I have may entries under the event field. I wanted a regex that separates extra out such as anything after GBP ,AMP
Eg - events

1 LOG-NOTIFYCMD-dce-<1SS4C413----> LOG-NOTIFYCMD-dce
2 LOG-NOTIFYCMD-abc-<1SS4C413---->LOG-NOTIFYCMD-abc
3 LOG-NOTIFYCMD-As1-<1SS4C413---->LOG-NOTIFYCMD-As1
.
.
.

Can you help me writing regex ,I am stuck in it.

Tags (1)
0 Karma

woodcock
Esteemed Legend

We have no idea what you mean. What is GBP (Great British Pound)? What is AMP (ampersand, amperes)? Why do this strings not appear in your event. This must be a troll.

0 Karma

jacobpevans
Motivator

Greetings @mayank101,

Assuming your data is in one line as you typed it and you want everything after and including CMD until the next space removed, you can trim it as such:

| makeresults
| eval _raw="1 LOG-NOTIFYCMD-dce- LOG-NOTIFYCMD-dce 2 LOG-NOTIFYCMD-abc-LOG-NOTIFYCMD-abc 3 LOG-NOTIFYCMD-As1-LOG-NOTIFYCMD-As1"
| eval _raw = replace(_raw, "CMD[^ ]+", "")
Cheers,
Jacob

If you feel this response answered your question, please do not forget to mark it as such. If it did not, but you do have the answer, feel free to answer your own post and accept that as the answer.
0 Karma

niketn
Legend

@mayank101 for the community to assist you better please add more details as to what you need to extract in the above event. Also what is the pattern before and after the text that you want to extract.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

mayank101
New Member

As I have mentioned in example....anything after CMD needs to be eliminated. And the pattern is that CMD is the last word in expression and they start with LOG.I have already given example to make it more clear.

0 Karma

niketn
Legend

@mayank101 well in your question you have mentioned GBP and AMP which is never present in your sample data. However, even if I assume you wanted to remove anything after CMD, the pattern would be CMD exist before the data to be removed and what should be there after data to be removed is taken out?

Does the text highlighted in red below need to be removed? Also whether you want to remove them or extract them or anonymize?

1 LOG-NOTIFYCMD- dce - LOG-NOTIFYCMD- dce 2 LOG-NOTIFYCMD- abc -LOG-NOTIFYCMD- abc 3 LOG-NOTIFYCMD- As1 -LOG-NOTIFYCMD- As1

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

mayank101
New Member

I want it to be extracted.Yes you are right it has to be extracted upto CMD.

Eg: event : LOG-NOTIFYCMD-dce-
LOG-NOTIFYCMD-`abc

Desired Result to be extracted: LOG-NOTIFYCMD
LOG-NOTIFYCMD

0 Karma

niketn
Legend

@mayank101 so still not clear. In a single event same text can occur several times and you need to extract all of them? Why? Please add context of what you have in data what you need to do for field extraction and once you have the field extracted how are you going to use it?

Is LOG_NOTIFYCMD going to be the same across or can it vary in your data, can you add sample?

Finally do try to understand that regular expression will be tightly coupled with the data you have and pattern in the data. So unless you explain your requirement correctly with correct data sample (you can definitely anonymize sensitive information so that regular expression does not change) for us to assist you better.

Following is a run anywhere example based on what you have described so far but I have no idea if this is really what you need and if you do, what would be the right use case for this?

|  makeresults
|  eval _raw="1 LOG-NOTIFYCMD- dce - LOG-NOTIFYCMD- dce 2 LOG-NOTIFYCMD- abc -LOG-NOTIFYCMD- abc 3 LOG-NOTIFYCMD- As1 -LOG-NOTIFYCMD- As1"
|  rex "(?<myfield>LOG-NOTIFYCMD)" max_match=0

Following is a more generic regular expression as per your data (with the same disclaimer that it may not work as per your expectations until you provide correct event samples and requirement for field extraction)

|  makeresults
|  eval _raw="1 LOG-NOTIFYCMD- dce - LOG-NOTIFYCMD- dce 2 LOG-NOTIFYCMD- abc -LOG-NOTIFYCMD- abc 3 LOG-NOTIFYCMD- As1 -LOG-NOTIFYCMD- As1"
|  rex "\s*(?<myfield>[^\-]+\-[^\-]+)\-\s[^\s]+" max_match=0

I would recommend you to try regex101.com for you to come up with regex extraction and understand the same (try sample of Reg Ex used above) . Or else use Interactive Field Extraction in Splunk (link to Step by Step IFX Splunk Documentation) where you let Splunk generate the RegEx based on the sample event and field value you highlight in the event.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

mayank101
New Member

I apologize niketnilay for being unclear. I will try to be more clear next time.

0 Karma

woodcock
Esteemed Legend

So try again. show us the raw events and a mockup of your desired final outcome.

0 Karma

woodcock
Esteemed Legend

Your use of extract is VERY unclear. Show the sample events and a mockup of the desire result. Then you won't need to use any words at all.

0 Karma

mayank101
New Member

I apologize woodcock for being unclear. I will try to be more clear next time.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...