|
337 | 337 | "## Customization\r\n", |
338 | 338 | "In this section you will learn how to customize existing rules and create new ones.\r\n", |
339 | 339 | "\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", |
341 | 349 | "" |
342 | 350 | ], |
343 | 351 | "metadata": { |
|
356 | 364 | { |
357 | 365 | "cell_type": "code", |
358 | 366 | "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", |
363 | 371 | "\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", |
365 | 374 | "$serverInstance\r\n", |
366 | 375 | "\r\n", |
367 | 376 | "$sqlDbMaster = $serverInstance | Get-SqlDatabase -Name master\r\n", |
368 | | - "$sqlDbMaster\r\n", |
369 | | - "" |
| 377 | + "$sqlDbMaster" |
370 | 378 | ], |
371 | 379 | "metadata": { |
372 | 380 | "azdata_cell_guid": "5df878e7-8204-45c8-8bb2-4861131f3588", |
|
381 | 389 | "# Disable a single rule using its ID (TF634)\r\n", |
382 | 390 | "# 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", |
383 | 391 | "# 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\")" |
385 | 393 | ], |
386 | 394 | "metadata": { |
387 | 395 | "azdata_cell_guid": "7a2a90f0-8341-4cd8-81a3-1fdedbd1adb6" |
388 | 396 | }, |
389 | 397 | "outputs": [], |
390 | | - "execution_count": 7 |
| 398 | + "execution_count": 4 |
391 | 399 | }, |
392 | 400 | { |
393 | 401 | "cell_type": "code", |
394 | 402 | "source": [ |
395 | 403 | "# Disable all Trace Flag rules using a tag\r\n", |
396 | 404 | "# 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\")" |
398 | 406 | ], |
399 | 407 | "metadata": { |
400 | 408 | "azdata_cell_guid": "35ee6731-70dd-42b9-b041-f3b09ac02a4d", |
401 | 409 | "tags": [] |
402 | 410 | }, |
403 | 411 | "outputs": [], |
404 | | - "execution_count": 9 |
| 412 | + "execution_count": 6 |
405 | 413 | }, |
406 | 414 | { |
407 | 415 | "cell_type": "code", |
408 | 416 | "source": [ |
409 | 417 | "# Combine configurations\r\n", |
410 | 418 | "# This example disables all trace flag rules except for performance-related ones using tags. \r\n", |
411 | 419 | "# 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\")" |
413 | 421 | ], |
414 | 422 | "metadata": { |
415 | 423 | "azdata_cell_guid": "4f79d729-4a3b-47a6-8cb3-d4a5b0c2db05" |
416 | 424 | }, |
417 | 425 | "outputs": [], |
418 | | - "execution_count": 11 |
| 426 | + "execution_count": 8 |
419 | 427 | }, |
420 | 428 | { |
421 | 429 | "cell_type": "markdown", |
|
439 | 447 | "source": [ |
440 | 448 | "# Create a new rule with TSQL probe\r\n", |
441 | 449 | "# 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\")" |
443 | 451 | ], |
444 | 452 | "metadata": { |
445 | 453 | "azdata_cell_guid": "1df3379f-e5fe-47ea-a43e-920265f3d0e2", |
446 | 454 | "tags": [] |
447 | 455 | }, |
448 | 456 | "outputs": [], |
449 | | - "execution_count": 45 |
| 457 | + "execution_count": 10 |
450 | 458 | }, |
451 | 459 | { |
452 | 460 | "cell_type": "code", |
453 | 461 | "source": [ |
454 | 462 | "# Override threshold parameter\r\n", |
455 | 463 | "# 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\")" |
457 | 465 | ], |
458 | 466 | "metadata": { |
459 | 467 | "azdata_cell_guid": "953cd87b-4311-4553-9170-e219c231642a" |
460 | 468 | }, |
461 | 469 | "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 |
463 | 496 | }, |
464 | 497 | { |
465 | 498 | "cell_type": "markdown", |
|
0 commit comments