[checkmk-commits] Check_MK Git: check_mk: Multisite: better implementation of table joins

git version control git at mathias-kettner.de
Sun May 1 20:06:24 CEST 2011


Module: check_mk
Branch: master
Commit: 10dc693fdca823a68347c6a76aaba750975a576b
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=10dc693fdca823a68347c6a76aaba750975a576b

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Sun May  1 20:06:19 2011 +0200

Multisite: better implementation of table joins

---

 web/htdocs/views.py              |   14 ++++++--------
 web/plugins/views/datasources.py |    3 +++
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index 0f70304..31f2e4d 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -1086,7 +1086,7 @@ def show_view(view, show_heading = False, show_buttons = True, show_footer = Tru
 
         # Now add join information, if there are join columns
         if len(join_painters) > 0:
-            do_table_join(rows, filterheaders, join_painters, join_columns, only_sites)
+            do_table_join(datasource, rows, filterheaders, join_painters, join_columns, only_sites)
     else:
         rows = []
 
@@ -1289,12 +1289,10 @@ def view_options(viewname):
         config.save_user_file("viewoptions", vo)
     return v
             
-def do_table_join(master_rows, master_filters, join_painters, join_columns, only_sites):
-    # TODO: Do not hard code this values, put it into the datasource?
-    join_table = "services" # TODO: detect / lookup
-    join_master_column = "host_name"
-    join_slave_column = "service_description"
-    datasource = multisite_datasources[join_table]
+def do_table_join(master_ds, master_rows, master_filters, join_painters, join_columns, only_sites):
+    join_table, join_master_column = master_ds["join"]
+    slave_ds = multisite_datasources[join_table]
+    join_slave_column = slave_ds["joinkey"]
 
     # Create additional filters
     join_filter = ""
@@ -1302,7 +1300,7 @@ def do_table_join(master_rows, master_filters, join_painters, join_columns, only
         join_filter += "Filter: %s = %s\n" % (join_slave_column, join_key )
     join_filter += "Or: %d\n" % len(join_painters)
     query = master_filters + join_filter 
-    rows = query_data(datasource, [join_master_column, join_slave_column] + join_columns, [], query, only_sites, None) 
+    rows = query_data(slave_ds, [join_master_column, join_slave_column] + join_columns, [], query, only_sites, None) 
     per_master_entry = {}
     current_key = None
     current_entry = None
diff --git a/web/plugins/views/datasources.py b/web/plugins/views/datasources.py
index 894b556..5179c91 100644
--- a/web/plugins/views/datasources.py
+++ b/web/plugins/views/datasources.py
@@ -39,6 +39,7 @@ multisite_datasources["hosts"] = {
     "table"   : "hosts",
     "infos"   : [ "host" ],
     "keys"    : [ "host_name", "host_downtimes" ],
+    "join"    : ( "services", "host_name" ),
 }
 
 multisite_datasources["hostsbygroup"] = {
@@ -46,6 +47,7 @@ multisite_datasources["hostsbygroup"] = {
     "table"   : "hostsbygroup",
     "infos"   : [ "host", "hostgroup" ],
     "keys"    : [ "host_name", "host_downtimes" ],
+    "join"    : ( "services", "host_name" ),
 }
 
 multisite_datasources["services"] = {
@@ -53,6 +55,7 @@ multisite_datasources["services"] = {
     "table"   : "services",
     "infos"   : [ "service", "host" ],
     "keys"    : [ "host_name", "service_description", "service_downtimes" ],
+    "joinkey" : "service_description",
 }
 
 multisite_datasources["servicesbygroup"] = {



More information about the checkmk-commits mailing list