Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Splunk Java SDK Example - Create/Remove TCPInput
/**
* Create a TCPInput in a specific namespace Will use the /servicesNS path
*/
public static void tcpInputCreateExample() {
Service splunkService = connectAndLoginToSplunkExample();
String tcpPort = "5150";
Args args = new Args();
args.put("owner", "admin");
args.put("app", "search");
// create TCP input
InputCollection inputs = splunkService.getInputs(args);
inputs.create(tcpPort, InputKind.Tcp);
TcpInput tcpInput = (TcpInput) inputs.get(tcpPort);
tcpInput.setConnectionHost("my.mac.book");
tcpInput.setHost("myhost");
tcpInput.setIndex("main");
tcpInput.setSource("tcp");
tcpInput.setSourceType("sdk-tests");
tcpInput.setSSL(false);
// persist to splunkd
tcpInput.update();
}
/**
* Remove a TCPInput in a specific namespace Will use the /servicesNS path
*/
public static void tcpInputRemoveExample() {
Service splunkService = connectAndLoginToSplunkExample();
String tcpPort = "5150";
Args args = new Args();
args.put("owner", "admin");
args.put("app", "search");
// get TCP input
InputCollection inputs = splunkService.getInputs(args);
TcpInput tcpInput = (TcpInput) inputs.get(tcpPort);
// remove TCP input
tcpInput.remove();
inputs.refresh();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.