Skip to content

Commit

Permalink
[azure][fix]: Ignore errors from Azure side (#2263)
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 authored Nov 8, 2024
1 parent 309a634 commit e0c1ae7
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 76 deletions.
1 change: 1 addition & 0 deletions plugins/azure/fix_plugin_azure/resource/cosmosdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,7 @@ class AzureCosmosDBLocation(CosmosDBLocationSetter, MicrosoftResource, PhantomBa
query_parameters=["api-version"],
access_path="value",
expect_array=True,
expected_error_codes={"Internal Server Error": None},
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
Expand Down
67 changes: 0 additions & 67 deletions plugins/azure/fix_plugin_azure/resource/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,72 +346,6 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
)


@define(eq=False, slots=False)
class AzureMonitorRuleDataSource:
kind: ClassVar[str] = "azure_monitor_rule_data_source"
mapping: ClassVar[Dict[str, Bender]] = {
"legacy_resource_id": S("legacyResourceId"),
"metric_namespace": S("metricNamespace"),
"type": S("odata.type"),
"resource_location": S("resourceLocation"),
"resource_uri": S("resourceUri"),
}
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
metric_namespace: Optional[str] = field(default=None, metadata={"description": "the namespace of the metric."})
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
resource_location: Optional[str] = field(default=None, metadata={"description": "the location of the resource."})
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


@define(eq=False, slots=False)
class AzureMonitorRuleCondition:
kind: ClassVar[str] = "azure_monitor_rule_condition"
mapping: ClassVar[Dict[str, Bender]] = {
"data_source": S("dataSource") >> Bend(AzureMonitorRuleDataSource.mapping),
"type": S("odata.type"),
}
data_source: Optional[AzureMonitorRuleDataSource] = field(default=None, metadata={'description': 'The resource from which the rule collects its data.'}) # fmt: skip
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


@define(eq=False, slots=False)
class AzureMonitorAlertRule(MicrosoftResource):
kind: ClassVar[str] = "azure_monitor_alert_rule"
_kind_display: ClassVar[str] = "Azure Monitor Alert Rule"
_kind_service: ClassVar[Optional[str]] = service_name
_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
_docs_url: ClassVar[str] = "https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-overview"
_metadata: ClassVar[Dict[str, Any]] = {"icon": "config", "group": "management"}
_create_provider_link: ClassVar[bool] = False
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
service="monitor",
version="2016-03-01",
path="/subscriptions/{subscriptionId}/providers/Microsoft.Insights/alertrules",
path_parameters=["subscriptionId"],
query_parameters=["api-version"],
access_path="value",
expect_array=True,
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
"tags": S("tags").or_else(K({})),
"name": S("name"),
"action": S("properties", "action", "odata.type"),
"actions": S("properties") >> S("actions", default=[]) >> ForallBend(S("odata.type")),
"rule_condition": S("properties", "condition") >> Bend(AzureMonitorRuleCondition.mapping),
"description": S("properties", "description"),
"is_enabled": S("properties", "isEnabled"),
"last_updated_time": S("properties", "lastUpdatedTime"),
"provisioning_state": S("properties", "provisioningState"),
}
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
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
rule_condition: Optional[AzureMonitorRuleCondition] = field(default=None, metadata={'description': 'The condition that results in the alert rule being activated.'}) # fmt: skip
description: Optional[str] = field(default=None, metadata={'description': 'the description of the alert rule that will be included in the alert email.'}) # fmt: skip
is_enabled: Optional[bool] = field(default=None, metadata={'description': 'the flag that indicates whether the alert rule is enabled.'}) # fmt: skip
last_updated_time: Optional[datetime] = field(default=None, metadata={'description': 'Last time the rule was updated in ISO8601 format.'}) # fmt: skip


@define(eq=False, slots=False)
class AzureMonitorAccessModeSettingsExclusion:
kind: ClassVar[str] = "azure_monitor_access_mode_settings_exclusion"
Expand Down Expand Up @@ -1463,7 +1397,6 @@ def execute() -> None:
resources: List[Type[MicrosoftResource]] = [
AzureMonitorActionGroup,
AzureMonitorActivityLogAlert,
AzureMonitorAlertRule,
AzureMonitorDataCollectionRule,
AzureMonitorLogProfile,
AzureMonitorMetricAlert,
Expand Down
1 change: 1 addition & 0 deletions plugins/azure/fix_plugin_azure/resource/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -6773,6 +6773,7 @@ class AzureNetworkDNSZone(MicrosoftResource, BaseDNSZone):
query_parameters=["api-version"],
access_path="value",
expect_array=True,
expected_error_codes={"BadRequest": None},
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
Expand Down
3 changes: 2 additions & 1 deletion plugins/azure/fix_plugin_azure/resource/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class AzureStorageAccountDeleted(MicrosoftResource, PhantomBaseResource):
query_parameters=["api-version"],
access_path="value",
expect_array=True,
expected_error_codes={"ProviderError": None},
)
mapping: ClassVar[Dict[str, Bender]] = {
"id": S("id"),
Expand Down Expand Up @@ -1082,7 +1083,7 @@ class AzureStorageAccountUsage(MicrosoftResource, AzureBaseUsage):
query_parameters=["api-version"],
access_path="value",
expect_array=True,
expected_error_codes=AzureBaseUsage._expected_error_codes,
expected_error_codes=AzureBaseUsage._expected_error_codes | {"SubscriptionNotFound": None},
)
mapping: ClassVar[Dict[str, Bender]] = AzureBaseUsage.mapping | {
"id": S("name", "value"),
Expand Down
4 changes: 2 additions & 2 deletions plugins/azure/test/collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def test_collect(
config, Cloud(id="azure"), azure_subscription, credentials, core_feedback, filter_unused_resources=False
)
subscription_collector.collect()
assert len(subscription_collector.graph.nodes) == 887
assert len(subscription_collector.graph.edges) == 1282
assert len(subscription_collector.graph.nodes) == 885
assert len(subscription_collector.graph.edges) == 1280

graph_collector = MicrosoftGraphOrganizationCollector(
config, Cloud(id="azure"), MicrosoftGraphOrganization(id="test", name="test"), credentials, core_feedback
Expand Down
6 changes: 0 additions & 6 deletions plugins/azure/test/monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from fix_plugin_azure.resource.monitor import (
AzureMonitorActionGroup,
AzureMonitorActivityLogAlert,
AzureMonitorAlertRule,
AzureMonitorLogProfile,
AzureMonitorMetricAlert,
AzureMonitorPrivateLinkScope,
Expand All @@ -25,11 +24,6 @@ def test_activity_log_alert(builder: GraphBuilder) -> None:
assert len(collected) == 2


def test_alert_rule(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureMonitorAlertRule, builder)
assert len(collected) == 2


def test_data_collection_rule(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureMonitorDataCollectionRule, builder)
assert len(collected) == 2
Expand Down

0 comments on commit e0c1ae7

Please sign in to comment.