Module: check_mk
Branch: master
Commit: 4cd8aed833d052c28ee06271050eb1150d0a9236
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4cd8aed833d052…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jul 25 10:07:07 2016 +0200
Added WATO hook to find hosts using same IP address
---
doc/treasures/wato_hook_check_duplicate_hosts.py | 49 ++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/doc/treasures/wato_hook_check_duplicate_hosts.py
b/doc/treasures/wato_hook_check_duplicate_hosts.py
new file mode 100644
index 0000000..a27d063
--- /dev/null
+++ b/doc/treasures/wato_hook_check_duplicate_hosts.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2014 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# This hook scans the whole WATO configuration for duplicate hosts having
+# duplicate names or IP addresses and warns the admin about this fact.
+
+# Put this script into local/share/check_mk/web/plugins/wato on a Check_MK site
+# and run "omd reload apache" as site user to ensure the plugin is loaded.
+
+
+def pre_activate_changes_check_duplicate_host(hosts):
+ addresses = {}
+
+ for host_name, attrs in hosts.items():
+ if attrs["ipaddress"]:
+ host_names = addresses.setdefault(attrs["ipaddress"], [])
+ host_names.append(host_name)
+
+
+ for address, host_names in addresses.items():
+ if len(host_names) > 1:
+ html.show_warning("The IP address %s is used for multiple hosts:
%s" %
+ (address, ",
".join(host_names)))
+
+
+register_hook('pre-activate-changes', pre_activate_changes_check_duplicate_host)