Splunk Search

Extract help...

a212830
Champion

Hi,

We log our filesystem utilization to Splunk, and I'd like to extract percentage used field, but the formats for Windows/*Nix are different. Was wondering if there are any regex experts out there that could take the two examples and create a universal regex that grabs the percent used utilization:

Nix (percentage is after "Use%")
14:42:21 05/05/2015 good 1048593817 [Linux][Baseline][SERVERA][FileSystem][/tmp] FileSystems\/tmp\Use%=1% 11:33243 0 1

Windows (percentage is after bracket and before %full):
14:56:34 05/05/2015 good 1039182967 [Windows][Baseline][ei0610vwin][DriveSpaceFree][C-MBFree] 93.414% full, 3372MB free, 51197MB total 2:251 93.414 3372

TIA...

Tags (2)
0 Karma

stephanefotso
Motivator

Hello! Here is what you can do. Working both for Windows/*Nix filesystems!

.....|rex field=_raw "^[^\n]*Use\%=(?P<tmpuse>\d+)"|rex field=_raw "^(?:[^ \n]* ){1,8}(?P<tmpuse>[0-9.]+)\%\s*full"|table tmpuse

Thanks!

SGF
0 Karma

a212830
Champion

This gave me an error - perhaps something was translated when posting? Is there a way to make this an extract?

0 Karma

stephanefotso
Motivator

Here is what to type.

|rex field=_raw "^[^\n]Use\%=(?P<tmpuse>\d+)"|rex field=_raw "^(?:[^ \n] ){1,8}(?P<tmpuse>[0-9.]+)\%\s*full"|table tmpuse

SGF
0 Karma

a212830
Champion

Thanks, not working though. Comes back blank.

0 Karma

stephanefotso
Motivator

The problem is the text editor. replace "&lt;" with < and "&gt;"with > in the code bellow
...|rex field=_raw "^[^\n]Use%=(?P&lt;tmpuse&gt;d+)"|rex field=_raw "^(?:[^ \n] ){1,8}(?P&lt;tmpuse&gt;[0-9.]+)\%s*full"|table tmpuse

SGF
0 Karma

a212830
Champion

Tried that:

|rex field=_raw "^[^\n]Use%=(?P&lt;tmpuse&gt;d+)"|rex field=_raw "^(?:[^ \n] ){1,8}(?P&lt;tmpuse&gt;[0-9.]+)\%s*full"|table tmpuse

Doesn't work.

0 Karma

stephanefotso
Motivator

Always errors in your above code! Escape all % caracters. And put a star(*) after all "[^ \n]", and do not forget to replace "&lt;" as mentioned earlier.
See my first query above.

SGF
0 Karma

woodcock
Esteemed Legend
([\d\.]*)%
0 Karma

woodcock
Esteemed Legend

Did you try mine? Here is the full search:
... | rex "(?&lt;myPct&gt;[\d\.]*)%" | table myPct

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

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...