KQL Flashcards

(24 cards)

1
Q

Search Operator

A

search “example”

Search in (SecurityEvent,SecurityAlert) “example”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Where Operator

A

SecurityEvent
| where TimeGenerated > ago(1d)

SecurityEvent
| where TimeGenerated > ago(1h) and EventID == “4624”

SecurityEvent
| where TimeGenerated > ago(1h)
| where EventID == 4624
| where AccountType =~ “user”

SecurityEvent | where EventID in (4624, 4625)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

let statement

A

bind names to expressions

let timeOffset = 7d;
let discardEventId = 4688;
SecurityEvent
| where TimeGenerated > ago(timeOffset*2) and TimeGenerated < ago(timeOffset)
| where EventID != discardEventId

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ago()
function

A

takes the current Date and Time and subtract the value provided

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

extend operator

A

create calculated columns and append the new columns to the result set

extend StartDir = substring(ProcessName,0, string_size(ProcessName)-string_size(Process))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

order by operator

A

Sort the rows of the input table by one or more columns, The default order for a column is descending

order by StartDir desc, Process asc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

project operators

A

control what columns to include, add, remove, or rename in the result set of a statement

project - Select the columns to include, rename or drop, and insert new computed columns.
project-away - Select what columns from the input to exclude from the output.
project-keep - Select what columns from the input to keep in the output.
project-rename - Select the columns to rename in the resulting output.
project-reorder - Set the column order in the resulting output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

summarize operator

A

You use the summarize operator with other operators like the count operator. The count operator with its variations creates a new column with the calculated result for the specified fields.

count(), countif() - Returns a count of the records per summarization group

dcount(), dcountif() - Returns an estimate for the number of distinct values taken by a scalar expression in the summary group.

avg(), avgif() - Calculates the average of Expr across the group.

max(), maxif() - Returns the maximum value across the group.

min(), minif() - Returns the minimum value across the group.
percentile() - Returns an estimate for the specified nearest-rank percentile of the population defined by Expr. The accuracy depends on the density of population in the region of the percentile.
stdev(), stdevif() - Calculates the standard deviation of Expr across the group, considering the group as a sample.
sum(), sumif() - Calculates the sum of Expr across the group.
variance(), varianceif() - Calculates the variance of Expr across the group, considering the group as a sample.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

dcount function

A

The following example returns a count of unique IP Addresses.

summarize dcount(IpAddress)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

summarize operator to filter data

A

The arg_max() and arg_min() functions filter out top and bottom rows respectively.

summarize arg_max(TimeGenerated,*) by Computer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

summarize operator to prepare data

A

The make_ functions return a dynamic (JSON) array based on the specific function’s purpose.

make_list() - returns a dynamic (JSON) array
make_set() - similar to list function, but it returns only the unique entries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

render operator

A

generates a visualization of the query results

Supported visuals are:
areachart
barchart
columnchart
piechart
scatterchart
timechart

Ex:
SecurityEvent
| summarize count() by Account
| render barchart

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

bin() function

A

rounds values down to an integer multiple of the given bin size. Used frequently in combination with summarize by ….

SecurityEvent
| summarize count() by bin(TimeGenerated, 1d)
| render timechart

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

union operator
multi table statement

A

takes two or more tables and returns the rows of all of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

join operator
multi table statements

A

merges the rows of two tables to form a new table by matching the specified columns’ values from each table.

LeftTable | join [JoinParameters] ( RightTable ) on Attributes

kind=leftanti, kind=leftantisemi - Returns all the records from the left side that don’t have matches from the right

kind=rightanti, kind=rightantisemi - Returns all the records from the right side that don’t have matches from the left.

kind unspecified, kind=innerunique - Only one row from the left side is matched for each value of the on key. The output contains a row for each match of this row with rows from the right

kind=leftsemi - Returns all the records from the left side that have matches from the right.

kind=rightsemi - Returns all the records from the right side that have matches from the left.

kind=inner - Contains a row in the output for every combination of matching rows from left and right.

kind=leftouter (or kind=rightouter or kind=fullouter) - Contains a row for every row on the left and right, even if it has no match. The unmatched output cells contain nulls.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

When you’re using the join operator, how do you specify fields from each table?

A

$left.columname and $right.columnname

17
Q

extract
extracting data from unstructered string field

A

extend Account_Name = extract(@”^(.\)?([^@])(@.*)?$”, 2, tolower(Account))

18
Q

Parse
extracting data from unstructered string field

A

evaluates a string expression and parses its value into one or more calculated columns. The computed columns have nulls for unsuccessfully parsed strings.

Syntax

T | parse [kind=regex [flags=regex_flags] |simple|relaxed] Expression with * (StringConstant ColumnName [: ColumnType]) *

19
Q

Dynamic Fields

A

Dynamic fields within the log analytics table contain Key-Value pairs like

{“eventCategory”:”Autoscale”,”eventName”:”GetOperationStatusResult”,”operationId”:”xxxxxxxx-6a53-4aed-bab4-575642a10226”,”eventProperties”:”{"OldInstancesCount":6,"NewInstancesCount":5}”,”eventDataId”:” xxxxxxxx -efe3-43c2-8c86-cd84f70039d3”,”eventSubmissionTimestamp”:”2020-11-30T04:06:17.0503722Z”,”resource”:”ch-appfevmss-pri”,”resourceGroup”:”CH-RETAILRG-PRI”,”resourceProviderValue”:”MICROSOFT.COMPUTE”,”subscriptionId”:” xxxxxxxx -7fde-4caf-8629-41dc15e3b352”,”activityStatusValue”:”Succeeded”}

To access strings within use dot notation ( DeviceDetail.operatingstem)

20
Q

JSON Extract data from structured string data

A

parse-json() or todynamic() - Interprets a string as a JSON value and returns the value as dynamic. Use either of these functions to refer to a field: JsonField.Key or JsonField[“Key”]

mv-expand - is applied on a dynamic-typed array or property bag column so that each value in the collection gets a separate row. All the other columns in an expanded row are duplicated. mv_expand is the easiest way to process JSON arrays.

mv-apply - Applies a subquery to each record and returns the union of the results of all subqueries. Apply a query to each value in an array.

21
Q

externaldata operator

A

returns a table whose schema is defined in the query itself

Syntax
externaldata ( ColumnName : ColumnType [, …] )
[ StorageConnectionString [, …] ]
[with ( PropertyName = PropertyValue [, …] )]

Arguments

ColumnName, ColumnType: The arguments define the schema of the table. The syntax is the same as the syntax used when defining a table in. create table.

StorageConnectionString: Storage connection strings that describe the storage artifacts holding the data to return.

PropertyName, PropertyValue, …: More properties that describe how to interpret the data retrieved from storage, as listed under ingestion properties.

22
Q

Parsers

A

are functions that define a virtual table with already parsed unstructured strings fields such as Syslog data.

In the Logs window, you create a query, select the Save button, enter the Name, and select Save As Function from the drop-down. In this case, if we name the function “PrivLogins”, I can then access the table using the name PrivLogins.

SecurityEvent
| where EventID == 4672 and AccountType == ‘User’

=

PrivLogins

23
Q

Which KQL statement should you use to parse external data into a virtual table?

24
Q

Common operators

A

count. Returns the count of rows in the table.
take. Returns up to the specified number of rows of data.
project. Selects a subset of columns.
sort. Sorts the rows of the input table into order by one or more columns.
top. Returns the first N records sorted by the specified columns.
extend. Computes derived columns.
summarize. Aggregates groups of rows.
render. Renders results as a graphical output.