Module: check_mk
Branch: master
Commit: 17942dc01f0712268797bac5832c8f7d212e21ae
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=17942dc01f0712…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Aug 9 14:10:11 2011 +0200
WATO: Added new hook "active-changes" which calls the registered hosts
with a dict of "dirty" hosts
---
ChangeLog | 2 +
web/htdocs/wato.py | 43 ++++++++++++++++++++++++++++++-
web/plugins/wato/builtin_attributes.py | 4 +++
3 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d5fa32b..dcbc8f6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -50,6 +50,8 @@
* Sidebar: Snapins can register for a triggered reload after a nagios
restart has been detected. Check interval is 30 seconds for now.
* Quicksearch snapin: Reloads host lists after a detected nagios restart.
+ * WATO: Added new hook "active-changes" which calls the registered hosts
+ with a dict of "dirty" hosts
WATO:
* Configration files can now be administered via the WEB UI
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 36f25da..a7f77b6 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -727,8 +727,6 @@ def get_hostnames_from_checkboxes():
selected_hosts.append(name)
return selected_hosts
-
-
# Form for host details (new, clone, edit)
def mode_edithost(phase, new):
hostname = html.var("host") # may be empty in new/clone mode
@@ -782,6 +780,7 @@ def mode_edithost(phase, new):
go_to_services = html.var("services")
if html.check_transaction():
g_hosts[hostname] = host
+ mark_as_dirty(g_hosts[hostname])
if new:
message = _("Created new host %s.") % hostname
log_pending(hostname, "create-host", message)
@@ -1213,6 +1212,7 @@ def mode_bulk_edit(phase):
hostnames = get_hostnames_from_checkboxes()
for hostname in hostnames:
host = g_hosts[hostname]
+ mark_as_dirty(host)
host.update(changed_attributes)
log_pending(hostname, "bulk-edit", _("Changed attributes
of host %s in bulk mode") % hostname)
write_the_configuration_file()
@@ -1254,6 +1254,7 @@ def mode_bulk_cleanup(phase):
hostnames = get_hostnames_from_checkboxes()
for hostname in hostnames:
host = g_hosts[hostname]
+ mark_as_dirty(host)
num_cleaned = 0
for attrname in to_clean:
num_cleaned += 1
@@ -1378,6 +1379,8 @@ def mode_changelog(phase):
elif html.check_transaction():
try:
check_mk_automation("restart")
+ call_hook_activate_changes()
+ undirt_hosts()
except Exception, e:
raise MKUserError(None, str(e))
log_commit_pending() # flush logfile with pending actions
@@ -1535,6 +1538,30 @@ def render_audit_log(log, what, with_filename = False):
# | Functions needed at various places |
# +----------------------------------------------------------------------+
+def get_dirty_hosts():
+ dirty_hosts = {}
+ load_folder_config()
+ for hostname, attributes in collect_hosts(g_root_folder).iteritems():
+ if attributes.get('dirty', 'no') == 'yes':
+ dirty_hosts[hostname] = attributes
+ return dirty_hosts
+
+def mark_as_dirty(host):
+ host['dirty'] = 'yes'
+
+def undirt_hosts():
+ # Seems very dirty with all the global things here. Clean this up!
+ global g_hosts, g_folder, g_file
+ old_file = g_file
+ old_folder = g_folder
+ for hostname, attributes in get_dirty_hosts().iteritems():
+ g_file = g_files[attributes['file']]
+ g_folder = find_folder(attributes['file'][:-1])
+ read_the_configuration_file()
+ del g_hosts[hostname]['dirty']
+ write_the_configuration_file()
+ g_file = old_file
+ g_folder = old_folder
def check_mk_automation(command, args=[], indata=""):
# Gather the command to use for executing --automation calls to check_mk
@@ -2262,6 +2289,7 @@ def move_hosts_to(hostnames, target_filename):
continue
target_hosts[hostname] = g_hosts[hostname]
+ mark_as_dirty(target_hosts[hostname])
target_file["num_hosts"] += 1
g_file["num_hosts"] -= 1
del g_hosts[hostname]
@@ -3138,6 +3166,7 @@ def collect_hosts(the_thing):
host["file"] = the_thing[".path"]
return effective_hosts
+
def call_hooks(name, *args):
n = 0
for hk in hooks.get(name, []):
@@ -3173,6 +3202,16 @@ def call_hook_file_or_folder_deleted(what, the_thing):
elif what == 'folder' and 'folder-deleted' in hooks:
call_hooks("folder-deleted", the_thing)
+def call_hook_activate_changes():
+ """
+ This hook is executed when one applies the pending configuration changes
+ from wato.
+
+ The registered hooks are called with a dictionary as parameter which
+ has the dirty hostnames as keys and the attributes of the hosts as values.
+ """
+ call_hooks("activate-changes", get_dirty_hosts())
+
# +----------------------------------------------------------------------+
# | ____ _ _ |
# | | _ \| |_ _ __ _(_)_ __ ___ |
diff --git a/web/plugins/wato/builtin_attributes.py
b/web/plugins/wato/builtin_attributes.py
index 5c6945f..c128bce 100644
--- a/web/plugins/wato/builtin_attributes.py
+++ b/web/plugins/wato/builtin_attributes.py
@@ -35,3 +35,7 @@ declare_host_attribute(IPAddressAttribute("ipaddress",
_("IP Address"),
show_in_table=True, show_in_folder=True)
+declare_host_attribute(EnumAttribute("dirty", _("Dirty"),
+ _("Modified since last "Active
Changes"?"),
+ "No", [ ('no', _('No')), ('yes',
_('Yes'))]),
+ show_in_table = False, show_in_folder = False)