Merge pull request #1532 from mbobakov/devel
Add custom parameter for a sensu_check
This commit is contained in:
commit
0f2cdbeee4
1 changed files with 32 additions and 0 deletions
|
@ -149,6 +149,12 @@ options:
|
||||||
- The low threshhold for flap detection
|
- The low threshhold for flap detection
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
custom:
|
||||||
|
description:
|
||||||
|
- A hash/dictionary of custom parameters for mixing to the configuration.
|
||||||
|
- You can't rewrite others module parameters using this
|
||||||
|
required: false
|
||||||
|
default: {}
|
||||||
requirements: [ ]
|
requirements: [ ]
|
||||||
author: "Anders Ingemann (@andsens)"
|
author: "Anders Ingemann (@andsens)"
|
||||||
'''
|
'''
|
||||||
|
@ -257,6 +263,31 @@ def sensu_check(module, path, name, state='present', backup=False):
|
||||||
changed = True
|
changed = True
|
||||||
reasons.append('`{opt}\' was removed'.format(opt=opt))
|
reasons.append('`{opt}\' was removed'.format(opt=opt))
|
||||||
|
|
||||||
|
if module.params['custom']:
|
||||||
|
# Convert to json
|
||||||
|
custom_params = module.params['custom']
|
||||||
|
overwrited_fields = set(custom_params.keys()) & set(simple_opts + ['type','subdue','subdue_begin','subdue_end'])
|
||||||
|
if overwrited_fields:
|
||||||
|
msg = 'You can\'t overwriting standard module parameters via "custom". You are trying overwrite: {opt}'.format(opt=list(overwrited_fields))
|
||||||
|
module.fail_json(msg=msg)
|
||||||
|
|
||||||
|
for k,v in custom_params.items():
|
||||||
|
if k in config['checks'][name]:
|
||||||
|
if not config['checks'][name][k] == v:
|
||||||
|
changed = True
|
||||||
|
reasons.append('`custom param {opt}\' was changed'.format(opt=k))
|
||||||
|
else:
|
||||||
|
changed = True
|
||||||
|
reasons.append('`custom param {opt}\' was added'.format(opt=k))
|
||||||
|
check[k] = v
|
||||||
|
simple_opts += custom_params.keys()
|
||||||
|
|
||||||
|
# Remove obsolete custom params
|
||||||
|
for opt in set(config['checks'][name].keys()) - set(simple_opts + ['type','subdue','subdue_begin','subdue_end']):
|
||||||
|
changed = True
|
||||||
|
reasons.append('`custom param {opt}\' was deleted'.format(opt=opt))
|
||||||
|
del check[opt]
|
||||||
|
|
||||||
if module.params['metric']:
|
if module.params['metric']:
|
||||||
if 'type' not in check or check['type'] != 'metric':
|
if 'type' not in check or check['type'] != 'metric':
|
||||||
check['type'] = 'metric'
|
check['type'] = 'metric'
|
||||||
|
@ -320,6 +351,7 @@ def main():
|
||||||
'aggregate': {'type': 'bool'},
|
'aggregate': {'type': 'bool'},
|
||||||
'low_flap_threshold': {'type': 'int'},
|
'low_flap_threshold': {'type': 'int'},
|
||||||
'high_flap_threshold': {'type': 'int'},
|
'high_flap_threshold': {'type': 'int'},
|
||||||
|
'custom': {'type': 'dict'},
|
||||||
}
|
}
|
||||||
|
|
||||||
required_together = [['subdue_begin', 'subdue_end']]
|
required_together = [['subdue_begin', 'subdue_end']]
|
||||||
|
|
Loading…
Reference in a new issue