use of com.splunk.ResultsReaderXml in project hop by apache.
the class SplunkInput method processRow.
@Override
public boolean processRow() throws HopException {
if (first) {
first = false;
// get the output fields...
//
data.outputRowMeta = new RowMeta();
meta.getFields(data.outputRowMeta, getTransformName(), null, getTransformMeta(), this, metadataProvider);
// Run a one shot search in blocking mode
//
JobResultsArgs args = new JobResultsArgs();
args.setCount(0);
args.setOutputMode(JobResultsArgs.OutputMode.XML);
data.eventsStream = data.service.oneshotSearch(resolve(meta.getQuery()), args);
}
try {
ResultsReaderXml resultsReader = new ResultsReaderXml(data.eventsStream);
HashMap<String, String> event;
while ((event = resultsReader.getNextEvent()) != null) {
Object[] outputRow = RowDataUtil.allocateRowData(data.outputRowMeta.size());
for (int i = 0; i < meta.getReturnValues().size(); i++) {
ReturnValue returnValue = meta.getReturnValues().get(i);
String value = event.get(returnValue.getSplunkName());
outputRow[i] = value;
}
incrementLinesInput();
putRow(data.outputRowMeta, outputRow);
}
} catch (Exception e) {
throw new HopException("Error reading from Splunk events stream", e);
} finally {
try {
data.eventsStream.close();
} catch (IOException e) {
throw new HopException("Unable to close events stream", e);
}
}
// Nothing more
//
setOutputDone();
return false;
}
use of com.splunk.ResultsReaderXml 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);
}
}
Aggregations