简体   繁体   English

使用Azure Power Shell或Azure CLI创建日志分析警报

[英]To create the Log Analytics alerts using Azure Power Shell or Azure CLI

I'm trying to create alerts in LogAnlytics in azure portal, need to create 6 alerts for 5 db's, so have to create 30 alerts manually and is time consuming. 我正在尝试在azure门户中的LogAnlytics中创建警报,需要为5个数据库创建6个警报,因此必须手动创建30个警报,这很耗时。

Hence would require an automated approach. 因此,将需要一种自动化的方法。

Tried to create via Creating Alerts Using Azure PowerShell , but this creates the alerts in the Alerts Classic under Monitor but this is not what is required, require it to be created in Log Analytics. 尝试通过使用Azure PowerShell创建警报来创建,但这会在Monitors下的Alerts Classic中创建警报,但这不是必需的,需要在Log Analytics中创建。

Next approach was via Create a metric alert with a Resource Manager template but this was metric alert and not LogAnalytics alert 下一种方法是通过使用Resource Manager模板创建度量标准警报,但这是度量标准警报,而不是LogAnalytics警报

At last tried Create and manage alert rules in Log Analytics with REST API , but this is a tedious process need to get the search id, schedule id, threshold id and action id. 最后尝试使用REST API在Log Analytics中创建和管理警报规则 ,但这是一个繁琐的过程,需要获取搜索ID,计划ID,阈值ID和操作ID。 Even after trying to create the threshold id or action id the error I'm facing is "404 - File or directory not found." 即使尝试创建阈值ID或操作ID之后,我仍然遇到的错误是“ 404-找不到文件或目录”。 (as in the image). (如图所示)。

错误

Could someone please suggest me on how should this be proceeded, or is there any other way to create alerts apart from the manual creation? 有人可以建议我如何进行此操作,或者除了手动创建以外,还有其他方法可以创建警报吗?

If you use the Add activity log alert to add a rule, you will find it in the Alerts of Log Analytics in the portal. 如果使用Add activity log alert来添加规则,则可以在门户网站的日志分析 警报中找到它。

Please refer to the Log Analytics Documentation , 请参考Log Analytics文档

Alerts are created by alert rules in Azure Monitor and can automatically run saved queries or custom log searches at regular intervals. 警报是由Azure Monitor中的警报规则创建的,可以定期自动运行保存的查询或自定义日志搜索。

Update : 更新

Please refer to my test screenshots, I think you should check the specific resource group or other things, etc. 请参考我的测试屏幕截图,我认为您应该检查特定的资源组或其他内容,等等。

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

Even so, activity log alert belongs to the alerts(classic) , alerts is a new metric alert type . 即便如此,活动日志警报仍属于警报(经典)警报是一种新的指标警报类型 You could check the link new metric alert type in this article , it points the alerts . 您可以在本文中检查链接new metric alert type ,它指向警报 it is not supported by powershell and CLI currently. 当前,PowerShell和CLI不支持它。

Please refer to: 请参阅:

1. Use PowerShell to create alerts for Azure services 1. 使用PowerShell为Azure服务创建警报

2. Use the cross-platform Azure CLI to create classic metric alerts in Azure Monitor for Azure services 2. 使用跨平台的Azure CLI在Azure Monitor for Azure服务中创建经典指标警报

As mentioned in the two articles: 如两篇文章所述:

This article describes how to create older classic metric alerts. 本文介绍如何创建较旧的经典指标警报。 Azure Monitor now supports newer, better metric alerts. Azure Monitor现在支持更新更好的指标警报。 These alerts can monitor multiple metrics and allow for alerting on dimensional metrics. 这些警报可以监视多个指标,并允许对维度指标进行警报。 PowerShell support for newer metric alerts is coming soon. PowerShell对较新的度量标准警报的支持即将推出。

This article describes how to create older classic metric alerts. 本文介绍如何创建较旧的经典指标警报。 Azure Monitor now supports newer, better metric alerts. Azure Monitor现在支持更新更好的指标警报。 These alerts can monitor multiple metrics and allow for alerting on dimensional metrics. 这些警报可以监视多个指标,并允许对维度指标进行警报。 Azure CLI support for newer metric alerts is coming soon. Azure CLI对较新的度量标准警报的支持即将推出。

@Shashikiran : You can use the script published in the GITHUB https://github.com/microsoft/manageability-toolkits/tree/master/Alert%20Toolkit @Shashikiran:您可以使用GITHUB中发布的脚本https://github.com/microsoft/manageability-toolkits/tree/master/Alert%20Toolkit

This can create a few sample alerts. 这可以创建一些示例警报。 For now we have included some sample core machine monitoring alerts like CPU , hardware failures , SQL , etc... Also these are only the log alerts. 目前,我们已经包括一些示例性的核心机器监视警报,例如CPU,硬件故障,SQL等等。这些仅仅是日志警报。 You can use this as a sample code and come up with your code. 您可以将其用作示例代码并提出您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Az CLI将Azure活动日志连接到Log Analytics实例 - Connecting Azure Activity Log to Log Analytics instance using Az CLI 如何使用警报/powershell/cli 获取 Azure 活动日志摘要? - How to get Azure Activity Log Summary with alerts/powershell/cli? 如何使用azure CLI和Power Shell脚本实现自动登录而无需用户从VSTS进入azure门户 - How to implement automated login without user interaction into azure portal from VSTS using azure CLI & power shell script 将自定义日志发送到 Azure 使用 Azure 数据工厂进行日志分析 - Sending Custom Logs to Azure Log analytics using Azure Data Factory Azure在Power Shell中获取证书 - Azure Get Certificate in Power Shell 在Azure中运行Power Shell脚本 - Running a power shell script in Azure 使用Power-Shell检索Azure Linux机器的私有IP - Retrieve private IP of azure Linux machine using power-shell 使用Power Shell从Azure存储中导入发布设置文件 - Importing publish settings file from azure storage using power shell 有没有办法使用 Azure Power Shell 使用 YAML 文件重新部署 ACI? - Is there a way to use Azure Power Shell to redeploy an ACI using a YAML file? Azure DevOps Pipeline - Power shell脚本,使用变量复制文件 - Azure DevOps Pipeline - Power shell script , Copy Files using Variables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM