Module: check_mk
Branch: master
Commit: d96bfd184bc82952eb110c49ca0200c4fd24d3b7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d96bfd184bc829…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Feb 11 15:39:51 2013 +0100
mknotifyd: intermediate state
---
mknotifyd/omd/MKNOTIFYD.hook | 4 ++--
mknotifyd/omd/logrotate.conf | 5 -----
mknotifyd/web/plugins/wato/mknotifyd.py | 1 +
modules/check_mk.py | 8 +-------
modules/notify.py | 20 ++++++++++----------
5 files changed, 14 insertions(+), 24 deletions(-)
diff --git a/mknotifyd/omd/MKNOTIFYD.hook b/mknotifyd/omd/MKNOTIFYD.hook
index c769805..7d0409c 100755
--- a/mknotifyd/omd/MKNOTIFYD.hook
+++ b/mknotifyd/omd/MKNOTIFYD.hook
@@ -1,9 +1,9 @@
#!/bin/bash
-# Alias: Start Daemon for Check_MK Notify
+# Alias: Start Check_MK Notification Spooler
# Menu: Addons
# Description:
-# This option enables mknotifyd
+# This option enables the Check_MK notification spooler
case "$1" in
default)
diff --git a/mknotifyd/omd/logrotate.conf b/mknotifyd/omd/logrotate.conf
index 68caaaf..bca3d9c 100644
--- a/mknotifyd/omd/logrotate.conf
+++ b/mknotifyd/omd/logrotate.conf
@@ -4,9 +4,4 @@
compress
delaycompress
notifempty
- sharedscripts
- olddir mkeventd
- postrotate
- echo "COMMAND REOPENLOG" | unixcat ###ROOT###/tmp/run/mkeventd/status
- endscript
}
diff --git a/mknotifyd/web/plugins/wato/mknotifyd.py
b/mknotifyd/web/plugins/wato/mknotifyd.py
index 80162cf..04b88bc 100644
--- a/mknotifyd/web/plugins/wato/mknotifyd.py
+++ b/mknotifyd/web/plugins/wato/mknotifyd.py
@@ -29,6 +29,7 @@ import config
try:
mknotifyd_enabled = config.mknotifyd_enabled
except:
+ # Non OMD-users: always show Spooling options
mknotifyd_enabled = True
config_dir = defaults.default_config_dir + "/mknotifyd.d/wato/"
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 9112a5b..6c1ea0b 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -319,11 +319,6 @@ host_attributes = {} # needed by WATO, ignored
by Check_MK
ping_levels = [] # special parameters for host/PING
check_command
check_periods = []
-# Notification Spooling
-notification_spooling = False
-notification_spool_to = None
-
-
# global variables used to cache temporary values (not needed in check_mk_base)
ip_to_hostname_cache = None
@@ -346,7 +341,7 @@ special_agent_info = {}
# Now include the other modules. They contain everything that is needed
# at check time (and many of that is also needed at administration time).
try:
- modules = [ 'check_mk_base', 'snmp' ]
+ modules = [ 'check_mk_base', 'snmp', 'notify' ]
for module in modules:
filename = modules_dir + "/" + module + ".py"
execfile(filename)
@@ -4862,7 +4857,6 @@ if __name__ == "__main__":
do_automation(a, args)
done = True
elif o == '--notify':
- execfile(modules_dir + "/notify.py")
sys.exit(do_notify(args))
except MKGeneralException, e:
diff --git a/modules/notify.py b/modules/notify.py
index 697b3f3..3f093fb 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -42,6 +42,11 @@ notification_spooldir = var_dir + "/notify/spool"
notification_log = notification_logdir + "/notify.log"
notification_logging = 0
+# Notification Spooling
+notification_spooling = False
+notification_spool_to = None
+
+
notification_log_template = \
u"$CONTACTNAME$ - $NOTIFICATIONTYPE$ - " \
u"$HOSTNAME$ $HOSTSTATE$ - " \
@@ -175,7 +180,7 @@ def notify_usage():
sys.stderr.write("""Usage: check_mk --notify
check_mk --notify fake-service <plugin>
check_mk --notify fake-host <plugin>
- check_mk --notify filename <spool_filename>
+ check_mk --notify spoolfile <filename>
Normally the notify module is called without arguments to send real
notification. But there are situations where this module is called with
@@ -186,8 +191,8 @@ Available commands:
notification data of a service notification.
fake-host <plugin> ... Calls the given notification plugin with fake
notification data of a host notification.
- spoolfile <spool_filename> ... Reads the given spoolfile and creates a
- notification event out of its data
+ spoolfile <filename> ... Reads the given spoolfile and creates a
+ notification out of its data
""")
@@ -198,7 +203,6 @@ def create_spoolfile(data):
os.makedirs(target_dir)
file_path = "%s/%0.2f_%s" % (target_dir, time.time(), uuid.uuid1())
notify_log("Creating spoolfile: %s" % file_path)
- # TODO: pprint entfernen
file(file_path,"w").write(pprint.pformat(data))
def get_readable_rel_date(timestamp):
@@ -360,18 +364,14 @@ def do_notify(args):
sys.exit(1)
notify_log("forward mode %s" % notification_forward_mode)
- # TODO:
+ # TODO: Umbauen auf neue Parameter
if notification_forward_mode in ["forward",
"forward_exclusive"]:
# Create spoolfile
create_spoolfile({"context": context, "forward":
notification_forward_to})
if notification_forward_mode == "forward_only":
return 0
- try:
- write_into_spoolfile = config.mknotifyd_enabled
- except:
- write_into_spoolfile = False
- process_context(context, write_into_spoolfile)
+ process_context(context, notification_spooling)
except Exception, e:
if g_interactive:
raise