From 4ae8eca14448bac6be46fbbf22d2ddc5d8ae7028 Mon Sep 17 00:00:00 2001 From: "Mytnyk, Volodymyr" Date: Wed, 18 Oct 2017 16:18:07 +0100 Subject: VES: add new tag to strip extra dashes The `!StripExtraDash` tag can be used in YAML configuration file to strip extra dashes in the YAML filed value. This may happen if some of the collectd plugin field (plugin_instance, type_instace etc.) is set to empty value but the field is specified in the YAML configuration file. For instance: "{vl.plugin_instance}-{vl.type_instance}" The result fo the example above can be string consisting extra dashes if `type_instace` field is not set by a collectd plugin: "load-" Change-Id: I5cf7b19902acdfb0b4a93f3bf0c8b8e05cff2e97 Signed-off-by: Mytnyk, Volodymyr --- 3rd_party/collectd-ves-app/ves_app/normalizer.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to '3rd_party/collectd-ves-app/ves_app/normalizer.py') diff --git a/3rd_party/collectd-ves-app/ves_app/normalizer.py b/3rd_party/collectd-ves-app/ves_app/normalizer.py index ddaad617..84de5e33 100644 --- a/3rd_party/collectd-ves-app/ves_app/normalizer.py +++ b/3rd_party/collectd-ves-app/ves_app/normalizer.py @@ -288,7 +288,7 @@ class Item(yaml.YAMLObject): def format_node(cls, mapping, metric): if mapping.tag in [ 'tag:yaml.org,2002:str', Bytes2Kibibytes.yaml_tag, - Number.yaml_tag]: + Number.yaml_tag, StripExtraDash.yaml_tag]: return yaml.ScalarNode(mapping.tag, mapping.value.format(**metric)) elif mapping.tag == 'tag:yaml.org,2002:map': values = [] @@ -459,6 +459,15 @@ class Number(yaml.YAMLObject): return float(node.value) +class StripExtraDash(yaml.YAMLObject): + """Class to process StripExtraDash tag""" + yaml_tag = u'!StripExtraDash' + + @classmethod + def from_yaml(cls, loader, node): + return '-'.join([ x for x in node.value.split('-') if len(x) > 0]) + + class MapValue(yaml.YAMLObject): """Class to process MapValue tag""" yaml_tag = u'!MapValue' -- cgit 1.2.3-korg