|
| 1 | +# Target pattern |
| 2 | + |
| 3 | +Target pattern specifies criteria for filtering rules and probe implementations. A rule will be applied to those SQL Server instances and databases, which match the rule's [target](./Rule.md#target) pattern. |
| 4 | + |
| 5 | +this mechanism allows rules specific to certain SQL Server versions or editions, or even specific to a certain database. When used in custom rulesets, SQL Server instances can be distinguished by name to apply different rules. For example, servers servers used for application development might not need frequent backups. |
| 6 | + |
| 7 | +## Target pattern structure |
| 8 | + |
| 9 | +Target pattern is represented by a JSON object of the following structure. All properties are optional. Every value is a match when a property is omitted. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +### engineEdition |
| 14 | + |
| 15 | +__Allowed values__: `PersonalOrDesktopEngine`, `Standard`, `Enterprise`, `Express`, `AzureDatabase`, `DataWarehouse`, `StretchDatabase`, `ManagedInstance`; |
| 16 | + |
| 17 | +`Azure` = `AzureDatabase`, `DataWarehouse`, `StretchDatabase`, `ManagedInstance`; |
| 18 | + |
| 19 | +`SqlServer` = `PersonalOrDesktopEngine`, `Standard`, `Enterprise`, `Express`. |
| 20 | + |
| 21 | +Any combination of comma-separated values above is allowed. Lists SQL Server engine editions matching this target pattern. `Azure` and `SqlServer` are short names for frequently used lists. |
| 22 | + |
| 23 | +In the following example __engineEdition__ is any on-premises edition or Azure Managed Instance. |
| 24 | + |
| 25 | +```json |
| 26 | +"engineEdtion": "SqlServer, ManagedInstance" |
| 27 | +``` |
| 28 | + |
| 29 | +### name |
| 30 | + |
| 31 | +A [string pattern](#string-pattern) for the target SQL |
| 32 | +Server object name. It's a database name or an instance name. |
| 33 | + |
| 34 | +In the following example __name__ matches anything except _master_, _tempdb_, and _model_. |
| 35 | + |
| 36 | +```json |
| 37 | +"name": { "not": [ "master", "tempdb", "model"]} |
| 38 | +``` |
| 39 | + |
| 40 | +### machineType |
| 41 | + |
| 42 | +A [string pattern](#string-pattern) for the type of machine hosting target SQL Server instance. |
| 43 | + |
| 44 | +Supported machine type values are: `Physical`, `AzureVm`, `Hypervisor`, `Other`. |
| 45 | + |
| 46 | +In the following example any physical or Azure virtual machine mathes the pattern. |
| 47 | + |
| 48 | +```json |
| 49 | +"machineType": ["AzureVm", "Physical"] |
| 50 | +``` |
| 51 | + |
| 52 | +### platform |
| 53 | + |
| 54 | +A [string pattern](#string-pattern) for the platform of machine hosting target SQL Server instance. |
| 55 | + |
| 56 | +Supported machine type values are: `Windows`, `Linux`. |
| 57 | + |
| 58 | +In the following example Windows and Linux installations match. |
| 59 | + |
| 60 | +```json |
| 61 | +"platform": ["Windows", "Linux"] |
| 62 | +``` |
| 63 | + |
| 64 | +### serverName |
| 65 | + |
| 66 | +A [string pattern](#string-pattern) for the SQL Server instance name. If target is a SQL SErver instance, then _serverName_ equals _name_, otherwise it's the name of SQL Server instance hosting the target object. |
| 67 | + |
| 68 | +In the following example all instances match except those with names ending with _Test_. |
| 69 | + |
| 70 | +```json |
| 71 | +"serverName": {"not": "/*.Test$/"} |
| 72 | +``` |
| 73 | + |
| 74 | +### type |
| 75 | + |
| 76 | +__Allowed values__: `Server`, `Database`. |
| 77 | + |
| 78 | +Any comma-separated list of allowed values defines which type of SQL Server object matches this pattern. |
| 79 | + |
| 80 | +Check's target is always either `Sever` or `Database`. For a probe it's often both. |
| 81 | + |
| 82 | +In the following example only databases match the pattern. |
| 83 | + |
| 84 | +```json |
| 85 | +"type": "Database" |
| 86 | +``` |
| 87 | + |
| 88 | +### version |
| 89 | + |
| 90 | +A [version pattern](#version-pattern) specifying ranges of matching SQL Server versions. |
| 91 | + |
| 92 | +In the following example the pattern matches SQL Server 2016 SP2+, 2014 SP3+, and 2019+. |
| 93 | + |
| 94 | +```json |
| 95 | +"version": ["[13.0.5026.0, 14.0)", "[12.0.6024.0, 13.0)", "[15.0)"] |
| 96 | +``` |
| 97 | + |
| 98 | +## String pattern |
| 99 | + |
| 100 | +String pattern defines matching strings. It can be a string, a JSON object, or a JSON array of string patterns. With arrays, string patterns have a recursive structure. An array matches a string when any of its elements is a match. |
| 101 | + |
| 102 | +A string pattern can be an arbitrary string. In this case SQL Assessment API looks for an exact match. |
| 103 | + |
| 104 | +When the string starts and ends with slash '/' ti represents a [regular expression](#regular-expression). |
| 105 | + |
| 106 | +When string pattern is represented by a JSON object, it may have only one property named __not__. The property value must be any string pattern. This means that the pattern matches anything which is not a match for the __not__property value. |
| 107 | + |
| 108 | +For example, the following matches anything that does not end with _Test_. |
| 109 | + |
| 110 | +```json |
| 111 | +{ "not": "/*.Test$/c" } |
| 112 | +``` |
| 113 | + |
| 114 | +### Regular expression |
| 115 | + |
| 116 | +Regular expressions are enclosed in slashes: `"/Win*./"`. Regular expression options can be specified after the closing slash. For example, this is the case sensitive search: `"/win.*/c"`. If the string does not start with a slash, it is treated as an exact string match. The string "_Linux_" is equivalent to the regular expression "_/^Linux$/_". |
| 117 | + |
| 118 | +SQL Assessment API supports [.NET Regular Expressions.](https://learn.microsoft.com/dotnet/standard/base-types/regular-expressions). |
| 119 | + |
| 120 | +Regular expression options are listed in the [Regular expression options](https://learn.microsoft.com/dotnet/standard/base-types/regular-expression-options) article. |
| 121 | + |
| 122 | +__NOTE:__ Regular expressions are case-insensitive by default. For case-sensitive matching use 'c' option. |
| 123 | + |
| 124 | + |
| 125 | +## Version pattern |
| 126 | + |
| 127 | +The version range list is a single [version range](#version-range) or an array of version ranges. A single version range is equivalent to an array containing the only element. The version range list matches any version matching any of its ranges. |
| 128 | + |
| 129 | +```json |
| 130 | +"version": [ |
| 131 | + "[10.0.4326,10.0.4371]", |
| 132 | + "[10.0.5794,10.50)", |
| 133 | + "[10.50.2806,11.0)", |
| 134 | + "[11.0.2316,)" |
| 135 | +] |
| 136 | +``` |
| 137 | + |
| 138 | +### Version range |
| 139 | + |
| 140 | +A range of versions is encoded by a string. The string contains one or two versions delimited by the comma and enclosed into optional parenthesis or brackets. If there are two versions, the former version must be less than or equal to the latter. They represent the range boundaries. The version must be specified at least by two numbers separated by the period: major and minor version numbers. |
| 141 | + |
| 142 | +Th version range format follows [Nuget version range format](https://learn.microsoft.com/nuget/concepts/package-versioning#version-ranges). |
| 143 | + |
| 144 | +|Version Range|Matches| |
| 145 | +|-|-| |
| 146 | +|"10.0"|Version 10.0 exactly.| |
| 147 | +|"[10.0, 13.0]"|Anything between 10.0 and 13.0, inclusive: 10.0, 10.50, 11.0.345, 13.0.| |
| 148 | +|"(10.0, 13.0)"|Anything between 10.0 and 13.0, exclusive: 10.50, 11.0.345. Does not match 10.0 or 13.0.| |
| 149 | +|"[10.0, 13.1)"|Anything between 10.0 and 13.1, excluding the right boundary: 10.0, 10.50, 11.0.345, 13.0, 13.0.234. Does not match 13.1.| |
| 150 | +|"(10.0, 13.1]"|Anything between 10.0 and 13.1, excluding 10.0.| |
| 151 | +|"[10.0,)"|10.0 and abo| |
| 152 | +|"(10.0,)"|Above 10.0, but not itself| |
| 153 | +|"(,10.0]"|10.0 or below| |
| 154 | +|"(,10.0)"|Below 10.0, but not 10.0.| |
0 commit comments