diff options
Diffstat (limited to 'roles/lib_zabbix')
| -rw-r--r-- | roles/lib_zabbix/library/zbx_trigger.py | 24 | 
1 files changed, 24 insertions, 0 deletions
| diff --git a/roles/lib_zabbix/library/zbx_trigger.py b/roles/lib_zabbix/library/zbx_trigger.py index 21d0fcfd2..ab7731faa 100644 --- a/roles/lib_zabbix/library/zbx_trigger.py +++ b/roles/lib_zabbix/library/zbx_trigger.py @@ -86,6 +86,24 @@ def get_trigger_status(inc_status):      return r_status +def get_template_id(zapi, template_name): +    ''' +    get related templates +    ''' +    template_ids = [] +    app_ids = {} +    # Fetch templates by name +    content = zapi.get_content('template', +                               'get', +                               {'search': {'host': template_name}, +                                'selectApplications': ['applicationid', 'name']}) +    if content.has_key('result'): +        template_ids.append(content['result'][0]['templateid']) +        for app in content['result'][0]['applications']: +            app_ids[app['name']] = app['applicationid'] + +    return template_ids, app_ids +  def main():      '''      Create a trigger in zabbix @@ -117,6 +135,7 @@ def main():              url=dict(default=None, type='str'),              status=dict(default=None, type='str'),              state=dict(default='present', type='str'), +            template_name=dict(default=None, type='str'),          ),          #supports_check_mode=True      ) @@ -132,11 +151,16 @@ def main():      state = module.params['state']      tname = module.params['name'] +    templateid = None +    if module.params['template_name']: +        templateid, _ = get_template_id(zapi, module.params['template_name']) +      content = zapi.get_content(zbx_class_name,                                 'get',                                 {'filter': {'description': tname},                                  'expandExpression': True,                                  'selectDependencies': 'triggerid', +                                'templateids': templateid,                                 })      # Get | 
