From 984c3f7e47039be37b700536367d26ca02b61522 Mon Sep 17 00:00:00 2001 From: Kenny Woodson Date: Tue, 22 Sep 2015 15:56:46 -0400 Subject: Added descriptions and parameters required for associating prototypes to discovery rules. --- roles/lib_zabbix/library/zbx_discoveryrule.py | 2 ++ roles/lib_zabbix/library/zbx_itemprototype.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'roles/lib_zabbix') diff --git a/roles/lib_zabbix/library/zbx_discoveryrule.py b/roles/lib_zabbix/library/zbx_discoveryrule.py index f32267818..f52f350a5 100644 --- a/roles/lib_zabbix/library/zbx_discoveryrule.py +++ b/roles/lib_zabbix/library/zbx_discoveryrule.py @@ -94,6 +94,7 @@ def main(): zbx_debug=dict(default=False, type='bool'), name=dict(default=None, type='str'), key=dict(default=None, type='str'), + description=dict(default=None, type='str'), interfaceid=dict(default=None, type='int'), ztype=dict(default='trapper', type='str'), delay=dict(default=60, type='int'), @@ -151,6 +152,7 @@ def main(): 'interfaceid': module.params['interfaceid'], 'lifetime': module.params['lifetime'], 'type': get_type(module.params['ztype']), + 'description': module.params['description'], } if params['type'] in [2, 5, 7, 11]: params.pop('interfaceid') diff --git a/roles/lib_zabbix/library/zbx_itemprototype.py b/roles/lib_zabbix/library/zbx_itemprototype.py index 75b9e25b7..4ec1b8e02 100644 --- a/roles/lib_zabbix/library/zbx_itemprototype.py +++ b/roles/lib_zabbix/library/zbx_itemprototype.py @@ -38,12 +38,12 @@ def exists(content, key='result'): return True -def get_rule_id(zapi, discoveryrule_name, templateid): +def get_rule_id(zapi, discoveryrule_key, templateid): '''get a discoveryrule by name ''' content = zapi.get_content('discoveryrule', 'get', - {'search': {'name': discoveryrule_name}, + {'search': {'key_': discoveryrule_key}, 'output': 'extend', 'templateids': templateid, }) @@ -152,6 +152,7 @@ def main(): zbx_debug=dict(default=False, type='bool'), name=dict(default=None, type='str'), key=dict(default=None, type='str'), + description=dict(default=None, type='str'), interfaceid=dict(default=None, type='int'), ztype=dict(default='trapper', type='str'), value_type=dict(default='float', type='str'), @@ -160,6 +161,8 @@ def main(): state=dict(default='present', type='str'), status=dict(default='enabled', type='str'), applications=dict(default=[], type='list'), + template_name=dict(default=None, type='str'), + discoveryrule_key=dict(default=None, type='str'), ), #supports_check_mode=True ) @@ -173,6 +176,7 @@ def main(): zbx_class_name = 'itemprototype' idname = "itemid" state = module.params['state'] + template = get_template(zapi, module.params['template_name']) # selectInterfaces doesn't appear to be working but is needed. content = zapi.get_content(zbx_class_name, @@ -203,12 +207,13 @@ def main(): if state == 'present': params = {'name': module.params['name'], 'key_': module.params['key'], - 'hostid': content['result'][0]['hostid'], + 'hostid': template['templateid'], 'interfaceid': module.params['interfaceid'], - 'ruleid': content['result'][0]['discoveryRule']['itemid'], + 'ruleid': get_rule_id(zapi, module.params['discoveryrule_key'], template['templateid']), 'type': get_type(module.params['ztype']), 'value_type': get_value_type(module.params['value_type']), 'applications': get_app_ids(zapi, module.params['applications']), + 'description': module.params['description'], } if params['type'] in [2, 5, 7, 8, 11, 15]: -- cgit v1.2.3