From b16d818755c43025446752553a3e32492ada7668 Mon Sep 17 00:00:00 2001 From: Moises Florenciano Date: Tue, 3 Jul 2018 16:37:37 +0200 Subject: [PATCH 1/8] Add tag template var support --- module/util.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/module/util.py b/module/util.py index 289944c..408638e 100644 --- a/module/util.py +++ b/module/util.py @@ -135,6 +135,13 @@ def servicename(self): else: return GraphiteMetric.normalize_name(self.cfg.hostcheck) + @property + def tags(self): + if self.element_type == 'service': + return self.element.host.cpe_registration_tags.split(',') or ['dummy_tag'] + else: + return self.element.cpe_registration_tags.split(',') or ['dummy_tag'] + # retrieve a style with graceful fallback def get_style(self, name): try: @@ -262,11 +269,16 @@ def _get_uris_from_file(self): # Split, we may have several images. - for img in html.substitute(context).split('\n'): - if not img: - continue - graph = GraphiteURL.parse(img, style=self.style) - uris.append(dict(link=graph.url('composer'), img_src=graph.url('render'))) + logger.info("[ui-graphite] tags elt={}...".format(self.hostname)) + for tag in self.tags: + logger.info("[ui-graphite] tag={}".format(tag)) + context['tag'] = tag + + for img in html.substitute(context).split('\n'): + if not img: + continue + graph = GraphiteURL.parse(img, style=self.style) + uris.append(dict(link=graph.url('composer'), img_src=graph.url('render'))) return uris From f1cf94865767b1571b4552880907a135a5674cea Mon Sep 17 00:00:00 2001 From: rednach Date: Tue, 25 Sep 2018 18:43:21 +0200 Subject: [PATCH 2/8] fea: tag/taglabel available in graph definitions --- module/graphite_utils.py | 7 ++++++- module/util.py | 44 +++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/module/graphite_utils.py b/module/graphite_utils.py index 5648018..fa5f929 100644 --- a/module/graphite_utils.py +++ b/module/graphite_utils.py @@ -27,6 +27,7 @@ import re import logging import urlparse +import copy # encapsulate graph styles @@ -135,6 +136,10 @@ def parse_graphite_args(part): def parse_graphite_part(part): logging.debug('Parsing %s', part) + + if part[0:2] == '__' and part[-2:] == '__': + return part[2:-2] + ndx = part.find('(') if ndx < 0: logging.debug('No function call') @@ -174,7 +179,7 @@ def __init__(self, server='', title='', style=GraphStyle(), start=0, end=0, min= if targets is not None: for t in targets: self.add_target(t) - self.style = style + self.style = copy.copy(style) for k in ('height', 'width', 'font_size', 'line_style'): if k in kwargs: setattr(self.style, k, kwargs[k]) diff --git a/module/util.py b/module/util.py index 408638e..141f4b3 100644 --- a/module/util.py +++ b/module/util.py @@ -25,6 +25,7 @@ import os from string import Template import json +import re from .graphite_utils import GraphiteURL, GraphiteMetric, graphite_time @@ -138,9 +139,17 @@ def servicename(self): @property def tags(self): if self.element_type == 'service': - return self.element.host.cpe_registration_tags.split(',') or ['dummy_tag'] + string_tags = self.element.host.cpe_registration_tags or "dummy_tag:'''dummy_taglabel'''" else: - return self.element.cpe_registration_tags.split(',') or ['dummy_tag'] + string_tags = self.element.cpe_registration_tags or "dummy_tag:'''dummy_taglabel'''" + + regex = re.compile(r"(?P[a-zA-Z0-9-_/\.]+):'''(?P[a-zA-Z0-9 \-_]*)'''($|\s)") + print("string_tags", string_tags) + self.logger.info("tags...string_tags -> [[%s]]", string_tags) + for match in regex.finditer(string_tags): + print(" - tags... %s->%s", match.group('tag'), match.group('taglabel')) + + return {match.group('tag'):match.group('taglabel') for match in regex.finditer(string_tags)} # retrieve a style with graceful fallback def get_style(self, name): @@ -269,16 +278,27 @@ def _get_uris_from_file(self): # Split, we may have several images. - logger.info("[ui-graphite] tags elt={}...".format(self.hostname)) - for tag in self.tags: - logger.info("[ui-graphite] tag={}".format(tag)) - context['tag'] = tag - - for img in html.substitute(context).split('\n'): - if not img: - continue - graph = GraphiteURL.parse(img, style=self.style) - uris.append(dict(link=graph.url('composer'), img_src=graph.url('render'))) + logger.debug("[ui-graphite] tags elt={}...".format(self.hostname)) + if '{tag}' in template_html: # Dirty hack for untagged templates + for tag in self.tags: + logger.debug("[ui-graphite] tag={}".format(tag)) + context['tag'] = tag + context['taglabel'] = self.tags[tag] + uris += self._get_uris_from_string_template(html, context, graph_start, graph_end) + else: + uris += self._get_uris_from_string_template(html, context, graph_start, graph_end) + return uris + + def _get_uris_from_string_template(self, template, context, graph_start, graph_end): + uris = [] + for img in template.substitute(context).split('\n'): + if not img: + continue + # FIXME Temporal fix for no time interval in uri + # https://github.com/shinken-monitoring/mod-ui-graphite/issues/16 + img = img + "&from=" + graph_start + "&until=" + graph_end + graph = GraphiteURL.parse(img, style=self.style) + uris.append(dict(link=graph.url('composer'), img_src=graph.url('render'))) return uris From e6c0ccc0009988cbe9debd64a0d0cb39ed9b23c5 Mon Sep 17 00:00:00 2001 From: rednach Date: Tue, 9 Oct 2018 11:08:11 +0200 Subject: [PATCH 3/8] fix: " included in label patern --- module/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/util.py b/module/util.py index 141f4b3..4ba77fd 100644 --- a/module/util.py +++ b/module/util.py @@ -143,7 +143,7 @@ def tags(self): else: string_tags = self.element.cpe_registration_tags or "dummy_tag:'''dummy_taglabel'''" - regex = re.compile(r"(?P[a-zA-Z0-9-_/\.]+):'''(?P[a-zA-Z0-9 \-_]*)'''($|\s)") + regex = re.compile(r"(?P[a-zA-Z0-9-_/\.]+):'''(?P[a-zA-Z0-9 \-_\"]*)'''($|\s)") print("string_tags", string_tags) self.logger.info("tags...string_tags -> [[%s]]", string_tags) for match in regex.finditer(string_tags): From 33b59662b6891947ff9011996b8bf16b1c97ab3b Mon Sep 17 00:00:00 2001 From: rednach Date: Thu, 1 Nov 2018 09:05:42 +0100 Subject: [PATCH 4/8] fix: graph label pattern --- module/util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/util.py b/module/util.py index 4ba77fd..399cbbb 100644 --- a/module/util.py +++ b/module/util.py @@ -143,11 +143,11 @@ def tags(self): else: string_tags = self.element.cpe_registration_tags or "dummy_tag:'''dummy_taglabel'''" - regex = re.compile(r"(?P[a-zA-Z0-9-_/\.]+):'''(?P[a-zA-Z0-9 \-_\"]*)'''($|\s)") - print("string_tags", string_tags) + regex = re.compile(r"(?P[a-zA-Z0-9-_/\.]+):'''(?P[a-zA-Z0-9 \-_\"+:\.]*)'''($|\s)") + # print("string_tags", string_tags) self.logger.info("tags...string_tags -> [[%s]]", string_tags) - for match in regex.finditer(string_tags): - print(" - tags... %s->%s", match.group('tag'), match.group('taglabel')) + # for match in regex.finditer(string_tags): + # print(" - tags... %s->%s", match.group('tag'), match.group('taglabel')) return {match.group('tag'):match.group('taglabel') for match in regex.finditer(string_tags)} From 77798c04b66f34f4ae0385e8d1e2becf3d37244f Mon Sep 17 00:00:00 2001 From: rednach Date: Wed, 26 Dec 2018 19:49:43 +0100 Subject: [PATCH 5/8] fix: * and comma allowed in interface label --- module/util.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/util.py b/module/util.py index 399cbbb..d5657a3 100644 --- a/module/util.py +++ b/module/util.py @@ -143,11 +143,11 @@ def tags(self): else: string_tags = self.element.cpe_registration_tags or "dummy_tag:'''dummy_taglabel'''" - regex = re.compile(r"(?P[a-zA-Z0-9-_/\.]+):'''(?P[a-zA-Z0-9 \-_\"+:\.]*)'''($|\s)") + regex = re.compile(r"(?P[a-zA-Z0-9-_/\.\*]+):'''(?P[a-zA-Z0-9 \-_\"+:\.,\*]*)'''($|\s)") # print("string_tags", string_tags) self.logger.info("tags...string_tags -> [[%s]]", string_tags) # for match in regex.finditer(string_tags): - # print(" - tags... %s->%s", match.group('tag'), match.group('taglabel')) + # print(" - tags... %s->%s", match.group('tag'), match.group('taglabel')) return {match.group('tag'):match.group('taglabel') for match in regex.finditer(string_tags)} @@ -220,7 +220,7 @@ def _generate_graph_uris(self): link=graph.url('composer'), img_src=graph.url('render') ) - self.logger.debug("[Graphite UI] uri: %s / %s", v['link'], v['img_src']) + self.logger.info("[Graphite UI] uri: %s / %s", v['link'], v['img_src']) uris.append(v) return uris From f82e78816fe078c9554d04b6275d7061b065eabb Mon Sep 17 00:00:00 2001 From: rednach Date: Mon, 18 Mar 2019 19:08:49 +0100 Subject: [PATCH 6/8] fix: "/" allowed in interfaces description --- module/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/util.py b/module/util.py index d5657a3..aa7597c 100644 --- a/module/util.py +++ b/module/util.py @@ -143,7 +143,7 @@ def tags(self): else: string_tags = self.element.cpe_registration_tags or "dummy_tag:'''dummy_taglabel'''" - regex = re.compile(r"(?P[a-zA-Z0-9-_/\.\*]+):'''(?P[a-zA-Z0-9 \-_\"+:\.,\*]*)'''($|\s)") + regex = re.compile(r"(?P[a-zA-Z0-9-_/\.\*]+):'''(?P[a-zA-Z0-9 \-_\"+:\.,\*\/]*)'''($|\s)") # print("string_tags", string_tags) self.logger.info("tags...string_tags -> [[%s]]", string_tags) # for match in regex.finditer(string_tags): From 8e677d878992c8508548ee9d3a59143ffd17e67e Mon Sep 17 00:00:00 2001 From: rednach Date: Fri, 26 Apr 2019 13:30:27 +0200 Subject: [PATCH 7/8] based on mod-webui "integ" branch approach --- module/module.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/module/module.py b/module/module.py index 6b1f1fa..f8ccbd5 100644 --- a/module/module.py +++ b/module/module.py @@ -29,20 +29,32 @@ for mainly get graphs and links. """ +import os import re import socket import time +ALIGNAK = False +if os.environ.get('ALIGNAK_SHINKEN_UI', None): + if os.environ.get('ALIGNAK_SHINKEN_UI') not in ['0']: + ALIGNAK = True + from .graphite_utils import GraphStyle, GraphiteMetric from .util import GraphFactory from shinken.log import logger -from shinken.basemodule import BaseModule + +if ALIGNAK: + from alignak.basemodule import BaseModule +else: + from shinken.basemodule import BaseModule + from shinken.misc.perfdata import PerfDatas properties = { 'daemons': ['webui'], - 'type': 'graphite_webui' + 'type': 'graphite_webui', + 'external': False } @@ -60,6 +72,10 @@ def __init__(self, modconf): self._uri = '' self.app = None + if ALIGNAK: + self.module_type = getattr(modconf, 'module_type', 'unset') + self.module_name = getattr(modconf, 'module_name', 'unset') + # service name to use for host check self.hostcheck = getattr(modconf, 'hostcheck', '') @@ -126,7 +142,8 @@ def _load_styles(self, modconf): # Try to connect if we got true parameter def init(self): - pass + if ALIGNAK: + return True # To load the webui application def load(self, app): From 3ae11d4df81feb8142b66b8b179cff797a75000e Mon Sep 17 00:00:00 2001 From: rednach Date: Sat, 17 Aug 2019 16:48:43 +0200 Subject: [PATCH 8/8] fix: taglabel pattern --- module/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/util.py b/module/util.py index aa7597c..aae547f 100644 --- a/module/util.py +++ b/module/util.py @@ -143,7 +143,7 @@ def tags(self): else: string_tags = self.element.cpe_registration_tags or "dummy_tag:'''dummy_taglabel'''" - regex = re.compile(r"(?P[a-zA-Z0-9-_/\.\*]+):'''(?P[a-zA-Z0-9 \-_\"+:\.,\*\/]*)'''($|\s)") + regex = re.compile(r"(?P[a-zA-Z0-9-_/\.\*]+):'''(?P[a-zA-Z0-9 \-_\"+:\.,\*\/#]*)'''($|\s)") # print("string_tags", string_tags) self.logger.info("tags...string_tags -> [[%s]]", string_tags) # for match in regex.finditer(string_tags):