Module: check_mk
Branch: master
Commit: c7efbb1e66aa09800e4a0b6922a0ac9c44b7d1ca
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c7efbb1e66aa09…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Nov 11 09:06:50 2014 +0100
visuals: helper functions for preparing context for being edited
---
web/htdocs/visuals.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/web/htdocs/visuals.py b/web/htdocs/visuals.py
index c006d05..1245c9d 100644
--- a/web/htdocs/visuals.py
+++ b/web/htdocs/visuals.py
@@ -1070,6 +1070,25 @@ def SingleInfoSelection(info_keys, **args):
args["choices"] = info_choices
return ListChoice(**args)
+# Converts a context from the form { filtername : { ... } } into
+# the for { infoname : { filtername : { } } for editing.
+def pack_context_for_editing(context):
+ # We need to pack all variables into dicts with the name of the
+ # info. Since we have no mapping from info the the filter variable,
+ # we pack into every info every filter. The dict valuespec will
+ # pick out what it needs. Yurks.
+ packed_context = {}
+ for info_name in infos.keys():
+ packed_context[info_name] = context
+ return packed_context
+
+def unpack_context_after_editing(packed_context):
+ context = {}
+ for info_type, its_context in packed_context.items():
+ context.update(its_context)
+ return context
+
+
#.
# .--Misc----------------------------------------------------------------.
Module: check_mk
Branch: master
Commit: cb349d4942358226c2c62689961ba8335eba9e0d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=cb349d49423582…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 10 13:37:18 2014 +0100
check_mail_loop: Added more helpful error message when mail can not be processed
---
doc/treasures/active_checks/check_mail_loop | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/treasures/active_checks/check_mail_loop b/doc/treasures/active_checks/check_mail_loop
index d004e24..7c92dc1 100755
--- a/doc/treasures/active_checks/check_mail_loop
+++ b/doc/treasures/active_checks/check_mail_loop
@@ -245,7 +245,7 @@ def fetch_mails():
if retcode == 'OK':
for num in messages[0].split(' '):
ty, data = g_M.fetch(num, '(RFC822)')
- if ty == 'OK'
+ if ty == 'OK':
mails[num] = email.message_from_string(data[0][1])
else:
raise Exception('Failed to fetch mail %s (%s). Available messages: %r' % (num, data[0], messages))
Module: check_mk
Branch: master
Commit: db1047facf0fefc941225fc8f1947b94f219203a
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=db1047facf0fef…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 10 13:36:24 2014 +0100
check_mail_loop: Added more helpful error message when mail can not be processed
---
doc/treasures/active_checks/check_mail_loop | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/doc/treasures/active_checks/check_mail_loop b/doc/treasures/active_checks/check_mail_loop
index 1d8761c..d004e24 100755
--- a/doc/treasures/active_checks/check_mail_loop
+++ b/doc/treasures/active_checks/check_mail_loop
@@ -245,7 +245,10 @@ def fetch_mails():
if retcode == 'OK':
for num in messages[0].split(' '):
ty, data = g_M.fetch(num, '(RFC822)')
- mails[num] = email.message_from_string(data[0][1])
+ if ty == 'OK'
+ mails[num] = email.message_from_string(data[0][1])
+ else:
+ raise Exception('Failed to fetch mail %s (%s). Available messages: %r' % (num, data[0], messages))
# Now filter out the messages for this check
pattern = re.compile('(?:Re: )?Check_MK-Mail-Loop ([^\s]+) ([^\s]+)')
Module: check_mk
Branch: master
Commit: 55c45c526746504488c16a1ca0cdc251bc246f3b
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=55c45c52674650…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 10 13:32:19 2014 +0100
check_mail_loop: Added missing threshold configuration
---
checks/check_mail_loop | 4 ++++
doc/treasures/active_checks/check_mail_loop | 22 +++++++++++++---------
pnp-templates/check_mk_active-mail_loop.php | 6 +++++-
web/plugins/wato/active_checks.py | 9 ++++++++-
4 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/checks/check_mail_loop b/checks/check_mail_loop
index 2e9edbc..067240e 100644
--- a/checks/check_mail_loop
+++ b/checks/check_mail_loop
@@ -70,6 +70,10 @@ def check_mail_loop_arguments(params):
args += ' --status-suffix=%s' % quote_shell_string(g_hostname + '-' + params['item'])
+ if 'duration' in params:
+ args += ' --warning=%d' % params['duration'][0]
+ args += ' --critical=%d' % params['duration'][1]
+
return args
diff --git a/doc/treasures/active_checks/check_mail_loop b/doc/treasures/active_checks/check_mail_loop
index 25d341a..1d8761c 100755
--- a/doc/treasures/active_checks/check_mail_loop
+++ b/doc/treasures/active_checks/check_mail_loop
@@ -59,10 +59,12 @@ OPTIONS:
--mail-from MAIL Use this mail address as sender address
--mail-to MAIL Use this mail address as recipient address
- --warning AGE Age of the most recent mail in seconds to result
- in a WARNING state
- --critical AGE Age of the most recent mail in seconds to result
- in a CRITICAL state. Defaults to 1 hour
+ --warning AGE Loop duration of the most recent mail in seconds or
+ the average of all received mails within a single
+ check to raise a WARNING state
+ --critical AGE Loop duration of the most recent mail in seconds or
+ the average of all received mails within a single
+ check to raise a CRITICAL state
--connect-timeout Timeout in seconds for network connects (defaults to 10)
--status-dir PATH This plugin needs a file to store information about
@@ -312,8 +314,10 @@ def check_mails():
if critical != None and duration >= critical:
state = 2
+ output.append(' (>= %d)' % critical)
elif warning != None and duration >= warning:
state = max(state, 1)
+ output.append(' (>= %d)' % warning)
del g_expected[ident] # remove message from expect list
num_received += 1
@@ -330,13 +334,13 @@ def check_mails():
num_pending += 1
if num_received == 1:
- output.append('Mail received within %d seconds' % duration)
- perfdata.append(('duration', duration))
+ output.insert(0, 'Mail received within %d seconds' % duration)
+ perfdata.append(('duration', duration, warning or '', critical or ''))
elif num_received > 1:
- output.append('Received %d mails within average of %d seconds' % (num_received, duration))
- perfdata.append(('duration', duration))
+ output.insert(0, 'Received %d mails within average of %d seconds' % (num_received, duration))
+ perfdata.append(('duration', duration, warning or '', critical or ''))
else:
- output.append('Did not receive any new mail')
+ output.insert(0, 'Did not receive any new mail')
if num_lost:
output.append('Lost: %d (Did not arrive within %d seconds)' % (num_lost, critical))
diff --git a/pnp-templates/check_mk_active-mail_loop.php b/pnp-templates/check_mk_active-mail_loop.php
index 569e798..74ac890 100644
--- a/pnp-templates/check_mk_active-mail_loop.php
+++ b/pnp-templates/check_mk_active-mail_loop.php
@@ -29,5 +29,9 @@ $def[1] = "DEF:dur=$RRDFILE[1]:$DS[1]:MAX ";
$def[1] .= "AREA:dur#80f000:\"Duration (seconds)\" ";
$def[1] .= "LINE:dur#408000 ";
$def[1] .= "GPRINT:dur:LAST:\"%7.2lf %s LAST\" ";
-$def[1] .= "GPRINT:dur:MAX:\"%7.2lf %s MAX\" ";
+$def[1] .= "GPRINT:dur:MAX:\"%7.2lf %s MAX\\n\" ";
+if ($WARN[1])
+ $def[1] .= "HRULE:$WARN[1]#FFFF00:\"Warning at $WARN[1] sec\" ";
+if ($CRIT[1])
+ $def[1] .= "HRULE:$CRIT[1]#FF0000:\"Critical at $CRIT[1] sec\" ";
?>
diff --git a/web/plugins/wato/active_checks.py b/web/plugins/wato/active_checks.py
index 41c7b63..8def316 100644
--- a/web/plugins/wato/active_checks.py
+++ b/web/plugins/wato/active_checks.py
@@ -1480,7 +1480,7 @@ register_rule(group,
'the SMTP protocol and then tries to receive these mails back by querying the '
'inbox of a IMAP or POP3 mailbox. With this check you can verify that your whole '
'mail delivery progress is working.'),
- optional_keys = ['smtp_server', 'smtp_tls', 'smtp_port', 'smtp_auth', 'connect_timeout', 'delete_messages'],
+ optional_keys = ['smtp_server', 'smtp_tls', 'smtp_port', 'smtp_auth', 'connect_timeout', 'delete_messages', 'duration'],
elements = [
('item', TextUnicode(
title = _('Name'),
@@ -1631,6 +1631,13 @@ register_rule(group,
default_value = 10,
unit = _('sec'),
)),
+ ("duration", Tuple(
+ title = _("Loop duration"),
+ elements = [
+ Age(title = _("Warning if above or equal")),
+ Age(title = _("Critical if above or equal")),
+ ])
+ ),
('delete_messages', FixedValue(True,
title = _('Delete processed messages'),
totext = _('Delete all processed message belonging to this check'),
Module: check_mk
Branch: master
Commit: 09fd2d81968401c66f77ae5c06c4017fecf12d33
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=09fd2d81968401…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Nov 10 10:53:23 2014 +0100
Implement kind of cron job URL in Multisite
---
scripts/setup.sh | 10 +++++++
web/htdocs/cron.py | 64 +++++++++++++++++++++++++++++++++++++++++++++
web/htdocs/index.py | 6 ++---
web/plugins/pages/cron.py | 31 ++++++++++++++++++++++
4 files changed, 108 insertions(+), 3 deletions(-)
diff --git a/scripts/setup.sh b/scripts/setup.sh
index 8101f88..7907667 100755
--- a/scripts/setup.sh
+++ b/scripts/setup.sh
@@ -955,8 +955,18 @@ and change the path there. Restart Apache afterwards."
Allow from all
Satisfy any
</Location>
+
+ # Trigger cron jobs. This is done without authentication
+ <Location "${url_prefix}check_mk/run_cron.py">
+ Order allow,deny
+ Allow from all
+ Satisfy any
+ </Location>
+
</IfModule>
+
+
<IfModule !mod_python.c>
Alias ${url_prefix}check_mk $web_dir/htdocs
<Directory $web_dir/htdocs>
diff --git a/web/htdocs/cron.py b/web/htdocs/cron.py
new file mode 100644
index 0000000..9748f74
--- /dev/null
+++ b/web/htdocs/cron.py
@@ -0,0 +1,64 @@
+#!/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-
+# ails. 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.
+
+import time
+from lib import *
+import defaults
+
+loaded_with_language = False
+multisite_cronjobs = []
+
+lock_file = defaults.tmp_dir + "/cron.lastrun"
+
+# Load all view plugins
+def load_plugins():
+ global loaded_with_language
+ if loaded_with_language == current_language:
+ return
+
+ global multisite_cronjobs
+ multisite_cronjobs = []
+ load_web_plugins("cron", globals())
+
+ loaded_with_language = current_language
+
+
+# Page called by some external trigger (usually cron job in OMD site)
+# Note: this URL is being called *without* any login. We have no
+# user. Everyone can call this! We must not read any URL variables.
+def page_run_cron():
+ now = time.time()
+ # Prevent cron jobs from being run too often, also we need
+ # locking in order to prevent overlapping runs
+ if os.path.exists(lock_file):
+ last_run = os.stat(lock_file).st_mtime
+ if time.time() - last_run < 59:
+ raise MKGeneralException("Cron called too early. Skipping.")
+ file(lock_file, "w") # touches the file
+ aquire_lock(lock_file)
+
+ for cron_job in multisite_cronjobs:
+ cron_job()
diff --git a/web/htdocs/index.py b/web/htdocs/index.py
index 67ee234..b889c96 100644
--- a/web/htdocs/index.py
+++ b/web/htdocs/index.py
@@ -67,7 +67,7 @@ if defaults.omd_root:
# Call the load_plugins() function in all modules
def load_all_plugins():
for module in [ hooks, userdb, visuals, views, sidebar, dashboard,
- wato, bi, mobile, notify, webapi, reporting ]:
+ wato, bi, mobile, notify, webapi, reporting, cron ]:
try:
module.load_plugins # just check if this function exists
except AttributeError:
@@ -90,8 +90,8 @@ def handler(req, fields = None, profiling = True):
html.enable_debug = config.debug
html.id = {} # create unique ID for this request
__builtin__.html = html
-
response_code = apache.OK
+
try:
# Ajax-Functions want no HTML output in case of an error but
@@ -160,7 +160,7 @@ def handler(req, fields = None, profiling = True):
# Special handling for automation.py. Sorry, this must be hardcoded
# here. Automation calls bybass the normal authentication stuff
- if html.myfile == "automation":
+ if html.myfile in [ "automation", "run_cron" ]:
try:
handler()
except Exception, e:
diff --git a/web/plugins/pages/cron.py b/web/plugins/pages/cron.py
new file mode 100644
index 0000000..9ec92df
--- /dev/null
+++ b/web/plugins/pages/cron.py
@@ -0,0 +1,31 @@
+#!/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-
+# ails. 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.
+
+import cron
+
+pagehandlers.update({
+ "run_cron" : cron.page_run_cron,
+})