且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

运行Powershell脚本以响应警报

更新时间:2023-02-03 20:40:21

嗨Sameer,



我没有测试过以下所有步骤但AFAIK您可以按照以下步骤来实现您的使用案例。

Hi Sameer,

I haven't tested all of the below steps but AFAIK you can follow these below steps to achieve your use case.


  1. 如果您没有,则创建一个Log Analytics工作区已经。
  2. 在要监控的服务器上安装它的代理。
  3. 如果您还没有Azure自动帐户,请创建一个Azure自动帐户。
  4. 创建Automation Runbook用于清理驱动器。
  5. 创建操作组。
  6. 将操作组的操作类型配置为Automati在Runbook上并以用户身份提供Runbook源,并提供您希望在触发警报时触发的Runbook(在上面#4中创建)。
  7. 开发Perf类型Kusto查询以获得免费
  8. 在Log Analytics工作区的Logs磁贴中测试它。
  9. 安装Hybrid Runbook Worker以利用该功能在服务器上本地运行Runbook。
  10. 服务器上的板载DSC,用于管理支持Hybrid Runbook Worker的服务器配置。
  11. 使用Kusto查询(在上面的#7中开发)配置警报以检查磁盘可用空间。配置警报时设置阈值,频率,周期详细信息。提供预期的操作组(在上面的#5中创建)以在警报
    被触发时收到通知。
  1. Create a Log Analytics workspace if you don't have one already.
  2. Install it's agent on the server which you want to monitor.
  3. Create a Azure Automation account if you don't have one already.
  4. Create Automation Runbook to clean the drive.
  5. Create action group.
  6. Configure action type of action group as Automation Runbook and provide runbook source as user and provide the runbook (that is created in #4 above) that you want to get triggered when an alert is triggered.
  7. Develop a Perf type Kusto query to get the free space.
  8. Test it in the Logs tile of your Log Analytics workspace.
  9. Install Hybrid Runbook Worker to leverage the feature to run runbooks locally on the server.
  10. Onboard DSC on your server to manage the configuration of your server that support Hybrid Runbook Worker.
  11. Configure alert using Kusto query (that is developed in #7 above) to check the disk free space. Set threshold value, frequency, period details while configuring an alert. Provide intended action group (that is created in #5 above) to get notified on alert getting triggered.

您可能需要按照规定开发的查询在#7看起来如下所示。

The query which you may have to develop as stated in #7 would look something like shown below.

Perf| where (Computer == "xxxxxxx" or Computer == "yyyyyyy")| where ( ObjectName == "LogicalDisk" )| where ( CounterName == "% Free Space" )| where ( InstanceName == "C:" )| summarize AggregatedValue= avg(CounterValue) by Computer, bin(TimeGenerated, 30s)




您可以参考以下Microsoft文档链接中的一些说明。

https://docs.microsoft.com / en-us / azure / azure-monitor / log-query / log-query-overview

https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-collect-windows-computer

https://docs.microsoft.com / en-us / azure / automation / automation-quickstart-create-Runbook

https://docs.microsoft.com/en-us/azure/azure-monitor/platform/action-groups

https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric

https://docs.microsoft.com/en-us/azure/自动化/自动化 - 创建 - 警报 - 触发 - Runbook

https://docs.microsoft.com/en-us/azure/automation/automation-windows-hrw-install

https://docs.microsoft.com/en-us/azure/automation/automation-hrw-run-runbooks

https:/ /docs.microsoft.com/en-us/azure/virtual-machines/windows/run-scripts-in-vm


You may refer to few below Microsoft documentation links for instructions.
https://docs.microsoft.com/en-us/azure/azure-monitor/log-query/log-query-overview
https://docs.microsoft.com/en-us/azure/azure-monitor/learn/quick-collect-windows-computer
https://docs.microsoft.com/en-us/azure/automation/automation-quickstart-create-runbook
https://docs.microsoft.com/en-us/azure/azure-monitor/platform/action-groups
https://docs.microsoft.com/en-us/azure/azure-monitor/platform/alerts-metric
https://docs.microsoft.com/en-us/azure/automation/automation-create-alert-triggered-runbook
https://docs.microsoft.com/en-us/azure/automation/automation-windows-hrw-install
https://docs.microsoft.com/en-us/azure/automation/automation-hrw-run-runbooks
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/run-scripts-in-vm

希望这个帮助!!