Skip to content

Commit cc00cec

Browse files
authored
Merge pull request #672 from alexprotsenko/master
[SQL Asmnt] Notebooks: Tutorial and Quick Start
2 parents e76d924 + c5c98ba commit cc00cec

10 files changed

Lines changed: 757 additions & 0 deletions
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+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "1.1",
4+
"name": "Custom Ruleset",
5+
"rules":[
6+
{
7+
"target": {
8+
"type": "Database",
9+
"engineEdition": "OnPremises, ManagedInstance",
10+
"version": [
11+
"[11.0,11.0.7001.0)",
12+
"[12.0,12.0.6259.0)",
13+
"[13.0,)"
14+
],
15+
"platform": "/Windows|Linux/"
16+
},
17+
"id": "DBSpaceAvailable",
18+
"itemType": "definition",
19+
"displayName": "Database files have little free space",
20+
"description": "Average available space in all the database files is less than the threshold.",
21+
"message": "Database has only @{SPACEAVAILABLEPERC}% of free space (threshold is set to @{threshold}%). Total space: @{SPACETOTALMB} MB. Free space: @{SPACEAVAILABLEMB} MB",
22+
"probes": ["DBSpaceAvailable"],
23+
"threshold": 25,
24+
"condition": [
25+
{"greater": ["@SPACEAVAILABLEPERC", "@threshold"]}
26+
]
27+
}
28+
],
29+
"probes":{
30+
"DBSpaceAvailable": [
31+
{
32+
"type": "SQL",
33+
"target": {
34+
"type": "Database",
35+
"engineEdition": "OnPremises, ManagedInstance",
36+
"platform": "/Windows|Linux/"
37+
},
38+
"implementation": {
39+
"useDatabase": true,
40+
"query":
41+
"SELECT convert(decimal(12,2),((sum (convert(decimal(12,2),round(a.size/128.000,2))) - sum(convert(decimal(12,2),round(fileproperty(a.name,'SpaceUsed')/128.000,2)))) /sum (convert(decimal(12,2),round(a.size/128.000,2)))*100)) as SPACEAVAILABLEPERC , SUM(convert(decimal(12,2),round(a.size/128.000,2))) as SPACETOTALMB , SUM(convert(decimal(12,2),round(fileproperty(a.name,'SpaceUsed')/128.000,2))) as SPACEUSEDMB , SUM(convert(decimal(12,2),round((a.size-fileproperty(a.name,'SpaceUsed'))/128.000,2))) as SPACEAVAILABLEMB FROM dbo.sysfiles a WHERE groupid <> 0;"
42+
}
43+
}
44+
]
45+
}
46+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "1.2",
4+
"name": "Custom Ruleset 2",
5+
"rules":[
6+
{
7+
"id": "DBSpaceAvailable",
8+
"itemType": "override",
9+
"threshold": 50
10+
}
11+
]
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "0.1.2",
4+
"name": "Custom Ruleset 2",
5+
"rules":[
6+
{
7+
"id": ["TraceFlag"],
8+
"itemType": "override",
9+
"enabled": false
10+
}
11+
]
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "0.1.2",
4+
"name": "Custom Ruleset 1",
5+
"rules":[
6+
{
7+
"id": "TF634",
8+
"itemType": "override",
9+
"enabled": false
10+
}
11+
]
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"version": "1.0",
4+
"name": "Demo",
5+
"rules":[
6+
{
7+
"id": ["Performance"],
8+
"itemType": "override",
9+
"enabled": true
10+
}
11+
]
12+
}
Binary file not shown.
Binary file not shown.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"metadata": {
3+
"kernelspec": {
4+
"name": "powershell",
5+
"display_name": "PowerShell"
6+
},
7+
"language_info": {
8+
"name": "powershell",
9+
"codemirror_mode": "shell",
10+
"mimetype": "text/x-sh",
11+
"file_extension": ".ps1"
12+
}
13+
},
14+
"nbformat_minor": 2,
15+
"nbformat": 4,
16+
"cells": [
17+
{
18+
"cell_type": "markdown",
19+
"source": [
20+
"# SQL Assessment API Quick Start\r\n",
21+
"## Assess your SQL Server configuration for best practices in 2 simple steps"
22+
],
23+
"metadata": {
24+
"azdata_cell_guid": "a49ad7c3-e68e-4829-bcec-0bfc9115e476"
25+
}
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"source": [
30+
"### 1. Setup\r\n",
31+
"You need to install PowerShell SqlServer module using the following command. It is a good practice to run Import-Module at the beginning of your session as well. Get-Module will show you the version you have installed. The minimum version you want is 21.1.18206 — it is the version of SqlServer module containing SQL Assessment API GA."
32+
],
33+
"metadata": {
34+
"azdata_cell_guid": "2060c61e-6488-4b54-8aa8-8604a6159c0c"
35+
}
36+
},
37+
{
38+
"cell_type": "code",
39+
"source": [
40+
"# Uncomment and run Install-Module only the first time \r\n",
41+
"# Install-Module -Name SqlServer -AllowClobber -Force\r\n",
42+
"Import-Module -Name SqlServer\r\n",
43+
"Get-Module"
44+
],
45+
"metadata": {
46+
"azdata_cell_guid": "d16282b0-a7fe-4f94-aa23-88b773dd0329"
47+
},
48+
"outputs": [],
49+
"execution_count": 4
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"source": [
54+
"### 2. Invoke an assessment\r\n",
55+
"This command runs an assessment against your local SQL Server instance.\r\n",
56+
""
57+
],
58+
"metadata": {
59+
"azdata_cell_guid": "69d60fd2-727d-4b30-b723-b217fa8ea128"
60+
}
61+
},
62+
{
63+
"cell_type": "code",
64+
"source": [
65+
"Get-SqlInstance -ServerInstance 'localhost' | Invoke-SqlAssessment"
66+
],
67+
"metadata": {
68+
"azdata_cell_guid": "7468c134-77ff-4786-a795-a3767b55bd3b"
69+
},
70+
"outputs": [],
71+
"execution_count": 5
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"source": [
76+
"\r\n",
77+
"You will see in the results that each rule has some properties (not the full list):\r\n",
78+
"- Severity (info, warning, critical) \r\n",
79+
"- Message property explains the recommendation but if you need more info, there is a HelpLink property that points at documentation on the subject.\r\n",
80+
"- Origin shows which ruleset and version the recommendation is coming from\r\n",
81+
"\r\n",
82+
"Visit SQL Assessment API GitHub page at http://aka.ms/sql-assessment-api for a full list of rules and properties.\r\n",
83+
"\r\n",
84+
"If you want to get recommendations for all databases on the local instance, you can run this command."
85+
],
86+
"metadata": {
87+
"azdata_cell_guid": "546c7f04-c14f-449d-ba34-53bc52e545a5"
88+
}
89+
},
90+
{
91+
"cell_type": "code",
92+
"source": [
93+
"Get-SqlDatabase -ServerInstance 'localhost' | Invoke-SqlAssessment"
94+
],
95+
"metadata": {
96+
"azdata_cell_guid": "bbe2ef33-c5db-4a64-bb32-cd93b906c48d"
97+
},
98+
"outputs": [],
99+
"execution_count": 6
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"source": [
104+
"### Learn more about SQL Assessment API\r\n",
105+
"To learn more about SQL Assesment API such as customizing and extending the rule set, saving the results in a table, etc., please visit:\r\n",
106+
"- Docs online page: https://docs.microsoft.com/sql/sql-assessment-api/sql-assessment-api-overview \r\n",
107+
"- GitHub repo: http://aka.ms/sql-assessment-api\r\n",
108+
"- SQL Assessment API Tutorial notebook: coming soon"
109+
],
110+
"metadata": {
111+
"azdata_cell_guid": "180b3a6d-1dab-4641-acd4-dc319e81ef1f"
112+
}
113+
}
114+
]
115+
}

0 commit comments

Comments
 (0)