Forum Discussion
Table count from custom log
Hi Rafi_Rabo,
How we can do a string regression. For example, if the table name is as follows then how we can include it in the query.
1. abc_3val_xyz_dd
2. txt_1data_abcd
Thanks
Hi alchem_rj ,
I can think of several options:
1. Look for more patterns in the the extract() function (You may use more complex RegExp to match more tables). Note that this is not scalable solution since you'll always need to add more patterns/ table names to the expression.
| extend table_name = (extract ("(table_[0-9]+)|(abc_3val_xyz_dd)|(txt_1data_abcd)", 0, LogText)), month=(getmonth(TimeGenerated))
2. Add a 'TableName' column to your custom logs, with the table name in the relevant rows. Easily you'll be able to filter out logs which are not related to tables, and summarize according to 'TableName'.
3. Write the message in your logs with a unique pattern for table, for example
- Rafi_RaboSep 17, 2020Microsoft
Hi alchem_rj.,
You can tweak the regular expression, using the operator $ which means end of match.
In your case:
extend table_name = (extract ("(abc_8val_yy$)", 0, RawData))
Reference for regular expressions supported in Kusto: https://github.com/google/re2/wiki/Syntax
Rafi
- Rafi_RaboSep 16, 2020Microsoft
Hi alchem_rj ,
This behavior is expected since the string "abc_8val_yy" is a sub-string of "abc_8val_yy_vw".
Follow the extract operator documentation for more details: https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/extractfunction
Rafi
- alchem_rjSep 16, 2020Copper Contributor
Hi Rafi_Rabo
Thanks a lot for your help.
I also notice that if I use a similar table name in the extend operator am getting same result.
extend table_name = (extract ("(abc_8val_yy)", 0, RawData))
The output (count of table name) of above query and below query is same
extend table_name = (extract ("(abc_8val_yy_vw)", 0, RawData))
- Rafi_RaboSep 16, 2020Microsoft
Hi alchem_rj ,
Try running the following: Go to Log Analytics and run query
I tweaked the regexp to:
abc_[0-9]+val_[0-9A-Za-z_]+
If you still have issues, please share the data and query you are trying to run.
Rafi
- Rafi_RaboSep 13, 2020Microsoft
Hi alchem_rj ,
The following should work: abc_[0-9]+val_.+
Here is a link to the regular expression syntax supported by Kusto: https://github.com/google/re2/wiki/Syntax
Rafi