Search in sources :

Example 1 with SplunkConnection

use of org.apache.hop.splunk.SplunkConnection in project hop by apache.

the class SplunkInputDialog method getReturnValues.

private void getReturnValues() {
    try {
        IHopMetadataSerializer<SplunkConnection> serializer = metadataProvider.getSerializer(SplunkConnection.class);
        SplunkConnection splunkConnection = serializer.load(variables.resolve(wConnection.getText()));
        Service service = Service.connect(splunkConnection.getServiceArgs(variables));
        Args args = new Args();
        args.put("connection_mode", JobArgs.ExecutionMode.BLOCKING.name());
        InputStream eventsStream = service.oneshotSearch(variables.resolve(wQuery.getText()), args);
        Set<String> detectedKeys = new HashSet<>();
        try {
            ResultsReaderXml resultsReader = new ResultsReaderXml(eventsStream);
            HashMap<String, String> event;
            int nrScanned = 0;
            while ((event = resultsReader.getNextEvent()) != null) {
                for (String key : event.keySet()) {
                    detectedKeys.add(key);
                }
                nrScanned++;
                if (nrScanned > 10) {
                    break;
                }
            }
        } finally {
            eventsStream.close();
        }
        for (String detectedKey : detectedKeys) {
            TableItem item = new TableItem(wReturns.table, SWT.NONE);
            item.setText(1, detectedKey);
            item.setText(2, detectedKey);
            item.setText(3, "String");
        }
        wReturns.removeEmptyRows();
        wReturns.setRowNums();
        wReturns.optWidth(true);
    } catch (Exception e) {
        new ErrorDialog(shell, "Error", "Error getting fields from Splunk query", e);
    }
}
Also used : Args(com.splunk.Args) JobArgs(com.splunk.JobArgs) InputStream(java.io.InputStream) Service(com.splunk.Service) ResultsReaderXml(com.splunk.ResultsReaderXml) SplunkConnection(org.apache.hop.splunk.SplunkConnection)

Aggregations

Args (com.splunk.Args)1 JobArgs (com.splunk.JobArgs)1 ResultsReaderXml (com.splunk.ResultsReaderXml)1 Service (com.splunk.Service)1 InputStream (java.io.InputStream)1 SplunkConnection (org.apache.hop.splunk.SplunkConnection)1