27
27
script_type:
28
28
description:
29
29
- Script type. Required when state is 'present'.
30
+ - A value of 'url' is only available in 7.0 or later
30
31
type: str
31
32
required: false
32
- choices: ["script", "ipmi", "ssh", "telnet", "webhook"]
33
+ choices: ["script", "ipmi", "ssh", "telnet", "webhook", "url"]
34
+ url:
35
+ description:
36
+ - The URL for quick access
37
+ - Required if script_type is C(url)
38
+ - Only available if script_type is C(url)
39
+ type: str
40
+ new_window:
41
+ description:
42
+ - Should URL be opened in a new window?
43
+ - Only available if script_type is C(url)
44
+ type: bool
45
+ default: true
33
46
command:
34
47
description:
35
48
- Command to run. Required when state is 'present'
203
216
204
217
from ansible_collections .community .zabbix .plugins .module_utils .base import ZabbixBase
205
218
import ansible_collections .community .zabbix .plugins .module_utils .helpers as zabbix_utils
219
+ from ansible .module_utils .compat .version import LooseVersion
206
220
207
221
208
222
class Script (ZabbixBase ):
@@ -214,21 +228,23 @@ def get_script_ids(self, script_name):
214
228
return script_ids
215
229
216
230
def create_script (self , name , script_type , command , scope , execute_on , menu_path , authtype , username , password ,
217
- publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout , parameters , description ):
231
+ publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout ,
232
+ parameters , description , url , new_window ):
218
233
if self ._module .check_mode :
219
234
self ._module .exit_json (changed = True )
220
235
221
236
self ._zapi .script .create (self .generate_script_config (name , script_type , command , scope , execute_on , menu_path ,
222
- authtype , username , password , publickey , privatekey , port , host_group , user_group , host_access , confirmation ,
223
- script_timeout , parameters , description ))
237
+ authtype , username , password , publickey , privatekey , port , host_group , user_group ,
238
+ host_access , confirmation , script_timeout , parameters , description , url , new_window ))
224
239
225
240
def delete_script (self , script_ids ):
226
241
if self ._module .check_mode :
227
242
self ._module .exit_json (changed = True )
228
243
self ._zapi .script .delete (script_ids )
229
244
230
245
def generate_script_config (self , name , script_type , command , scope , execute_on , menu_path , authtype , username , password ,
231
- publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout , parameters , description ):
246
+ publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout ,
247
+ parameters , description , url , new_window ):
232
248
if host_group == "all" :
233
249
groupid = "0"
234
250
else :
@@ -253,8 +269,8 @@ def generate_script_config(self, name, script_type, command, scope, execute_on,
253
269
"ssh" ,
254
270
"telnet" ,
255
271
"" ,
256
- "webhook" ], script_type )) ,
257
- "command" : command ,
272
+ "webhook" ,
273
+ "url" ], script_type )) ,
258
274
"scope" : str (zabbix_utils .helper_to_numeric_value ([
259
275
"" ,
260
276
"action_operation" ,
@@ -264,6 +280,9 @@ def generate_script_config(self, name, script_type, command, scope, execute_on,
264
280
"groupid" : groupid
265
281
}
266
282
283
+ if command :
284
+ request ["command" ] = command
285
+
267
286
if description is not None :
268
287
request ["description" ] = description
269
288
@@ -291,6 +310,13 @@ def generate_script_config(self, name, script_type, command, scope, execute_on,
291
310
else :
292
311
request ["confirmation" ] = confirmation
293
312
313
+ if script_type == "url" :
314
+ request ["url" ] = url
315
+ if new_window :
316
+ request ["new_window" ] = "1"
317
+ else :
318
+ request ["new_window" ] = "0"
319
+
294
320
if script_type == "ssh" :
295
321
request ["authtype" ] = str (zabbix_utils .helper_to_numeric_value ([
296
322
"password" ,
@@ -317,10 +343,11 @@ def generate_script_config(self, name, script_type, command, scope, execute_on,
317
343
return request
318
344
319
345
def update_script (self , script_id , name , script_type , command , scope , execute_on , menu_path , authtype , username , password ,
320
- publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout , parameters , description ):
346
+ publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout , parameters ,
347
+ description , url , new_window ):
321
348
generated_config = self .generate_script_config (name , script_type , command , scope , execute_on , menu_path , authtype , username ,
322
349
password , publickey , privatekey , port , host_group , user_group , host_access ,
323
- confirmation , script_timeout , parameters , description )
350
+ confirmation , script_timeout , parameters , description , url , new_window )
324
351
live_config = self ._zapi .script .get ({"filter" : {"name" : name }})[0 ]
325
352
326
353
change_parameters = {}
@@ -342,8 +369,10 @@ def main():
342
369
name = dict (type = "str" , required = True ),
343
370
script_type = dict (
344
371
type = "str" ,
345
- choices = ["script" , "ipmi" , "ssh" , "telnet" , "webhook" ]),
372
+ choices = ["script" , "ipmi" , "ssh" , "telnet" , "webhook" , "url" ]),
346
373
command = dict (type = "str" ),
374
+ url = dict (type = "str" ),
375
+ new_window = dict (type = "bool" , default = True ),
347
376
scope = dict (
348
377
type = "str" ,
349
378
choices = ["action_operation" , "manual_host_action" , "manual_event_action" ],
@@ -385,11 +414,15 @@ def main():
385
414
))
386
415
387
416
required_if = [
388
- ("state" , "present" , ("script_type" , "command" ,)),
389
- ("script_type" , "ssh" , ("authtype" , "username" ,)),
417
+ ("state" , "present" , ("script_type" ,)),
418
+ ("script_type" , "ssh" , ("authtype" , "username" , "command" ,)),
419
+ ("script_type" , "url" , ("new_window" , "url" ,)),
390
420
("authtype" , "password" , ("password" ,)),
391
421
("authtype" , "public_key" , ("publickey" , "privatekey" ,)),
392
- ("script_type" , "telnet" , ("username" , "password" )),
422
+ ("script_type" , "telnet" , ("username" , "password" , "command" ,)),
423
+ ("script_type" , "script" , ("command" ,)),
424
+ ("script_type" , "ipmi" , ("command" ,)),
425
+ ("script_type" , "webhook" , ("command" ,))
393
426
]
394
427
395
428
module = AnsibleModule (
@@ -418,6 +451,8 @@ def main():
418
451
parameters = module .params ["parameters" ]
419
452
description = module .params ["description" ]
420
453
state = module .params ["state" ]
454
+ url = module .params ["url" ]
455
+ new_window = module .params ["new_window" ]
421
456
422
457
script = Script (module )
423
458
script_ids = script .get_script_ids (name )
@@ -430,14 +465,24 @@ def main():
430
465
module .exit_json (changed = True , result = "Successfully deleted script(s) %s" % name )
431
466
432
467
elif state == "present" :
468
+ if script_type == "url" :
469
+ if LooseVersion (script ._zbx_api_version ) < LooseVersion ('7.0' ):
470
+ module .fail_json (changed = False , msg = "A type of 'url' is only available for Zabbix >= 7.0" )
471
+ if scope not in ["manual_host_action" , "manual_event_action" ]:
472
+ module .fail_json (changed = False , msg = "A scope of '%s' is not valid for type of 'url'" % scope )
473
+ else :
474
+ if url :
475
+ module .fail_json (changed = False , msg = "A url can only be set for a type of 'url'" )
476
+
433
477
if not script_ids :
434
478
script .create_script (name , script_type , command , scope , execute_on , menu_path , authtype , username , password ,
435
- publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout , parameters , description )
479
+ publickey , privatekey , port , host_group , user_group , host_access , confirmation , script_timeout ,
480
+ parameters , description , url , new_window )
436
481
module .exit_json (changed = True , msg = "Script %s created" % name )
437
482
else :
438
483
script .update_script (script_ids [0 ], name , script_type , command , scope , execute_on , menu_path , authtype , username ,
439
484
password , publickey , privatekey , port , host_group , user_group , host_access , confirmation ,
440
- script_timeout , parameters , description )
485
+ script_timeout , parameters , description , url , new_window )
441
486
442
487
443
488
if __name__ == "__main__" :
0 commit comments