Splunk Search

expiry notification use case

avi123
Explorer

Hi All,

I have designed a splunk query:

| inputlookup Expiry_details_list.csv
| lookup SupportTeamEmails.csv Application_name OUTPUT Owner_Email_address Ops_Leads_Email_address Escalation_Contacts_Email_address
| eval Expiry_Date = strptime(Expiry_date, "%m/%d/%Y")
| eval Current_Time = now()
| eval Expiry_Date_Timestamp = strftime(Expiry_Date, "%Y/%m/%d %H:%M:%S")
| eval Days_until_expiry = round((Expiry_Date - Current_Time) / 86400, 0)
| eval alert_type = case(
Days_until_expiry <= 7, "Owner",
Days_until_expiry <= 15, "Support",
Days_until_expiry < 1, "Expired",
Days_until_expiry > 15, "Others",
true(), "None")
| search alert_type != "None"
| eval email_list = case(
alert_type == "Owner", Escalation_Contacts_Email_address,
alert_type == "Support", Ops_Leads_Email_address,
alert_type == "Expired", mvappend(Owner_Email_address, Ops_Leads_Email_address, Escalation_Contacts_Email_address),
true(), "None")
| eval email_list = split(mvjoin(email_list, ","), ",")
| eval cc_email_list = case(
alert_type == "Owner", Owner_Email_address,
alert_type == "Support", Owner_Email_address,
true(), "None")
| eval cc_email_list = split(mvjoin(cc_email_list, ","), ",")
| dedup Application_name Environment email_list
| eval email_recipient = mvdedup(email_list)
| eval email_recipient = mvjoin(email_recipient, ",")
| eval email_cc = mvdedup(cc_email_list)
| eval email_cc = mvjoin(email_cc, ",")
| table Application_name, Environment, Type, Sub_Type, Expiry_Date_Timestamp, Days_until_expiry, email_recipient, email_cc
| fields - alert_type, Owner_Email_address, Ops_Leads_Email_address, Escalation_Contacts_Email_address

Now this is returning output as provided in the attached file, what I am expecting is in email_list it should return only Escalation_contacts_email_address and in cc_email_list it should merge the email address of Owner_Email_address and Ops_Leads_Email_address seperated by a comma when the alert_type == "Expired"

How do I get this using splunk query?

Labels (1)
Tags (1)
0 Karma

defection-io
Explorer

Hi @avi123 ,

I'm not 100% sure if I understood the requirements, but I'm giving it a shot here. Let me know if this works for you:

| inputlookup Expiry_details_list.csv 
| lookup SupportTeamEmails.csv Application_name OUTPUT Owner_Email_address Ops_Leads_Email_address Escalation_Contacts_Email_address 
| eval Expiry_Date = strptime(Expiry_date, "%m/%d/%Y") 
| eval Current_Time = now() 
| eval Expiry_Date_Timestamp = strftime(Expiry_Date, "%Y/%m/%d %H:%M:%S") 
| eval Days_until_expiry = round((Expiry_Date - Current_Time) / 86400, 0) 
| eval alert_type = case(
    Days_until_expiry <= 7, "Owner",
    Days_until_expiry <= 15, "Support",
    Days_until_expiry < 1, "Expired",
    Days_until_expiry > 15, "Others",
    true(), "None") 
| search alert_type != "None" 
| eval email_list = case(
    alert_type == "Owner", Escalation_Contacts_Email_address,
    alert_type == "Support", Ops_Leads_Email_address,
    alert_type == "Expired", Escalation_Contacts_Email_address,
    true(), "None") 
| eval cc_email_list = case(
    alert_type == "Owner", Owner_Email_address,
    alert_type == "Support", Owner_Email_address,
    alert_type == "Expired", mvappend(Owner_Email_address, Ops_Leads_Email_address),
    true(), "None") 
| eval email_list = split(mvjoin(email_list, ","), ",") 
| eval cc_email_list = split(mvjoin(cc_email_list, ","), ",") 
| dedup Application_name Environment email_list 
| eval email_recipient = mvdedup(email_list) 
| eval email_recipient = mvjoin(email_recipient, ",") 
| eval email_cc = mvdedup(cc_email_list) 
| eval email_cc = mvjoin(email_cc, ",") 
| table Application_name, Environment, Type, Sub_Type, Expiry_Date_Timestamp, Days_until_expiry, email_recipient, email_cc 
| fields - alert_type, Owner_Email_address, Ops_Leads_Email_address, Escalation_Contacts_Email_address

 

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!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...