Skip to content

Commit 99cfea6

Browse files
authored
Merge pull request #2076 from AkhtarAmir/H-plugin/synapse-workspace-diagnostic-logging
H-plugin synapse workspace diagnostic logs enabled
2 parents 77e8136 + d15fc1a commit 99cfea6

File tree

4 files changed

+197
-0
lines changed

4 files changed

+197
-0
lines changed

exports.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ module.exports = {
12221222
'workspaceManagedIdentity' : require(__dirname + '/plugins/azure/synapse/workspaceManagedIdentity.js'),
12231223
'synapseWorkspaceAdAuthEnabled' : require(__dirname + '/plugins/azure/synapse/synapseWorkspaceAdAuthEnabled.js'),
12241224
'synapseWorkspacPrivateEndpoint': require(__dirname + '/plugins/azure/synapse/synapseWorkspacPrivateEndpoint.js'),
1225+
'workspaceDiagnosticLogsEnabled': require(__dirname + '/plugins/azure/synapse/workspaceDiagnosticLogsEnabled.js'),
12251226
'workspaceDoubleEncryption' : require(__dirname + '/plugins/azure/synapse/workspaceDoubleEncryption.js'),
12261227

12271228
'apiInstanceManagedIdentity' : require(__dirname + '/plugins/azure/apiManagement/apiInstanceManagedIdentity.js'),

helpers/azure/api.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,11 @@ var tertiarycalls = {
12771277
properties: ['id'],
12781278
url: 'https://management.azure.com/{id}/providers/microsoft.insights/diagnosticSettings?api-version=2021-05-01-preview'
12791279
},
1280+
listByWorkspaces: {
1281+
reliesOnPath: 'synapse.listWorkspaces',
1282+
properties: ['id'],
1283+
url: 'https://management.azure.com/{id}/providers/microsoft.insights/diagnosticSettings?api-version=2021-05-01-preview'
1284+
}
12801285
},
12811286
backupShortTermRetentionPolicies: {
12821287
listByDatabase: {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
var async = require('async');
2+
var helpers = require('../../../helpers/azure');
3+
4+
module.exports = {
5+
title: 'Synapse Workspace Diagnostic Logging Enabled',
6+
category: 'AI & ML',
7+
domain: 'Machine Learning',
8+
severity: 'Medium',
9+
description: 'Ensures that diagnostic logging is enabled for Synapse workspace.',
10+
more_info: 'Enabling diagnostic logs in Azure Synapse workspace is important for monitoring, troubleshooting, and optimizing performance. These logs provide detailed insights into resource usage, query execution, and potential issues, allowing administrators to identify bottlenecks, track errors, and improve the overall efficiency and reliability of the workspace.',
11+
recommended_action: 'Enable diagnostic logging for all Synapse workspaces.',
12+
link: 'https://learn.microsoft.com/en-us/azure/synapse-analytics/monitor-synapse-analytics',
13+
apis: ['synapse:listWorkspaces', 'diagnosticSettings:listByWorkspaces'],
14+
realtime_triggers: ['microsoftsynapse:workspaces:write','microsoftsynapse:workspaces:delete','microsoftinsights:diagnosticSettings:delete','microsoftinsights:diagnosticSettings:write'],
15+
16+
run: function(cache, settings, callback) {
17+
const results = [];
18+
const source = {};
19+
const locations = helpers.locations(settings.govcloud);
20+
21+
async.each(locations.synapse, function(location, rcb) {
22+
const workspaces = helpers.addSource(cache, source,
23+
['synapse', 'listWorkspaces', location]);
24+
25+
if (!workspaces) return rcb();
26+
27+
if (workspaces.err || !workspaces.data) {
28+
helpers.addResult(results, 3, 'Unable to query Synapse workspaces: ' + helpers.addError(workspaces), location);
29+
return rcb();
30+
}
31+
32+
if (!workspaces.data.length) {
33+
helpers.addResult(results, 0, 'No existing Synapse workspaces found', location);
34+
return rcb();
35+
}
36+
37+
for (let workspace of workspaces.data) {
38+
if (!workspace.id) continue;
39+
40+
var diagnosticSettings = helpers.addSource(cache, source,
41+
['diagnosticSettings', 'listByWorkspaces', location, workspace.id]);
42+
43+
if (!diagnosticSettings || diagnosticSettings.err || !diagnosticSettings.data) {
44+
helpers.addResult(results, 3, `Unable to query for Synapse workspace diagnostic settings: ${helpers.addError(diagnosticSettings)}`,
45+
location, workspace.id);
46+
continue;
47+
}
48+
49+
var found = diagnosticSettings.data.find(ds => ds.logs && ds.logs.length);
50+
51+
if (found) {
52+
helpers.addResult(results, 0, 'Synapse workspace has diagnostic logs enabled', location, workspace.id);
53+
} else {
54+
helpers.addResult(results, 2, 'Synapse workspace does not have diagnostic logs enabled', location, workspace.id);
55+
}
56+
}
57+
58+
rcb();
59+
}, function() {
60+
// Global checking goes here
61+
callback(null, results, source);
62+
});
63+
}
64+
};
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
var expect = require('chai').expect;
2+
var workspaceDiagnosticLogsEnabled = require('./workspaceDiagnosticLogsEnabled');
3+
4+
const workspaces = [
5+
{
6+
type: "Microsoft.Synapse/workspaces",
7+
id: "/subscriptions/123/resourceGroups/rsgrp/providers/Microsoft.Synapse/workspaces/test",
8+
location: "eastus",
9+
name: "test",
10+
}
11+
];
12+
13+
14+
const diagnosticSettings = [
15+
{
16+
id: "/subscriptions/123/resourceGroups/rsgrp/providers/Microsoft.Synapse/workspaces/test",
17+
type: 'Microsoft.Insights/diagnosticSettings',
18+
name: 'test',
19+
location: 'eastus',
20+
kind: null,
21+
tags: null,
22+
eventHubName: null,
23+
metrics: [],
24+
logs: [
25+
{
26+
"category": null,
27+
"categoryGroup": "allLogs",
28+
"enabled": true,
29+
"retentionPolicy": {
30+
"enabled": false,
31+
"days": 0
32+
}
33+
},
34+
{
35+
"category": null,
36+
"categoryGroup": "audit",
37+
"enabled": false,
38+
"retentionPolicy": {
39+
"enabled": false,
40+
"days": 0
41+
}
42+
}
43+
],
44+
logAnalyticsDestinationType: null
45+
}
46+
];
47+
48+
const createCache = (workspaces, ds) => {
49+
const id = workspaces && workspaces.length ? workspaces[0].id : null;
50+
return {
51+
synapse: {
52+
listWorkspaces: {
53+
'eastus': {
54+
data: workspaces
55+
}
56+
}
57+
},
58+
diagnosticSettings: {
59+
listByWorkspaces: {
60+
'eastus': {
61+
[id]: {
62+
data: ds
63+
}
64+
}
65+
}
66+
67+
},
68+
};
69+
};
70+
71+
describe('workspaceDiagnosticLogsEnabled', function() {
72+
describe('run', function() {
73+
it('should give a passing result if no Synapse workspaces are found', function (done) {
74+
const cache = createCache([], null);
75+
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => {
76+
expect(results.length).to.equal(1);
77+
expect(results[0].status).to.equal(0);
78+
expect(results[0].message).to.include('No existing Synapse workspaces found');
79+
expect(results[0].region).to.equal('eastus');
80+
done();
81+
});
82+
});
83+
84+
it('should give unknown result if unable to query for Synapse workspaces', function (done) {
85+
const cache = createCache(null, ['error']);
86+
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => {
87+
expect(results.length).to.equal(1);
88+
expect(results[0].status).to.equal(3);
89+
expect(results[0].message).to.include('Unable to query Synapse workspaces: Unable to obtain data');
90+
expect(results[0].region).to.equal('eastus');
91+
done();
92+
});
93+
});
94+
it('should give unknown result if unable to query for diagnostic settings', function(done) {
95+
const cache = createCache([workspaces[0]], null);
96+
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => {
97+
expect(results.length).to.equal(1);
98+
expect(results[0].status).to.equal(3);
99+
expect(results[0].message).to.include('Unable to query for Synapse workspace diagnostic settings');
100+
expect(results[0].region).to.equal('eastus');
101+
done();
102+
});
103+
});
104+
105+
it('should give passing result if diagnostic logs enabled', function(done) {
106+
const cache = createCache([workspaces[0]], [diagnosticSettings[0]]);
107+
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => {
108+
expect(results.length).to.equal(1);
109+
expect(results[0].status).to.equal(0);
110+
expect(results[0].message).to.include('Synapse workspace has diagnostic logs enabled');
111+
expect(results[0].region).to.equal('eastus');
112+
done();
113+
});
114+
});
115+
116+
it('should give failing result if diagnostic logs not enabled', function(done) {
117+
const cache = createCache([workspaces[0]], [[]]);
118+
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => {
119+
expect(results.length).to.equal(1);
120+
expect(results[0].status).to.equal(2);
121+
expect(results[0].message).to.include('Synapse workspace does not have diagnostic logs enabled');
122+
expect(results[0].region).to.equal('eastus');
123+
done();
124+
});
125+
});
126+
});
127+
});

0 commit comments

Comments
 (0)