Module: check_mk
Branch: master
Commit: 3dd6d868b02311720a546211b9c8e9039916d10b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3dd6d868b02311…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jan 8 17:50:26 2013 +0100
New script multisite_to_mrpe for exporting services from a remote system
---
ChangeLog | 1 +
doc/treasures/.gitignore | 1 +
.../{multisite_to_local => multisite_to_mrpe} | 60 ++++++++++++++++----
web/plugins/views/builtin.py | 28 +++++++++
4 files changed, 78 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e161bc0..5988096 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,7 @@
* FIX: zpool_status: fixed crash when spare devices were available
* FIX: hr_fs: handle negative values in order to larger disks (thanks to Christof
Musik)
* FIX: mssql_backup: Fixed wrong calculation of backup age in seconds
+ * New script multisite_to_mrpe for exporting services from a remote system
Multisite:
diff --git a/doc/treasures/.gitignore b/doc/treasures/.gitignore
new file mode 100644
index 0000000..c332f1d
--- /dev/null
+++ b/doc/treasures/.gitignore
@@ -0,0 +1 @@
+.f12
diff --git a/doc/treasures/multisite_to_local b/doc/treasures/multisite_to_mrpe
similarity index 62%
rename from doc/treasures/multisite_to_local
rename to doc/treasures/multisite_to_mrpe
index b2a0fde..9274880 100755
--- a/doc/treasures/multisite_to_local
+++ b/doc/treasures/multisite_to_mrpe
@@ -2,12 +2,35 @@
# encoding: utf-8
# Fetches the current state of all services of a host via Multisite and
-# outputs a <<<local>>> section reflecting these states. This script
is
+# outputs an <<<mrpe>>> section reflecting these states. This script
is
# intended to be used as a datasource program.
#
-# Still missing:
-# - Output of performance data (not included in standard view)
-# - Assignment of corrent PNP template (need original check command)
+# Why? This allows you to "import" monitoring data from another
+# Check_MK system via HTTP without having livestatus access. The
+# administrator of the remote system has full control over this
+# channel and can also select a subset of hosts/services to export
+# by simply using standard contact <-> object relation for that
+# user.
+#
+# How to setup:
+# 1. On the remote system create a user for the export and
+# set its authentication method to 'Automation'. In this
+# step a secret is being created.
+# 2. In your local monitoring system create one host for
+# each remote host that you want to import (sorry, this
+# has really to be done manually)
+# 3. Configure this script as a datasource program for those
+# hosts. Call me with --help for details.
+# 4. Do Inventory and activate your configuration
+#
+# Note: Whenever the list of services of an imported host
+# changes on the remote system you have to do a re-inventory
+# of that host.
+#
+# Here is an example for a datasource_programs-definition (assuming
+# that the user is "automation"):
+# "$OMD_ROOT/local/lib/multisite_to_mrpe --secret dasistgeheim --url
http://localhost/remote/check_mk/ <HOST>"
+#
import os, sys, getopt, time, urllib
@@ -27,11 +50,11 @@ def verbose(text):
sys.stdout.write(text + "\n")
def usage():
- sys.stdout.write("""Usage: multisite_to_local [OPTIONS] HOST
+ sys.stdout.write("""Usage: multisite_to_mrpe [OPTIONS] HOST
This program is intended to be used as a datasource program.
It fetches the current state of all services of a host
-from a remote Multisite and create a <<<local>>> section
+from a remote Multisite and create a <<<mrpe>>> section
from it. That way all those services can be added to the
monitoring of another OMD site.
@@ -44,16 +67,19 @@ Options:
-u, --user U Name of automation user (default: "automation")
-U, --url U Multisite URL of the remote server including
-S, --secret S Automation secret (default: public)
+ --debug Let Python exceptions come through
""")
short_options = 'hvu:U:S:'
-long_options = [ "help", "verbose", "user=",
"url=", "secret=" ]
+long_options = [ "help", "verbose", "user=",
"url=", "secret=", "debug" ]
opt_verbose = False
opt_user = "automation"
opt_secret = None
opt_url = None
+opt_debug = False
+
if omd_site:
opt_url = "http://localhost/" + omd_site + "/check_mk/"
@@ -73,6 +99,8 @@ for o,a in opts:
# Modifiers
elif o in [ '-v', '--verbose']:
opt_verbose = True
+ elif o == '--debug':
+ opt_debug = True
elif o in [ '-u', '--user']:
opt_user = a
elif o in [ '-S', '--secret']:
@@ -85,6 +113,8 @@ if omd_site and not opt_secret:
opt_secret = file(omd_root + "/var/check_mk/web/" + opt_user
+ "/automation.secret").read().strip()
except Exception, e:
+ if opt_debug:
+ raise
bail_out("Cannot read automation secret from user %s: %s" %
(opt_user, e))
@@ -112,7 +142,7 @@ variables = [
( "_username", opt_user ),
( "_secret", opt_secret ),
( "host", arg_host ),
- ( "view_name", "host" ),
+ ( "view_name", "host_export" ),
( "output_format", "python" ),
]
@@ -122,16 +152,22 @@ verbose("URL: " + url)
try:
pipe = urllib.urlopen(url)
answer = pipe.read()
+ if answer.startswith("ERROR:"):
+ bail_out("Error response from remote Multisite: %s" % answer[7:])
services = convert_from_multisite(eval(answer))
except Exception, e:
+ if opt_debug:
+ raise
bail_out("Cannot call Multisite URL: %s" % e)
-sys.stdout.write('<<<local>>>\n')
+sys.stdout.write('<<<mrpe>>>\n')
for service in services:
state = { "OK" : 0, "WARN" : 1, "CRIT" : 2,
"UNKNOWN" : 3}.get(service['service_state'])
if state != None: # skip pending services
- sys.stdout.write("%d %s - %s\n" % (
- state,
+ sys.stdout.write("(%s) %s %d %s|%s\n" % (
+ service["svc_check_command"],
service["service_description"].replace(" ",
"_"),
- service["svc_plugin_output"]))
+ state,
+ service["svc_plugin_output"],
+ service["svc_perf_data"]))
diff --git a/web/plugins/views/builtin.py b/web/plugins/views/builtin.py
index 49ea300..0d701ed 100644
--- a/web/plugins/views/builtin.py
+++ b/web/plugins/views/builtin.py
@@ -361,6 +361,34 @@ multisite_builtin_views.update({
'sorters': [('svcdescr', False)],
'linktitle': _('Services'),
'title': _('Services of Host')},
+ 'host_export': {'browser_reload': 30,
+ 'column_headers': 'pergroup',
+ 'datasource': 'services',
+ 'description': 'All services of a given host. The host and site
must be set via HTML variables.',
+ 'group_painters': [('host_with_state', 'hoststatus')],
+ 'hard_filters': [],
+ 'hard_filtervars': [('st0', 'on'),
+ ('st1', 'on'),
+ ('st2', 'on'),
+ ('st3', 'on'),
+ ('stp', 'on')],
+ 'hidden': True,
+ 'hide_filters': ['site', 'host'],
+ 'icon': 'services',
+ 'layout': 'boxed',
+ 'mustsearch': False,
+ 'num_columns': 1,
+ 'painters': [('service_state', None),
+ ('service_description', 'service'),
+ ('svc_plugin_output', None),
+ ('svc_perf_data', None),
+ ('svc_check_command', None)],
+ 'play_sounds': False,
+ 'public': True,
+ 'show_filters': ['svcstate', 'serviceregex'],
+ 'sorters': [('svcdescr', False)],
+ 'linktitle': _('Services'),
+ 'title': _('Services of Host')},
'hosts': {'browser_reload': 30,
'column_headers': 'off',
'datasource': 'services',