-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2076 from AkhtarAmir/H-plugin/synapse-workspace-d…
…iagnostic-logging H-plugin synapse workspace diagnostic logs enabled
- Loading branch information
Showing
4 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var async = require('async'); | ||
var helpers = require('../../../helpers/azure'); | ||
|
||
module.exports = { | ||
title: 'Synapse Workspace Diagnostic Logging Enabled', | ||
category: 'AI & ML', | ||
domain: 'Machine Learning', | ||
severity: 'Medium', | ||
description: 'Ensures that diagnostic logging is enabled for Synapse workspace.', | ||
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.', | ||
recommended_action: 'Enable diagnostic logging for all Synapse workspaces.', | ||
link: 'https://learn.microsoft.com/en-us/azure/synapse-analytics/monitor-synapse-analytics', | ||
apis: ['synapse:listWorkspaces', 'diagnosticSettings:listByWorkspaces'], | ||
realtime_triggers: ['microsoftsynapse:workspaces:write','microsoftsynapse:workspaces:delete','microsoftinsights:diagnosticSettings:delete','microsoftinsights:diagnosticSettings:write'], | ||
|
||
run: function(cache, settings, callback) { | ||
const results = []; | ||
const source = {}; | ||
const locations = helpers.locations(settings.govcloud); | ||
|
||
async.each(locations.synapse, function(location, rcb) { | ||
const workspaces = helpers.addSource(cache, source, | ||
['synapse', 'listWorkspaces', location]); | ||
|
||
if (!workspaces) return rcb(); | ||
|
||
if (workspaces.err || !workspaces.data) { | ||
helpers.addResult(results, 3, 'Unable to query Synapse workspaces: ' + helpers.addError(workspaces), location); | ||
return rcb(); | ||
} | ||
|
||
if (!workspaces.data.length) { | ||
helpers.addResult(results, 0, 'No existing Synapse workspaces found', location); | ||
return rcb(); | ||
} | ||
|
||
for (let workspace of workspaces.data) { | ||
if (!workspace.id) continue; | ||
|
||
var diagnosticSettings = helpers.addSource(cache, source, | ||
['diagnosticSettings', 'listByWorkspaces', location, workspace.id]); | ||
|
||
if (!diagnosticSettings || diagnosticSettings.err || !diagnosticSettings.data) { | ||
helpers.addResult(results, 3, `Unable to query for Synapse workspace diagnostic settings: ${helpers.addError(diagnosticSettings)}`, | ||
location, workspace.id); | ||
continue; | ||
} | ||
|
||
var found = diagnosticSettings.data.find(ds => ds.logs && ds.logs.length); | ||
|
||
if (found) { | ||
helpers.addResult(results, 0, 'Synapse workspace has diagnostic logs enabled', location, workspace.id); | ||
} else { | ||
helpers.addResult(results, 2, 'Synapse workspace does not have diagnostic logs enabled', location, workspace.id); | ||
} | ||
} | ||
|
||
rcb(); | ||
}, function() { | ||
// Global checking goes here | ||
callback(null, results, source); | ||
}); | ||
} | ||
}; |
127 changes: 127 additions & 0 deletions
127
plugins/azure/synapse/workspaceDiagnosticLogsEnabled.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
var expect = require('chai').expect; | ||
var workspaceDiagnosticLogsEnabled = require('./workspaceDiagnosticLogsEnabled'); | ||
|
||
const workspaces = [ | ||
{ | ||
type: "Microsoft.Synapse/workspaces", | ||
id: "/subscriptions/123/resourceGroups/rsgrp/providers/Microsoft.Synapse/workspaces/test", | ||
location: "eastus", | ||
name: "test", | ||
} | ||
]; | ||
|
||
|
||
const diagnosticSettings = [ | ||
{ | ||
id: "/subscriptions/123/resourceGroups/rsgrp/providers/Microsoft.Synapse/workspaces/test", | ||
type: 'Microsoft.Insights/diagnosticSettings', | ||
name: 'test', | ||
location: 'eastus', | ||
kind: null, | ||
tags: null, | ||
eventHubName: null, | ||
metrics: [], | ||
logs: [ | ||
{ | ||
"category": null, | ||
"categoryGroup": "allLogs", | ||
"enabled": true, | ||
"retentionPolicy": { | ||
"enabled": false, | ||
"days": 0 | ||
} | ||
}, | ||
{ | ||
"category": null, | ||
"categoryGroup": "audit", | ||
"enabled": false, | ||
"retentionPolicy": { | ||
"enabled": false, | ||
"days": 0 | ||
} | ||
} | ||
], | ||
logAnalyticsDestinationType: null | ||
} | ||
]; | ||
|
||
const createCache = (workspaces, ds) => { | ||
const id = workspaces && workspaces.length ? workspaces[0].id : null; | ||
return { | ||
synapse: { | ||
listWorkspaces: { | ||
'eastus': { | ||
data: workspaces | ||
} | ||
} | ||
}, | ||
diagnosticSettings: { | ||
listByWorkspaces: { | ||
'eastus': { | ||
[id]: { | ||
data: ds | ||
} | ||
} | ||
} | ||
|
||
}, | ||
}; | ||
}; | ||
|
||
describe('workspaceDiagnosticLogsEnabled', function() { | ||
describe('run', function() { | ||
it('should give a passing result if no Synapse workspaces are found', function (done) { | ||
const cache = createCache([], null); | ||
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('No existing Synapse workspaces found'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give unknown result if unable to query for Synapse workspaces', function (done) { | ||
const cache = createCache(null, ['error']); | ||
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(3); | ||
expect(results[0].message).to.include('Unable to query Synapse workspaces: Unable to obtain data'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
it('should give unknown result if unable to query for diagnostic settings', function(done) { | ||
const cache = createCache([workspaces[0]], null); | ||
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(3); | ||
expect(results[0].message).to.include('Unable to query for Synapse workspace diagnostic settings'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give passing result if diagnostic logs enabled', function(done) { | ||
const cache = createCache([workspaces[0]], [diagnosticSettings[0]]); | ||
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(0); | ||
expect(results[0].message).to.include('Synapse workspace has diagnostic logs enabled'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should give failing result if diagnostic logs not enabled', function(done) { | ||
const cache = createCache([workspaces[0]], [[]]); | ||
workspaceDiagnosticLogsEnabled.run(cache, {}, (err, results) => { | ||
expect(results.length).to.equal(1); | ||
expect(results[0].status).to.equal(2); | ||
expect(results[0].message).to.include('Synapse workspace does not have diagnostic logs enabled'); | ||
expect(results[0].region).to.equal('eastus'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |