Hi.
I am trying to run a search from a Splunk API in java, store the results with fields host, sourcetype, source in the JobResultsArgs and stored in an input stream. Now I want to run through each result and retrieve the host and source.
public void search(String query,String startDate, String endDate){
String url = System.getProperty("SPLUNK.HOST");
int port = Integer.getInteger("SPLUNK.PORT");
String username = System.getProperty("SPLUNK.USERNAME");
String password = System.getProperty("SPLUNK.PASSWORD");
String searchQuery_normal = "search * | head 100";
Service client = new Service(url.trim(), port);
client.login(username, password);
JobArgs jobArgs = new JobArgs();
jobArgs.setEarliestTime(startDate);
jobArgs.setLatestTime(endDate);
Job job = client.getJobs().create(searchQuery_normal,jobArgs);
while (!job.isDone()) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
JobResultsArgs jobRes = new JobResultsArgs();
String[] fields = {"_raw" , "host", "sourcetype", "source"};
jobRes.setFieldList(fields);
jobRes.setCount(2500);
InputStream inpStream = job.getResults(jobRes);
System.out.println("result size: " + job.getResultCount());
for (int i = 0; i < job.getResultCount(); i++){
Here I want to get the host and source. I am stuck here.
Can you please help me, how I can proceed. I know I can use the RessultReadonJson but not sure how to retrieve those elements.
Is there an example of this kind?
... View more