reporting/reports.py | 11 +++++++++++
reporting/reports/data/inactive-systems | 7 +++++--
reporting/spacewalk-report | 7 +------
3 files changed, 17 insertions(+), 8 deletions(-)
New commits:
commit d05f7724d1a06ddabc7568338526d6105d3fcb96
Author: Tomas Kasparek <tkasparek(a)redhat.com>
Date: Thu Jan 17 10:34:59 2013 +0100
parametrization of spacewalk-report with spacewalk config
added new section params: to spacewalk-reports
in this section there's list of sql bind variables excepted with their source
example
params:
tresh web.system_checkin_threshold
and in sql:
.* numtodsinterval(:tresh * 86400, 'second') .*
diff --git a/reporting/reports.py b/reporting/reports.py
index 3a97706..3cf46bf 100644
--- a/reporting/reports.py
+++ b/reporting/reports.py
@@ -3,6 +3,8 @@ import os
import re
import sys
+from spacewalk.common.rhnConfig import RHNOptions
+
REPORT_DEFINITIONS = "/usr/share/spacewalk/reports/data"
def available_reports():
@@ -21,6 +23,7 @@ class report:
self.multival_column_names = {}
self.multival_columns_reverted = {}
self.multival_columns_stop = []
+ self.params = {}
self._load(full_path)
def _load(self, full_path):
@@ -96,6 +99,14 @@ class report:
if description != None:
self.column_descriptions[c] = description
i = i + 1
+ elif tag == 'params':
+ lines = filter(lambda x: x != '', re.split('\s*\n\s*', value))
+ for l in lines:
+ ( p, v ) = re.split('\s+', l, 1)
+ ( component, option ) = re.split('\.', v, 1)
+ cfg = RHNOptions(component)
+ cfg.parse()
+ self.params[p] = str(cfg.get(option))
elif tag == 'multival_columns':
# the multival_columns specifies either
# a "stop" column, usually the first one,
diff --git a/reporting/reports/data/inactive-systems
b/reporting/reports/data/inactive-systems
index 525e53a..0e73a79 100644
--- a/reporting/reports/data/inactive-systems
+++ b/reporting/reports/data/inactive-systems
@@ -14,6 +14,10 @@ columns:
organization_id Id of organization system belongs to
last_checkin Last check of the system
+params:
+
+ tresh web.system_checkin_threshold
+
sql:
select * from (
@@ -24,8 +28,7 @@ sql:
from rhnServer
join rhnServerInfo on rhnServer.id=rhnServerInfo.server_id
where rhnServerInfo.checkin < current_timestamp - numtodsinterval(
- -- checkin_threshold_placeholder
- * 86400, 'second')
+ :tresh * 86400, 'second')
) X
-- where placeholder
order by system_id, organization_id
diff --git a/reporting/spacewalk-report b/reporting/spacewalk-report
index af0676c..bd6dfda 100755
--- a/reporting/spacewalk-report
+++ b/reporting/spacewalk-report
@@ -180,16 +180,11 @@ if __name__ == '__main__':
the_sql = report.sql
- if report_name == "inactive-systems":
- cfg = RHNOptions('web')
- cfg.parse()
- the_dict_where['tresh'] = str(cfg.get('system_checkin_threshold'))
- the_sql = the_sql.replace('-- checkin_threshold_placeholder',
':tresh')
if the_sql_where:
the_sql = the_sql.replace('-- where placeholder', 'where %s' % '
and '.join(the_sql_where))
h = rhnSQL.prepare(the_sql)
- h.execute(**the_dict_where)
+ h.execute(**dict(report.params.items() + the_dict_where.items()))
db_columns = map(lambda x: x[0].lower(), h.description)
if db_columns != report.columns:
Show replies by date