Splunk Search

Extract erros from logs

haist
Explorer

Hi,

I'm new to Splunk and I would like to get top errors on a table, but the external API returns a stack tracing making it difficult to work on it.

I'm trying to make a regex that groups those errors by error code "*Return code: [<code>]*"( letting it work with other errors), than count it.

Could you help me, please? 🥺

Labels (3)
0 Karma
1 Solution

haist
Explorer

Hi @gcusello, thanks for the suggestion

I used Rex to create a new field with return code, then stats to count and show similar errors

 

 

...
| rex field=Response.body.Result "(?<code>(Return code: \[\d+]|null))"
| stats first(Response.body.Result) as Logs count(code) as Events
| table Logs, Events

 

 

 

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @haist,

if you need help in regex creation, you should share some log examples.

If instead you need help in search, you have to follow these steps:

  • identify the error conditions (e.g. in ora errors are identified by ORA9999),
  • create a new field (code) using the identified regex,
  • Use the new field to filter your logs to have only the error logs,
  • identify the relevant fields to display in the table (e.g. host, earliest, latest),
  • identify eventual aggregation fields (e.g. code),
  • create simple search like the following:
index=your_index code IN ("error1","error2","error3")
| stats values(host) AS host earliest(_time) AS earliest latest(_time) AS latest count BY code
| eval 
   earliest=strftime(earliest,"%Y-%m-%d %H:%M:%S"),
   latest=strftime(latest,"%Y-%m-%d %H:%M:%S")

 Ciao.

Giuseppe

haist
Explorer

Hi @gcusello, thanks for the suggestion

I used Rex to create a new field with return code, then stats to count and show similar errors

 

 

...
| rex field=Response.body.Result "(?<code>(Return code: \[\d+]|null))"
| stats first(Response.body.Result) as Logs count(code) as Events
| table Logs, Events

 

 

 

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @haist,

ok, I don't understand where you are taking the field "counter" that it's in teh table command but it isn't in the stats command.

Remember that after a stats command you have only the fields expressed in the stats command, in your case only "Logs" and "Events", not "counter"!

Anyway, if my answer solves your problem, please accept it for the other people of Community, otherwise, tell me how can I help you.

Ciao and happy splunking.

Giuseppe

P.S.: Karma Points are appreciated 😉

haist
Explorer

That's true, I was generalizing and translating the names and mismatched here, thanks for attention 😀

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Laser Bananas and Edge Hubs: Exploring Operational Technology (OT) Data Through a ...

  OT is a different environment to traditional IT and can have interesting challenges when interfacing the ...

Event Series: Mastering AI Tokenomics and Splunk Agent Observability

Beyond the Black Box: Correlating AI Performance and Tokenomics with Splunk Agent Observability   As ...

span_metrics: The OpenTelemetry-Idiomatic Way to See Inside Your Services

You open a trace in Splunk Observability Cloud and everything looks fine. One root span, order-pipeline, with ...