Skip to content

Commit 0873e58

Browse files
ABZhang0Alan Zhang
andauthored
[Monitor] az monitor dashboard: Support dashboard with Grafana (#32414)
Co-authored-by: Alan Zhang <[email protected]>
1 parent 104cb2e commit 0873e58

File tree

9 files changed

+1327
-0
lines changed

9 files changed

+1327
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command_group(
15+
"monitor dashboard",
16+
)
17+
class __CMDGroup(AAZCommandGroup):
18+
"""Manage Dashboard with Grafana resources
19+
"""
20+
pass
21+
22+
23+
__all__ = ["__CMDGroup"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from .__cmd_group import *
12+
from ._create import *
13+
from ._delete import *
14+
from ._list import *
15+
from ._show import *
16+
from ._wait import *
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
# --------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
#
5+
# Code generated by aaz-dev-tools
6+
# --------------------------------------------------------------------------------------------
7+
8+
# pylint: skip-file
9+
# flake8: noqa
10+
11+
from azure.cli.core.aaz import *
12+
13+
14+
@register_command(
15+
"monitor dashboard create",
16+
)
17+
class Create(AAZCommand):
18+
"""Create a Dashboard with Grafana resource. This API is idempotent, so user can either create a new dashboard or update an existing dashboard.
19+
20+
:example: Create a Dashboard with Grafana
21+
az monitor dashboard create --resource-group myResourceGroup --dashboard-name myDashboard --location westus
22+
"""
23+
24+
_aaz_info = {
25+
"version": "2025-09-01-preview",
26+
"resources": [
27+
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.dashboard/dashboards/{}", "2025-09-01-preview"],
28+
]
29+
}
30+
31+
AZ_SUPPORT_NO_WAIT = True
32+
33+
def _handler(self, command_args):
34+
super()._handler(command_args)
35+
return self.build_lro_poller(self._execute_operations, self._output)
36+
37+
_args_schema = None
38+
39+
@classmethod
40+
def _build_arguments_schema(cls, *args, **kwargs):
41+
if cls._args_schema is not None:
42+
return cls._args_schema
43+
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)
44+
45+
# define Arg Group ""
46+
47+
_args_schema = cls._args_schema
48+
_args_schema.dashboard_name = AAZStrArg(
49+
options=["-n", "--name", "--dashboard-name"],
50+
help="The name of the Azure Managed Dashboard.",
51+
required=True,
52+
fmt=AAZStrArgFormat(
53+
pattern="^[a-zA-Z][a-z0-9A-Z-]{0,28}[a-z0-9A-Z]$",
54+
),
55+
)
56+
_args_schema.resource_group = AAZResourceGroupNameArg(
57+
required=True,
58+
)
59+
60+
# define Arg Group "RequestBodyParameters"
61+
62+
_args_schema = cls._args_schema
63+
_args_schema.location = AAZResourceLocationArg(
64+
arg_group="RequestBodyParameters",
65+
help="The geo-location where the resource lives",
66+
required=True,
67+
fmt=AAZResourceLocationArgFormat(
68+
resource_group_arg="resource_group",
69+
),
70+
)
71+
_args_schema.tags = AAZDictArg(
72+
options=["--tags"],
73+
arg_group="RequestBodyParameters",
74+
help="Resource tags.",
75+
)
76+
77+
tags = cls._args_schema.tags
78+
tags.Element = AAZStrArg()
79+
return cls._args_schema
80+
81+
def _execute_operations(self):
82+
self.pre_operations()
83+
yield self.ManagedDashboardsCreate(ctx=self.ctx)()
84+
self.post_operations()
85+
86+
@register_callback
87+
def pre_operations(self):
88+
pass
89+
90+
@register_callback
91+
def post_operations(self):
92+
pass
93+
94+
def _output(self, *args, **kwargs):
95+
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
96+
return result
97+
98+
class ManagedDashboardsCreate(AAZHttpOperation):
99+
CLIENT_TYPE = "MgmtClient"
100+
101+
def __call__(self, *args, **kwargs):
102+
request = self.make_request()
103+
session = self.client.send_request(request=request, stream=False, **kwargs)
104+
if session.http_response.status_code in [202]:
105+
return self.client.build_lro_polling(
106+
self.ctx.args.no_wait,
107+
session,
108+
self.on_200_201,
109+
self.on_error,
110+
lro_options={"final-state-via": "azure-async-operation"},
111+
path_format_arguments=self.url_parameters,
112+
)
113+
if session.http_response.status_code in [200, 201]:
114+
return self.client.build_lro_polling(
115+
self.ctx.args.no_wait,
116+
session,
117+
self.on_200_201,
118+
self.on_error,
119+
lro_options={"final-state-via": "azure-async-operation"},
120+
path_format_arguments=self.url_parameters,
121+
)
122+
123+
return self.on_error(session.http_response)
124+
125+
@property
126+
def url(self):
127+
return self.client.format_url(
128+
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Dashboard/dashboards/{dashboardName}",
129+
**self.url_parameters
130+
)
131+
132+
@property
133+
def method(self):
134+
return "PUT"
135+
136+
@property
137+
def error_format(self):
138+
return "MgmtErrorFormat"
139+
140+
@property
141+
def url_parameters(self):
142+
parameters = {
143+
**self.serialize_url_param(
144+
"dashboardName", self.ctx.args.dashboard_name,
145+
required=True,
146+
),
147+
**self.serialize_url_param(
148+
"resourceGroupName", self.ctx.args.resource_group,
149+
required=True,
150+
),
151+
**self.serialize_url_param(
152+
"subscriptionId", self.ctx.subscription_id,
153+
required=True,
154+
),
155+
}
156+
return parameters
157+
158+
@property
159+
def query_parameters(self):
160+
parameters = {
161+
**self.serialize_query_param(
162+
"api-version", "2025-09-01-preview",
163+
required=True,
164+
),
165+
}
166+
return parameters
167+
168+
@property
169+
def header_parameters(self):
170+
parameters = {
171+
**self.serialize_header_param(
172+
"Content-Type", "application/json",
173+
),
174+
**self.serialize_header_param(
175+
"Accept", "application/json",
176+
),
177+
}
178+
return parameters
179+
180+
@property
181+
def content(self):
182+
_content_value, _builder = self.new_content_builder(
183+
self.ctx.args,
184+
typ=AAZObjectType,
185+
typ_kwargs={"flags": {"required": True, "client_flatten": True}}
186+
)
187+
_builder.set_prop("location", AAZStrType, ".location", typ_kwargs={"flags": {"required": True}})
188+
_builder.set_prop("tags", AAZDictType, ".tags")
189+
190+
tags = _builder.get(".tags")
191+
if tags is not None:
192+
tags.set_elements(AAZStrType, ".")
193+
194+
return self.serialize_content(_content_value)
195+
196+
def on_200_201(self, session):
197+
data = self.deserialize_http_content(session)
198+
self.ctx.set_var(
199+
"instance",
200+
data,
201+
schema_builder=self._build_schema_on_200_201
202+
)
203+
204+
_schema_on_200_201 = None
205+
206+
@classmethod
207+
def _build_schema_on_200_201(cls):
208+
if cls._schema_on_200_201 is not None:
209+
return cls._schema_on_200_201
210+
211+
cls._schema_on_200_201 = AAZObjectType()
212+
213+
_schema_on_200_201 = cls._schema_on_200_201
214+
_schema_on_200_201.id = AAZStrType(
215+
flags={"read_only": True},
216+
)
217+
_schema_on_200_201.location = AAZStrType(
218+
flags={"required": True},
219+
)
220+
_schema_on_200_201.name = AAZStrType(
221+
flags={"read_only": True},
222+
)
223+
_schema_on_200_201.properties = AAZObjectType(
224+
flags={"client_flatten": True},
225+
)
226+
_schema_on_200_201.system_data = AAZObjectType(
227+
serialized_name="systemData",
228+
flags={"read_only": True},
229+
)
230+
_schema_on_200_201.tags = AAZDictType()
231+
_schema_on_200_201.type = AAZStrType(
232+
flags={"read_only": True},
233+
)
234+
235+
properties = cls._schema_on_200_201.properties
236+
properties.provisioning_state = AAZStrType(
237+
serialized_name="provisioningState",
238+
flags={"read_only": True},
239+
)
240+
241+
system_data = cls._schema_on_200_201.system_data
242+
system_data.created_at = AAZStrType(
243+
serialized_name="createdAt",
244+
)
245+
system_data.created_by = AAZStrType(
246+
serialized_name="createdBy",
247+
)
248+
system_data.created_by_type = AAZStrType(
249+
serialized_name="createdByType",
250+
)
251+
system_data.last_modified_at = AAZStrType(
252+
serialized_name="lastModifiedAt",
253+
)
254+
system_data.last_modified_by = AAZStrType(
255+
serialized_name="lastModifiedBy",
256+
)
257+
system_data.last_modified_by_type = AAZStrType(
258+
serialized_name="lastModifiedByType",
259+
)
260+
261+
tags = cls._schema_on_200_201.tags
262+
tags.Element = AAZStrType()
263+
264+
return cls._schema_on_200_201
265+
266+
267+
class _CreateHelper:
268+
"""Helper class for Create"""
269+
270+
271+
__all__ = ["Create"]

0 commit comments

Comments
 (0)