question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] How to create a dynamic alert rule ?

See original GitHub issue

Hi guys, I need to create a Dynamic Threshold Alert Rule for my Application Insisghts instance. Recently I was creating a static rule:

var api = Azure.Configure()
               .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
               .Authenticate(credentials)
               .WithSubscription(subscriptionId);

await api.AlertRules
 		 .MetricAlerts
 		 .Define("Test rule")
 		 .WithExistingResourceGroup(resourceGroup) 		 
 		 .WithTargetResource(appInsightsId)
 		 .WithPeriod(new TimeSpan(0, 5, 0)) //Aggregation granularity (Period)
 		 .WithFrequency(new TimeSpan(0, 5, 0)) //Frequency of evaluation
 		 .WithAlertDetails(2, "test desc")
 		 .WithActionGroups(id)
 		 .DefineAlertCriteria("condition name")
 		 .WithMetricName("metric name")
 		 .WithCondition(MetricAlertRuleTimeAggregation.Count, MetricAlertRuleCondition.GreaterThanOrEqual, 1)
 		 .Attach()
 		 .CreateAsync()

but now I need to create a dynamic rule - looking at the json payload for creating a Dynamic Alert Rule for Single Resource https://docs.microsoft.com/pl-pl/rest/api/monitor/metricalerts/createorupdate#create-or-update-a-dynamic-alert-rule-for-single-resource I can see the matching classes in the source code whose indicates the appropiate fields in that payload (e.g. DynamicMetricCriteria, DynamicThresholdFailingPeriods and so on), but they are not publicly available to be used in the SDK. Or am I wrong ?

To create a workaround, I use the IGenericResource to create that alert rule:

await _genericResources.Define(name)
                .WithRegion(region)
                .WithExistingResourceGroup(resourceGroup)
                .WithResourceType("metricAlerts")
                .WithProviderNamespace("microsoft.insights")
                .WithoutPlan()
                .WithApiVersion("2018-03-01")
                .WithParentResource("")
                .WithProperties(...)
                .CreateAsync();

but that approach does not provide the way to set the required location field, and I end up with the error message: The provided location 'WestEurope' is not available for resource type 'microsoft.insights/metricalerts'. List of available regions for the resource type is 'global'.

So, any ideas how to deal with it ? It does no matter for me whether I use the Fluent API or the IGenericResource interface.

Environment:

  • Microsoft.Azure.Management.Fluent v1.32.0
  • Microsoft.Azure.Management.ResourceManager.Fluen v1.32.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
harelbrcommented, Jun 16, 2020

Hi @tony6636, it seems like this is an issue with the way the payload is passed into the .WithProperties() method. This method expects an object as an input parameter.

Can you please try taking the same properties payload you’ve specified in your previous reply, and construct an object of it:

string s = “{<the payload properties>}”;
var payload = JObject.Parse(s);

And then pass that payload object to the WithProperties() method.

1reaction
harelbrcommented, Jun 12, 2020

Hi @tony6636 - The ‘No registered resource provider…’ error indicates the resource type being used is Microsoft.Insights/components, while it needs to be Microsoft.Insights/metricAlerts.

Can you please double check that the correct resource type is specified: .WithResourceType(“metricAlerts”)

If that’s not the case, can you please share the full command you’re trying to run?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic thresholds for metric alerting - Azure
When an alert rule is first created, dynamic thresholds use 10 days of historical data to calculate hourly or daily seasonal patterns.
Read more >
Create or edit an alert rule - Azure Monitor
Create or edit an alert rule in the Azure portal · In the portal, select Monitor > Alerts. · Open the + Create...
Read more >
Microsoft Azure - Configuring an Alert Rule with ...
To create a new alert click the Alerts option and then click + New alert rule. Next, to select a target resource that...
Read more >
Create Grafana-managed alert rules
In the left-side menu, click Alerts & IRM and then Alerting. · Click Alert rules. · Click + Create alert rule. · In...
Read more >
Static vs Dynamic Alert Thresholds for Monitoring
Alert thresholds for monitoring is a topic of some debate. We discuss the pros & cons of static vs dynamic alert thresholds for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found