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');
|
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(workspacesUrl).toContain('azuremonitor');
|
||||||
expect(azureLogAnalyticsUrl).toContain('sameasloganalyticsazure');
|
expect(azureLogAnalyticsUrl).toContain('loganalyticsazure');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -22,9 +22,7 @@ export default class AzureLogAnalyticsDatasource {
|
|||||||
private templateSrv: TemplateSrv
|
private templateSrv: TemplateSrv
|
||||||
) {
|
) {
|
||||||
this.id = instanceSettings.id;
|
this.id = instanceSettings.id;
|
||||||
this.baseUrl = this.instanceSettings.jsonData.azureLogAnalyticsSameAs
|
this.baseUrl = '/loganalyticsazure';
|
||||||
? '/sameasloganalyticsazure'
|
|
||||||
: `/loganalyticsazure`;
|
|
||||||
this.url = instanceSettings.url;
|
this.url = instanceSettings.url;
|
||||||
this.defaultOrFirstWorkspace = this.instanceSettings.jsonData.logAnalyticsDefaultWorkspace;
|
this.defaultOrFirstWorkspace = this.instanceSettings.jsonData.logAnalyticsDefaultWorkspace;
|
||||||
|
|
||||||
|
@ -38,6 +38,8 @@ const setup = (propOverrides?: object) => {
|
|||||||
},
|
},
|
||||||
subscriptions: [],
|
subscriptions: [],
|
||||||
workspaces: [],
|
workspaces: [],
|
||||||
|
makeSameAs: jest.fn(),
|
||||||
|
onUpdateOptions: jest.fn(),
|
||||||
onUpdateOption: jest.fn(),
|
onUpdateOption: jest.fn(),
|
||||||
onResetOptionKey: jest.fn(),
|
onResetOptionKey: jest.fn(),
|
||||||
onLoadSubscriptions: jest.fn(),
|
onLoadSubscriptions: jest.fn(),
|
||||||
|
@ -8,6 +8,8 @@ export interface Props {
|
|||||||
options: AzureDataSourceSettings;
|
options: AzureDataSourceSettings;
|
||||||
subscriptions: SelectableValue[];
|
subscriptions: SelectableValue[];
|
||||||
workspaces: SelectableValue[];
|
workspaces: SelectableValue[];
|
||||||
|
makeSameAs: () => void;
|
||||||
|
onUpdateOptions: (options: AzureDataSourceSettings) => void;
|
||||||
onUpdateOption: (key: string, val: any, secure: boolean) => void;
|
onUpdateOption: (key: string, val: any, secure: boolean) => void;
|
||||||
onResetOptionKey: (key: string) => void;
|
onResetOptionKey: (key: string) => void;
|
||||||
onLoadSubscriptions: (type?: string) => void;
|
onLoadSubscriptions: (type?: string) => void;
|
||||||
@ -35,8 +37,31 @@ export class AnalyticsConfig extends PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onAzureLogAnalyticsSameAsChange = () => {
|
onAzureLogAnalyticsSameAsChange = () => {
|
||||||
const { options } = this.props;
|
const { options, onUpdateOptions, makeSameAs } = this.props;
|
||||||
this.props.onUpdateOption('azureLogAnalyticsSameAs', !options.jsonData.azureLogAnalyticsSameAs, false);
|
|
||||||
|
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 = () => {
|
onLogAnalyticsResetClientSecret = () => {
|
||||||
@ -83,6 +108,13 @@ export class AnalyticsConfig extends PureComponent<Props> {
|
|||||||
tooltip: 'Workspaces are pulled from default subscription selected above.',
|
tooltip: 'Workspaces are pulled from default subscription selected above.',
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const showSameAsHelpMsg =
|
||||||
|
jsonData.azureLogAnalyticsSameAs &&
|
||||||
|
secureJsonFields &&
|
||||||
|
!secureJsonFields.clientSecret &&
|
||||||
|
!secureJsonData.clientSecret;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h3 className="page-heading">Azure Log Analytics API Details</h3>
|
<h3 className="page-heading">Azure Log Analytics API Details</h3>
|
||||||
@ -92,6 +124,13 @@ export class AnalyticsConfig extends PureComponent<Props> {
|
|||||||
onChange={this.onAzureLogAnalyticsSameAsChange}
|
onChange={this.onAzureLogAnalyticsSameAsChange}
|
||||||
{...addtlAttrs}
|
{...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 && (
|
{!jsonData.azureLogAnalyticsSameAs && (
|
||||||
<AzureCredentialsForm
|
<AzureCredentialsForm
|
||||||
subscriptionOptions={subscriptions}
|
subscriptionOptions={subscriptions}
|
||||||
|
@ -77,6 +77,27 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
|||||||
updateDatasourcePluginResetKeyOption(this.props, key);
|
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) => {
|
updateOptions = (options: AzureDataSourceSettings) => {
|
||||||
if (options.hasOwnProperty('secureJsonData')) {
|
if (options.hasOwnProperty('secureJsonData')) {
|
||||||
if (options.secureJsonData.hasOwnProperty('clientSecret') && options.secureJsonData.clientSecret.length === 0) {
|
if (options.secureJsonData.hasOwnProperty('clientSecret') && options.secureJsonData.clientSecret.length === 0) {
|
||||||
@ -134,10 +155,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
|||||||
await this.backendSrv
|
await this.backendSrv
|
||||||
.put(`/api/datasources/${this.props.options.id}`, this.props.options)
|
.put(`/api/datasources/${this.props.options.id}`, this.props.options)
|
||||||
.then((result: AzureDataSourceSettings) => {
|
.then((result: AzureDataSourceSettings) => {
|
||||||
this.updateOptions({
|
updateDatasourcePluginOption(this.props, 'version', result.version);
|
||||||
...this.props.options,
|
|
||||||
version: result.version,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (type && type === 'workspacesloganalytics') {
|
if (type && type === 'workspacesloganalytics') {
|
||||||
@ -257,6 +275,7 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
|||||||
<MonitorConfig
|
<MonitorConfig
|
||||||
options={options}
|
options={options}
|
||||||
subscriptions={subscriptions}
|
subscriptions={subscriptions}
|
||||||
|
makeSameAs={this.makeSameAs}
|
||||||
onLoadSubscriptions={this.onLoadSubscriptions}
|
onLoadSubscriptions={this.onLoadSubscriptions}
|
||||||
onUpdateOption={this.updateOption}
|
onUpdateOption={this.updateOption}
|
||||||
onResetOptionKey={this.resetKey}
|
onResetOptionKey={this.resetKey}
|
||||||
@ -266,6 +285,8 @@ export class ConfigEditor extends PureComponent<Props, State> {
|
|||||||
options={options}
|
options={options}
|
||||||
workspaces={logAnalyticsWorkspaces}
|
workspaces={logAnalyticsWorkspaces}
|
||||||
subscriptions={logAnalyticsSubscriptions}
|
subscriptions={logAnalyticsSubscriptions}
|
||||||
|
makeSameAs={this.makeSameAs}
|
||||||
|
onUpdateOptions={this.updateOptions}
|
||||||
onUpdateOption={this.updateOption}
|
onUpdateOption={this.updateOption}
|
||||||
onResetOptionKey={this.resetKey}
|
onResetOptionKey={this.resetKey}
|
||||||
onLoadSubscriptions={this.onLoadSubscriptions}
|
onLoadSubscriptions={this.onLoadSubscriptions}
|
||||||
|
@ -13,6 +13,7 @@ const azureClouds = [
|
|||||||
export interface Props {
|
export interface Props {
|
||||||
options: AzureDataSourceSettings;
|
options: AzureDataSourceSettings;
|
||||||
subscriptions: SelectableValue[];
|
subscriptions: SelectableValue[];
|
||||||
|
makeSameAs: (updatedClientSecret?: string) => void;
|
||||||
onUpdateOption: (key: string, val: any, secure: boolean) => void;
|
onUpdateOption: (key: string, val: any, secure: boolean) => void;
|
||||||
onResetOptionKey: (key: string) => void;
|
onResetOptionKey: (key: string) => void;
|
||||||
onLoadSubscriptions: () => void;
|
onLoadSubscriptions: () => void;
|
||||||
@ -32,7 +33,13 @@ export class MonitorConfig extends PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onClientSecretChange = (event: ChangeEvent<HTMLInputElement>) => {
|
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 = () => {
|
onResetClientSecret = () => {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
exports[`Render should render component 1`] = `
|
exports[`Render should render component 1`] = `
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<MonitorConfig
|
<MonitorConfig
|
||||||
|
makeSameAs={[Function]}
|
||||||
onLoadSubscriptions={[Function]}
|
onLoadSubscriptions={[Function]}
|
||||||
onResetOptionKey={[Function]}
|
onResetOptionKey={[Function]}
|
||||||
onUpdateOption={[Function]}
|
onUpdateOption={[Function]}
|
||||||
@ -37,10 +38,12 @@ exports[`Render should render component 1`] = `
|
|||||||
subscriptions={Array []}
|
subscriptions={Array []}
|
||||||
/>
|
/>
|
||||||
<AnalyticsConfig
|
<AnalyticsConfig
|
||||||
|
makeSameAs={[Function]}
|
||||||
onLoadSubscriptions={[Function]}
|
onLoadSubscriptions={[Function]}
|
||||||
onLoadWorkspaces={[Function]}
|
onLoadWorkspaces={[Function]}
|
||||||
onResetOptionKey={[Function]}
|
onResetOptionKey={[Function]}
|
||||||
onUpdateOption={[Function]}
|
onUpdateOption={[Function]}
|
||||||
|
onUpdateOptions={[Function]}
|
||||||
options={
|
options={
|
||||||
Object {
|
Object {
|
||||||
"access": "proxy",
|
"access": "proxy",
|
||||||
|
@ -131,25 +131,6 @@
|
|||||||
{ "name": "Cache-Control", "content": "public, max-age=60" },
|
{ "name": "Cache-Control", "content": "public, max-age=60" },
|
||||||
{ "name": "Accept-Encoding", "content": "gzip" }
|
{ "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