From dcefe9522f99a4ea115d983a65570bd607c47c67 Mon Sep 17 00:00:00 2001 From: Enrique Fernandez Date: Sun, 29 May 2022 19:22:00 +0200 Subject: [PATCH] fix(config): Use official HttpProxySettings to configure Splunk Datasource --- Makefile | 11 --- README.md | 10 --- .../datasources/splunk-datasource.yml | 8 +- src/ConfigEditor.tsx | 77 ++----------------- src/datasource.ts | 12 +-- src/plugin.json | 12 --- 6 files changed, 18 insertions(+), 112 deletions(-) diff --git a/Makefile b/Makefile index 93348aa..e50e22e 100644 --- a/Makefile +++ b/Makefile @@ -15,17 +15,6 @@ build-splunk-datasource: up: docker-compose up -d - sleep 60 - $(MAKE) configure - -configure: | configure-splunk - - -SPLUNK_CONTAINER=grafana-plugin-splunk-datasource-splunk-1 -SPLUNK_CONFIG_FILE=/opt/splunk/etc/system/default/server.conf -configure-splunk: - docker exec $(SPLUNK_CONTAINER) sudo sed -i -E 's/^(enableSplunkdSSL = ).*$$/\1false/g' $(SPLUNK_CONFIG_FILE) - docker exec $(SPLUNK_CONTAINER) sudo /opt/splunk/bin/splunk restart down: -docker-compose down diff --git a/README.md b/README.md index b8a5909..65e3a31 100644 --- a/README.md +++ b/README.md @@ -42,16 +42,6 @@ as source of inspiration. However, the plugin can also be manually configured by an administrator from Grafana's UI `Configuration --> Datasources --> Add data source`. -| Field | Description | -|:----------------:|------------------------------------------------------------------------------------------------| -| Endpoint | URL of your Splunk instance's REST API endpoint (eg. `http://localhost:8089`) | -| Basic Auth Token | Basic64 encoding of your Basic Auth username and password, separated with a single colon (`:`) | - -> You may also need to disable SSL on your Splunk instance. You can read more -> about how to do this in Splunk's [official documentation](https://docs.splunk.com/Documentation/Splunk/latest/Admin/Serverconf) -> (search for `enableSplunkdSSL`). - - ### Getting Started 1. Build the project diff --git a/provisioning/datasources/splunk-datasource.yml b/provisioning/datasources/splunk-datasource.yml index 53852ab..84665a2 100644 --- a/provisioning/datasources/splunk-datasource.yml +++ b/provisioning/datasources/splunk-datasource.yml @@ -5,7 +5,11 @@ datasources: type: efcasado-splunk-datasource orgId: 1 isDefault: true + access: proxy + url: https://splunk:8089 + basicAuth: true + basicAuthUser: admin jsonData: - endpoint: 'http://splunk:8089' + tlsSkipVerify: true secureJsonData: - basicAuthToken: 'YWRtaW46dGhpc2lzYXNlY3JldA==' + basicAuthPassword: thisisasecret diff --git a/src/ConfigEditor.tsx b/src/ConfigEditor.tsx index c71e8f6..5fdc541 100644 --- a/src/ConfigEditor.tsx +++ b/src/ConfigEditor.tsx @@ -1,83 +1,22 @@ -import React, { ChangeEvent, PureComponent } from 'react'; -import { LegacyForms } from '@grafana/ui'; +import React, { PureComponent } from 'react'; +import { DataSourceHttpSettings } from '@grafana/ui'; import { DataSourcePluginOptionsEditorProps } from '@grafana/data'; -import { SplunkDataSourceOptions, SplunkSecureJsonData } from './types'; - -const { SecretFormField, FormField } = LegacyForms; +import { SplunkDataSourceOptions } from './types'; interface Props extends DataSourcePluginOptionsEditorProps {} interface State {} export class ConfigEditor extends PureComponent { - onEndpointChange = (event: ChangeEvent) => { - const { onOptionsChange, options } = this.props; - const jsonData = { - ...options.jsonData, - endpoint: event.target.value, - }; - onOptionsChange({ ...options, jsonData }); - }; - - // Secure field (only sent to the backend) - onBasicAuthTokenChange = (event: ChangeEvent) => { - const { onOptionsChange, options } = this.props; - onOptionsChange({ - ...options, - secureJsonData: { - basicAuthToken: event.target.value, - }, - }); - }; - - onResetBasicAuthToken = () => { - const { onOptionsChange, options } = this.props; - onOptionsChange({ - ...options, - secureJsonFields: { - ...options.secureJsonFields, - basicAuthToken: false, - }, - secureJsonData: { - ...options.secureJsonData, - basicAuthToken: '', - }, - }); - }; + constructor(props: Props) { + super(props); + } render() { - const { options } = this.props; - const { jsonData, secureJsonFields } = options; - const secureJsonData = (options.secureJsonData || {}) as SplunkSecureJsonData; + const { options, onOptionsChange } = this.props; return ( -
-
- -
- -
-
- -
-
-
+ ); } } diff --git a/src/datasource.ts b/src/datasource.ts index 8401160..649d37a 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -65,12 +65,11 @@ export class DataSource extends DataSourceApi) { - const routePath = '/splunk-datasource'; const { range } = options; const from = Math.floor(range!.from.valueOf() / 1000); const to = Math.floor(range!.to.valueOf() / 1000); @@ -129,7 +126,7 @@ export class DataSource extends DataSourceApi