Splunk Search

Why is .net SDK unable to run a blocking search?

vinaypradhan
Explorer

Hello all, if anybody had luck running a blocking search using the C# SDK, would appreciate your help.

I am trying to run a blocking search from a C# application. This is my code:

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var service = new Service(new Uri("mySplunkURL:8089"));
await service.LogOnAsync("username", "password");

SearchResultStream searchResultStream;
Job job;

job = await service.Jobs.CreateAsync(
"search index=_internal | head 10"
,new JobArgs() { ExecutionMode = ExecutionMode.Blocking });

At this point, I get an error that says
JobArgs does not contain a definition for 'ExecutionMode' 
I am following the documentation on the Splunk site, and doing exactly same 
https://dev.splunk.com/enterprise/docs/devtools/csharp/sdk-csharp/howdoicsharp2x/howtorunsearches

I don't know what am I missing here? Any help is greatly appreciated !! 

Vinay

Labels (1)
Tags (2)
0 Karma
1 Solution

vinaypradhan
Explorer

hey yes, this is how I did it. 

SearchResultStream searchResultStream; 
 Job job;
  
 //create a job, setting the execution mode to "blocking"
 job = await service.Jobs.CreateAsync("yoursearchstring");
  
 // print search results
 IEnumerable<SearchResult> myresults;
 using (searchResultStream = await job.GetSearchResultsAsync())
 {
 myresults = searchResultStream.AsEnumerable<SearchResult>();
 foreach (SearchResult result in searchResultStream)
 {
 _time = Convert.ToDateTime(result.GetValue("_time"));
 UserName = result.GetValue("UserName");
 ComputerName = result.GetValue("ComputerName");
 }
 }

 

View solution in original post

0 Karma

ksorayya
New Member

Hey;

Did you figure out this issue?  I have the same problem.

 

0 Karma

vinaypradhan
Explorer

hey yes, this is how I did it. 

SearchResultStream searchResultStream; 
 Job job;
  
 //create a job, setting the execution mode to "blocking"
 job = await service.Jobs.CreateAsync("yoursearchstring");
  
 // print search results
 IEnumerable<SearchResult> myresults;
 using (searchResultStream = await job.GetSearchResultsAsync())
 {
 myresults = searchResultStream.AsEnumerable<SearchResult>();
 foreach (SearchResult result in searchResultStream)
 {
 _time = Convert.ToDateTime(result.GetValue("_time"));
 UserName = result.GetValue("UserName");
 ComputerName = result.GetValue("ComputerName");
 }
 }

 

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...