1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
import com.splunk.*;
public static void main (String[] args) throws IOException {
// Create a map of arguments and add login parameters
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("admin");
loginArgs.setPassword("servus");
loginArgs.setHost("localhost");
loginArgs.setPort(8089);
HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
String json="{" +
" \"Class\": \"11\"," +
" \"date\": \"05/16/2016\"," +
" \"Student\": [" +
" {" +
" \"RollNo\": \"1234\"," +
" \"SubjectDetails\": [" +
" {" +
" \"type\": \"Mandatory\"," +
" \"startTime\": \"05/16/2016 21:30\"," +
" \"endTime\": \"05/16/2016 22:00\"," +
" \"name\": \"English\"" +
" }," +
" {" +
" \"type\": \"Optional\"," +
" \"startTime\": \"05/16/2016 20:30\"," +
" \"endTime\": \"05/16/2016 21:30\"," +
" \"name\": \"Math\"" +
" }," +
" ]" +
" }" +
" ]" +
" }" +
" ";
// Create a Service instance and log in with the argument map
Service splunkService = Service.connect(loginArgs);
Receiver receiver=splunkService.getReceiver();
Args logArgs=new Args();
logArgs.put("sourcetype","hellosplunk");
receiver.log("testrmscindex",logArgs,json); |
Partager