解析事件日志中的FQDN和项



我收到这个事件文本,我需要能够解析出每行的FQDN以及方面名称。我已经尝试了几个FQDN正则表达式的例子,唯一接近的是^[^.]+,但仍然只捕获主机名,我会很好。但我似乎无法同时获取两组数据。

的例子:

线:Test1.test。本地系统预留73.2%

输出:

FQDN = Test1.test.local

Aspect Name = System Reserved

'Performance Disk Utilization Exceeds 50%' threshold

Description: Average disk utilization during the past 2 minutes exceeds 50%

New Items (11)

Occurred at 10/21/2021 10:38:06 AM

Display Name Aspect Name Aspect Value
Test1.test.local System Reserved 73.2 %
Test1-stage.test.local System Reserved 69.3 %
test-stage.test.local \?Volume{c2e5b983-0000-0000-0000-006225000000} 83.3 %
test2.test.local System Reserved 73.2 %
test2.test.local E: - Data 62.5 %
test.test.LOCAL System Reserved 69.3 %
test.test.LOCAL \?Volume{0833abcb-0000-0000-0000-006225000000} 83.3 %
test3.test.local System Reserved 69.4 %
test3.test.local E: - SCCM 85.7 %
test3.cdp.local C: 53.1 %
test3.cdp.local \?Volume{fa03c719-0000-0000-0000-f0e17c000000} 83.3 %

您可以使用2个捕获组,并匹配末尾后跟百分号的数字:

([^s.]+(?:.[^s.]+)+) (.+?) d+(?:.d+)? %
  • (Capturegroup 1
    • [^s.]+匹配除空白字符以外的1+字符或.
    • (?:.[^s.]+)+重复1+次匹配点后面跟着1+个字符(空白字符或.除外),以匹配至少一个点
  • )关闭组1
  • (.+?)捕获组2中的1位或以上数字
  • d+(?:.d+)? %匹配1+数字(可选的小数部分)和%

regex演示

const regex = /([^s.]+(?:.[^s.]+)+) (.+?) d+(?:.d+)? %/gm;
const str = `Test1.test.local System Reserved 73.2 %
Test1-stage.test.local System Reserved 69.3 %
test-stage.test.local \\?\Volume{c2e5b983-0000-0000-0000-006225000000}\ 83.3 %
test2.test.local System Reserved 73.2 %
test2.test.local E:\ - Data 62.5 %
test.test.LOCAL System Reserved 69.3 %
test.test.LOCAL \\?\Volume{0833abcb-0000-0000-0000-006225000000}\ 83.3 %
test3.test.local System Reserved 69.4 %
test3.test.local E:\ - SCCM 85.7 %
test3.cdp.local C:\ 53.1 %
test3.cdp.local \\?\Volume{fa03c719-0000-0000-0000-f0e17c000000}\ 83.3 %`;
console.log(Array.from(str.matchAll(regex), m => ({
"FQDN": m[1],
"AspectName": m[2]
})));

相关内容

  • 没有找到相关文章

最新更新