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

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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...