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!

Automatic Discovery Part 1: What is Automatic Discovery in Splunk Observability Cloud ...

If you’ve ever deployed a new database cluster, spun up a caching layer, or added a load balancer, you know it ...

Real-Time Fraud Detection: How Splunk Dashboards Protect Financial Institutions

Financial fraud isn't slowing down. If anything, it's getting more sophisticated. Account takeovers, credit ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

 Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...