Getting Data In

How do I Email results from Python script to users through REST API?

harshavelocity
Engager

Hello Experts,

I have created a machine learning model and am fetching data from Splunk to generate real-time predictions for my problem. I'm extracting the data from Splunk using REST API python library.

Question:

Once I generate the prediction from Python script, I have to email the result to specific users. I'm not sure how do I do that?

Through REST API is there an Option to send the results using "sendemail" command? ( how do I pass result variable through REST ?)

import splunklib.client as client
import splunklib.results as results
import sys
from time import sleep

service = client.connect(
  host=HOST,
  port=PORT,
  username=USERNAME,
  password=PASSWORD)
searchquery_normal = r"search criteria " 

kwargs_normalsearch = {"exec_mode": "normal"}
job = service.jobs.create(searchquery_normal, **kwargs_normalsearch)

#results as a dataframe
lst = list(results.ResultsReader(job.results()))
df = pd.DataFrame(lst)

#Apply the ML model and print the prediction
prediction = fittedModel.predict(np.array(df.head(1)))
print('Prediction = '+'{:,}'.format(int(p)))

#Send the prediction to a receipient


####something like
####searchquery_normal = r"|sendemail prediction value recipientaddress " 

I would really appreciate your help here.

Thanks!
Best,
Harsha

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...