在Kusto,我正在努力解决算法问题。我得到了一个大的ip列表(Azure Monitor),以及一个白名单范围列表。如果IP在第二个列表的范围内,我如何排除第一个列表的行?
当然,我们将使用ipv4_is_in_range()
和mv-apply
,但我不知道如何。
示例项目:
let ranges_to_whitelist = "['127.0.0.1', 10.0.0.0/28']";
let big_table_of_rows = datatable (ip_range: string) ['1.2.3.4', '10.0.0.254', '172.16.1.2', '10.0.0.1'];
应该收益率:
datatable (ip_range: string) ['10.0.0.1'];
谢谢!
如果我正确理解需求,您需要首先将范围数组扩展到白名单(使用mv-expand
或mv-apply
),然后基于ipv4_is_in_range()
应用过滤器:
let ranges_to_whitelist = dynamic(['127.0.0.1', '10.0.0.0/28']);
let big_table_of_rows = datatable (ip: string) ['1.2.3.4', '10.0.0.254', '172.16.1.2', '10.0.0.1'];
big_table_of_rows
| mv-apply ip_range = ranges_to_whitelist to typeof(string) on (
where ipv4_is_in_range(ip, ip_range)
)
| project-away ip_range
<表类>ip tbody><<tr>10.0.0.1 表示表类>
只是为了跟踪记录,Kusto丰富了新的功能:ipv4_is_in_any_range
正是这个功能。总比权宜之计好。