[Question] How to create a dynamic alert rule ?
See original GitHub issueHi 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:
- Created 3 years ago
- Comments:9
Top GitHub Comments
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:
And then pass that payload object to the
WithProperties()
method.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!