Merge "Detect Endpoint Changes in Http Check"
This commit is contained in:
commit
53f6df0ddf
|
@ -1,4 +1,4 @@
|
|||
# (C) Copyright 2015 Hewlett Packard Enterprise Development Company LP
|
||||
# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development Company LP
|
||||
|
||||
"""Classes to aid in configuration of the agent."""
|
||||
|
||||
|
@ -92,3 +92,16 @@ def save_plugin_config(config_dir, plugin_name, user, conf):
|
|||
gid = pwd.getpwnam(user).pw_gid
|
||||
os.chmod(config_path, 0o640)
|
||||
os.chown(config_path, 0, gid)
|
||||
|
||||
|
||||
def check_endpoint_changes(value, config):
|
||||
new_url = value['instances'][0]['url']
|
||||
old_urls = [i['url'] for i in config['instances'] if 'url' in i]
|
||||
new_path = new_url.split("://")[1]
|
||||
old_paths = [url.split("://")[1] for url in old_urls]
|
||||
for i, old_path in enumerate(old_paths):
|
||||
if old_path == new_path:
|
||||
if config['instances'][i]['url'] == config['instances'][i]['name']:
|
||||
config['instances'][i]['name'] = new_url
|
||||
config['instances'][i]['url'] = new_url
|
||||
return value, config
|
||||
|
|
|
@ -139,6 +139,9 @@ def modify_config(args, detected_config):
|
|||
old_config = agent_config.read_plugin_config_from_disk(args.config_dir, key)
|
||||
# merge old and new config, new has precedence
|
||||
if old_config is not None:
|
||||
if key is "http_check":
|
||||
old_config_urls = [i['url'] for i in old_config['instances'] if 'url' in i]
|
||||
value, old_config = agent_config.check_endpoint_changes(value, old_config)
|
||||
agent_config.merge_by_name(value['instances'], old_config['instances'])
|
||||
# Sort before compare, if instances have no name the sort will fail making order changes significant
|
||||
try:
|
||||
|
@ -146,8 +149,13 @@ def modify_config(args, detected_config):
|
|||
old_config['instances'].sort(key=lambda k: k['name'])
|
||||
except Exception:
|
||||
pass
|
||||
if value == old_config: # Don't write config if no change
|
||||
continue
|
||||
value_urls = [i['url'] for i in value['instances'] if 'url' in i]
|
||||
if key is "http_check":
|
||||
if value_urls is old_config_urls: # Don't write config if no change
|
||||
continue
|
||||
else:
|
||||
if value is old_config:
|
||||
continue
|
||||
changes = True
|
||||
if args.dry_run:
|
||||
log.info("Changes would be made to the config file for the {0} check plugin".format(key))
|
||||
|
|
Loading…
Reference in New Issue