本文整理汇总了Java中com.splunk.Service.connect方法的典型用法代码示例。如果您正苦于以下问题:Java Service.connect方法的具体用法?Java Service.connect怎么用?Java Service.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.splunk.Service
的用法示例。
在下文中一共展示了Service.connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import com.splunk.Service; //导入方法依赖的package包/类
/**
* Create connection with the splunk server.
*/
@Override
public void connect()
{
try {
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername(userName);
loginArgs.setPassword(password);
loginArgs.setHost(host);
loginArgs.setPort(port);
service = Service.connect(loginArgs);
} catch (Exception e) {
throw new RuntimeException("closing connection", e);
}
}
示例2: main
import com.splunk.Service; //导入方法依赖的package包/类
public static void main(String[] args) {
// Create login parameters. We suggest finding
// a better way to store these than hard coding
// them in your program for production code.
ServiceArgs serviceArgs = new ServiceArgs();
serviceArgs.setUsername("admin");
serviceArgs.setPassword("changeme");
serviceArgs.setHost("localhost");
serviceArgs.setPort(8089);
// Create a Service instance and log in with the argument map
Service service = Service.connect(serviceArgs);
// Set the parameters for the search
Args oneshotSearchArgs = new Args();
// For a full list of options, see:
//
// http://docs.splunk.com/Documentation/Splunk/latest/RESTAPI/RESTsearch#POST_search.2Fjobs
// oneshotSearchArgs.put("earliest_time", "now-1w");
// oneshotSearchArgs.put("latest_time", "now");
InputStream resultsStream = service.oneshotSearch("search * | head 5",
oneshotSearchArgs);
try {
ResultsReaderXml resultsReader = new ResultsReaderXml(resultsStream);
for (Event event : resultsReader) {
// Process each event
for (String key: event.keySet()) {
System.out.println(key + ": " + event.get(key));
}
System.out.println("");
}
resultsReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: connect
import com.splunk.Service; //导入方法依赖的package包/类
public static Service connect(String username, String password, String host, int port ) {
ServiceArgs loginArgs = getLoginArgs(
username,
password,
host,
port);
return Service.connect(loginArgs);
}