From d8c9be6185af0a29ffe301168b3129389d577cf9 Mon Sep 17 00:00:00 2001 From: "ning.xie" Date: Thu, 7 May 2015 18:40:28 +0800 Subject: [PATCH] fix #1612 --- shinken/misc/datamanager.py | 28 ++++++++++++++++++++++------ shinken/misc/regenerator.py | 28 +++++++++++++++++++++------- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/shinken/misc/datamanager.py b/shinken/misc/datamanager.py index d691c62c25..0793042a8b 100755 --- a/shinken/misc/datamanager.py +++ b/shinken/misc/datamanager.py @@ -136,10 +136,18 @@ def get_realm(self, r): # Get the hosts tags sorted by names, and zero size in the end def get_host_tags_sorted(self): r = [] - names = self.rg.tags.keys() - names.sort() + names = set() + for sched_instance_id in self.rg.hosts_tags: + for tpl_name in self.rg.hosts_tags.get(sched_instance_id): + names.add(tpl_name) + names = sorted(names) for n in names: - r.append((n, self.rg.tags[n])) + # we may have the same template in some schedulers, because + # hosts in different schedulers may use the same host template + count = 0 + for sched_instance_id in self.rg.hosts_tags: + count += self.rg.hosts_tags.get(sched_instance_id).get(n, 0) + r.append((n, count)) return r # Get the hosts tagged with a specific tag @@ -153,10 +161,18 @@ def get_hosts_tagged_with(self, tag): # Get the services tags sorted by names, and zero size in the end def get_service_tags_sorted(self): r = [] - names = self.rg.services_tags.keys() - names.sort() + names = set() + for sched_instance_id in self.rg.services_tags: + for tpl_name in self.rg.services_tags.get(sched_instance_id): + names.add(tpl_name) + names = sorted(names) for n in names: - r.append((n, self.rg.services_tags[n])) + # we may have the same template in some schedulers, because + # hosts in different schedulers may use the same host template + count = 0 + for sched_instance_id in self.rg.services_tags: + count += self.rg.services_tags.get(sched_instance_id).get(n, 0) + r.append((n, count)) return r def get_important_impacts(self): diff --git a/shinken/misc/regenerator.py b/shinken/misc/regenerator.py index 0932e32803..5fd334ccc8 100755 --- a/shinken/misc/regenerator.py +++ b/shinken/misc/regenerator.py @@ -67,7 +67,7 @@ def __init__(self): self.receivers = ReceiverLinks([]) # From now we only look for realms names self.realms = set() - self.tags = {} + self.hosts_tags = {} self.services_tags = {} # And in progress one @@ -228,9 +228,9 @@ def all_done_linking(self, inst_id): # Linkify tags for t in h.tags: - if t not in self.tags: - self.tags[t] = 0 - self.tags[t] += 1 + if t not in self.hosts_tags[inst_id]: + self.hosts_tags[inst_id][t] = 0 + self.hosts_tags[inst_id][t] += 1 # We can really declare this host OK now self.hosts.add_item(h) @@ -287,9 +287,9 @@ def all_done_linking(self, inst_id): # Linkify services tags for t in s.tags: - if t not in self.services_tags: - self.services_tags[t] = 0 - self.services_tags[t] += 1 + if t not in self.services_tags[inst_id]: + self.services_tags[inst_id][t] = 0 + self.services_tags[inst_id][t] += 1 # We can really declare this host OK now self.services.add_item(s, index=True) @@ -494,6 +494,20 @@ def manage_program_status_brok(self, b): # Clean the old "hard" objects + # if this is the first time WebUI load the program_status brok, + # then we should add an entry for the corresponding 'instance_id'; + # otherwise it should be a reload phrase, then we just need to clear + # the tags corresponding to the 'instance_id'. + if c_id in self.hosts_tags: + self.hosts_tags[c_id].clear() + else: + self.hosts_tags[c_id] = {} + + if c_id in self.services_tags: + self.services_tags[c_id].clear() + else: + self.services_tags[c_id] = {} + # We should clean all previously added hosts and services safe_print("Clean hosts/service of", c_id) to_del_h = [h for h in self.hosts if h.instance_id == c_id]