Splunk Search

How to create a report on error codes and how many times each occurred over a period of time using regex and timechart?

parameshjava
Explorer

In my application, it will print some error codes like OPT-00A001, OPT-00A002, OPT-00A003, upto OPT-00A010. I need to prepare a report to know each error code and how many times occurred over a period of time.

No idea how to use regex and timechart to get this kind of report. Please suggest.

0 Karma
1 Solution

sundareshr
Legend

Without actual logs, it is very difficult to isolate the pattern for your errorcode to write the correct regex. Having said that, if you error codes are always the same patter "OPT-" followed by 6 characters, then you can use this. This also assumes the error code appears only once an event. This also assumes, this pattern of OPT- followed by 6 chars doesn't occur anywhere else in the event. If it does, this regex will only get the first occurrence

| rex "(?<ec>OPT-\w{6})" | timechart count by ec

View solution in original post

sundareshr
Legend

Without actual logs, it is very difficult to isolate the pattern for your errorcode to write the correct regex. Having said that, if you error codes are always the same patter "OPT-" followed by 6 characters, then you can use this. This also assumes the error code appears only once an event. This also assumes, this pattern of OPT- followed by 6 chars doesn't occur anywhere else in the event. If it does, this regex will only get the first occurrence

| rex "(?<ec>OPT-\w{6})" | timechart count by ec

jmallorquin
Builder

Can you provide some lines of log just to ensure the rex match?

0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

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 ...