Kusto Query- i need past 7 days off each day count and past 30days of each day count of Unauthorized messages in single output result format

Viewed 61

I need past 24 hrs and past 7 days of each day count and past 30 days of each day count which is having azure in message column.

Past 24hrs query:

| where message has "azure" 
| where timestamp  > ago(24h)   
| summarize count() by message = "azure"

Past 7days of each day count query:

| where message has "azure"
| where timestamp >= startofday(ago(7d))
| where timestamp  < startofday(now())
| summarize count() by startofday(timestamp) , message ="azure" 

Past 30days of each day count query:

| where message has "azure"
| where timestamp >= 'startofday'(ago(30d))`enter code here`
| where timestamp  < `startofday'(now())
| summarize count() by startofday(timestamp) ,  message = "azure" 

Can we combine these 3 queries and make output result as single? Sample data:

Timestamp message
2009-09-17 12:45:37 Azure
2009-09-18 12:45:39 Aws
2009-09-29 13:29:12 Google
2009-09-12 13:29:14 Aws
2009-09-19 13:29:17 Azure
2009-09-14 13:29:23 Google

Expected output:

Timestamp message count_24hrs count_7days count_30days
2009-09-16 12:45:37 Azure 152 152 152
2009-09-15 12:45:39 Azure 65 65
2009-09-14 13:29:12 Azure 6587 6587
2009-09-13 13:29:14 Azure 98 98
2009-09-12 13:29:17 Azure 54365 54365
2009-09-11 13:29:23 Azure 12 12
97 97
987
98

... Up to past 30days

1 Answers

It seems you are looking for something like this, although this is definitely not the way I would have chosen to display this data.

// Data sample generation. Not part of the solution.
let t = materialize(range i from 1 to 1000 step 1 | extend timestamp = ago(35d*rand()), message = tostring(dynamic(["Azure", "AWS", "GCP"])[toint(rand(3))])); 
// Solution starts here
t
| where timestamp >= startofday(ago(30d))
| summarize count_24h   = countif(timestamp >= ago(24h))
           ,count_7d    = countif(timestamp >= startofday(ago(7d)) and timestamp < startofday(now()))
           ,count_30d   = countif(timestamp < startofday(now()))
            by message, startofday(timestamp)
| order by message, timestamp
message timestamp count_24h count_7d count_30d
GCP 2022-09-15T00:00:00Z 6 0 0
GCP 2022-09-14T00:00:00Z 1 9 9
GCP 2022-09-13T00:00:00Z 0 12 12
GCP 2022-09-12T00:00:00Z 0 7 7
GCP 2022-09-11T00:00:00Z 0 7 7
GCP 2022-09-10T00:00:00Z 0 11 11
GCP 2022-09-09T00:00:00Z 0 14 14
GCP 2022-09-08T00:00:00Z 0 10 10
GCP 2022-09-07T00:00:00Z 0 0 9
GCP 2022-09-06T00:00:00Z 0 0 12
GCP 2022-09-05T00:00:00Z 0 0 12
GCP 2022-09-04T00:00:00Z 0 0 6
GCP 2022-09-03T00:00:00Z 0 0 9
GCP 2022-09-02T00:00:00Z 0 0 12
GCP 2022-09-01T00:00:00Z 0 0 6
GCP 2022-08-31T00:00:00Z 0 0 12
GCP 2022-08-30T00:00:00Z 0 0 12
GCP 2022-08-29T00:00:00Z 0 0 12
GCP 2022-08-28T00:00:00Z 0 0 5
GCP 2022-08-27T00:00:00Z 0 0 8
GCP 2022-08-26T00:00:00Z 0 0 10
GCP 2022-08-25T00:00:00Z 0 0 15
GCP 2022-08-24T00:00:00Z 0 0 11
GCP 2022-08-23T00:00:00Z 0 0 9
GCP 2022-08-22T00:00:00Z 0 0 12
GCP 2022-08-21T00:00:00Z 0 0 10
GCP 2022-08-20T00:00:00Z 0 0 11
GCP 2022-08-19T00:00:00Z 0 0 6
GCP 2022-08-18T00:00:00Z 0 0 10
GCP 2022-08-17T00:00:00Z 0 0 8
GCP 2022-08-16T00:00:00Z 0 0 6
Azure 2022-09-15T00:00:00Z 7 0 0
Azure 2022-09-14T00:00:00Z 1 6 6
Azure 2022-09-13T00:00:00Z 0 14 14
Azure 2022-09-12T00:00:00Z 0 10 10
Azure 2022-09-11T00:00:00Z 0 13 13
Azure 2022-09-10T00:00:00Z 0 7 7
Azure 2022-09-09T00:00:00Z 0 12 12
Azure 2022-09-08T00:00:00Z 0 5 5
Azure 2022-09-07T00:00:00Z 0 0 10
Azure 2022-09-06T00:00:00Z 0 0 10
Azure 2022-09-05T00:00:00Z 0 0 5
Azure 2022-09-04T00:00:00Z 0 0 11
Azure 2022-09-03T00:00:00Z 0 0 7
Azure 2022-09-02T00:00:00Z 0 0 8
Azure 2022-09-01T00:00:00Z 0 0 10
Azure 2022-08-31T00:00:00Z 0 0 8
Azure 2022-08-30T00:00:00Z 0 0 10
Azure 2022-08-29T00:00:00Z 0 0 13
Azure 2022-08-28T00:00:00Z 0 0 14
Azure 2022-08-27T00:00:00Z 0 0 9
Azure 2022-08-26T00:00:00Z 0 0 8
Azure 2022-08-25T00:00:00Z 0 0 3
Azure 2022-08-24T00:00:00Z 0 0 8
Azure 2022-08-23T00:00:00Z 0 0 10
Azure 2022-08-22T00:00:00Z 0 0 8
Azure 2022-08-21T00:00:00Z 0 0 17
Azure 2022-08-20T00:00:00Z 0 0 7
Azure 2022-08-19T00:00:00Z 0 0 11
Azure 2022-08-18T00:00:00Z 0 0 9
Azure 2022-08-17T00:00:00Z 0 0 7
Azure 2022-08-16T00:00:00Z 0 0 8
AWS 2022-09-15T00:00:00Z 3 0 0
AWS 2022-09-14T00:00:00Z 2 4 4
AWS 2022-09-13T00:00:00Z 0 11 11
AWS 2022-09-12T00:00:00Z 0 8 8
AWS 2022-09-11T00:00:00Z 0 8 8
AWS 2022-09-10T00:00:00Z 0 10 10
AWS 2022-09-09T00:00:00Z 0 13 13
AWS 2022-09-08T00:00:00Z 0 7 7
AWS 2022-09-07T00:00:00Z 0 0 11
AWS 2022-09-06T00:00:00Z 0 0 12
AWS 2022-09-05T00:00:00Z 0 0 7
AWS 2022-09-04T00:00:00Z 0 0 10
AWS 2022-09-03T00:00:00Z 0 0 8
AWS 2022-09-02T00:00:00Z 0 0 13
AWS 2022-09-01T00:00:00Z 0 0 5
AWS 2022-08-31T00:00:00Z 0 0 11
AWS 2022-08-30T00:00:00Z 0 0 9
AWS 2022-08-29T00:00:00Z 0 0 9
AWS 2022-08-28T00:00:00Z 0 0 14
AWS 2022-08-27T00:00:00Z 0 0 14
AWS 2022-08-26T00:00:00Z 0 0 8
AWS 2022-08-25T00:00:00Z 0 0 15
AWS 2022-08-24T00:00:00Z 0 0 9
AWS 2022-08-23T00:00:00Z 0 0 7
AWS 2022-08-22T00:00:00Z 0 0 9
AWS 2022-08-21T00:00:00Z 0 0 11
AWS 2022-08-20T00:00:00Z 0 0 6
AWS 2022-08-19T00:00:00Z 0 0 12
AWS 2022-08-18T00:00:00Z 0 0 12
AWS 2022-08-17T00:00:00Z 0 0 9
AWS 2022-08-16T00:00:00Z 0 0 5

Fiddle

Related