Skip to content

Instantly share code, notes, and snippets.

@marcusschiesser
Created November 24, 2021 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusschiesser/4c3d3f247fc0f1d7e848b283b53c10ad to your computer and use it in GitHub Desktop.
Save marcusschiesser/4c3d3f247fc0f1d7e848b283b53c10ad to your computer and use it in GitHub Desktop.
How to programmatically connect a search datasource to a Splunk visualization (without using the dashboard)
import React, { useState } from 'react';
import Table from '@splunk/visualizations/Table';
import { SplunkSearch } from '@splunk/datasources';
const DSTable = () => {
const [dsResult, setDsResult] = useState(null);
const ds = new SplunkSearch({
query: '| inputlookup example_kv',
queryParameters: {
earliest: '0',
},
});
ds.setup();
ds.request({ offset: 0, count: 10 })({
next: (x) => setDsResult(x),
error: (err) => console.error(err),
complete: () => console.log('Observer got a complete'),
});
return (
<Table options={{}} dataSources={{ primary: dsResult }} />
);
};
DSTable.config = {
key: 'splunk.DSTable',
name: 'DSTable',
};
DSTable.propTypes = {};
DSTable.defaultProps = {};
export default DSTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment