Create Azure Log Analytics KQL
Budget: €8 – €30 EUR
I have a KQL for Azure Log Analytics that needs to be created:
To do this, do the following:
I want to have the following field:
let ErrorMessage = ""
let Days = ""
Here I can enter the following e.g.
let ErrorMessage = "Remote host closed".
let Days = "5"
These are used to find out if the described error occurs in a session.
The ErrorMessage can occur maybe 10 times within a session, because it is logged at different places.
But I want to find out in which sessions ErrorMessage occurs compared to the total number of sessions.
However, this requires making multiple queries to determine a session. This goes as follows:
First, the following query must be made:
1) Search within the "Message" column for "New case created with id " up to the time "Days" back.
Then you would get, for example, 10 rows that could look like the following:
"New case created with id e0a34bbc-8eb9-4a42-8684-3faf52832699"
"New case created with id b56bbf1c-a7a4-447d-b20e-f98721e71ea5"
"New case created with id 168b40ba-a5c5-4108-bdb9-283a6846806d"
"New case created with id 2bdc34d1-3315-4342-841c-4aa3b30e14a8"
Here you get a GUID for each session that was started. In our case it would have:
e0a34bbc-8eb9-4a42-8684-3faf52832699
b56bbf1c-a7a4-447d-b20e-f98721e71ea5
168b40ba-a5c5-4108-bdb9-283a6846806d
2bdc34d1-3315-4342-841c-4aa3b30e14a8
Now these sessions are stored in a table.
We now have a table with a column with only SessionIds.
2) Now we would have to search within "Message" for every single SessionID that are present in the table from step 1:
In our case it would be Message contains e0a34bbc-8eb9-4a42-8684-3faf52832699.
Now we get a lot of lines where e0a34bbc-8eb9-4a42-8684-3faf52832699 occurs in the message.
Each of these lines has also the column TraceIdentifier_g.
Now another column is added to the table from step 1 for the TraceIdentifier_g.
Now the TraceIdentifier_g determined from the query Message contains e0a34bbc-8eb9-4a42-8684-3faf52832699 are assigned to the SessionId.
This means we now have a column with a unique SessionID and a column with all TraceIdentifier_g related to this SessionID.
The TraceIdentifier_g is also a GUID and must not consist only of "0".
3) Now we wanted to check which sessions this ErrorMessage has.
For this we search within Message for the ErrorMessage.
Now we look again at the TraceIdentifier_g that are stored here and create a new table with all TraceIdentifier_g that contained the ErrorMessage without double identical TraceIdentifier_g.
4) Now we create the result for the user.
We now know from the first table in step 1 and 2 how many sessions we had in total.
From the query in step 3, we know in which TraceIdentifier_g the ErrorMessage occurs.
Now we can determine which session is affected by this error by checking which TraceIdentifier_g from step 3 in which session from step 1 and 2.
Now we can search for this ErrorMessage.
Each of these ErrorMessage is also assigned to a TraceIdentifier_g.
Based on the assignment in step 2 we now know that it occurs e.g. in two TraceIdentifier_g but both are assigned to the session e0a34bbc-8eb9-4a42-8684-3faf52832699.
This means that the problem has occurred a total of one time.
To do this, do the following:
I want to have the following field:
let ErrorMessage = ""
let Days = ""
Here I can enter the following e.g.
let ErrorMessage = "Remote host closed".
let Days = "5"
These are used to find out if the described error occurs in a session.
The ErrorMessage can occur maybe 10 times within a session, because it is logged at different places.
But I want to find out in which sessions ErrorMessage occurs compared to the total number of sessions.
However, this requires making multiple queries to determine a session. This goes as follows:
First, the following query must be made:
1) Search within the "Message" column for "New case created with id " up to the time "Days" back.
Then you would get, for example, 10 rows that could look like the following:
"New case created with id e0a34bbc-8eb9-4a42-8684-3faf52832699"
"New case created with id b56bbf1c-a7a4-447d-b20e-f98721e71ea5"
"New case created with id 168b40ba-a5c5-4108-bdb9-283a6846806d"
"New case created with id 2bdc34d1-3315-4342-841c-4aa3b30e14a8"
Here you get a GUID for each session that was started. In our case it would have:
e0a34bbc-8eb9-4a42-8684-3faf52832699
b56bbf1c-a7a4-447d-b20e-f98721e71ea5
168b40ba-a5c5-4108-bdb9-283a6846806d
2bdc34d1-3315-4342-841c-4aa3b30e14a8
Now these sessions are stored in a table.
We now have a table with a column with only SessionIds.
2) Now we would have to search within "Message" for every single SessionID that are present in the table from step 1:
In our case it would be Message contains e0a34bbc-8eb9-4a42-8684-3faf52832699.
Now we get a lot of lines where e0a34bbc-8eb9-4a42-8684-3faf52832699 occurs in the message.
Each of these lines has also the column TraceIdentifier_g.
Now another column is added to the table from step 1 for the TraceIdentifier_g.
Now the TraceIdentifier_g determined from the query Message contains e0a34bbc-8eb9-4a42-8684-3faf52832699 are assigned to the SessionId.
This means we now have a column with a unique SessionID and a column with all TraceIdentifier_g related to this SessionID.
The TraceIdentifier_g is also a GUID and must not consist only of "0".
3) Now we wanted to check which sessions this ErrorMessage has.
For this we search within Message for the ErrorMessage.
Now we look again at the TraceIdentifier_g that are stored here and create a new table with all TraceIdentifier_g that contained the ErrorMessage without double identical TraceIdentifier_g.
4) Now we create the result for the user.
We now know from the first table in step 1 and 2 how many sessions we had in total.
From the query in step 3, we know in which TraceIdentifier_g the ErrorMessage occurs.
Now we can determine which session is affected by this error by checking which TraceIdentifier_g from step 3 in which session from step 1 and 2.
Now we can search for this ErrorMessage.
Each of these ErrorMessage is also assigned to a TraceIdentifier_g.
Based on the assignment in step 2 we now know that it occurs e.g. in two TraceIdentifier_g but both are assigned to the session e0a34bbc-8eb9-4a42-8684-3faf52832699.
This means that the problem has occurred a total of one time.