Module: check_mk
Branch: master
Commit: 1e03f849b3f8756e63ed96944bf32c630d6bd182
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=1e03f849b3f875…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jan 29 09:21:48 2016 +0100
Fixed renaming of hosts after rewrite of BI editor
---
web/htdocs/wato.py | 34 +---------------------------
web/plugins/wato/bi.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 34 deletions(-)
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 23e57bb..9c46ba8 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -1877,39 +1877,7 @@ def rename_host_in_multisite(oldname, newname):
def rename_host_in_bi(oldname, newname):
- renamed = 0
- aggregations, rules = load_bi_rules()
- for aggregation in aggregations:
- renamed += rename_host_in_bi_aggregation(aggregation, oldname, newname)
- for rule in rules.values():
- renamed += rename_host_in_bi_rule(rule, oldname, newname)
- if renamed:
- save_bi_rules(aggregations, rules)
- return [ "bi" ] * renamed
- else:
- return []
-
-
-def rename_host_in_bi_aggregation(aggregation, oldname, newname):
- node = aggregation["node"]
- if node[0] == 'call':
- if rename_host_in_list(aggregation["node"][1][1], oldname, newname):
- return 1
- return 0
-
-
-def rename_host_in_bi_rule(rule, oldname, newname):
- renamed = 0
- nodes = rule["nodes"]
- for nr, node in enumerate(nodes):
- if node[0] in [ "host", "service", "remaining" ]:
- if node[1][0] == oldname:
- nodes[nr] = (node[0], ( newname, ) + node[1][1:])
- renamed = 1
- elif node[0] == "call":
- if rename_host_in_list(node[1][1], oldname, newname):
- renamed = 1
- return renamed
+ return BIHostRenamer().rename_host(oldname, newname)
def rename_hosts_in_check_mk(renamings):
diff --git a/web/plugins/wato/bi.py b/web/plugins/wato/bi.py
index 9b119a3..55d0db1 100644
--- a/web/plugins/wato/bi.py
+++ b/web/plugins/wato/bi.py
@@ -143,7 +143,6 @@ class ModeBI(WatoMode):
}
-
except Exception, e:
if config.debug:
raise
@@ -1694,3 +1693,60 @@ modes.update({
"bi_edit_aggregation": (["bi_rules"], ModeBIEditAggregation),
})
+
+#.
+# .--Rename Hosts--------------------------------------------------------.
+# | ____ _ _ _ |
+# | | _ \ ___ _ __ __ _ _ __ ___ ___ | | | | ___ ___| |_ ___ |
+# | | |_) / _ \ '_ \ / _` | '_ ` _ \ / _ \ | |_| |/ _ \/ __| __/ __| |
+# | | _ < __/ | | | (_| | | | | | | __/ | _ | (_) \__ \ |_\__ \ |
+# | |_| \_\___|_| |_|\__,_|_| |_| |_|\___| |_| |_|\___/|___/\__|___/ |
+# | |
+# +----------------------------------------------------------------------+
+# | Class just for renaming hosts in the BI configuration. |
+# '----------------------------------------------------------------------'
+
+class BIHostRenamer(ModeBI):
+ def __init__(self):
+ ModeBI.__init__(self)
+
+ def rename_host(self, oldname, newname):
+ renamed = 0
+ for pack in self._packs.values():
+ renamed += self.rename_host_in_pack(pack, oldname, newname)
+ if renamed:
+ self.save_config()
+ return [ "bi" ] * renamed
+ else:
+ return []
+
+
+ def rename_host_in_pack(self, pack, oldname, newname):
+ renamed = 0
+ for aggregation in pack["aggregations"]:
+ renamed += self.rename_host_in_aggregation(aggregation, oldname, newname)
+ for rule in pack["rules"].values():
+ renamed += self.rename_host_in_rule(rule, oldname, newname)
+ return renamed
+
+
+ def rename_host_in_aggregation(self, aggregation, oldname, newname):
+ node = aggregation["node"]
+ if node[0] == 'call':
+ if rename_host_in_list(aggregation["node"][1][1], oldname,
newname):
+ return 1
+ return 0
+
+
+ def rename_host_in_rule(self, rule, oldname, newname):
+ renamed = 0
+ nodes = rule["nodes"]
+ for nr, node in enumerate(nodes):
+ if node[0] in [ "host", "service", "remaining"
]:
+ if node[1][0] == oldname:
+ nodes[nr] = (node[0], ( newname, ) + node[1][1:])
+ renamed = 1
+ elif node[0] == "call":
+ if rename_host_in_list(node[1][1], oldname, newname):
+ renamed = 1
+ return renamed