我正在尝试查找超出我的阈值限制的所有Azure实例。我的系统检测到实例,现在我想从文本中提取所有机器并采取措施。在下面的文本中,我只有PowerShell作为一个选项来标识所有以RD *开头的实例。
@{DescriptionEntryId=343578460;
Issue:
</td><td>
An xxxxxx has been triggered for 59 distinct instances of this xxxxxxx
</td></tr><tr><td>Description:</td><td>setting up this to identify issue</td></tr><tr><td>Severity:</td><td>Warning</td></tr><tr><td colspan="2"><dl><dt>RDxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.393 and 6.054.</dd><dt>RDxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.722 and 6.813.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.481 and 5.909.</dd><dt>RDxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.412 and 6.588.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.375 and 6.24.</dd><dt>RDxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.382 and 6.863.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 0.418 and 11.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.059 and 6.667.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.255 and 7.5.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.545 and 5.291.</dd><dt>RDxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.691 and 5.6.</dd><dt>RDxxxxxxxxxxxx</dt><dd>The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 2 and 6.755.</dd><dt>RDxxxxxxxxxxx</dt><dd>The threshold (2) was met for 15 of 15 minutes</div><div>
View additional information about why the xxxx fired
</div></td></tr><tr><td> </td></tr><tr><td><div><a
</div></td></tr><tr><td> </td></tr><tr><td><div><a href="xxxxxxxxxxxxxxx" target="_blank">Suppress (Snooze) </a></div><div>
</div></td></tr><tr><td> </td></tr><tr><td><div><a
</div></td></tr><tr><td> </td></tr></tbody></table></div></div></span>; RenderType=Html; Initials=; SubmittedByDisplayName=}
答案 0 :(得分:1)
似乎您正在显示某种HTML报告,并希望使用Powershell对其进行分析。对于此解决方案,您需要将报告保存为.html文件。
让我们假设您已这样做,并将报告保存到D:\Report.html
的磁盘上
然后您可以这样做:
# read the report file as string
$htmlReport = Get-Content -Path 'D:\Report.html' -Raw
# create a Regular Expression object to capture the RD machines and their issues
$regex = [regex] '<dt>(?<Name>RD[^<]*)</dt><dd>(?<Issue>[^<]+)</dd>'
$matches = $regex.Match($htmlReport)
while ($matches.Success) {
New-Object -TypeName PSObject -Property ([ordered]@{ Name = $matches.Groups['Name'].Value; Issue = $matches.Groups['Issue'].Value })
$matches = $matches.NextMatch()
}
使用您提供的报告,这将会产生
Name Issue
---- -----
RDxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.393 and 6.054.
RDxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.722 and 6.813.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.481 and 5.909.
RDxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.412 and 6.588.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.375 and 6.24.
RDxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.382 and 6.863.
RDxxxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 0.418 and 11.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 3.059 and 6.667.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.255 and 7.5.
RDxxxxxxxxxxxx The threshold (2) was met for 15 of 15 minutes. The data points during the evaluation window ranged between 2.545 and 5.291.
RDxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 1.691 and 5.6.
RDxxxxxxxxxxxx The threshold (2) was met for 14 of 15 minutes. The data points during the evaluation window ranged between 2 and 6.755.