summaryrefslogtreecommitdiffstats
path: root/roles/lib_zabbix/library/zbx_item.py
diff options
context:
space:
mode:
Diffstat (limited to 'roles/lib_zabbix/library/zbx_item.py')
-rw-r--r--roles/lib_zabbix/library/zbx_item.py65
1 files changed, 62 insertions, 3 deletions
diff --git a/roles/lib_zabbix/library/zbx_item.py b/roles/lib_zabbix/library/zbx_item.py
index 2ccc21292..189485fb7 100644
--- a/roles/lib_zabbix/library/zbx_item.py
+++ b/roles/lib_zabbix/library/zbx_item.py
@@ -28,7 +28,7 @@
# pylint: disable=duplicate-code
# pylint: disable=import-error
-from openshift_tools.monitoring.zbxapi import ZabbixAPI, ZabbixConnection
+from openshift_tools.zbxapi import ZabbixAPI, ZabbixConnection
def exists(content, key='result'):
''' Check if key exists in content or the size of content[key] > 0
@@ -41,6 +41,24 @@ def exists(content, key='result'):
return True
+def get_data_type(data_type):
+ '''
+ Possible values:
+ 0 - decimal;
+ 1 - octal;
+ 2 - hexadecimal;
+ 3 - bool;
+ '''
+ vtype = 0
+ if 'octal' in data_type:
+ vtype = 1
+ elif 'hexadecimal' in data_type:
+ vtype = 2
+ elif 'bool' in data_type:
+ vtype = 3
+
+ return vtype
+
def get_value_type(value_type):
'''
Possible values:
@@ -53,6 +71,8 @@ def get_value_type(value_type):
vtype = 0
if 'int' in value_type:
vtype = 3
+ elif 'log' in value_type:
+ vtype = 2
elif 'char' in value_type:
vtype = 1
elif 'str' in value_type:
@@ -105,6 +125,39 @@ def get_multiplier(inval):
return rval, 0
+def get_zabbix_type(ztype):
+ '''
+ Determine which type of discoverrule this is
+ '''
+ _types = {'agent': 0,
+ 'SNMPv1': 1,
+ 'trapper': 2,
+ 'simple': 3,
+ 'SNMPv2': 4,
+ 'internal': 5,
+ 'SNMPv3': 6,
+ 'active': 7,
+ 'aggregate': 8,
+ 'web': 9,
+ 'external': 10,
+ 'database monitor': 11,
+ 'ipmi': 12,
+ 'ssh': 13,
+ 'telnet': 14,
+ 'calculated': 15,
+ 'JMX': 16,
+ 'SNMP trap': 17,
+ }
+
+ for typ in _types.keys():
+ if ztype in typ or ztype == typ:
+ _vtype = _types[typ]
+ break
+ else:
+ _vtype = 2
+
+ return _vtype
+
# The branches are needed for CRUD and error handling
# pylint: disable=too-many-branches
def main():
@@ -121,8 +174,11 @@ def main():
name=dict(default=None, type='str'),
key=dict(default=None, type='str'),
template_name=dict(default=None, type='str'),
- zabbix_type=dict(default=2, type='int'),
+ zabbix_type=dict(default='trapper', type='str'),
value_type=dict(default='int', type='str'),
+ data_type=dict(default='decimal', type='str'),
+ interval=dict(default=60, type='int'),
+ delta=dict(default=0, type='int'),
multiplier=dict(default=None, type='str'),
description=dict(default=None, type='str'),
units=dict(default=None, type='str'),
@@ -180,13 +236,16 @@ def main():
params = {'name': module.params.get('name', module.params['key']),
'key_': module.params['key'],
'hostid': templateid[0],
- 'type': module.params['zabbix_type'],
+ 'type': get_zabbix_type(module.params['zabbix_type']),
'value_type': get_value_type(module.params['value_type']),
+ 'data_type': get_data_type(module.params['data_type']),
'applications': get_app_ids(module.params['applications'], app_name_ids),
'formula': formula,
'multiplier': use_multiplier,
'description': module.params['description'],
'units': module.params['units'],
+ 'delay': module.params['interval'],
+ 'delta': module.params['delta'],
}
# Remove any None valued params