Skip to content

Commit

Permalink
[azure][feat]: Add more connections from monitor (#2239)
Browse files Browse the repository at this point in the history
  • Loading branch information
1101-1 authored Oct 16, 2024
1 parent b9595dd commit 6cacdf9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
48 changes: 45 additions & 3 deletions plugins/azure/fix_plugin_azure/resource/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class AzureMonitorActivityLogAlert(MicrosoftResource):
_metadata: ClassVar[Dict[str, Any]] = {"icon": "alarm", "group": "management"}
_reference_kinds: ClassVar[ModelReference] = {
"predecessors": {"default": [AzureMonitorActionGroup.kind]},
"successors": {"default": [MicrosoftResource.kind]},
}
_create_provider_link: ClassVar[bool] = False
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
Expand Down Expand Up @@ -336,6 +337,14 @@ def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
for ref in self.action_groups or []:
builder.add_edge(self, reverse=True, clazz=AzureMonitorActionGroup, id=ref.action_group_id)

if scopes := self.scopes:
for scope_id in scopes:
builder.add_edge(
self,
clazz=MicrosoftResource,
id=scope_id,
)


@define(eq=False, slots=False)
class AzureMonitorRuleDataSource:
Expand Down Expand Up @@ -867,14 +876,22 @@ class AzureMetricAlertAction:


@define(eq=False, slots=False)
class AzureMetricAlert(MicrosoftResource):
kind: ClassVar[str] = "azure_metric_alert"
class AzureMonitorMetricAlert(MicrosoftResource):
kind: ClassVar[str] = "azure_monitor_metric_alert"
_kind_display: ClassVar[str] = "Azure Metric Alert"
_kind_service: ClassVar[Optional[str]] = service_name
_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
_docs_url: ClassVar[str] = "https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-metric-overview"
_metadata: ClassVar[Dict[str, Any]] = {"icon": "alarm", "group": "management"}
_create_provider_link: ClassVar[bool] = False
_reference_kinds: ClassVar[ModelReference] = {
"predecessors": {
"default": [
AzureMonitorActionGroup.kind,
]
},
"successors": {"default": [MicrosoftResource.kind]},
}
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
service="monitor",
version="2018-03-01",
Expand Down Expand Up @@ -915,6 +932,19 @@ class AzureMetricAlert(MicrosoftResource):
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
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

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
if alert_actions := self.alert_actions:
for alert_action in alert_actions:
if a_group_id := alert_action.action_group_id:
builder.add_edge(self, clazz=AzureMonitorActionGroup, reverse=True, id=a_group_id)
if scopes := self.scopes:
for scope_id in scopes:
builder.add_edge(
self,
clazz=MicrosoftResource,
id=scope_id,
)


@define(eq=False, slots=False)
class AzureMonitorSyslogReceiver:
Expand Down Expand Up @@ -1257,6 +1287,9 @@ class AzureMonitorScheduledQueryRule(MicrosoftResource):
_docs_url: ClassVar[str] = "https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-scheduled-query"
_metadata: ClassVar[Dict[str, Any]] = {"icon": "config", "group": "management"}
_create_provider_link: ClassVar[bool] = False
_reference_kinds: ClassVar[ModelReference] = {
"successors": {"default": [MicrosoftResource.kind]},
}
api_spec: ClassVar[AzureResourceSpec] = AzureResourceSpec(
service="monitor",
version="2024-01-01-preview",
Expand Down Expand Up @@ -1322,6 +1355,15 @@ class AzureMonitorScheduledQueryRule(MicrosoftResource):
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
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

def connect_in_graph(self, builder: GraphBuilder, source: Json) -> None:
if scopes := self.scopes:
for scope_id in scopes:
builder.add_edge(
self,
clazz=MicrosoftResource,
id=scope_id,
)


@define(eq=False, slots=True)
class AzureDiagnosticLogRetentionPolicy:
Expand Down Expand Up @@ -1424,7 +1466,7 @@ def execute() -> None:
AzureMonitorAlertRule,
AzureMonitorDataCollectionRule,
AzureMonitorLogProfile,
AzureMetricAlert,
AzureMonitorMetricAlert,
AzureMonitorPrivateLinkScope,
AzureMonitorWorkspace,
AzureMonitorPipelineGroup,
Expand Down
4 changes: 2 additions & 2 deletions plugins/azure/test/monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
AzureMonitorActivityLogAlert,
AzureMonitorAlertRule,
AzureMonitorLogProfile,
AzureMetricAlert,
AzureMonitorMetricAlert,
AzureMonitorPrivateLinkScope,
AzureMonitorWorkspace,
AzureMonitorDataCollectionRule,
Expand Down Expand Up @@ -41,7 +41,7 @@ def test_log_profile(builder: GraphBuilder) -> None:


def test_alert(builder: GraphBuilder) -> None:
collected = roundtrip_check(AzureMetricAlert, builder)
collected = roundtrip_check(AzureMonitorMetricAlert, builder)
assert len(collected) == 2


Expand Down

0 comments on commit 6cacdf9

Please sign in to comment.