Skip to content

Commit 39b7418

Browse files
authored
fix(config): Use official HttpProxySettings to configure Splunk Datasource (#30)
1 parent ddb5280 commit 39b7418

File tree

6 files changed

+18
-112
lines changed

6 files changed

+18
-112
lines changed

Makefile

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ build-splunk-datasource:
1515

1616
up:
1717
docker-compose up -d
18-
sleep 60
19-
$(MAKE) configure
20-
21-
configure: | configure-splunk
22-
23-
24-
SPLUNK_CONTAINER=grafana-plugin-splunk-datasource-splunk-1
25-
SPLUNK_CONFIG_FILE=/opt/splunk/etc/system/default/server.conf
26-
configure-splunk:
27-
docker exec $(SPLUNK_CONTAINER) sudo sed -i -E 's/^(enableSplunkdSSL = ).*$$/\1false/g' $(SPLUNK_CONFIG_FILE)
28-
docker exec $(SPLUNK_CONTAINER) sudo /opt/splunk/bin/splunk restart
2918

3019
down:
3120
-docker-compose down

README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ as source of inspiration. However, the plugin can also be manually configured
4242
by an administrator from Grafana's UI `Configuration --> Datasources --> Add data source`.
4343

4444

45-
| Field | Description |
46-
|:----------------:|------------------------------------------------------------------------------------------------|
47-
| Endpoint | URL of your Splunk instance's REST API endpoint (eg. `http://localhost:8089`) |
48-
| Basic Auth Token | Basic64 encoding of your Basic Auth username and password, separated with a single colon (`:`) |
49-
50-
> You may also need to disable SSL on your Splunk instance. You can read more
51-
> about how to do this in Splunk's [official documentation](https://docs.splunk.com/Documentation/Splunk/latest/Admin/Serverconf)
52-
> (search for `enableSplunkdSSL`).
53-
54-
5545
### Getting Started
5646

5747
1. Build the project

provisioning/datasources/splunk-datasource.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ datasources:
55
type: efcasado-splunk-datasource
66
orgId: 1
77
isDefault: true
8+
access: proxy
9+
url: https://splunk:8089
10+
basicAuth: true
11+
basicAuthUser: admin
812
jsonData:
9-
endpoint: 'http://splunk:8089'
13+
tlsSkipVerify: true
1014
secureJsonData:
11-
basicAuthToken: 'YWRtaW46dGhpc2lzYXNlY3JldA=='
15+
basicAuthPassword: thisisasecret

src/ConfigEditor.tsx

Lines changed: 8 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,22 @@
1-
import React, { ChangeEvent, PureComponent } from 'react';
2-
import { LegacyForms } from '@grafana/ui';
1+
import React, { PureComponent } from 'react';
2+
import { DataSourceHttpSettings } from '@grafana/ui';
33
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
4-
import { SplunkDataSourceOptions, SplunkSecureJsonData } from './types';
5-
6-
const { SecretFormField, FormField } = LegacyForms;
4+
import { SplunkDataSourceOptions } from './types';
75

86
interface Props extends DataSourcePluginOptionsEditorProps<SplunkDataSourceOptions> {}
97

108
interface State {}
119

1210
export class ConfigEditor extends PureComponent<Props, State> {
13-
onEndpointChange = (event: ChangeEvent<HTMLInputElement>) => {
14-
const { onOptionsChange, options } = this.props;
15-
const jsonData = {
16-
...options.jsonData,
17-
endpoint: event.target.value,
18-
};
19-
onOptionsChange({ ...options, jsonData });
20-
};
21-
22-
// Secure field (only sent to the backend)
23-
onBasicAuthTokenChange = (event: ChangeEvent<HTMLInputElement>) => {
24-
const { onOptionsChange, options } = this.props;
25-
onOptionsChange({
26-
...options,
27-
secureJsonData: {
28-
basicAuthToken: event.target.value,
29-
},
30-
});
31-
};
32-
33-
onResetBasicAuthToken = () => {
34-
const { onOptionsChange, options } = this.props;
35-
onOptionsChange({
36-
...options,
37-
secureJsonFields: {
38-
...options.secureJsonFields,
39-
basicAuthToken: false,
40-
},
41-
secureJsonData: {
42-
...options.secureJsonData,
43-
basicAuthToken: '',
44-
},
45-
});
46-
};
11+
constructor(props: Props) {
12+
super(props);
13+
}
4714

4815
render() {
49-
const { options } = this.props;
50-
const { jsonData, secureJsonFields } = options;
51-
const secureJsonData = (options.secureJsonData || {}) as SplunkSecureJsonData;
16+
const { options, onOptionsChange } = this.props;
5217

5318
return (
54-
<div className="gf-form-group">
55-
<div className="gf-form">
56-
<FormField
57-
label="Endpoint"
58-
labelWidth={6}
59-
inputWidth={20}
60-
onChange={this.onEndpointChange}
61-
value={jsonData.endpoint || ''}
62-
placeholder="<endpoint>"
63-
/>
64-
</div>
65-
66-
<div className="gf-form-inline">
67-
<div className="gf-form">
68-
<SecretFormField
69-
isConfigured={(secureJsonFields && secureJsonFields.basicAuthToken) as boolean}
70-
value={secureJsonData.basicAuthToken || ''}
71-
label="Basic Auth token"
72-
placeholder="<token>"
73-
labelWidth={10}
74-
inputWidth={16}
75-
onReset={this.onResetBasicAuthToken}
76-
onChange={this.onBasicAuthTokenChange}
77-
/>
78-
</div>
79-
</div>
80-
</div>
19+
<DataSourceHttpSettings defaultUrl="http://splunk:8089" dataSourceConfig={options} onChange={onOptionsChange} />
8120
);
8221
}
8322
}

src/datasource.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ export class DataSource extends DataSourceApi<SplunkQuery, SplunkDataSourceOptio
6565
output_mode: 'json',
6666
exec_mode: 'oneshot',
6767
}).toString();
68-
const routePath = '/splunk-datasource';
6968

7069
return getBackendSrv()
7170
.datasourceRequest({
7271
method: 'POST',
73-
url: this.url + routePath + '/services/search/jobs',
72+
url: this.url + '/services/search/jobs',
7473
headers: {
7574
'Content-Type': 'application/x-www-form-urlencoded',
7675
},
@@ -95,11 +94,10 @@ export class DataSource extends DataSourceApi<SplunkQuery, SplunkDataSourceOptio
9594
}
9695

9796
async doSearchStatusRequest(sid: string) {
98-
const routePath = '/splunk-datasource';
9997
const result: boolean = await getBackendSrv()
10098
.datasourceRequest({
10199
method: 'GET',
102-
url: this.url + routePath + '/services/search/jobs/' + sid,
100+
url: this.url + '/services/search/jobs/' + sid,
103101
params: {
104102
output_mode: 'json',
105103
},
@@ -114,7 +112,6 @@ export class DataSource extends DataSourceApi<SplunkQuery, SplunkDataSourceOptio
114112
}
115113

116114
async doSearchRequest(query: SplunkQuery, options: DataQueryRequest<SplunkQuery>) {
117-
const routePath = '/splunk-datasource';
118115
const { range } = options;
119116
const from = Math.floor(range!.from.valueOf() / 1000);
120117
const to = Math.floor(range!.to.valueOf() / 1000);
@@ -129,7 +126,7 @@ export class DataSource extends DataSourceApi<SplunkQuery, SplunkDataSourceOptio
129126
const sid: string = await getBackendSrv()
130127
.datasourceRequest({
131128
method: 'POST',
132-
url: this.url + routePath + '/services/search/jobs',
129+
url: this.url + '/services/search/jobs',
133130
headers: {
134131
'Content-Type': 'application/x-www-form-urlencoded',
135132
},
@@ -151,11 +148,10 @@ export class DataSource extends DataSourceApi<SplunkQuery, SplunkDataSourceOptio
151148
let results: any[] = [];
152149

153150
while (!isFinished) {
154-
const routePath = '/splunk-datasource';
155151
await getBackendSrv()
156152
.datasourceRequest({
157153
method: 'GET',
158-
url: this.url + routePath + '/services/search/jobs/' + sid + '/results',
154+
url: this.url + '/services/search/jobs/' + sid + '/results',
159155
params: {
160156
output_mode: 'json',
161157
offset: offset,

src/plugin.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
"type": "datasource",
44
"name": "splunk-datasource",
55
"id": "efcasado-splunk-datasource",
6-
"routes": [
7-
{
8-
"path": "splunk-datasource",
9-
"url": "{{ .JsonData.endpoint }}",
10-
"headers": [
11-
{
12-
"name": "Authorization",
13-
"content": "Basic {{ .SecureJsonData.basicAuthToken }}"
14-
}
15-
]
16-
}
17-
],
186
"metrics": true,
197
"info": {
208
"description": "",

0 commit comments

Comments
 (0)