Alerting

Generate email alerts based on conditions

hushang999
New Member

Hello,

I'm trying to create searches for that would generate emails for the following conditions:

1 ) If the "transaction_date" field is more than three days after the "term_date" then send out an email

2 ) If the "lastlogon" date is more than one day after the "term date" then send out an email

3 ) Send out a monthly report for showing #1 and #2

So far I'm using the following search to generate the search:

"eventtype=sws_employee_terms transaction_type=Terminate"

Tags (2)
0 Karma

lguinn2
Legend

Assuming that the date fields are stored in Linux epoch time

eventtype=sws_employee_terms transaction_type=Terminate
| where (transaction_date > term_date + (3 * 86400)) OR (lastlogon > term_date + 86400)

Set up the alert to trigger for number of results > 0 and set the trigger action to email.

Run the same search over a 30 days period to see the report. You could also start with this search and then format the report better.

If the date fields are NOT stored in Linux epoch time, use this to convert them

| eval transaction_date = strptime(transaction_date,"%Y-%m-%d %H:%M:%S")
| eval term_date = strptime(term_date,"%Y-%m-%d %H:%M:%S")
| eval lastlogon = strptime(lastlogon,"%Y-%m-%d %H:%M:%S")

Insert these lines after the first line of the original search. Edit the format strings as needed.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

For time-related maths you may want to look at relative_time(): http://docs.splunk.com/Documentation/Splunk/6.1.1/SearchReference/CommonEvalFunctions
That'd turn the where row into this:

... | where (transaction_date > relative_time(term_date, "+3d")) OR (lastlogon > relative_time(term_date, "+1d"))
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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...