nagios-charmers team mailing list archive
-
nagios-charmers team
-
Mailing list archive
-
Message #01097
Re: [Merge] ~peppepetra86/charm-nagios:extra_contacts into charm-nagios:master
Replied to one comment.
Diff comments:
> diff --git a/hooks/upgrade_charm.py b/hooks/upgrade_charm.py
> index bbbb8ac..cc20507 100755
> --- a/hooks/upgrade_charm.py
> +++ b/hooks/upgrade_charm.py
> @@ -58,6 +69,53 @@ def warn_legacy_relations():
> "WARNING")
>
>
> +# Parses a list of extra Nagios contacts from a YAML string
> +# Does basic sanitization only
> +def get_extra_contacts(yaml_string, log=False):
> + # Final result
> + extra_contacts = []
> +
> + # Valid characters for contact names
> + valid_name_chars = (
> + 'abcdefghijklmnopqrstuvwxyz'
> + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
> + '0123456789_-'
> + )
> +
> + try:
> + extra_contacts_raw = yaml.load(yaml_string, Loader=yaml.SafeLoader) or []
> + if not isinstance(extra_contacts_raw, list):
> + raise ValueError('not a list')
> +
> + for contact in extra_contacts_raw:
> + if {'name', 'host', 'service'} > set(contact.keys()):
> + if log:
> + hookenv.log(
> + 'Contact {} is missing fields.'.format(contact))
we are not sure name is defined in contact. That's the warning
> + continue
> +
> + if set(contact['name']) >= set(valid_name_chars):
> + if log:
> + hookenv.log(
> + 'Contact name {} is illegal'.format(contact['name']))
> + continue
> +
> + if '\n' in (contact['host'] + contact['service']):
> + if log:
> + hookenv.log('Line breaks not allowed in commands')
> + continue
> + contact['name'] = contact['name'].lower()
> + contact['alias'] = contact['name'].capitalize()
> + extra_contacts.append(contact)
> +
> + except (ValueError, yaml.error.YAMLError) as e:
> + if log:
> + hookenv.log(
> + 'Invalid "extra_contacts" configuration: {}'.format(e))
> +
> + return extra_contacts
> +
> +
> # If the charm has extra configuration provided, write that to the
> # proper nagios3 configuration file, otherwise remove the config
> def write_extra_config():
--
https://code.launchpad.net/~peppepetra86/charm-nagios/+git/charm-nagios/+merge/388119
Your team Nagios Charm developers is subscribed to branch charm-nagios:master.
References