mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Azure Monitor: Copy AM Creds to Log Analytics When Using Same As (#21032)
* copy creds draft * copy azure monitor creds to log analystics for sameas * alert * update snapshot
This commit is contained in:
parent
e5695b155b
commit
c14398edc8
@ -71,9 +71,9 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
await ctx.ds.metricFindQuery('workspace("aworkspace").AzureActivity | distinct Category');
|
||||
});
|
||||
|
||||
it('should use the sameasloganalyticsazure plugin route', () => {
|
||||
it('should use the loganalyticsazure plugin route', () => {
|
||||
expect(workspacesUrl).toContain('azuremonitor');
|
||||
expect(azureLogAnalyticsUrl).toContain('sameasloganalyticsazure');
|
||||
expect(azureLogAnalyticsUrl).toContain('loganalyticsazure');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -22,9 +22,7 @@ export default class AzureLogAnalyticsDatasource {
|
||||
private templateSrv: TemplateSrv
|
||||
) {
|
||||
this.id = instanceSettings.id;
|
||||
this.baseUrl = this.instanceSettings.jsonData.azureLogAnalyticsSameAs
|
||||
? '/sameasloganalyticsazure'
|
||||
: `/loganalyticsazure`;
|
||||
this.baseUrl = '/loganalyticsazure';
|
||||
this.url = instanceSettings.url;
|
||||
this.defaultOrFirstWorkspace = this.instanceSettings.jsonData.logAnalyticsDefaultWorkspace;
|
||||
|
||||
|
@ -38,6 +38,8 @@ const setup = (propOverrides?: object) => {
|
||||
},
|
||||
subscriptions: [],
|
||||
workspaces: [],
|
||||
makeSameAs: jest.fn(),
|
||||
onUpdateOptions: jest.fn(),
|
||||
onUpdateOption: jest.fn(),
|
||||
onResetOptionKey: jest.fn(),
|
||||
onLoadSubscriptions: jest.fn(),
|
||||
|
@ -8,6 +8,8 @@ export interface Props {
|
||||
options: AzureDataSourceSettings;
|
||||
subscriptions: SelectableValue[];
|
||||
workspaces: SelectableValue[];
|
||||
makeSameAs: () => void;
|
||||
onUpdateOptions: (options: AzureDataSourceSettings) => void;
|
||||
onUpdateOption: (key: string, val: any, secure: boolean) => void;
|
||||
onResetOptionKey: (key: string) => void;
|
||||
onLoadSubscriptions: (type?: string) => void;
|
||||
@ -35,8 +37,31 @@ export class AnalyticsConfig extends PureComponent<Props> {
|
||||
};
|
||||
|
||||
onAzureLogAnalyticsSameAsChange = () => {
|
||||
const { options } = this.props;
|
||||
this.props.onUpdateOption('azureLogAnalyticsSameAs', !options.jsonData.azureLogAnalyticsSameAs, false);
|
||||
const { options, onUpdateOptions, makeSameAs } = this.props;
|
||||
|
||||
if (!options.jsonData.azureLogAnalyticsSameAs && options.secureJsonData.clientSecret) {
|
||||
makeSameAs();
|
||||
} else if (!options.jsonData.azureLogAnalyticsSameAs) {
|
||||
// if currently off, clear monitor secret
|
||||
onUpdateOptions({
|
||||
...options,
|
||||
jsonData: {
|
||||
...options.jsonData,
|
||||
azureLogAnalyticsSameAs: !options.jsonData.azureLogAnalyticsSameAs,
|
||||
},
|
||||
secureJsonData: {
|
||||
...options.secureJsonData,
|
||||
clientSecret: '',
|
||||
},
|
||||
secureJsonFields: {
|
||||
clientSecret: false,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
this.props.onUpdateOption('azureLogAnalyticsSameAs', !options.jsonData.azureLogAnalyticsSameAs, false);
|
||||
}
|
||||
|
||||
// init popover to warn secret needs to be re-entered
|
||||
};
|
||||
|
||||
onLogAnalyticsResetClientSecret = () => {
|
||||
@ -83,6 +108,13 @@ export class AnalyticsConfig extends PureComponent<Props> {
|
||||
tooltip: 'Workspaces are pulled from default subscription selected above.',
|
||||
}),
|
||||
};
|
||||
|
||||
const showSameAsHelpMsg =
|
||||
jsonData.azureLogAnalyticsSameAs &&
|
||||
secureJsonFields &&
|
||||
!secureJsonFields.clientSecret &&
|
||||
!secureJsonData.clientSecret;
|
||||
|
||||
return (
|
||||
<>
|
||||
<h3 className="page-heading">Azure Log Analytics API Details</h3>
|
||||
@ -92,6 +124,13 @@ export class AnalyticsConfig extends PureComponent<Props> {
|
||||
onChange={this.onAzureLogAnalyticsSameAsChange}
|
||||
{...addtlAttrs}
|
||||
/>
|
||||
{showSameAsHelpMsg && (
|
||||
<div className="grafana-info-box m-t-2">
|
||||
<div className="alert-body">
|
||||
<p>Re-enter your Azure Monitor Client Secret to use this setting.</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!jsonData.azureLogAnalyticsSameAs && (
|
||||
<AzureCredentialsForm
|
||||
subscriptionOptions={subscriptions}
|
||||
|
@ -77,6 +77,27 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
||||
updateDatasourcePluginResetKeyOption(this.props, key);
|
||||
};
|
||||
|
||||
makeSameAs = (updatedClientSecret?: string) => {
|
||||
const { options } = this.props;
|
||||
const clientSecret = updatedClientSecret || options.secureJsonData.clientSecret;
|
||||
|
||||
this.updateOptions({
|
||||
...options,
|
||||
jsonData: {
|
||||
...options.jsonData,
|
||||
azureLogAnalyticsSameAs: true,
|
||||
logAnalyticsSubscriptionId: options.jsonData.subscriptionId,
|
||||
logAnalyticsTenantId: options.jsonData.tenantId,
|
||||
logAnalyticsClientId: options.jsonData.clientId,
|
||||
},
|
||||
secureJsonData: {
|
||||
...options.secureJsonData,
|
||||
clientSecret,
|
||||
logAnalyticsClientSecret: clientSecret,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
updateOptions = (options: AzureDataSourceSettings) => {
|
||||
if (options.hasOwnProperty('secureJsonData')) {
|
||||
if (options.secureJsonData.hasOwnProperty('clientSecret') && options.secureJsonData.clientSecret.length === 0) {
|
||||
@ -134,10 +155,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
||||
await this.backendSrv
|
||||
.put(`/api/datasources/${this.props.options.id}`, this.props.options)
|
||||
.then((result: AzureDataSourceSettings) => {
|
||||
this.updateOptions({
|
||||
...this.props.options,
|
||||
version: result.version,
|
||||
});
|
||||
updateDatasourcePluginOption(this.props, 'version', result.version);
|
||||
});
|
||||
|
||||
if (type && type === 'workspacesloganalytics') {
|
||||
@ -257,6 +275,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
||||
<MonitorConfig
|
||||
options={options}
|
||||
subscriptions={subscriptions}
|
||||
makeSameAs={this.makeSameAs}
|
||||
onLoadSubscriptions={this.onLoadSubscriptions}
|
||||
onUpdateOption={this.updateOption}
|
||||
onResetOptionKey={this.resetKey}
|
||||
@ -266,6 +285,8 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
||||
options={options}
|
||||
workspaces={logAnalyticsWorkspaces}
|
||||
subscriptions={logAnalyticsSubscriptions}
|
||||
makeSameAs={this.makeSameAs}
|
||||
onUpdateOptions={this.updateOptions}
|
||||
onUpdateOption={this.updateOption}
|
||||
onResetOptionKey={this.resetKey}
|
||||
onLoadSubscriptions={this.onLoadSubscriptions}
|
||||
|
@ -13,6 +13,7 @@ const azureClouds = [
|
||||
export interface Props {
|
||||
options: AzureDataSourceSettings;
|
||||
subscriptions: SelectableValue[];
|
||||
makeSameAs: (updatedClientSecret?: string) => void;
|
||||
onUpdateOption: (key: string, val: any, secure: boolean) => void;
|
||||
onResetOptionKey: (key: string) => void;
|
||||
onLoadSubscriptions: () => void;
|
||||
@ -32,7 +33,13 @@ export class MonitorConfig extends PureComponent<Props> {
|
||||
};
|
||||
|
||||
onClientSecretChange = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
this.props.onUpdateOption('clientSecret', event.target.value, true);
|
||||
const { options, makeSameAs } = this.props;
|
||||
|
||||
if (options.jsonData.azureLogAnalyticsSameAs && event.target.value) {
|
||||
makeSameAs(event.target.value);
|
||||
} else {
|
||||
this.props.onUpdateOption('clientSecret', event.target.value, true);
|
||||
}
|
||||
};
|
||||
|
||||
onResetClientSecret = () => {
|
||||
|
@ -3,6 +3,7 @@
|
||||
exports[`Render should render component 1`] = `
|
||||
<Fragment>
|
||||
<MonitorConfig
|
||||
makeSameAs={[Function]}
|
||||
onLoadSubscriptions={[Function]}
|
||||
onResetOptionKey={[Function]}
|
||||
onUpdateOption={[Function]}
|
||||
@ -37,10 +38,12 @@ exports[`Render should render component 1`] = `
|
||||
subscriptions={Array []}
|
||||
/>
|
||||
<AnalyticsConfig
|
||||
makeSameAs={[Function]}
|
||||
onLoadSubscriptions={[Function]}
|
||||
onLoadWorkspaces={[Function]}
|
||||
onResetOptionKey={[Function]}
|
||||
onUpdateOption={[Function]}
|
||||
onUpdateOptions={[Function]}
|
||||
options={
|
||||
Object {
|
||||
"access": "proxy",
|
||||
|
@ -131,25 +131,6 @@
|
||||
{ "name": "Cache-Control", "content": "public, max-age=60" },
|
||||
{ "name": "Accept-Encoding", "content": "gzip" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "sameasloganalyticsazure",
|
||||
"method": "GET",
|
||||
"url": "https://api.loganalytics.io/v1/workspaces",
|
||||
"tokenAuth": {
|
||||
"url": "https://login.microsoftonline.com/{{.JsonData.tenantId}}/oauth2/token",
|
||||
"params": {
|
||||
"grant_type": "client_credentials",
|
||||
"client_id": "{{.JsonData.clientId}}",
|
||||
"client_secret": "{{.SecureJsonData.clientSecret}}",
|
||||
"resource": "https://api.loganalytics.io"
|
||||
}
|
||||
},
|
||||
"headers": [
|
||||
{ "name": "x-ms-app", "content": "Grafana" },
|
||||
{ "name": "Cache-Control", "content": "public, max-age=60" },
|
||||
{ "name": "Accept-Encoding", "content": "gzip" }
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user