azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Can't create an Alert for a VM on Azure using: az monitor alert-rules create ...

Open jefffall opened this issue 9 years ago • 2 comments

Description

Outline the issue here: I have tried many permutations to create ANY monitoring alert on Azure using az cli.

Here is an example invoke of the az cli 2.0:

az monitor alert-rules create --is-enabled IS_ENABLED --name JeffFallRuleTestCPU --resource-group M-Monitoring-R --alert-rule-resource-name /subscriptions/my_subscription/resourceGroups/HCM-Monitoring-RG/providers/Microsoft.Compute/virtualMachines/my_vm --location westus --condition @{jeffcondition} --description 'processor time'

Here is the condition file I am using:

more jeffcondition
{
      "data_source": {
        "metric_name": "Percentage CPU",
        "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
        "resource_uri": "/subscriptions/3fd8391b-f9e7-4d54-bf96-f7fb9844c4c1/resourceGroups/HCM-Monitoring-RG/providers/Microsoft.Compute/virtualMachines/hcm99mon01"
      },
      "odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
      "operator" : "GreaterThan",
      "threshold": 90,
      "time_aggregation" : "Average",
      "window_size": "PT5M"

After lots of trial and error for two days, I would be VERY HAPPY to create any working alert at all.

I really need alerts about CPU load.

If you could get me a condition file that can produce one working Alert for CPU - I would be really happy.

Want to use:

az monitor alert-rules create ......

IF I can't get az monitor alert-rules create to ever work and create monitoring Alerts on Azure, I'll have to punt and

Go for the REST API.

Two full days spent trying to get Azure CLI to work with: az monitor alert-rules create


Environment summary

Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here:

with the bash installer on a Mac running Sierra

CLI Version: What version of the CLI and modules are installed? (Use az --version)
Answer here:

[ZZZM00650289A:~] c5256381% az --version
azure-cli (2.0.3)

acr (2.0.1)
acs (2.0.3)
appservice (0.1.3)
batch (2.0.1)
cloud (2.0.1)
component (2.0.1)
configure (2.0.3)
container (0.1.3)
core (2.0.3)
documentdb (0.1.3)
feedback (2.0.1)
find (0.0.2)
iot (0.1.3)
keyvault (2.0.1)
lab (0.0.2)
monitor (0.0.2)
network (2.0.3)
nspkg (2.0.0)
profile (2.0.3)
redis (0.2.0)
resource (2.0.3)
role (2.0.2)
sql (2.0.1)
storage (2.0.3)
vm (2.0.3)

Python (Darwin) 2.7.10 (default, Feb  6 2017, 23:53:20)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]

OS Version: What OS and version are you using?
Answer here:

macOS Sierra 10.12.4

Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here:

csh
c cshell

  PID TTY           TIME CMD
 4783 ttys000    0:00.03 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server
 4785 ttys000    0:00.11 -csh
 5169 ttys001    0:00.03 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server
 5171 ttys001    0:00.11 -csh
 8008 ttys002    0:00.01 -csh

jefffall avatar Apr 28 '17 04:04 jefffall

Ah yes. Most importantly when I run the command:

c5256381% az monitor alert-rules create --is-enabled IS_ENABLED --name JeffFallRuleTestCPU --resource-group HCM-Monitoring-RG --alert-rule-resource-name /subscriptions/my_subscription/resourceGroups/H-Monitoring-R/providers/Microsoft.Compute/virtualMachines/myvm --location westus --condition @{jeffcondition} --description 'processor time' Request content is not well formed or supported.

I get this back in RED

Request content is not well formed or supported.

Which does NOT tell me what I did wrong (sadly)

jefffall avatar Apr 28 '17 04:04 jefffall

Hi @jefffall please see this issue #3052. There is a bug in this command. You are putting the VM id in "alert-rule-resource-name". Because of the bug, you actually would put "JeffFallRuleTestCPU" for this parameter, you can literally put ANYTHING for "name" (it shouldn't be exposed) and your VM ID goes inside that "condition" object.

tjprescott avatar Apr 28 '17 16:04 tjprescott