14
14
from zabbix_cli .app import app
15
15
from zabbix_cli .exceptions import ZabbixNotFoundError
16
16
from zabbix_cli .output .console import exit_err
17
+ from zabbix_cli .output .console import info
18
+ from zabbix_cli .output .console import success
17
19
from zabbix_cli .output .console import warning
18
20
from zabbix_cli .output .prompts import str_prompt
19
21
from zabbix_cli .output .render import render_result
@@ -169,6 +171,11 @@ def create_notification_user(
169
171
"--usergroups" ,
170
172
help = "Comma-separated list of usergroups to add the user to. Overrides user groups in config file." ,
171
173
),
174
+ dryrun : bool = typer .Option (
175
+ False ,
176
+ "--dryrun" ,
177
+ help = "Do not create the user, just show what would be done." ,
178
+ ),
172
179
# Legacy V2 args
173
180
args : Optional [list [str ]] = ARGS_POSITIONAL ,
174
181
) -> None :
@@ -191,8 +198,7 @@ def create_notification_user(
191
198
Adds the user to the default user group and default notification user group
192
199
unless [option]--usergroups[/option] is specified.
193
200
"""
194
- from zabbix_cli .models import Result
195
- from zabbix_cli .pyzabbix .types import User
201
+ from zabbix_cli .commands .results .user import CreateNotificationUserResult
196
202
from zabbix_cli .pyzabbix .types import UserMedia
197
203
198
204
if args :
@@ -233,6 +239,7 @@ def create_notification_user(
233
239
ug_list : list [str ] = []
234
240
ug_list .extend (app .state .config .app .default_notification_users_usergroups )
235
241
ug_list .extend (app .state .config .app .default_create_user_usergroups )
242
+
236
243
with app .status ("Fetching user group(s)..." ):
237
244
ugroups = [app .state .client .get_usergroup (ug ) for ug in set (ug_list )]
238
245
@@ -246,6 +253,14 @@ def create_notification_user(
246
253
)
247
254
]
248
255
256
+ result = CreateNotificationUserResult (
257
+ username = username , media = user_media , userid = "" , usergroups = ugroups
258
+ )
259
+ if dryrun :
260
+ info ("Would create:" )
261
+ render_result (result )
262
+ return
263
+
249
264
with app .status ("Creating user..." ):
250
265
userid = app .state .client .create_user (
251
266
username = username ,
@@ -257,12 +272,10 @@ def create_notification_user(
257
272
media = user_media ,
258
273
)
259
274
260
- render_result (
261
- Result (
262
- message = f"Created notification user { username !r} ({ userid } )." ,
263
- result = User (userid = userid , username = username ),
264
- ),
265
- )
275
+ result .userid = userid
276
+
277
+ success (f"Created notification user { username !r} ({ userid } )." )
278
+ render_result (result )
266
279
267
280
268
281
@app .command ("remove_user" , rich_help_panel = HELP_PANEL )
0 commit comments