Module: check_mk
Branch: master
Commit: 271a7e91b1f7d3f8dc51181bea7df25e9ee3fdb3
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=271a7e91b1f7d3…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Aug 17 10:17:24 2015 +0200
added two helper functions in check_mk/doc/helpers to create automatically a check and a manpage
---
doc/helpers/mkcheck | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++
doc/helpers/mkman | 45 +++++++++++++++++++++++++++
2 files changed, 131 insertions(+)
diff --git a/doc/helpers/mkcheck b/doc/helpers/mkcheck
new file mode 100755
index 0000000..8343a47
--- /dev/null
+++ b/doc/helpers/mkcheck
@@ -0,0 +1,86 @@
+#!/bin/bash
+# usage:
+# 'mkcheck NAME' for a standard check
+# 'mkcheck NAME snmp' for a snmp check
+content_std="#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \\/ | |/ / |
+# | | | | '_ \\ / _ \\/ __| |/ / | |\\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \\ |
+# | \\____|_| |_|\\___|\\___|_|\\_\\___|_| |_|_|\\_\\ |
+# | |
+# | Copyright Mathias Kettner YEAR 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.
+
+
+# example output:
+#
+
+
+factory_settings['CHECKNAME_default_variables' = {
+ 'LEVELS' : None,
+}
+
+
+def inventory_CHECKNAME(info):
+ print info
+ return []
+
+
+def check_CHECKNAME(item, params, info):
+ return (3, 'Not yet implemented')
+
+
+check_info['CHECKNAME'] = {
+ 'inventory_function' : inventory_CHECKNAME,
+ 'check_function' : check_CHECKNAME,
+ 'service_description' : 'DESCRIPTION %s',
+ 'has_perfdata' : True,
+ 'default_level_variable' : 'CHECKNAME_default_variables',
+ 'includes' : [],"
+content_snmp="
+ 'snmp_info' : INFO,
+ 'snmp_scan_function' : lambda oid: FUNCTION,
+}"
+path=`pwd`
+filename=$1
+snmp=$2
+path2file=$path"/"$filename
+no_name=$path"/no_name"
+year=`date +"%Y"`
+if [ -z "$filename" ]; then
+ echo "No name or argument given. Please determine one."
+else
+ content_std=${content_std//CHECKNAME/$filename}
+ content_std=${content_std//YEAR/$year}
+ if [ ! -f "$path2file" ]; then
+ if [ -z $snmp ]; then
+ content_std=$content_std"\n#\n}"
+ elif [ $snmp = "snmp" ]; then
+ content_std=$content_std$content_snmp:
+ else
+ echo "Wrong arguments."
+ exit 0
+ fi
+ echo "New check '$filename' is created and stored in '$path2file'."
+ echo -e "${content_std}" > $path2file
+ else
+ echo "File already exists."
+ fi
+fi
diff --git a/doc/helpers/mkman b/doc/helpers/mkman
new file mode 100755
index 0000000..acfaa66
--- /dev/null
+++ b/doc/helpers/mkman
@@ -0,0 +1,45 @@
+#!/bin/bash
+# useage:
+# 'mkcheck' for a standard check
+# 'mkchecksnmp' for a snmp check
+content_std="title:
+agents: TYPE
+catalog:
+license: GPL
+distribution: check_mk
+description:
+
+item:
+
+examples:
+
+perfdata:
+
+inventory:
+
+[parameters]
+
+[configuration]"
+path=`pwd`
+filename=$1
+snmp=$2
+path2file=$path"/"$filename
+if [ -z "$filename" ]; then
+ echo "No name given. Please determine one."
+ exit 0
+else
+ if [ ! -f "$path2file" ]; then
+ if [ -z $snmp ]; then
+ content_std=${content_std//" TYPE"/}
+ elif [ $snmp = "snmp" ]; then
+ content_std=${content_std//" TYPE"/" snmp"}
+ else
+ echo "Wrong arguments."
+ exit 0
+ fi
+ echo "New check '$filename' created and stored in '$path2file'."
+ echo -e "${content_std}" > $path2file
+ else
+ echo "File already exists."
+ fi
+fi
Module: check_mk
Branch: master
Commit: f964ec216116e6a88bd069eaf6934eb0696aedf1
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f964ec216116e6…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Aug 14 16:01:22 2015 +0200
#2537 BI Editor: restructured, now show tree structure of aggregations, show unused rules
The WATO module for BI aggregations has undergone a slight rework. Aggregations and Rules are
now show on separate pages. In the table of aggregations you now can unfold the tree of rules
(which is not the same as the final tree of items).
A new page shows all rules that are not called by any other aggregation or rule. This helps
to cleanup your configuration.
---
.werks/2537 | 14 ++
ChangeLog | 1 +
web/htdocs/htmllib.py | 10 +-
web/htdocs/images/button_bitree_hi.png | Bin 0 -> 1808 bytes
web/htdocs/images/button_bitree_lo.png | Bin 0 -> 2672 bytes
web/htdocs/images/icon_bilist.png | Bin 0 -> 2372 bytes
web/htdocs/images/icon_bitree.png | Bin 0 -> 2672 bytes
web/htdocs/images/icon_unusedbirules.png | Bin 0 -> 2978 bytes
web/htdocs/wato.css | 55 ++-----
web/htdocs/wato.py | 250 ++++++++++++++++++++----------
web/plugins/wato/builtin_modules.py | 2 +-
11 files changed, 207 insertions(+), 125 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=f964ec2161…
Module: check_mk
Branch: master
Commit: 6e294c890bcefde83ea8fd4b2b21459500ea8db0
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6e294c890bcefd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Aug 14 09:58:14 2015 +0200
#2508 It is now possible to upload multiple zipped MIB files at once
If you have to upload a lot of MIB files to the Event Console, you
can now pack them in a zip archive and upload the zip archive. The
files need to be located in the root directory of the zip file.
Files in subdirectories will not be processed.
---
.werks/2508 | 12 +++++++
ChangeLog | 1 +
mkeventd/web/plugins/wato/mkeventd.py | 56 ++++++++++++++++++++++++++++-----
3 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/.werks/2508 b/.werks/2508
new file mode 100644
index 0000000..a8e7ad6
--- /dev/null
+++ b/.werks/2508
@@ -0,0 +1,12 @@
+Title: It is now possible to upload multiple zipped MIB files at once
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.2.7i3
+Date: 1439539012
+Class: feature
+
+If you have to upload a lot of MIB files to the Event Console, you
+can now pack them in a zip archive and upload the zip archive. The
+files need to be located in the root directory of the zip file.
+Files in subdirectories will not be processed.
diff --git a/ChangeLog b/ChangeLog
index d2e957e..320d522 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -181,6 +181,7 @@
Event Console:
* 2411 Check check_mkevents: Now able to look for events matching the host alias...
* 2533 Allow inverted match in Event Console rules
+ * 2508 It is now possible to upload multiple zipped MIB files at once...
* 2322 FIX: mkeventd: MIBs are now only loaded if SNMP Traps translation is activated...
* 2460 FIX: Slightly more robust SNMP trap translation...
* 2534 FIX: Fixed implementation of skipping rule packs
diff --git a/mkeventd/web/plugins/wato/mkeventd.py b/mkeventd/web/plugins/wato/mkeventd.py
index 5b10368..f2c0e28 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -25,6 +25,8 @@
# Boston, MA 02110-1301 USA.
import mkeventd, defaults
+import zipfile
+import cStringIO
mkeventd_enabled = config.mkeventd_enabled
@@ -1868,7 +1870,6 @@ def mode_mkeventd_mibs(phase):
try:
msg = upload_mib(filename, mimetype, content)
return None, msg
- log_mkeventd("uploaded-mib", _("Uploaded MIB %s: %s") % (filename, msg))
except Exception, e:
if config.debug:
raise
@@ -1878,7 +1879,11 @@ def mode_mkeventd_mibs(phase):
return
html.write("<h3>" + _("Upload MIB file") + "</h3>")
- html.write(_("Allowed are single MIB files - usually with the extension <tt>.mib</tt> or <tt>.txt</tt>.<br><br>"))
+ html.write(_("Use this form to upload MIB files for translating incoming SNMP traps. "
+ "You can upload single MIB files with the extension <tt>.mib</tt> or "
+ "<tt>.txt</tt>, but you can also upload multiple MIB files at once by "
+ "packing them into a <tt>.zip</tt> file. Only files in the root directory "
+ "of the zip file will be processed.<br><br>"))
html.begin_form("upload_form", method = "POST")
forms.header(_("Upload MIB file"))
@@ -1986,6 +1991,9 @@ def validate_and_compile_mib(mibname, content):
compiler.addSearchers(StubSearcher(*baseMibs))
try:
+ if not content.strip():
+ raise Exception(_("The file is empty"))
+
results = compiler.compile(mibname, ignoreErrors=True)
errors = []
@@ -2011,15 +2019,48 @@ def validate_and_compile_mib(mibname, content):
def upload_mib(filename, mimetype, content):
+ validate_mib_file_name(filename)
+
+ if zipfile.is_zipfile(cStringIO.StringIO(content)):
+ msg = process_uploaded_zip_file(filename, content)
+ else:
+ if mimetype == "application/tar" or filename.lower().endswith(".gz") or filename.lower().endswith(".tgz"):
+ raise Exception(_("Sorry, uploading TAR/GZ files is not yet implemented."))
+
+ msg = process_uploaded_mib_file(filename, content)
+
+ return msg
+
+
+def process_uploaded_zip_file(filename, content):
+ zip_obj = zipfile.ZipFile(cStringIO.StringIO(content))
+ messages = []
+ for entry in zip_obj.infolist():
+ success, fail = 0, 0
+ try:
+ mib_file_name = entry.filename
+ if mib_file_name[-1] == "/":
+ continue # silently skip directories
+
+ validate_mib_file_name(mib_file_name)
+
+ mib_obj = zip_obj.open(mib_file_name)
+ messages.append(process_uploaded_mib_file(mib_file_name, mib_obj.read()))
+ success += 1
+ except Exception, e:
+ messages.append(_("Skipped %s: %s") % (html.attrencode(mib_file_name), e))
+ fail += 1
+
+ return "<br>\n".join(messages) + \
+ "<br><br>\nProcessed %d MIB files, skipped %d MIB files" % (success, fail)
+
+
+def validate_mib_file_name(filename):
if filename.startswith(".") or "/" in filename:
raise Exception(_("Invalid filename"))
- if mimetype == "application/zip" or filename.lower().endswith(".zip"):
- raise Exception(_("Sorry, uploading ZIP files is not yet implemented."))
-
- if mimetype == "application/tar" or filename.lower().endswith(".gz") or filename.lower().endswith(".tgz"):
- raise Exception(_("Sorry, uploading TAR/GZ files is not yet implemented."))
+def process_uploaded_mib_file(filename, content):
if '.' in filename:
mibname = filename.split('.')[0]
else:
@@ -2027,6 +2068,7 @@ def upload_mib(filename, mimetype, content):
msg = validate_and_compile_mib(mibname.upper(), content)
file(mkeventd.mib_upload_dir + "/" + filename, "w").write(content)
+ log_mkeventd("uploaded-mib", _("MIB %s: %s") % (filename, msg))
return msg