Skip to content

Commit 9206928

Browse files
authored
add entity query templates with examples (#15306)
* add entity query templates with examples * fix spelling * adding EntityQueryTemplates to readme file * fix lint
1 parent 09fe30c commit 9206928

File tree

4 files changed

+475
-0
lines changed

4 files changed

+475
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Security Insights",
5+
"description": "API spec for Microsoft.SecurityInsights (Azure Security Insights) resource provider",
6+
"version": "2021-03-01-preview"
7+
},
8+
"host": "management.azure.com",
9+
"schemes": [
10+
"https"
11+
],
12+
"consumes": [
13+
"application/json"
14+
],
15+
"produces": [
16+
"application/json"
17+
],
18+
"security": [
19+
{
20+
"azure_auth": [
21+
"user_impersonation"
22+
]
23+
}
24+
],
25+
"securityDefinitions": {
26+
"azure_auth": {
27+
"type": "oauth2",
28+
"authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize",
29+
"flow": "implicit",
30+
"description": "Azure Active Directory OAuth2 Flow",
31+
"scopes": {
32+
"user_impersonation": "impersonate your user account"
33+
}
34+
}
35+
},
36+
"paths": {
37+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{operationalInsightsResourceProvider}/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/entityQueryTemplates": {
38+
"get": {
39+
"x-ms-examples": {
40+
"Get all entity query templates.": {
41+
"$ref": "./examples/entityQueryTemplates/GetEntityQueryTemplates.json"
42+
}
43+
},
44+
"tags": [
45+
"EntityQueries"
46+
],
47+
"description": "Gets all entity query templates.",
48+
"operationId": "EntityQueryTemplates_List",
49+
"parameters": [
50+
{
51+
"$ref": "#/parameters/EntityQueryTemplateKind"
52+
},
53+
{
54+
"$ref": "../../../../../common-types/resource-management/v2/types.json#/parameters/ApiVersionParameter"
55+
},
56+
{
57+
"$ref": "../../../../../common-types/resource-management/v2/types.json#/parameters/SubscriptionIdParameter"
58+
},
59+
{
60+
"$ref": "../../../../../common-types/resource-management/v2/types.json#/parameters/ResourceGroupNameParameter"
61+
},
62+
{
63+
"$ref": "../../../common/1.0/types.json#/parameters/OperationalInsightsResourceProvider"
64+
},
65+
{
66+
"$ref": "../../../common/1.0/types.json#/parameters/WorkspaceName"
67+
}
68+
],
69+
"responses": {
70+
"200": {
71+
"description": "OK",
72+
"schema": {
73+
"$ref": "#/definitions/EntityQueryTemplateList"
74+
}
75+
},
76+
"default": {
77+
"description": "Error response describing why the operation failed.",
78+
"schema": {
79+
"$ref": "../../../common/1.0/types.json#/definitions/CloudError"
80+
}
81+
}
82+
},
83+
"x-ms-pageable": {
84+
"nextLinkName": "nextLink"
85+
}
86+
}
87+
},
88+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{operationalInsightsResourceProvider}/workspaces/{workspaceName}/providers/Microsoft.SecurityInsights/entityQueryTemplates/{entityQueryTemplateId}": {
89+
"get": {
90+
"x-ms-examples": {
91+
"Get an Activity entity query template.": {
92+
"$ref": "./examples/entityQueryTemplates/GetActivityEntityQueryTemplateById.json"
93+
}
94+
},
95+
"tags": [
96+
"EntityQueries"
97+
],
98+
"description": "Gets an entity query.",
99+
"operationId": "EntityQueryTemplates_Get",
100+
"parameters": [
101+
{
102+
"$ref": "../../../../../common-types/resource-management/v2/types.json#/parameters/ApiVersionParameter"
103+
},
104+
{
105+
"$ref": "../../../../../common-types/resource-management/v2/types.json#/parameters/SubscriptionIdParameter"
106+
},
107+
{
108+
"$ref": "../../../../../common-types/resource-management/v2/types.json#/parameters/ResourceGroupNameParameter"
109+
},
110+
{
111+
"$ref": "../../../common/1.0/types.json#/parameters/OperationalInsightsResourceProvider"
112+
},
113+
{
114+
"$ref": "../../../common/1.0/types.json#/parameters/WorkspaceName"
115+
},
116+
{
117+
"$ref": "#/parameters/EntityQueryTemplateId"
118+
}
119+
],
120+
"responses": {
121+
"200": {
122+
"description": "OK",
123+
"schema": {
124+
"$ref": "#/definitions/EntityQueryTemplate"
125+
}
126+
},
127+
"default": {
128+
"description": "Error response describing why the operation failed.",
129+
"schema": {
130+
"$ref": "../../../common/1.0/types.json#/definitions/CloudError"
131+
}
132+
}
133+
}
134+
}
135+
}
136+
},
137+
"definitions": {
138+
"EntityQueryTemplateKind": {
139+
"description": "The kind of the entity query template.",
140+
"enum": [
141+
"Activity"
142+
],
143+
"type": "string",
144+
"x-ms-enum": {
145+
"modelAsString": true,
146+
"name": "EntityQueryTemplateKind",
147+
"values": [
148+
{
149+
"value": "Activity"
150+
}
151+
]
152+
}
153+
},
154+
"EntityQueryTemplateList": {
155+
"description": "List of all the entity query templates.",
156+
"properties": {
157+
"nextLink": {
158+
"description": "URL to fetch the next set of entity query templates.",
159+
"readOnly": true,
160+
"type": "string"
161+
},
162+
"value": {
163+
"description": "Array of entity query templates.",
164+
"items": {
165+
"$ref": "#/definitions/EntityQueryTemplate"
166+
},
167+
"type": "array"
168+
}
169+
},
170+
"required": [
171+
"value"
172+
],
173+
"type": "object"
174+
},
175+
"EntityQueryTemplate": {
176+
"allOf": [
177+
{
178+
"$ref": "../../../common/1.0/types.json#/definitions/Resource"
179+
}
180+
],
181+
"description": "Specific entity query template.",
182+
"discriminator": "kind",
183+
"properties": {
184+
"kind": {
185+
"$ref": "#/definitions/EntityQueryTemplateKind",
186+
"description": "the entity query template kind"
187+
}
188+
},
189+
"type": "object",
190+
"required": [
191+
"kind"
192+
]
193+
},
194+
"ActivityEntityQueryTemplate": {
195+
"description": "Represents Activity entity query.",
196+
"allOf": [
197+
{
198+
"$ref": "#/definitions/EntityQueryTemplate"
199+
}
200+
],
201+
"properties": {
202+
"properties": {
203+
"$ref": "#/definitions/ActivityEntityQueryTemplateProperties",
204+
"description": "Activity entity query properties",
205+
"x-ms-client-flatten": true
206+
}
207+
},
208+
"type": "object",
209+
"x-ms-discriminator-value": "Activity"
210+
},
211+
"ActivityEntityQueryTemplateProperties": {
212+
"description": "Describes activity entity query properties",
213+
"properties": {
214+
"title": {
215+
"description": "The entity query title",
216+
"type": "string"
217+
},
218+
"content": {
219+
"description": "The entity query content to display in timeline",
220+
"type": "string"
221+
},
222+
"description": {
223+
"description": "The entity query description",
224+
"type": "string"
225+
},
226+
"queryDefinitions": {
227+
"description": "The Activity query definitions",
228+
"properties": {
229+
"query": {
230+
"description": "The Activity query to run on a given entity",
231+
"type": "string"
232+
},
233+
"summarizeBy": {
234+
"description": "The dimensions we want to summarize the timeline results on, this is comma separated list",
235+
"type": "string"
236+
}
237+
},
238+
"type": "object"
239+
},
240+
"dataTypes": {
241+
"description": "List of required data types for the given entity query template",
242+
"items": {
243+
"$ref": "#/definitions/DataTypeDefinitions"
244+
},
245+
"type": "array"
246+
},
247+
"inputEntityType": {
248+
"$ref": "EntityDefinitions.json#/definitions/EntityInnerType",
249+
"description": "The type of the query's source entity"
250+
},
251+
"requiredInputFieldsSets": {
252+
"description": "List of the fields of the source entity that are required to run the query",
253+
"items": {
254+
"description": "Sub sets of the field of the source entity that are required to run the query",
255+
"items": {
256+
"description": "Required input field name",
257+
"type": "string"
258+
},
259+
"type": "array"
260+
},
261+
"type": "array"
262+
},
263+
"entitiesFilter": {
264+
"description": "The query applied only to entities matching to all filters",
265+
"type": "object",
266+
"additionalProperties": {
267+
"description": "Filter field name",
268+
"items": {
269+
"description": "Filter field values",
270+
"type": "string"
271+
},
272+
"type": "array"
273+
}
274+
}
275+
},
276+
"type": "object"
277+
},
278+
"DataTypeDefinitions": {
279+
"description": "The data type definition",
280+
"properties": {
281+
"dataType": {
282+
"description": "The data type name",
283+
"type": "string"
284+
}
285+
},
286+
"type": "object"
287+
}
288+
},
289+
"parameters": {
290+
"EntityQueryTemplateId": {
291+
"description": "entity query template ID",
292+
"in": "path",
293+
"name": "entityQueryTemplateId",
294+
"required": true,
295+
"type": "string",
296+
"x-ms-parameter-location": "method"
297+
},
298+
"EntityQueryTemplateKind": {
299+
"description": "The entity template query kind we want to fetch",
300+
"in": "query",
301+
"name": "kind",
302+
"required": false,
303+
"enum": [
304+
"Activity"
305+
],
306+
"type": "string",
307+
"x-ms-parameter-location": "method"
308+
}
309+
}
310+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"parameters": {
3+
"api-version": "2021-03-01-preview",
4+
"subscriptionId": "d0cfe6b2-9ac0-4464-9919-dccaee2e48c0",
5+
"resourceGroupName": "myRg",
6+
"workspaceName": "myWorkspace",
7+
"operationalInsightsResourceProvider": "Microsoft.OperationalIinsights",
8+
"entityQueryTemplateId": "07da3cc8-c8ad-4710-a44e-334cdcb7882b"
9+
},
10+
"responses": {
11+
"200": {
12+
"body": {
13+
"id": "/subscriptions/d0cfe6b2-9ac0-4464-9919-dccaee2e48c0/resourceGroups/myRg/providers/Microsoft.OperationalInsights/workspaces/myWorkspace/providers/Microsoft.SecurityInsights/entityQueryTemplates/07da3cc8-c8ad-4710-a44e-334cdcb7882b",
14+
"name": "07da3cc8-c8ad-4710-a44e-334cdcb7882b",
15+
"type": "Microsoft.SecurityInsights/entityQueryTemplate",
16+
"kind": "Activity",
17+
"properties": {
18+
"title": "An account was deleted on this host",
19+
"content": "On '{{Computer}}' the account '{{TargetAccount}}' was deleted by '{{AddedBy}}'",
20+
"description": "Account deleted on host",
21+
"queryDefinitions": {
22+
"query": "let GetAccountActions = (v_Host_Name:string, v_Host_NTDomain:string, v_Host_DnsDomain:string, v_Host_AzureID:string, v_Host_OMSAgentID:string){\nSecurityEvent\n| where EventID in (4725, 4726, 4767, 4720, 4722, 4723, 4724)\n// parsing for Host to handle variety of conventions coming from data\n| extend Host_HostName = case(\nComputer has '@', tostring(split(Computer, '@')[0]),\nComputer has '\\\\', tostring(split(Computer, '\\\\')[1]),\nComputer has '.', tostring(split(Computer, '.')[0]),\nComputer\n)\n| extend Host_NTDomain = case(\nComputer has '\\\\', tostring(split(Computer, '\\\\')[0]), \nComputer has '.', tostring(split(Computer, '.')[-2]), \nComputer\n)\n| extend Host_DnsDomain = case(\nComputer has '\\\\', tostring(split(Computer, '\\\\')[0]), \nComputer has '.', strcat_array(array_slice(split(Computer,'.'),-2,-1),'.'), \nComputer\n)\n| where (Host_HostName =~ v_Host_Name and Host_NTDomain =~ v_Host_NTDomain) \nor (Host_HostName =~ v_Host_Name and Host_DnsDomain =~ v_Host_DnsDomain) \nor v_Host_AzureID =~ _ResourceId \nor v_Host_OMSAgentID == SourceComputerId\n| project TimeGenerated, EventID, Activity, Computer, TargetAccount, TargetUserName, TargetDomainName, TargetSid, SubjectUserName, SubjectUserSid, _ResourceId, SourceComputerId\n| extend AddedBy = SubjectUserName\n// Future support for Activities\n| extend timestamp = TimeGenerated, HostCustomEntity = Computer, AccountCustomEntity = TargetAccount\n};\nGetAccountActions('{{Host_HostName}}', '{{Host_NTDomain}}', '{{Host_DnsDomain}}', '{{Host_AzureID}}', '{{Host_OMSAgentID}}')\n \n| where EventID == 4726 "
23+
},
24+
"inputEntityType": "Host",
25+
"requiredInputFieldsSets": [
26+
[
27+
"Host_HostName",
28+
"Host_NTDomain"
29+
],
30+
[
31+
"Host_HostName",
32+
"Host_DnsDomain"
33+
],
34+
[
35+
"Host_AzureID"
36+
],
37+
[
38+
"Host_OMSAgentID"
39+
]
40+
],
41+
"entitiesFilter": {
42+
"Host_OsFamily": [
43+
"Windows"
44+
]
45+
},
46+
"dataTypes": [
47+
{
48+
"dataType": "AuditLogs"
49+
},
50+
{
51+
"dataType": "SecurityEvent"
52+
}
53+
]
54+
}
55+
}
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)