Skip to content

Commit c5c98ba

Browse files
Brought back CLR probe stuff
Added a CLR probe section to the notebook, put 2 dlls and 1 json in the CustomizationSamples folder
1 parent d04c624 commit c5c98ba

7 files changed

Lines changed: 91 additions & 21 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "0.1.2",
4+
"name": "Custom Ruleset 7",
5+
"probes":{
6+
"ManagedCodeRuleProbe": [
7+
{
8+
"type": "CLR",
9+
"target": {
10+
"type": "Server"
11+
},
12+
"implementation": {
13+
"class": "TestsProbeLibrary.Probe1",
14+
"assembly": "C:\\SQLAsmnt\\CustomizationSamples\\TestsProbeLibrary.dll"
15+
}
16+
}
17+
]
18+
},
19+
"rules":[
20+
{
21+
"id": ["DefaultRuleset"],
22+
"itemType": "override",
23+
"enabled": false
24+
},
25+
{
26+
"id": "ManagedCodeRule",
27+
"itemType": "definition",
28+
"displayName": "Check uses 3rd-party assembly",
29+
"description": "This is an example of a check using an assembly to get required data.",
30+
"message": "Method from the assembly returned a number greater than the threshold: @{QueryResult} > @{threshold}.",
31+
"target": { "type": "Server" },
32+
"probes": ["ManagedCodeRuleProbe"],
33+
"threshold": 83,
34+
"condition": { "less": ["@QueryResult", "@threshold"] }
35+
}
36+
]
37+
}

samples/manage/sql-assessment-api/notebooks/CustomizationSamples/CustomRuleTSQLProbe.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"itemType": "definition",
1919
"displayName": "Database files have little free space",
2020
"description": "Average available space in all the database files is less than the threshold.",
21-
"message": "Database has only @{SPACEAVAILABLEPERC}% of free space. Total space: @{SPACETOTALMB} MB. Free space: @{SPACEAVAILABLEMB} MB",
21+
"message": "Database has only @{SPACEAVAILABLEPERC}% of free space (threshold is set to @{threshold}%). Total space: @{SPACETOTALMB} MB. Free space: @{SPACEAVAILABLEMB} MB",
2222
"probes": ["DBSpaceAvailable"],
2323
"threshold": 25,
2424
"condition": [

samples/manage/sql-assessment-api/notebooks/CustomizationSamples/DisableAllTF.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
"enabled": false
1010
}
1111
]
12-
}
12+
}

samples/manage/sql-assessment-api/notebooks/CustomizationSamples/DisableTF634.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
"enabled": false
1010
}
1111
]
12-
}
12+
}
Binary file not shown.
Binary file not shown.

samples/manage/sql-assessment-api/notebooks/SQLAssessmentAPITutorialNotebook.ipynb

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,15 @@
337337
"## Customization\r\n",
338338
"In this section you will learn how to customize existing rules and create new ones.\r\n",
339339
"\r\n",
340-
"As a prerequisite, make sure to grab the JSON files in the CustomizationSamples folder and place them in an accessible path and then edit the first script below to point at the right path and server instance for your environment. We encourage you to look into every JSON sample so you can understand better the making of customizations for SQL Assessment.\r\n",
340+
"As a prerequisite, make sure to grab the JSON files in the CustomizationSamples folder and place them in an accessible path and then edit the first script below to point at the right path and server instance for your environment. By default, we use in this notebook the following parameters:\r\n",
341+
"- SQL Instance to assess is \"localhost\"\r\n",
342+
"- JSON samples and DLLs are available by path \"C:\\SQLAsmnt\\CustomizationSamples\\\"\r\n",
343+
"\r\n",
344+
"The final code block in this notebook has its own prerequisites, please complete them prior to running it:\r\n",
345+
"- There are 2 dlls in CustomizationSamples folder. They both should be unblocked: https://stackoverflow.com/questions/34400546/could-not-load-file-or-assembly-operation-is-not-supported-exception-from-hres/45221477\r\n",
346+
"- Then open CustomRuleCLRProbe.json and make sure that assembly key contains the right path to TestsProbeLibrary.dll, double backslashes are required.\r\n",
347+
"\r\n",
348+
"We encourage you to look into every JSON sample so you can understand better the making of customizations for SQL Assessment.\r\n",
341349
""
342350
],
343351
"metadata": {
@@ -356,17 +364,17 @@
356364
{
357365
"cell_type": "code",
358366
"source": [
359-
"#Setup two parameters that are used in all the customization examples below\r\n",
360-
"#$binariesPath='<replace this with the path to customization json files, e.g. \"C:\\SQLAsmnt\\CustomizationSamples\">' \r\n",
361-
"$binariesPath='C:\\SQLAsmnt\\CustomizationSamples'\r\n",
362-
"$binariesPath\r\n",
367+
"#Setup three parameters that are used in all the customization examples below\r\n",
368+
"#$samplesPath='<replace this with the path to customization json files, e.g. \"C:\\SQLAsmnt\\CustomizationSamples\">' \r\n",
369+
"$samplesPath='C:\\SQLAsmnt\\CustomizationSamples'\r\n",
370+
"$samplesPath\r\n",
363371
"\r\n",
364-
"$serverInstance = Get-SqlInstance -ServerInstance 'localhost'\r\n",
372+
"#$serverInstance = Get-SqlInstance -ServerInstance 'localhost'\r\n",
373+
"$serverInstance = Get-SqlInstance -ServerInstance '.\\sql2017express'\r\n",
365374
"$serverInstance\r\n",
366375
"\r\n",
367376
"$sqlDbMaster = $serverInstance | Get-SqlDatabase -Name master\r\n",
368-
"$sqlDbMaster\r\n",
369-
""
377+
"$sqlDbMaster"
370378
],
371379
"metadata": {
372380
"azdata_cell_guid": "5df878e7-8204-45c8-8bb2-4861131f3588",
@@ -381,41 +389,41 @@
381389
"# Disable a single rule using its ID (TF634)\r\n",
382390
"# To see this in action, make sure you have trace flag 634 turned on in the instance you are testing. Otherwise this rule will not fire even when enabled.\r\n",
383391
"# You will see that TF634 is not enabled (On=False)\r\n",
384-
"Get-SqlAssessmentItem $serverInstance -Configuration $(join-path $binariesPath \"DisableTF634.json\")"
392+
"Get-SqlAssessmentItem $serverInstance -Configuration $(join-path $samplesPath \"DisableTF634.json\")"
385393
],
386394
"metadata": {
387395
"azdata_cell_guid": "7a2a90f0-8341-4cd8-81a3-1fdedbd1adb6"
388396
},
389397
"outputs": [],
390-
"execution_count": 7
398+
"execution_count": 4
391399
},
392400
{
393401
"cell_type": "code",
394402
"source": [
395403
"# Disable all Trace Flag rules using a tag\r\n",
396404
"# You will see that all TF rules are set to False (disabled)\r\n",
397-
"Get-SqlAssessmentItem $serverInstance -Configuration $(join-path $binariesPath \"DisableAllTF.json\")"
405+
"Get-SqlAssessmentItem $serverInstance -Configuration $(join-path $samplesPath \"DisableAllTF.json\")"
398406
],
399407
"metadata": {
400408
"azdata_cell_guid": "35ee6731-70dd-42b9-b041-f3b09ac02a4d",
401409
"tags": []
402410
},
403411
"outputs": [],
404-
"execution_count": 9
412+
"execution_count": 6
405413
},
406414
{
407415
"cell_type": "code",
408416
"source": [
409417
"# Combine configurations\r\n",
410418
"# This example disables all trace flag rules except for performance-related ones using tags. \r\n",
411419
"# The order of json files is important. First we disable all TF rules, then enable performance rules which re-enables performance-related TF rules.\r\n",
412-
"Get-SqlAssessmentItem $serverInstance -Configuration $(join-path $binariesPath \"DisableAllTF.json\"), $(join-path $binariesPath \"EnablePerformance.json\")"
420+
"Get-SqlAssessmentItem $serverInstance -Configuration $(join-path $samplesPath \"DisableAllTF.json\"), $(join-path $samplesPath \"EnablePerformance.json\")"
413421
],
414422
"metadata": {
415423
"azdata_cell_guid": "4f79d729-4a3b-47a6-8cb3-d4a5b0c2db05"
416424
},
417425
"outputs": [],
418-
"execution_count": 11
426+
"execution_count": 8
419427
},
420428
{
421429
"cell_type": "markdown",
@@ -439,27 +447,52 @@
439447
"source": [
440448
"# Create a new rule with TSQL probe\r\n",
441449
"# This rule applies to databases and uses a TSQL statement to get the data for the rule. \r\n",
442-
"Invoke-SqlAssessment $sqlDbMaster -configuration $(join-path $binariesPath \"CustomRuleTSQLProbe.json\")"
450+
"Invoke-SqlAssessment $sqlDbMaster -configuration $(join-path $samplesPath \"CustomRuleTSQLProbe.json\")"
443451
],
444452
"metadata": {
445453
"azdata_cell_guid": "1df3379f-e5fe-47ea-a43e-920265f3d0e2",
446454
"tags": []
447455
},
448456
"outputs": [],
449-
"execution_count": 45
457+
"execution_count": 10
450458
},
451459
{
452460
"cell_type": "code",
453461
"source": [
454462
"# Override threshold parameter\r\n",
455463
"# CustomRuleThresholdChange.json defines a new threshold value for DBSpaceAvailable rule created above\r\n",
456-
"Invoke-SqlAssessment $sqlDbMaster -configuration $(join-path $binariesPath \"CustomRuleTSQLProbe.json\"),$(join-path $binariesPath \"CustomRuleThresholdChange.json\")"
464+
"Invoke-SqlAssessment $sqlDbMaster -configuration $(join-path $samplesPath \"CustomRuleTSQLProbe.json\"),$(join-path $samplesPath \"CustomRuleThresholdChange.json\")"
457465
],
458466
"metadata": {
459467
"azdata_cell_guid": "953cd87b-4311-4553-9170-e219c231642a"
460468
},
461469
"outputs": [],
462-
"execution_count": 106
470+
"execution_count": 13
471+
},
472+
{
473+
"cell_type": "markdown",
474+
"source": [
475+
"### Managed code probe"
476+
],
477+
"metadata": {
478+
"azdata_cell_guid": "54a36d0b-6934-468e-a94c-b767d13b3b07"
479+
}
480+
},
481+
{
482+
"cell_type": "code",
483+
"source": [
484+
"# Create a new rule with CLR probe. CustomRuleCLRProbe.json, in addition to a check with a CLR probe, contains an ovveride to disable all the rules of the DefaultRuleset.\r\n",
485+
"# !!! Complete the prerequisites below before running this block.\r\n",
486+
"# !!! There are 2 dlls in CustomizationSamples folder. Make sure that they both are not blocked: https://stackoverflow.com/questions/34400546/could-not-load-file-or-assembly-operation-is-not-supported-exception-from-hres/45221477\r\n",
487+
"# !!! Then open CustomRuleCLRProbe.json in the same folder and make sure that assembly key contains the right path to TestsProbeLibrary.dll, double slashes are required.\r\n",
488+
"# !!! You're all set. Run this block\r\n",
489+
"Invoke-SqlAssessment $serverInstance -configuration $(join-path $samplesPath \"CustomRuleCLRProbe.json\")"
490+
],
491+
"metadata": {
492+
"azdata_cell_guid": "a4761c60-e0cc-4e7c-b386-1397ca532e44"
493+
},
494+
"outputs": [],
495+
"execution_count": 19
463496
},
464497
{
465498
"cell_type": "markdown",

0 commit comments

Comments
 (0)