Skip to content

Commit 033f417

Browse files
authored
Merge pull request #791 from altanatsedenova/master
Examples for different probe types
2 parents b6e7c25 + 9e8c13e commit 033f417

6 files changed

Lines changed: 313 additions & 5 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"name": "CmdShell check",
4+
"version": "1.0.0",
5+
"rules": [
6+
{
7+
"id": "DirectoryCheck",
8+
"itemType": "definition",
9+
"target": {
10+
"type": "Server",
11+
"platform": "Windows",
12+
"engineEdition": "OnPremises",
13+
"version": "[11.0,)"
14+
},
15+
"displayName": "CmdShell probe",
16+
"description": "This is an example of cmdshell probe type. ",
17+
"message": "Empty list",
18+
"level": "Warning",
19+
"condition": "@stdout",
20+
"probes": [
21+
"ListOfDirectoryFilesAndSubdirectories"
22+
]
23+
},
24+
{
25+
"id": ["DefaultRuleset"],
26+
"itemType": "override",
27+
"enabled": false
28+
}
29+
],
30+
"probes": {
31+
"ListOfDirectoryFilesAndSubdirectories": [
32+
{
33+
"type": "CmdShell",
34+
"target": {
35+
"type": "Server",
36+
"platform": "Windows",
37+
"engineEdition": "OnPremises",
38+
"version": "[11.0,)"
39+
},
40+
"implementation": {
41+
"command": "dir"
42+
}
43+
}
44+
]
45+
}
46+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"name": "NO NAME",
4+
"version": "1.0.0",
5+
"rules": [
6+
{
7+
"id": "PowerShellVersion",
8+
"itemType": "definition",
9+
"target": {
10+
"type": "Server",
11+
"platform": "Windows",
12+
"engineEdition": "OnPremises",
13+
"version": "[11.0,)"
14+
},
15+
"displayName": "PowerShell host information",
16+
"description": "Information about the PowerShell console host ",
17+
"message": "Upgrade PowerShell. Installed version is @{Output.Version}, latest available is @{latestVersion}.",
18+
"level": "Warning",
19+
"latestVersion": "7.0.2",
20+
"condition": {
21+
"eq": [
22+
"@Output.Version",
23+
"@latestVersion"
24+
]
25+
},
26+
"probes": [
27+
"PowershellHostInformation"
28+
]
29+
}
30+
],
31+
"probes": {
32+
"PowershellHostInformation": [
33+
{
34+
"type": "PowerShell",
35+
"target": {
36+
"type": "Server",
37+
"platform": "Windows",
38+
"engineEdition": "OnPremises",
39+
"version": "[11.0,)"
40+
},
41+
"implementation": {
42+
"command": "Get-Host"
43+
}
44+
}
45+
]
46+
}
47+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"name": "Registry check",
4+
"version": "1.0.0",
5+
"rules": [
6+
{
7+
"id": "ComputerNameRule",
8+
"itemType": "definition",
9+
"target": {
10+
"type": "Server",
11+
"platform": "Windows",
12+
"engineEdition": "OnPremises",
13+
"version": "[11.0,)"
14+
},
15+
"displayName": "Computer name",
16+
"description": "Computer name can't be empty.",
17+
"message": "Computer name in 'HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet' cannot be empty",
18+
"level": "Warning",
19+
"condition": "@ComputerName",
20+
"probes": [
21+
"ComputerName"
22+
]
23+
},
24+
{
25+
"id": ["DefaultRuleset"],
26+
"itemType": "override",
27+
"enabled": false
28+
}
29+
],
30+
"probes": {
31+
"ComputerName": [
32+
{
33+
"type": "Registry",
34+
"target": {
35+
"type": "Server",
36+
"platform": "Windows",
37+
"engineEdition": "OnPremises",
38+
"version": "[11.0,)"
39+
},
40+
"implementation": {
41+
"query": {
42+
"HKEY_LOCAL_MACHINE": {
43+
"SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName": [
44+
"ComputerName"
45+
]
46+
}
47+
}
48+
}
49+
}
50+
]
51+
}
52+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"schemaVersion": "1.0",
3+
"name": "WMI check",
4+
"version": "1.0.0",
5+
"rules": [
6+
{
7+
"id": "Win32Volume",
8+
"itemType": "definition",
9+
"target": {
10+
"type": "Server",
11+
"platform": "Windows",
12+
"engineEdition": "OnPremises",
13+
"version": "[11.0,)"
14+
},
15+
"displayName": "Block size",
16+
"description": "This is an example of using WMI query.",
17+
"message": "Format volume @{Output.Name} to recommended block size of 64KB. Current size is @{Output.BlockSize} bytes",
18+
"level": "Warning",
19+
"BlockSize": 65536,
20+
"condition": {
21+
"or": [
22+
{
23+
"not": "@Output.Name"
24+
},
25+
{
26+
"eq": [
27+
"@Output.BlockSize",
28+
"@BlockSize"
29+
]
30+
}
31+
]
32+
},
33+
"probes": [
34+
"Win32Volumes"
35+
]
36+
},
37+
{
38+
"id": ["DefaultRuleset"],
39+
"itemType": "override",
40+
"enabled": false
41+
}
42+
],
43+
"probes": {
44+
"Win32Volumes": [
45+
{
46+
"type": "WMI",
47+
"target": {
48+
"type": "Server",
49+
"platform": "Windows",
50+
"engineEdition": "OnPremises",
51+
"version": "[11.0,)"
52+
},
53+
"implementation": {
54+
"query": "SELECT Name, BlockSize FROM Win32_Volume WHERE Capacity <> NULL"
55+
}
56+
}
57+
]
58+
}
59+
}

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

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
"azdata_cell_guid": "dc8b69d6-6d20-4115-a68a-f6abd39d6c4a"
172172
},
173173
"outputs": [],
174-
"execution_count": 0
174+
"execution_count": null
175175
},
176176
{
177177
"cell_type": "markdown",
@@ -472,10 +472,114 @@
472472
{
473473
"cell_type": "markdown",
474474
"source": [
475-
"### Managed code probe"
475+
"## Probe types\r\n",
476+
"### CmdShell\r\n",
477+
"Create a new rule with CmdShell probe. CmdShell probe executes a CMD.EXE shell command and returns lines of text in variable @stdout. Use CMDSHELL instead of QUERY in probe definition to load a .cmd file. Use Regex parser transformation to extract data from @stdout\r\n",
478+
""
479+
],
480+
"metadata": {
481+
"azdata_cell_guid": "86aed978-b91a-47f0-8a78-f8254c5ec6f1"
482+
}
483+
},
484+
{
485+
"cell_type": "code",
486+
"source": [
487+
"#Create new rule with cmd probe type. It runs 'dir' cmd command and checks that resulted list is'n empty.\r\n",
488+
"#Make sure that xp_cmdshell is enabled\r\n",
489+
"Invoke-SqlAssessment $serverInstance -configuration $(join-path $samplesPath \"CustomRuleCmdShellProbe.json\")"
490+
],
491+
"metadata": {
492+
"azdata_cell_guid": "a75ebf02-e27e-4d19-b306-ce4e04481acd"
493+
},
494+
"outputs": [],
495+
"execution_count": null
496+
},
497+
{
498+
"cell_type": "markdown",
499+
"source": [
500+
"### PowerShell\r\n",
501+
"\r\n",
502+
"PowerShell probe executes a command in PowerShell on target machine and returns pipeline output in @Output variable.\r\n",
503+
"Use $ (dollar) sign to access probe parameters passed from checks.\r\n",
504+
"Use . (dot) to access properties of the output object. For example, if a returned object is string, then @Output.Length returns its length."
505+
],
506+
"metadata": {
507+
"azdata_cell_guid": "4450f005-b008-4464-8b83-059b5d3fa8f6"
508+
}
509+
},
510+
{
511+
"cell_type": "code",
512+
"source": [
513+
"#Create new rule with Powershell probe type.\r\n",
514+
"#It runs query to get major PS version\r\n",
515+
"#Make sure that xp_cmdshell is enabled and PS execution policy is RemoteSigned or Unrestricted.\r\n",
516+
"Invoke-SqlAssessment $serverInstance -configuration $(join-path $samplesPath \"CustomRulePowerShellProbe.json\")"
517+
],
518+
"metadata": {
519+
"azdata_cell_guid": "0be17782-0051-4d49-931e-a29aaca34d02"
520+
},
521+
"outputs": [],
522+
"execution_count": null
523+
},
524+
{
525+
"cell_type": "markdown",
526+
"source": [
527+
"### Registry\r\n",
528+
"\r\n",
529+
"Registry probe obtains data from target machine's registry. The key name will be returned in @RegistryKeyName. Use * (asterisk) symbol to enumerate all keys."
530+
],
531+
"metadata": {
532+
"azdata_cell_guid": "9277b49b-7f19-4d9b-8e37-d3592962c03f"
533+
}
534+
},
535+
{
536+
"cell_type": "code",
537+
"source": [
538+
"#Create new rule with Registry probe\r\n",
539+
"#Make sure that xp_cmdshell is enabled\r\n",
540+
"Invoke-SqlAssessment $serverInstance -configuration $(join-path $samplesPath \"CustomRuleRegistryProbe.json\")"
541+
],
542+
"metadata": {
543+
"azdata_cell_guid": "6a100496-4356-4e15-b857-4cdf44177010",
544+
"tags": []
545+
},
546+
"outputs": [],
547+
"execution_count": null
548+
},
549+
{
550+
"cell_type": "markdown",
551+
"source": [
552+
"### WMI\r\n",
553+
"\r\n",
554+
"WMI probe runs a WMI query and returns results in @Output variable in the same way as a PowerShell probe does.\r\n",
555+
"Use $ (dollar) sign to access probe parameters passed from checks."
556+
],
557+
"metadata": {
558+
"azdata_cell_guid": "3a03fb80-361d-4b41-9a52-a2eedd1e85a0"
559+
}
560+
},
561+
{
562+
"cell_type": "code",
563+
"source": [
564+
"#Create new rule with WMI probe\r\n",
565+
"#Make sure that xp_cmdshell is enabled.\r\n",
566+
"Invoke-SqlAssessment $serverInstance -configuration $(join-path $samplesPath \"CustomRuleWmiProbe.json\")"
567+
],
568+
"metadata": {
569+
"azdata_cell_guid": "143eea26-62d1-40e8-a97a-9f1ed8ac2532"
570+
},
571+
"outputs": [],
572+
"execution_count": null
573+
},
574+
{
575+
"cell_type": "markdown",
576+
"source": [
577+
"### Managed code probe\r\n",
578+
"\r\n",
579+
"For CLR probe use \"External\" probe type."
476580
],
477581
"metadata": {
478-
"azdata_cell_guid": "54a36d0b-6934-468e-a94c-b767d13b3b07"
582+
"azdata_cell_guid": "815584d6-ceac-4160-ba9a-020c59e14221"
479583
}
480584
},
481585
{
@@ -489,10 +593,10 @@
489593
"Invoke-SqlAssessment $serverInstance -configuration $(join-path $samplesPath \"CustomRuleCLRProbe.json\")"
490594
],
491595
"metadata": {
492-
"azdata_cell_guid": "a4761c60-e0cc-4e7c-b386-1397ca532e44"
596+
"azdata_cell_guid": "bcff0e69-65e8-4b44-90b8-83f1241589bd"
493597
},
494598
"outputs": [],
495-
"execution_count": 19
599+
"execution_count": null
496600
},
497601
{
498602
"cell_type": "markdown",
3.38 KB
Binary file not shown.

0 commit comments

Comments
 (0)