Skip to content

Commit e0c1ae7

Browse files
authored
[azure][fix]: Ignore errors from Azure side (#2263)
1 parent 309a634 commit e0c1ae7

File tree

6 files changed

+6
-76
lines changed

6 files changed

+6
-76
lines changed

plugins/azure/fix_plugin_azure/resource/cosmosdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,7 @@ class AzureCosmosDBLocation(CosmosDBLocationSetter, MicrosoftResource, PhantomBa
20572057
query_parameters=["api-version"],
20582058
access_path="value",
20592059
expect_array=True,
2060+
expected_error_codes={"Internal Server Error": None},
20602061
)
20612062
mapping: ClassVar[Dict[str, Bender]] = {
20622063
"id": S("id"),

plugins/azure/fix_plugin_azure/resource/monitor.py

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -346,72 +346,6 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
346346
)
347347

348348

349-
@define(eq=False, slots=False)
350-
class AzureMonitorRuleDataSource:
351-
kind: ClassVar[str] = "azure_monitor_rule_data_source"
352-
mapping: ClassVar[Dict[str, Bender]] = {
353-
"legacy_resource_id": S("legacyResourceId"),
354-
"metric_namespace": S("metricNamespace"),
355-
"type": S("odata.type"),
356-
"resource_location": S("resourceLocation"),
357-
"resource_uri": S("resourceUri"),
358-
}
359-
legacy_resource_id: Optional[str] = field(default=None, metadata={'description': 'the legacy resource identifier of the resource the rule monitors. **NOTE**: this property cannot be updated for an existing rule.'}) # fmt: skip
360-
metric_namespace: Optional[str] = field(default=None, metadata={"description": "the namespace of the metric."})
361-
type: Optional[str] = field(default=None, metadata={'description': 'specifies the type of data source. There are two types of rule data sources: RuleMetricDataSource and RuleManagementEventDataSource'}) # fmt: skip
362-
resource_location: Optional[str] = field(default=None, metadata={"description": "the location of the resource."})
363-
resource_uri: Optional[str] = field(default=None, metadata={'description': 'the resource identifier of the resource the rule monitors. **NOTE**: this property cannot be updated for an existing rule.'}) # fmt: skip
364-
365-
366-
@define(eq=False, slots=False)
367-
class AzureMonitorRuleCondition:
368-
kind: ClassVar[str] = "azure_monitor_rule_condition"
369-
mapping: ClassVar[Dict[str, Bender]] = {
370-
"data_source": S("dataSource") >> Bend(AzureMonitorRuleDataSource.mapping),
371-
"type": S("odata.type"),
372-
}
373-
data_source: Optional[AzureMonitorRuleDataSource] = field(default=None, metadata={'description': 'The resource from which the rule collects its data.'}) # fmt: skip
374-
type: Optional[str] = field(default=None, metadata={'description': 'specifies the type of condition. This can be one of three types: ManagementEventRuleCondition (occurrences of management events), LocationThresholdRuleCondition (based on the number of failures of a web test), and ThresholdRuleCondition (based on the threshold of a metric).'}) # fmt: skip
375-
376-
377-
@define(eq=False, slots=False)
378-
class AzureMonitorAlertRule(MicrosoftResource):
379-
kind: ClassVar[str] = "azure_monitor_alert_rule"
380-
_kind_display: ClassVar[str] = "Azure Monitor Alert Rule"
381-
_kind_service: ClassVar[Optional[str]] = service_name
382-
_kind_description: ClassVar[str] = "Azure Monitor Alert Rule is a feature in Microsoft Azure that defines conditions for monitoring resources and triggers notifications when specified thresholds are met. It evaluates metrics, logs, and activity data from Azure services, then sends alerts via various channels when predefined criteria are satisfied, helping administrators respond to issues and maintain system health." # fmt: skip
383-
_docs_url: ClassVar[str] = "https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-overview"
384-
_metadata: ClassVar[Dict[str, Any]] = {"icon": "config", "group": "management"}
385-
_create_provider_link: ClassVar[bool] = False
386-
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
387-
service="monitor",
388-
version="2016-03-01",
389-
path="/subscriptions/{subscriptionId}/providers/Microsoft.Insights/alertrules",
390-
path_parameters=["subscriptionId"],
391-
query_parameters=["api-version"],
392-
access_path="value",
393-
expect_array=True,
394-
)
395-
mapping: ClassVar[Dict[str, Bender]] = {
396-
"id": S("id"),
397-
"tags": S("tags").or_else(K({})),
398-
"name": S("name"),
399-
"action": S("properties", "action", "odata.type"),
400-
"actions": S("properties") >> S("actions", default=[]) >> ForallBend(S("odata.type")),
401-
"rule_condition": S("properties", "condition") >> Bend(AzureMonitorRuleCondition.mapping),
402-
"description": S("properties", "description"),
403-
"is_enabled": S("properties", "isEnabled"),
404-
"last_updated_time": S("properties", "lastUpdatedTime"),
405-
"provisioning_state": S("properties", "provisioningState"),
406-
}
407-
action: Optional[str] = field(default=None, metadata={'description': 'The action that is performed when the alert rule becomes active, and when an alert condition is resolved.'}) # fmt: skip
408-
actions: Optional[List[str]] = field(default=None, metadata={'description': 'the array of actions that are performed when the alert rule becomes active, and when an alert condition is resolved.'}) # fmt: skip
409-
rule_condition: Optional[AzureMonitorRuleCondition] = field(default=None, metadata={'description': 'The condition that results in the alert rule being activated.'}) # fmt: skip
410-
description: Optional[str] = field(default=None, metadata={'description': 'the description of the alert rule that will be included in the alert email.'}) # fmt: skip
411-
is_enabled: Optional[bool] = field(default=None, metadata={'description': 'the flag that indicates whether the alert rule is enabled.'}) # fmt: skip
412-
last_updated_time: Optional[datetime] = field(default=None, metadata={'description': 'Last time the rule was updated in ISO8601 format.'}) # fmt: skip
413-
414-
415349
@define(eq=False, slots=False)
416350
class AzureMonitorAccessModeSettingsExclusion:
417351
kind: ClassVar[str] = "azure_monitor_access_mode_settings_exclusion"
@@ -1463,7 +1397,6 @@ def execute() -> None:
14631397
resources: List[Type[MicrosoftResource]] = [
14641398
AzureMonitorActionGroup,
14651399
AzureMonitorActivityLogAlert,
1466-
AzureMonitorAlertRule,
14671400
AzureMonitorDataCollectionRule,
14681401
AzureMonitorLogProfile,
14691402
AzureMonitorMetricAlert,

plugins/azure/fix_plugin_azure/resource/network.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6773,6 +6773,7 @@ class AzureNetworkDNSZone(MicrosoftResource, BaseDNSZone):
67736773
query_parameters=["api-version"],
67746774
access_path="value",
67756775
expect_array=True,
6776+
expected_error_codes={"BadRequest": None},
67766777
)
67776778
mapping: ClassVar[Dict[str, Bender]] = {
67786779
"id": S("id"),

plugins/azure/fix_plugin_azure/resource/storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class AzureStorageAccountDeleted(MicrosoftResource, PhantomBaseResource):
204204
query_parameters=["api-version"],
205205
access_path="value",
206206
expect_array=True,
207+
expected_error_codes={"ProviderError": None},
207208
)
208209
mapping: ClassVar[Dict[str, Bender]] = {
209210
"id": S("id"),
@@ -1082,7 +1083,7 @@ class AzureStorageAccountUsage(MicrosoftResource, AzureBaseUsage):
10821083
query_parameters=["api-version"],
10831084
access_path="value",
10841085
expect_array=True,
1085-
expected_error_codes=AzureBaseUsage._expected_error_codes,
1086+
expected_error_codes=AzureBaseUsage._expected_error_codes | {"SubscriptionNotFound": None},
10861087
)
10871088
mapping: ClassVar[Dict[str, Bender]] = AzureBaseUsage.mapping | {
10881089
"id": S("name", "value"),

plugins/azure/test/collector_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def test_collect(
4848
config, Cloud(id="azure"), azure_subscription, credentials, core_feedback, filter_unused_resources=False
4949
)
5050
subscription_collector.collect()
51-
assert len(subscription_collector.graph.nodes) == 887
52-
assert len(subscription_collector.graph.edges) == 1282
51+
assert len(subscription_collector.graph.nodes) == 885
52+
assert len(subscription_collector.graph.edges) == 1280
5353

5454
graph_collector = MicrosoftGraphOrganizationCollector(
5555
config, Cloud(id="azure"), MicrosoftGraphOrganization(id="test", name="test"), credentials, core_feedback

plugins/azure/test/monitor_test.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from fix_plugin_azure.resource.monitor import (
44
AzureMonitorActionGroup,
55
AzureMonitorActivityLogAlert,
6-
AzureMonitorAlertRule,
76
AzureMonitorLogProfile,
87
AzureMonitorMetricAlert,
98
AzureMonitorPrivateLinkScope,
@@ -25,11 +24,6 @@ def test_activity_log_alert(builder: GraphBuilder) -> None:
2524
assert len(collected) == 2
2625

2726

28-
def test_alert_rule(builder: GraphBuilder) -> None:
29-
collected = roundtrip_check(AzureMonitorAlertRule, builder)
30-
assert len(collected) == 2
31-
32-
3327
def test_data_collection_rule(builder: GraphBuilder) -> None:
3428
collected = roundtrip_check(AzureMonitorDataCollectionRule, builder)
3529
assert len(collected) == 2

0 commit comments

Comments
 (0)