Alerting

Compare text strings over 2 days

ssaenger
Communicator

Hello,

i have a log file which is capturing processed files.

The file text always has the same string, its just the date prefix which changes. 
So i would like to read in the files processed today and compare to yesterday and how the difference.

I have used the answers to other questions to get the file date read in by day, however the diff command does not work, is this only for integers rather than string.

  Successfully processed file 20211105-zone-Foo Bar1.txt

  Successfully processed file 20211105-zone-Bar 1.txt

  Successfully processed file 20211106_zone-Foo Bar1.txt

  Successfully processed file 20211106-zone-Bar Foo1.txt

 

index=foo source=bar earliest=-1d@d latest=now "Successfully processed file"
| rex "\-zone\-(?<File>.+)"
| eval Day=if(_time<relative_time(now(),"@d"),"Yesterday","Today")
| chart values(File) by Day
| eval Diff=Yesterday-Today
| where Yesterday!=Today

 

i would like to report that Bar 1.txt and Bar Foo1.txt are the differences.

Labels (1)
Tags (2)

ITWhisperer
SplunkTrust
SplunkTrust
| makeresults 
| eval _raw= "Successfully processed file 20211105-zone-Foo Bar1.txt
Successfully processed file 20211105-zone-Bar 1.txt
Successfully processed file 20211106-zone-Foo Bar1.txt
Successfully processed file 20211106-zone-Bar Foo1.txt"
| multikv noheader=t
| table _raw
``` The lines above set up example data (correcting typo?) ```
| rex "(?<date>\d+)\-zone\-(?<file>.+)"
| stats count by file
| where count = 1

inventsekar
SplunkTrust
SplunkTrust

Please check this.. this works fine picking up the Date and File name..

| makeresults | eval log= "Successfully processed file 20211105-zone-Foo Bar1.txt
Successfully processed file 20211105-zone-Bar 1.txt
Successfully processed file 20211106_zone-Foo Bar1.txt
Successfully processed file 20211106-zone-Bar Foo1.txt"
| rex field=log max_match=0 "(?P<Date>\d+)\-zone\-(?<File>.+)"
| table Date File

 

i have come up with compare logic, but the eval works only once.. not sure of how to do the eval multiple times..   as you have the real logs, pls check this and update us what happen:

| makeresults | eval log= "Successfully processed file 20211105-zone-Foo Bar1.txt
Successfully processed file 20211105-zone-Bar 1.txt
Successfully processed file 20211106_zone-Foo Bar1.txt
Successfully processed file 20211106-zone-Bar Foo1.txt"
| rex field=log max_match=0 "(?P<Date>\d+)\-zone\-(?<File>.+)"
| eval compare=strptime(Date,"%Y%m%d")
| where compare > strptime(Date,"%Y%m%d")
| table Date File Day

rex-date.png

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

richgalloway
SplunkTrust
SplunkTrust

The diff command does indeed work on strings, but produces output like that of the Linux diff command, which probably is not what you seek.

 

@@ -1 +1 @@
-Bar Foo1.txt Foo Bar1.txt
+Bar 1.txt Foo Bar1.txt

I regret that don't know how to solve the problem.

 

 

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

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

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...