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."""
|
"""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
|
gid = pwd.getpwnam(user).pw_gid
|
||||||
os.chmod(config_path, 0o640)
|
os.chmod(config_path, 0o640)
|
||||||
os.chown(config_path, 0, gid)
|
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)
|
old_config = agent_config.read_plugin_config_from_disk(args.config_dir, key)
|
||||||
# merge old and new config, new has precedence
|
# merge old and new config, new has precedence
|
||||||
if old_config is not None:
|
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'])
|
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
|
# Sort before compare, if instances have no name the sort will fail making order changes significant
|
||||||
try:
|
try:
|
||||||
|
@ -146,7 +149,12 @@ def modify_config(args, detected_config):
|
||||||
old_config['instances'].sort(key=lambda k: k['name'])
|
old_config['instances'].sort(key=lambda k: k['name'])
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
if value == old_config: # Don't write config if no change
|
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
|
continue
|
||||||
changes = True
|
changes = True
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
|
|
Loading…
Reference in New Issue