Hi guys I got a trouble on getting data to Splunk by java and I really need your help!
I followed the instructions of To add data directly to an index in http://dev.splunk.com/view/java-sdk/SP-CAAAEJ2#add2index , using the attachWith method. Here is my code:
public static void main(String[] args) {
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setUsername("admin");
serviceArgs.setPassword("admin");
serviceArgs.setHost("local");
serviceArgs.setPort(8089);
Index myIndex = service.getIndexes().get("folder");
try {
myIndex.attachWith(new ReceiverBehavior() {
public void run(OutputStream stream) {
Event event = service.
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss");
String date = dateFormat.format(new Date());
String eventText = date+" text=Testing!";
try {
stream.write(eventText.getBytes("UTF8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
The event was successfully indexed by Splunk, but with sourcetype "http-stream-too_small". By submit method in To add data directly to an index, it provides arguments to set the values of host, source, sourcetype and so on as we want. However, I don't see any argument as such in the example of attachwith method. Is it possible to customize the host and sourcetype by this way?
... View more