Splunk Search

Error in rex

geetanjali
Path Finder

Hi,

I am trying to extract fields using rex. I want to display graph according to guestname (kitoa01,kitoa05).

The log file path is :

C:\opt\app\samba\mnt\powersupply\kitoa01\KITOPS01

C:\opt\app\samba\mnt\powersupply\kitoa05\KITOPS05

And i have indexed data with host_segment=7. Bcoz KITOPS01,KITOPS05 are hostnames.If i am searching data by host,it is working fine.

but i need to extract by guest name.I am trying this query:

index="dummy" sourcetype="power_dummy" | rex field=source "(((?<kit>([^\]+))\)+?)" | search guest="$guestname$" | timechart max(Power_consumption) by host

its giving me error : Error in 'rex' command: Encountered the following error while compiling the regex '(((?<kit>([^\]+))\)+?)': Regex: syntax error in subpattern name (missing terminator)

Tags (1)
0 Karma

sideview
SplunkTrust
SplunkTrust

NOTE: I'm not positive but since it really sounded like you had backslashes in there instead of regular slashes, I took the liberty of editing your question to have backslashes in the search and in the error message from rex...

0 Karma

geetanjali
Path Finder

Yes. In actual path, there is backslash in path. i have used the same rex for extracting guest. but it is giving 0 matching result.

I am not very much aware of regular expression.
Please help.

0 Karma

sideview
SplunkTrust
SplunkTrust

I suspect that you meant to have backslashes in the rex instead of forward slashes, but that you used forward slashes because the answers site tends to swallow backslashes?

In the answers site you need to type two consecutive backslashes if you want the site to print a single backslash. UNLESS the text is wrapped in backtick characters (`) or indented with 4 spaces.

And the answer is somewhat similar in the search language -- in the rex command and in the search language in general, you have to type in two consecutive backslash characters whenever you mean to send a single backslash character. Hence the correct search to copy and paste should be:

index="dummy" sourcetype="power_dummy" | rex field=source "(((?<kit>([^\\]+))\\)+?)" | search guest="$guestname$" | timechart max(Power_consumption) by host
0 Karma

sideview
SplunkTrust
SplunkTrust

Try again - it looks like if you indent the code sample, the answers site stops requiring backslashes to be escaped. So I had accidentally double-escaped the backslashes. Try copying and pasting the search now.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...