Module: check_mk
Branch: master
Commit: 62d22fea12c0b30a5e437e124b8201662b30fede
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=62d22fea12c0b3…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Nov 8 09:37:42 2012 +0100
Added comments into example notification script
---
notifications/debug | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/notifications/debug b/notifications/debug
index c9ee5b4..8cf29ee 100755
--- a/notifications/debug
+++ b/notifications/debug
@@ -1,6 +1,21 @@
#!/bin/bash
# Debug Notifications
-# Turn on notification logging and you will see the environment in
-# your notification logfile (var/check_mk/notify/notify.log)
+
+# This notification script is just an example and shows how the
+# script is being called:
+
+# Check_MK will call this without an command line arguments.
+# All information is passed in environment variables that begin
+# with NOTIFY_.
+
+# This debug script will fetch those variables and simply
+# write them to the standard output. If you have enabled
+# notification logging by setting notification_logging=1
+# or notification_logging=2 in main.mk (or via WATO in the
+# global settings: Notification -> Debug notifications, then
+# you will see this output in the notitifcation log file.
+# Under OMD this file is in ~/var/check_mk/notify/notify.log.
+
+# Please refer to the official documentation for more details.
env | grep NOTIFY_ | sort
Module: check_mk
Branch: master
Commit: 996755e1ce00254a187af9e4d940eaa47dec8072
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=996755e1ce0025…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Nov 8 08:59:48 2012 +0100
Fixed setting of global var to disable the dashboard title
---
web/htdocs/dashboard.py | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/web/htdocs/dashboard.py b/web/htdocs/dashboard.py
index 7aa0907..2f389d8 100644
--- a/web/htdocs/dashboard.py
+++ b/web/htdocs/dashboard.py
@@ -127,6 +127,7 @@ def render_dashboard(name):
if title is None:
# If the title is none, hide the header line
html.set_render_headfoot(False)
+ global header_height
header_height = 0
title = ''
Module: check_mk
Branch: master
Commit: 04c4a2236e368c1e6ab552c88ac4b72f7856ae88
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=04c4a2236e368c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Nov 8 09:02:12 2012 +0100
Fixed ImportError "Cannot import name attrencode" when importing wato module (at least in some rare situations/python versions)
---
web/htdocs/valuespec.py | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 0801d6b..5da0caa 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -24,9 +24,8 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-import math, os, time, re, sre_constants, urlparse, forms
+import math, os, time, re, sre_constants, urlparse, forms, htmllib
from lib import *
-from htmllib import attrencode
# Abstract base class of all value declaration classes.
class ValueSpec:
@@ -310,7 +309,7 @@ class TextAscii(ValueSpec):
return _("none")
else:
if self._attrencode:
- return attrencode(value)
+ return htmllib.attrencode(value)
else:
return value
Module: check_mk
Branch: master
Commit: 796e62ad33e21eadba867ca316de280fb2b39e7e
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=796e62ad33e21e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Nov 7 09:38:40 2012 +0100
Fix inline docu in check
---
checks/fileinfo | 8 ++--
modules/notify.py | 96 +++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 76 insertions(+), 28 deletions(-)
diff --git a/checks/fileinfo b/checks/fileinfo
index 9fb3e57..6086fce 100644
--- a/checks/fileinfo
+++ b/checks/fileinfo
@@ -36,10 +36,10 @@
# M:\crash.exe|20024|12968154426
# Parameters
-# "minsize" : ( 5000, 4000 ), in bytes
-# "maxsize" : ( 8000, 9000 ), in bytes
-# "minage" : ( 10, 20 ), in minutes
-# "maxage" : ( 50, 80 ), in minutes
+# "minsize" : ( 5000, 4000 ), in bytes
+# "maxsize" : ( 8000, 9000 ), in bytes
+# "minage" : ( 600, 1200 ), in seconds
+# "maxage" : ( 6000, 12000 ), in seconds
fileinfo_groups = []
def inventory_fileinfo(info, case):
diff --git a/modules/notify.py b/modules/notify.py
index 600a0c9..92791c6 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -89,6 +89,22 @@ def do_notify(args):
sys.stderr.write("check_mk --notify does not take any arguments.\n")
sys.exit(1)
+
+ # Hier müssen wir erstmal rausfinden, an wen die Notifikation gehen soll.
+ # Das sollte hoffentlich als Env-Variable da sein. Wenn nicht in check_mk_templates.cfg
+ # einbauen. Dann können wir in den Kontaktdefinitionen nachschauen. Diese sollten
+ # ja in main.mk/conf.d vorhanden sein. Die neue Notifikationstabelle muss auf jeden
+ # fall da rein. Für den Benutzer rufen also diese Tabelle auf. Wenn es die
+ # nicht gibt (garkein Eintrag), verfahren wir nach dem alten Verfahren und
+ # senden direkt eine Email. Wenn es die Tabelle aber gibt, werten wir
+ # Zeile für Zeile aus:
+ # - Bestimmen, ob die Zeile aktiv ist. Dazu ist evtl. eine Livestatus-Rückanfrage
+ # notwendig. Das ist nicht optimal, aber zumindest wegen der Timeperiods notwendig.
+ # - Wenn aktiv, dann rufen wir das Plugin dazu auf. Dieses hat sich mit einer
+ # Python-Funktion registriert. Wo werden diese definiert? Im precompiled-Fall
+ # brauchen wir das *nicht*. Man könnte die Plugins also einfach nur bei --notify
+ # einlesen. Zeitkritisch ist das nicht sehr, denn Notifikationen sind selten.
+
# Information about notification is excpected in the
# environment in variables with the prefix NOTIFY_
context = dict([
@@ -115,32 +131,19 @@ def do_notify(args):
"that are prefixed with NOTIFY_\n")
sys.exit(1)
- try:
- notify_log(substitute_context(notification_log_template, context))
+ # Get notification settings for the contact in question - if available.
+ method = "email"
+ contact = contacts.get(context["CONTACTNAME"])
- if "SERVICEDESC" in context:
- subject_t = notification_service_subject
- body_t = notification_service_body
+ try:
+ if contact:
+ method = contact.get("notification_method")
+ else:
+ method = 'email'
+ if type(method) == tuple and method[0] == 'flexible':
+ notify_flexible(contact, context, method[1])
else:
- subject_t = notification_host_subject
- body_t = notification_host_body
-
- subject = substitute_context(subject_t, context)
- context["SUBJECT"] = subject
- body = substitute_context(notification_common_body + body_t, context)
- command = substitute_context(notification_mail_command, context)
- command_utf8 = command.encode("utf-8")
- if notification_logging >= 2:
- notify_log("Executing command: %s" % command)
- notify_log(body)
- # Make sure that mail(x) is using UTF-8. More then
- # setting the locale cannot be done here. We hope that
- # C.UTF-8 is always available. Please check the output
- # of 'locale -a' on your system if you are curious.
- os.putenv("LANG", "C.UTF-8")
- if notification_logging >= 2:
- file(var_dir + "/notify/body.log", "w").write(body.encode("utf-8"))
- os.popen(command_utf8, "w").write(body.encode("utf-8"))
+ notify_via_email(context)
except Exception, e:
notify_log("ERROR: %s\n%s" % (e, format_exception()))
@@ -148,12 +151,57 @@ def do_notify(args):
if notification_log:
sys.stderr.write("Details have been logged to %s.\n" % notification_log)
sys.exit(1)
+
except Exception, e:
crash_dir = var_dir + "/notify"
if not os.path.exists(crash_dir):
os.makedirs(crash_dir)
file(crash_dir + "/crash.log", "a").write("CRASH:\n%s\n\n" % format_exception())
+
+def notify_via_email(context):
+ notify_log(substitute_context(notification_log_template, context))
+
+ if "SERVICEDESC" in context:
+ subject_t = notification_service_subject
+ body_t = notification_service_body
+ else:
+ subject_t = notification_host_subject
+ body_t = notification_host_body
+
+ subject = substitute_context(subject_t, context)
+ context["SUBJECT"] = subject
+ body = substitute_context(notification_common_body + body_t, context)
+ command = substitute_context(notification_mail_command, context)
+ command_utf8 = command.encode("utf-8")
+ if notification_logging >= 2:
+ notify_log("Executing command: %s" % command)
+ notify_log(body)
+ # Make sure that mail(x) is using UTF-8. More then
+ # setting the locale cannot be done here. We hope that
+ # C.UTF-8 is always available. Please check the output
+ # of 'locale -a' on your system if you are curious.
+ os.putenv("LANG", "C.UTF-8")
+ if notification_logging >= 2:
+ file(var_dir + "/notify/body.log", "w").write(body.encode("utf-8"))
+ os.popen(command_utf8, "w").write(body.encode("utf-8"))
+
+def notify_flexible(contact, context, notification_table):
+ notify_log("Flexible notification for %s" % context["CONTACTNAME"])
+ for entry in notification_table:
+ plugin = entry["plugin"]
+ notify_log("Plugin: %s" % plugin)
+ if entry["disabled"]:
+ notify_log("- Skipping: it is disabled for this user")
+ continue
+ # Was fehlt noch?
+ # 1. Event-Typ filtern
+ # 2. timepreriod filtern (dazu Livestatusanfrage notwendig, wenn nicht 7X24
+ # 3. Eskalation
+ # 4. Dann das Plugin aufrufen, dabei aber das Environment vorher vorbereiten
+ notify_log(repr(notification_table))
+
+
def format_exception():
import traceback, StringIO, sys
txt = StringIO.StringIO()