Pārlūkot izejas kodu

Merge pull request #566 from kwoodson/item_fix

Adding desc, units, and multiplier functionality to zabbix items.
Matt Woodson 9 gadi atpakaļ
vecāks
revīzija
6dfeaccd2a

+ 31 - 2
roles/lib_zabbix/library/zbx_item.py

@@ -88,6 +88,23 @@ def get_template_id(zapi, template_name):
 
     return template_ids, app_ids
 
+def get_multiplier(inval):
+    ''' Determine the multiplier
+    '''
+    if inval == None or inval == '':
+        return None, None
+
+    rval = None
+    try:
+        rval = int(inval)
+    except ValueError:
+        pass
+
+    if rval:
+        return rval, True
+
+    return rval, False
+
 # The branches are needed for CRUD and error handling
 # pylint: disable=too-many-branches
 def main():
@@ -106,6 +123,9 @@ def main():
             template_name=dict(default=None, type='str'),
             zabbix_type=dict(default=2, type='int'),
             value_type=dict(default='int', type='str'),
+            multiplier=dict(default=None, type='str'),
+            description=dict(default=None, type='str'),
+            units=dict(default=None, type='str'),
             applications=dict(default=None, type='list'),
             state=dict(default='present', type='str'),
         ),
@@ -137,11 +157,15 @@ def main():
                                 'templateids': templateid,
                                })
 
-    # Get
+    #******#
+    # GET
+    #******#
     if state == 'list':
         module.exit_json(changed=False, results=content['result'], state="list")
 
-    # Delete
+    #******#
+    # DELETE
+    #******#
     if state == 'absent':
         if not exists(content):
             module.exit_json(changed=False, state="absent")
@@ -152,12 +176,17 @@ def main():
     # Create and Update
     if state == 'present':
 
+        formula, use_multiplier = get_multiplier(module.params['multiplier'])
         params = {'name': module.params.get('name', module.params['key']),
                   'key_': module.params['key'],
                   'hostid': templateid[0],
                   'type': module.params['zabbix_type'],
                   'value_type': get_value_type(module.params['value_type']),
                   'applications': get_app_ids(module.params['applications'], app_name_ids),
+                  'formula': formula,
+                  'multiplier': use_multiplier,
+                  'description': module.params['description'],
+                  'units': module.params['units'],
                  }
 
         # Remove any None valued params

+ 3 - 0
roles/lib_zabbix/tasks/create_template.yml

@@ -30,6 +30,9 @@
     key: "{{ item.key }}"
     name: "{{ item.name | default(item.key, true) }}"
     value_type: "{{ item.value_type | default('int') }}"
+    description: "{{ item.description | default('', True) }}"
+    multiplier: "{{ item.multiplier | default('', True) }}"
+    units: "{{ item.units | default('', True) }}"
     template_name: "{{ template.name }}"
     applications: "{{ item.applications }}"
   with_items: template.zitems

+ 6 - 0
roles/os_zabbix/vars/template_os_linux.yml

@@ -111,6 +111,9 @@ g_template_os_linux:
     applications:
     - Memory
     value_type: int
+    description: used memory
+    multiplier: 1024
+    units: B
 
   - key: kernel.all.cpu.user
     applications:
@@ -131,6 +134,9 @@ g_template_os_linux:
     applications:
     - Memory
     value_type: int
+    description: cached memory
+    multiplier: 1024
+    units: B
 
   - key: kernel.all.cpu.steal
     applications: