Skip to content

Commit 6cacdf9

Browse files
authored
[azure][feat]: Add more connections from monitor (#2239)
1 parent b9595dd commit 6cacdf9

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

plugins/azure/fix_plugin_azure/resource/monitor.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ class AzureMonitorActivityLogAlert(MicrosoftResource):
305305
_metadata: ClassVar[Dict[str, Any]] = {"icon": "alarm", "group": "management"}
306306
_reference_kinds: ClassVar[ModelReference] = {
307307
"predecessors": {"default": [AzureMonitorActionGroup.kind]},
308+
"successors": {"default": [MicrosoftResource.kind]},
308309
}
309310
_create_provider_link: ClassVar[bool] = False
310311
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
@@ -336,6 +337,14 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
336337
for ref in self.action_groups or []:
337338
builder.add_edge(self, reverse=True, clazz=AzureMonitorActionGroup, id=ref.action_group_id)
338339

340+
if scopes := self.scopes:
341+
for scope_id in scopes:
342+
builder.add_edge(
343+
self,
344+
clazz=MicrosoftResource,
345+
id=scope_id,
346+
)
347+
339348

340349
@define(eq=False, slots=False)
341350
class AzureMonitorRuleDataSource:
@@ -867,14 +876,22 @@ class AzureMetricAlertAction:
867876

868877

869878
@define(eq=False, slots=False)
870-
class AzureMetricAlert(MicrosoftResource):
871-
kind: ClassVar[str] = "azure_metric_alert"
879+
class AzureMonitorMetricAlert(MicrosoftResource):
880+
kind: ClassVar[str] = "azure_monitor_metric_alert"
872881
_kind_display: ClassVar[str] = "Azure Metric Alert"
873882
_kind_service: ClassVar[Optional[str]] = service_name
874883
_kind_description: ClassVar[str] = "Azure Metric Alert is a monitoring service in Microsoft Azure that tracks specified metrics for resources. It evaluates data against predefined thresholds and triggers notifications when these thresholds are breached. Users can configure alerts for various metrics, set custom conditions, and define actions such as sending emails or executing automated responses when alert conditions are met." # fmt: skip
875884
_docs_url: ClassVar[str] = "https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-metric-overview"
876885
_metadata: ClassVar[Dict[str, Any]] = {"icon": "alarm", "group": "management"}
877886
_create_provider_link: ClassVar[bool] = False
887+
_reference_kinds: ClassVar[ModelReference] = {
888+
"predecessors": {
889+
"default": [
890+
AzureMonitorActionGroup.kind,
891+
]
892+
},
893+
"successors": {"default": [MicrosoftResource.kind]},
894+
}
878895
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
879896
service="monitor",
880897
version="2018-03-01",
@@ -915,6 +932,19 @@ class AzureMetricAlert(MicrosoftResource):
915932
target_resource_type: Optional[str] = field(default=None, metadata={'description': 'the resource type of the target resource(s) on which the alert is created/updated. Mandatory if the scope contains a subscription, resource group, or more than one resource.'}) # fmt: skip
916933
window_size: Optional[str] = field(default=None, metadata={'description': 'the period of time (in ISO 8601 duration format) that is used to monitor alert activity based on the threshold.'}) # fmt: skip
917934

935+
def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
936+
if alert_actions := self.alert_actions:
937+
for alert_action in alert_actions:
938+
if a_group_id := alert_action.action_group_id:
939+
builder.add_edge(self, clazz=AzureMonitorActionGroup, reverse=True, id=a_group_id)
940+
if scopes := self.scopes:
941+
for scope_id in scopes:
942+
builder.add_edge(
943+
self,
944+
clazz=MicrosoftResource,
945+
id=scope_id,
946+
)
947+
918948

919949
@define(eq=False, slots=False)
920950
class AzureMonitorSyslogReceiver:
@@ -1257,6 +1287,9 @@ class AzureMonitorScheduledQueryRule(MicrosoftResource):
12571287
_docs_url: ClassVar[str] = "https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-scheduled-query"
12581288
_metadata: ClassVar[Dict[str, Any]] = {"icon": "config", "group": "management"}
12591289
_create_provider_link: ClassVar[bool] = False
1290+
_reference_kinds: ClassVar[ModelReference] = {
1291+
"successors": {"default": [MicrosoftResource.kind]},
1292+
}
12601293
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
12611294
service="monitor",
12621295
version="2024-01-01-preview",
@@ -1322,6 +1355,15 @@ class AzureMonitorScheduledQueryRule(MicrosoftResource):
13221355
target_resource_types: Optional[List[str]] = field(default=None, metadata={'description': 'List of resource type of the target resource(s) on which the alert is created/updated. For example if the scope is a resource group and targetResourceTypes is Microsoft.Compute/virtualMachines, then a different alert will be fired for each virtual machine in the resource group which meet the alert criteria. Relevant only for rules of the kind LogAlert'}) # fmt: skip
13231356
window_size: Optional[str] = field(default=None, metadata={'description': 'The period of time (in ISO 8601 duration format) on which the Alert query will be executed (bin size). Relevant and required only for rules of the kind LogAlert.'}) # fmt: skip
13241357

1358+
def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
1359+
if scopes := self.scopes:
1360+
for scope_id in scopes:
1361+
builder.add_edge(
1362+
self,
1363+
clazz=MicrosoftResource,
1364+
id=scope_id,
1365+
)
1366+
13251367

13261368
@define(eq=False, slots=True)
13271369
class AzureDiagnosticLogRetentionPolicy:
@@ -1424,7 +1466,7 @@ def execute() -> None:
14241466
AzureMonitorAlertRule,
14251467
AzureMonitorDataCollectionRule,
14261468
AzureMonitorLogProfile,
1427-
AzureMetricAlert,
1469+
AzureMonitorMetricAlert,
14281470
AzureMonitorPrivateLinkScope,
14291471
AzureMonitorWorkspace,
14301472
AzureMonitorPipelineGroup,

plugins/azure/test/monitor_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
AzureMonitorActivityLogAlert,
66
AzureMonitorAlertRule,
77
AzureMonitorLogProfile,
8-
AzureMetricAlert,
8+
AzureMonitorMetricAlert,
99
AzureMonitorPrivateLinkScope,
1010
AzureMonitorWorkspace,
1111
AzureMonitorDataCollectionRule,
@@ -41,7 +41,7 @@ def test_log_profile(builder: GraphBuilder) -> None:
4141

4242

4343
def test_alert(builder: GraphBuilder) -> None:
44-
collected = roundtrip_check(AzureMetricAlert, builder)
44+
collected = roundtrip_check(AzureMonitorMetricAlert, builder)
4545
assert len(collected) == 2
4646

4747

0 commit comments

Comments
 (0)