rel-eng/packages/spacewalk-reports | 2
reporting/reports.py | 7 ++
reporting/reports/data/channel-packages | 5 +
reporting/reports/data/channels | 7 +-
reporting/reports/data/entitlements | 15 ++--
reporting/reports/data/errata-list | 7 +-
reporting/reports/data/errata-list-all | 7 +-
reporting/reports/data/errata-systems | 7 +-
reporting/reports/data/inventory | 27 ++++++--
reporting/reports/data/system-history | 5 -
reporting/reports/data/system-history-channels | 12 ++-
reporting/reports/data/system-history-configuration | 10 ++-
reporting/reports/data/system-history-entitlements | 12 ++-
reporting/reports/data/system-history-errata | 10 ++-
reporting/reports/data/system-history-kickstart | 10 ++-
reporting/reports/data/system-history-packages | 10 ++-
reporting/reports/data/users | 9 +-
reporting/reports/data/users-systems | 11 ++-
reporting/spacewalk-report | 64 ++++++++++++++++++--
reporting/spacewalk-reports.spec | 5 +
20 files changed, 185 insertions(+), 57 deletions(-)
New commits:
commit 75ea7c17d8655b3cc6be4ff0b4b5070940a37b65
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Fri Jun 24 11:17:53 2011 +0200
Automatic commit of package [spacewalk-reports] release [1.5.3-1].
diff --git a/rel-eng/packages/spacewalk-reports b/rel-eng/packages/spacewalk-reports
index b1b7c59..bbb62df 100644
--- a/rel-eng/packages/spacewalk-reports
+++ b/rel-eng/packages/spacewalk-reports
@@ -1 +1 @@
-1.5.2-1 reporting/
+1.5.3-1 reporting/
diff --git a/reporting/spacewalk-reports.spec b/reporting/spacewalk-reports.spec
index 74ff920..035035c 100644
--- a/reporting/spacewalk-reports.spec
+++ b/reporting/spacewalk-reports.spec
@@ -2,7 +2,7 @@ Name: spacewalk-reports
Summary: Script based reporting
Group: Applications/Internet
License: GPLv2
-Version: 1.5.2
+Version: 1.5.3
Release: 1%{?dist}
URL:
https://fedorahosted.org/spacewalk
Source0:
https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -42,6 +42,9 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man8/spacewalk-report.8*
%changelog
+* Fri Jun 24 2011 Jan Pazdziora 1.5.3-1
+- Add support for the --where-column-id=value parameter.
+
* Wed Jun 01 2011 Jan Pazdziora 1.5.2-1
- Fixing the SGML source of the spacewalk-report man page.
commit 49cf58e2f2b2dd5c62b372fe95485b9d4c0a0d2f
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Mon Jun 20 16:43:54 2011 +0200
Forcing the string Done to be understood as string.
diff --git a/reporting/reports/data/system-history-channels
b/reporting/reports/data/system-history-channels
index 4e67a44..356dcdf 100755
--- a/reporting/reports/data/system-history-channels
+++ b/reporting/reports/data/system-history-channels
@@ -28,7 +28,7 @@ sql:
rhnserverhistory.id as event_id,
to_char(rhnserverhistory.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
rhnserverhistory.created as created_raw_date,
- 'Done' as status,
+ 'D' || 'one' as status,
case when rhnserverhistory.summary like 'subscribed to channel %' then
'Subscribed to channel'
when rhnserverhistory.summary like 'unsubscribed from channel %' then
'Unsubscribed from channel'
end as event,
diff --git a/reporting/reports/data/system-history-entitlements
b/reporting/reports/data/system-history-entitlements
index 94a724a..52e698a 100755
--- a/reporting/reports/data/system-history-entitlements
+++ b/reporting/reports/data/system-history-entitlements
@@ -28,7 +28,7 @@ sql:
rhnserverhistory.id as event_id,
to_char(rhnserverhistory.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
rhnserverhistory.created as created_raw_date,
- 'Done' as status,
+ 'D' || 'one' as status,
case when rhnserverhistory.summary like 'Updated system release %' then
'Updated system release'
else trim(upper(substr(rhnserverhistory.summary, 1, 1)) ||
substr(rhnserverhistory.summary, 2)) end as event,
case when summary in ( 'added system entitlement ', 'removed system
entitlement ') then details
commit aeb5103658f6b8943204869dae835fd408d50977
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Mon Jun 20 16:38:56 2011 +0200
Mark and process integer columns.
diff --git a/reporting/reports.py b/reporting/reports.py
index 868ec39..8d47091 100644
--- a/reporting/reports.py
+++ b/reporting/reports.py
@@ -15,6 +15,7 @@ class report:
self.synopsis = None
self.columns = None
self.column_indexes = None
+ self.column_types = None
self.column_descriptions = None
self.multival_column_names = {}
self.multival_columns_reverted = {}
@@ -74,6 +75,7 @@ class report:
if tag == 'columns':
self.columns = []
self.column_indexes = {}
+ self.column_types = {}
self.column_descriptions = {}
lines = filter(lambda x: x != '', re.split('\s*\n\s*', value))
i = 0
@@ -83,8 +85,13 @@ class report:
( c, description ) = re.split('\s+', l, 1)
except:
c = l
+ try:
+ ( c, t ) = re.split(':', c, 1)
+ except:
+ t = 's'
self.columns.append(c)
self.column_indexes[c] = i
+ self.column_types[c] = t
if description != None:
self.column_descriptions[c] = description
i = i + 1
diff --git a/reporting/reports/data/channels b/reporting/reports/data/channels
index 20cd067..ce36132 100755
--- a/reporting/reports/data/channels
+++ b/reporting/reports/data/channels
@@ -12,7 +12,7 @@ columns:
channel_label Channel label
channel_name Channel name
- number_of_packages Number of packages in the channel
+ number_of_packages:i Number of packages in the channel
sql:
diff --git a/reporting/reports/data/entitlements b/reporting/reports/data/entitlements
index c9b333d..87bc32c 100755
--- a/reporting/reports/data/entitlements
+++ b/reporting/reports/data/entitlements
@@ -11,14 +11,14 @@ description:
columns:
- organization_id Organization identifier
+ organization_id:i Organization identifier
organization Organization name
entitlement_type 'system' or 'channel'
entitlement System entitlement name or channel name
- used How many entitlements are currently used
- total The total number of entitlements
- flex_used How many Flex entitlements are currently used
- flex_total The total number of Flex entitlements
+ used:i How many entitlements are currently used
+ total:i The total number of entitlements
+ flex_used:i How many Flex entitlements are currently used
+ flex_total:i The total number of Flex entitlements
multival_columns:
diff --git a/reporting/reports/data/errata-list b/reporting/reports/data/errata-list
index 3c1bdcd..fa36cd1 100755
--- a/reporting/reports/data/errata-list
+++ b/reporting/reports/data/errata-list
@@ -15,7 +15,7 @@ columns:
type Advisory type (Enhancement, Bug Fix, Security)
cve List of CVE names (Common Vulnerabilities and Exposures Identifiers) addressed by
the errata
synopsis Synopsis of the errata
- systems_affected Number of systems to which this errata is applicable
+ systems_affected:i Number of systems to which this errata is applicable
multival_columns:
diff --git a/reporting/reports/data/errata-systems
b/reporting/reports/data/errata-systems
index 7531831..41e34ae 100755
--- a/reporting/reports/data/errata-systems
+++ b/reporting/reports/data/errata-systems
@@ -10,7 +10,7 @@ description:
columns:
advisory Advisory / errata identifier
- server_id System identifier
+ server_id:i System identifier
profile_name Profile name, as stored on server
hostname Hostname, as reported by the system
ip_address IP address, as reported by the system
diff --git a/reporting/reports/data/inventory b/reporting/reports/data/inventory
index b58de47..836b4b4 100755
--- a/reporting/reports/data/inventory
+++ b/reporting/reports/data/inventory
@@ -10,7 +10,7 @@ description:
columns:
- server_id System identifier
+ server_id:i System identifier
profile_name Profile name, as stored on server
hostname Hostname, as reported by the system
ip_address IP address, as reported by the system
@@ -18,14 +18,14 @@ columns:
registration_time Registration time
last_checkin_time Last checkin time
kernel_version Kernel version, as reported by the system
- packages_out_of_date Number of packages that can be upgraded
- errata_out_of_date Number of erratas that can be applied
+ packages_out_of_date:i Number of packages that can be upgraded
+ errata_out_of_date:i Number of erratas that can be applied
software_channel List of channels to which the system is registered
configuration_channel List of configuration channels
entitlements List of entitlements
system_group List of system group to which the system belongs
organization Organization name
- virtual_host System identifier of host, if system is a guest
+ virtual_host:i System identifier of host, if system is a guest
architecture Architecture of the system
hardware Hardware information
diff --git a/reporting/reports/data/system-history
b/reporting/reports/data/system-history
index fc29947..d03932f 100755
--- a/reporting/reports/data/system-history
+++ b/reporting/reports/data/system-history
@@ -9,8 +9,8 @@ description:
columns:
- server_id System identifier
- event_id Event id
+ server_id:i System identifier
+ event_id:i Event id
time Time of event
status Status of the event
event Type of the event
diff --git a/reporting/reports/data/system-history-channels
b/reporting/reports/data/system-history-channels
index ad24c52..4e67a44 100755
--- a/reporting/reports/data/system-history-channels
+++ b/reporting/reports/data/system-history-channels
@@ -9,8 +9,8 @@ description:
columns:
- server_id System identifier
- event_id Event id
+ server_id:i System identifier
+ event_id:i Event id
created_date Date created
status Status of the event
event Type of the event
diff --git a/reporting/reports/data/system-history-configuration
b/reporting/reports/data/system-history-configuration
index 7a0344c..5ac53d7 100755
--- a/reporting/reports/data/system-history-configuration
+++ b/reporting/reports/data/system-history-configuration
@@ -9,8 +9,8 @@ description:
columns:
- server_id System identifier
- event_id Event id
+ server_id:i System identifier
+ event_id:i Event id
created_date Date created
earliest_action Earliest date this action will occur
pickup_date The date/time the action was picked up
diff --git a/reporting/reports/data/system-history-entitlements
b/reporting/reports/data/system-history-entitlements
index 86418db..94a724a 100755
--- a/reporting/reports/data/system-history-entitlements
+++ b/reporting/reports/data/system-history-entitlements
@@ -9,8 +9,8 @@ description:
columns:
- server_id System identifier
- event_id Event id
+ server_id:i System identifier
+ event_id:i Event id
created_date Date created
status Status of the event
event Type of the event
diff --git a/reporting/reports/data/system-history-errata
b/reporting/reports/data/system-history-errata
index 0b211a4..2e55d92 100755
--- a/reporting/reports/data/system-history-errata
+++ b/reporting/reports/data/system-history-errata
@@ -9,8 +9,8 @@ description:
columns:
- server_id System identifier
- event_id Event id
+ server_id:i System identifier
+ event_id:i Event id
created_date Date created
earliest_action Earliest date this action will occur
pickup_date The date/time the action was picked up
diff --git a/reporting/reports/data/system-history-kickstart
b/reporting/reports/data/system-history-kickstart
index df3460d..291d9c5 100755
--- a/reporting/reports/data/system-history-kickstart
+++ b/reporting/reports/data/system-history-kickstart
@@ -9,8 +9,8 @@ description:
columns:
- server_id System identifier
- event_id Event id
+ server_id:i System identifier
+ event_id:i Event id
created_date Date created
earliest_action Earliest date this action will occur
pickup_date The date/time the action was picked up
diff --git a/reporting/reports/data/system-history-packages
b/reporting/reports/data/system-history-packages
index 81e83a9..0178e9a 100755
--- a/reporting/reports/data/system-history-packages
+++ b/reporting/reports/data/system-history-packages
@@ -9,8 +9,8 @@ description:
columns:
- server_id System identifier
- event_id Event id
+ server_id:i System identifier
+ event_id:i Event id
created_date Date created
earliest_action Earliest date this action will occur
pickup_date The date/time the action was picked up
diff --git a/reporting/reports/data/users b/reporting/reports/data/users
index af84cdc..c939b86 100755
--- a/reporting/reports/data/users
+++ b/reporting/reports/data/users
@@ -10,9 +10,9 @@ description:
columns:
- organization_id Organization identifier
+ organization_id:i Organization identifier
organization Organization name
- user_id Internal user id
+ user_id:i Internal user id
username User name / login
last_name Last name
first_name First name(s)
diff --git a/reporting/reports/data/users-systems b/reporting/reports/data/users-systems
index faf5295..6a76d56 100755
--- a/reporting/reports/data/users-systems
+++ b/reporting/reports/data/users-systems
@@ -9,12 +9,12 @@ description:
columns:
- organization_id Organization identifier
- user_id Internal user id
+ organization_id:i Organization identifier
+ user_id:i Internal user id
username User name / login
- server_id System identifier
+ server_id:i System identifier
group Group through the user has access to the system
- admin_access 1 if the user has access by being org administrator
+ admin_access:i 1 if the user has access by being org administrator
multival_columns:
diff --git a/reporting/spacewalk-report b/reporting/spacewalk-report
index 13c9ab1..a7c9461 100755
--- a/reporting/spacewalk-report
+++ b/reporting/spacewalk-report
@@ -27,6 +27,7 @@ try:
import os
import csv
from optparse import Option, OptionParser
+ import re
import errno
except KeyboardInterrupt:
systemExit(-1, "\nUser interrupted process.")
@@ -153,6 +154,8 @@ if __name__ == '__main__':
systemExit(-6, 'Unknown column [%s] in report [%s].' % (k, report_name))
val = ''
for x in where[k]:
+ if report.column_types[k] == 'i' and not re.match('^[0-9]+$', x):
+ systemExit(-7, 'Column [%s] in report [%s] only accepts integer value.' %
(k, report_name))
if val != '':
val = val + ', '
val = val + ":p%d" % pi
commit d6c0962f8099e466d9743713ef8b226f1ffae069
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Mon Jun 20 16:21:24 2011 +0200
Make the group column name work even if it is a reserved word.
diff --git a/reporting/spacewalk-report b/reporting/spacewalk-report
index cd5b7e3..13c9ab1 100755
--- a/reporting/spacewalk-report
+++ b/reporting/spacewalk-report
@@ -159,7 +159,10 @@ if __name__ == '__main__':
the_dict_where["p%d" % pi] = x
pi += 1
- the_sql_where.append("%s in ( %s )" % (k, val))
+ if k == 'group':
+ the_sql_where.append('"%s" in ( %s )' % (k.upper(), val))
+ else:
+ the_sql_where.append('%s in ( %s )' % (k, val))
initCFG('server')
rhnSQL.initDB(options.db)
commit 7484d37393f3f47be92f16bb18a3db3c6e7d7098
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Mon Jun 20 16:18:17 2011 +0200
Add where placeholder to support the --where-column-id=value parameter.
diff --git a/reporting/reports/data/channel-packages
b/reporting/reports/data/channel-packages
index fdb2f97..8cf023d 100755
--- a/reporting/reports/data/channel-packages
+++ b/reporting/reports/data/channel-packages
@@ -20,6 +20,7 @@ columns:
sql:
+ select * from (
select rhnchannel.label channel_label, rhnchannel.name channel_name,
rhnpackagename.name,
rhnpackageevr.version, rhnpackageevr.release, rhnpackageevr.epoch,
@@ -32,5 +33,7 @@ sql:
and rhnpackage.name_id = rhnpackagename.id
and rhnpackage.evr_id = rhnpackageevr.id
and rhnpackage.package_arch_id = rhnpackagearch.id
- order by rhnchannel.label, rhnpackagename.name, rhnpackageevr.version,
rhnpackageevr.release, rhnpackageevr.epoch, rhnpackagearch.label
+ ) X
+ -- where placeholder
+ order by channel_label, name, version, release, epoch, arch
diff --git a/reporting/reports/data/channels b/reporting/reports/data/channels
index 39651e1..20cd067 100755
--- a/reporting/reports/data/channels
+++ b/reporting/reports/data/channels
@@ -16,9 +16,12 @@ columns:
sql:
+ select * from (
select rhnchannel.label channel_label, rhnchannel.name channel_name,
count(rhnchannelpackage.channel_id) number_of_packages
from rhnchannel left outer join rhnchannelpackage
on rhnchannel.id = rhnchannelpackage.channel_id
group by rhnchannel.id, rhnchannel.label, rhnchannel.name
- order by rhnchannel.label
+ ) X
+ -- where placeholder
+ order by channel_label
diff --git a/reporting/reports/data/entitlements b/reporting/reports/data/entitlements
index 9a31a95..c9b333d 100755
--- a/reporting/reports/data/entitlements
+++ b/reporting/reports/data/entitlements
@@ -28,6 +28,7 @@ multival_columns:
sql:
+ select * from (
select organization_id,
web_customer.name as organization,
entitlement_type,
@@ -59,7 +60,9 @@ sql:
and rhnservergroup.max_members > 0
) entitlements, web_customer
where entitlements.organization_id = web_customer.id
- order by entitlements.organization_id,
+ ) X
+ -- where placeholder
+ order by organization_id,
case when entitlement_type = 'channel' then 1 else 0 end,
entitlement
diff --git a/reporting/reports/data/errata-list b/reporting/reports/data/errata-list
index 6781810..3c1bdcd 100755
--- a/reporting/reports/data/errata-list
+++ b/reporting/reports/data/errata-list
@@ -24,6 +24,7 @@ multival_columns:
sql:
+ select * from (
select rhnErrata.advisory_name as advisory,
rhnErrata.advisory_type as type,
rhnCVE.name as cve,
@@ -40,4 +41,6 @@ sql:
rhnErrata.advisory_type,
rhnCVE.name,
rhnErrata.synopsis
- order by rhnErrata.advisory_name, rhnCVE.name
+ ) X
+ -- where placeholder
+ order by advisory, cve
diff --git a/reporting/reports/data/errata-list-all
b/reporting/reports/data/errata-list-all
index d8f32c0..657036b 100755
--- a/reporting/reports/data/errata-list-all
+++ b/reporting/reports/data/errata-list-all
@@ -23,7 +23,8 @@ multival_columns:
sql:
- select rhnErrata.advisory_name as advisory,
+ select advisory, type, cve, synopsis from (
+ select rhnErrata.id, rhnErrata.advisory_name as advisory,
rhnErrata.advisory_type as type,
rhnCVE.name as cve,
rhnErrata.synopsis
@@ -31,4 +32,6 @@ sql:
on rhnErrata.id = rhnErrataCVE.errata_id
left outer join rhnCVE
on rhnErrataCVE.cve_id = rhnCVE.id
- order by rhnErrata.advisory_name, rhnErrata.id, rhnCVE.name
+ ) X
+ -- where placeholder
+ order by advisory, id, cve
diff --git a/reporting/reports/data/errata-systems
b/reporting/reports/data/errata-systems
index 314ecb9..7531831 100755
--- a/reporting/reports/data/errata-systems
+++ b/reporting/reports/data/errata-systems
@@ -17,6 +17,7 @@ columns:
sql:
+ select * from (
select rhnErrata.advisory_name as advisory,
rhnServerNeededErrataCache.server_id,
rhnServer.name as profile_name,
@@ -35,5 +36,7 @@ sql:
on rhnServerNeededErrataCache.server_id = rhnservernetwork.server_id
where rhnErrata.id = rhnServerNeededErrataCache.errata_id
and rhnServerNeededErrataCache.server_id = rhnServer.id
- order by rhnErrata.advisory_name, rhnServerNeededErrataCache.server_id
+ ) X
+ -- where placeholder
+ order by advisory, server_id
diff --git a/reporting/reports/data/inventory b/reporting/reports/data/inventory
index 38f9811..b58de47 100755
--- a/reporting/reports/data/inventory
+++ b/reporting/reports/data/inventory
@@ -40,6 +40,12 @@ multival_columns:
sql:
+ select server_id, profile_name, hostname, ip_address, registered_by,
+ registration_time, last_checkin_time, kernel_version,
+ packages_out_of_date, errata_out_of_date,
+ software_channel, configuration_channel,
+ entitlements, system_group, organization, virtual_host, architecture, hardware
+ from (
select rhnserver.id as server_id, rhnserver.name as profile_name,
rhnservernetwork.hostname, trim(rhnservernetwork.ipaddr) as ip_address,
( select login from web_contact where rhnserver.creator_id = web_contact.id ) as
registered_by,
@@ -51,9 +57,14 @@ sql:
and rhnserverneededpackagecache.package_id = rhnpackage.id ) as
packages_out_of_date,
( select count(*) from rhnServerNeededErrataCache where rhnserver.id = server_id ) as
errata_out_of_date,
rhnchannel.name as software_channel,
+ rhnchannel.parent_channel as parent_channel,
+ rhnchannel.id as channel_id,
rhnconfigchannel.name as configuration_channel,
+ rhnconfigchannel.id as configuration_channel_id,
entitlement_data.name as entitlements,
+ entitlement_data.server_group_id as entitlements_server_group_id,
group_data.name as system_group,
+ group_data.server_group_id as system_group_server_group_id,
(
select name from web_customer where rhnserver.org_id = web_customer.id
) as organization,
@@ -104,7 +115,9 @@ sql:
where host_system_id is not null
) virtual_data
on rhnserver.id = virtual_data.virtual_system_id
- order by server_id, rhnchannel.parent_channel nulls first, rhnchannel.id,
- rhnconfigchannel.id, entitlement_data.server_group_id, group_data.server_group_id,
- virtual_data.host_system_id
+ ) X
+ -- where placeholder
+ order by server_id, parent_channel nulls first, channel_id,
+ configuration_channel_id, entitlements_server_group_id, system_group_server_group_id,
+ virtual_host
diff --git a/reporting/reports/data/system-history
b/reporting/reports/data/system-history
index a11c338..fc29947 100755
--- a/reporting/reports/data/system-history
+++ b/reporting/reports/data/system-history
@@ -85,5 +85,6 @@ sql:
end
from rhnserverhistory
) X
+ -- where placeholder
order by server_id, time, event_id
diff --git a/reporting/reports/data/system-history-channels
b/reporting/reports/data/system-history-channels
index 560f0f6..ad24c52 100755
--- a/reporting/reports/data/system-history-channels
+++ b/reporting/reports/data/system-history-channels
@@ -23,9 +23,11 @@ multival_columns:
sql:
+ select server_id, event_id, created_date, status, event, event_data from (
select rhnserverhistory.server_id,
rhnserverhistory.id as event_id,
to_char(rhnserverhistory.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
+ rhnserverhistory.created as created_raw_date,
'Done' as status,
case when rhnserverhistory.summary like 'subscribed to channel %' then
'Subscribed to channel'
when rhnserverhistory.summary like 'unsubscribed from channel %' then
'Unsubscribed from channel'
@@ -33,5 +35,7 @@ sql:
details as event_data
from rhnserverhistory
where (rhnserverhistory.summary like 'subscribed to channel %' or
rhnserverhistory.summary like 'unsubscribed from channel %')
- order by rhnserverhistory.server_id, rhnserverhistory.created, rhnserverhistory.id
+ ) X
+ -- where placeholder
+ order by server_id, created_raw_date, event_id
diff --git a/reporting/reports/data/system-history-configuration
b/reporting/reports/data/system-history-configuration
index a812d06..7a0344c 100755
--- a/reporting/reports/data/system-history-configuration
+++ b/reporting/reports/data/system-history-configuration
@@ -26,9 +26,11 @@ multival_columns:
sql:
+ select server_id, event_id, created_date, earliest_action, pickup_date, completed_date,
status, event, event_data from (
select rhnserveraction.server_id,
rhnserveraction.action_id as event_id,
to_char(rhnaction.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
+ rhnaction.created as created_raw_date,
to_char(rhnaction.earliest_action, 'YYYY-MM-DD HH24:MI:SS') as
earliest_action,
to_char(rhnserveraction.pickup_time, 'YYYY-MM-DD HH24:MI:SS') as pickup_date,
to_char(rhnserveraction.completion_time, 'YYYY-MM-DD HH24:MI:SS') as
completed_date,
@@ -44,5 +46,7 @@ sql:
and rhnactionconfigrevision.config_revision_id = rhnconfigrevision.id
and rhnconfigrevision.config_file_id = rhnconfigfile.id
and rhnconfigfile.config_file_name_id = rhnconfigfilename.id
- order by rhnserveraction.server_id, rhnaction.created, rhnserveraction.action_id
+ ) X
+ -- where placeholder
+ order by server_id, created_raw_date, event_id
diff --git a/reporting/reports/data/system-history-entitlements
b/reporting/reports/data/system-history-entitlements
index 614c641..86418db 100755
--- a/reporting/reports/data/system-history-entitlements
+++ b/reporting/reports/data/system-history-entitlements
@@ -23,9 +23,11 @@ multival_columns:
sql:
+ select server_id, event_id, created_date, status, event, event_data from (
select rhnserverhistory.server_id,
rhnserverhistory.id as event_id,
to_char(rhnserverhistory.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
+ rhnserverhistory.created as created_raw_date,
'Done' as status,
case when rhnserverhistory.summary like 'Updated system release %' then
'Updated system release'
else trim(upper(substr(rhnserverhistory.summary, 1, 1)) ||
substr(rhnserverhistory.summary, 2)) end as event,
@@ -35,5 +37,7 @@ sql:
from rhnserverhistory
where rhnserverhistory.summary not like 'subscribed to channel %'
and rhnserverhistory.summary not like 'unsubscribed from channel %'
- order by rhnserverhistory.server_id, rhnserverhistory.created, rhnserverhistory.id
+ ) X
+ -- where placeholder
+ order by server_id, created_raw_date, event_id
diff --git a/reporting/reports/data/system-history-errata
b/reporting/reports/data/system-history-errata
index f681b3e..0b211a4 100755
--- a/reporting/reports/data/system-history-errata
+++ b/reporting/reports/data/system-history-errata
@@ -26,9 +26,11 @@ multival_columns:
sql:
+ select server_id, event_id, created_date, earliest_action, pickup_date, completed_date,
status, event, event_data from (
select rhnserveraction.server_id,
rhnserveraction.action_id as event_id,
to_char(rhnaction.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
+ rhnaction.created as created_raw_date,
to_char(rhnaction.earliest_action, 'YYYY-MM-DD HH24:MI:SS') as
earliest_action,
to_char(rhnserveraction.pickup_time, 'YYYY-MM-DD HH24:MI:SS') as pickup_date,
to_char(rhnserveraction.completion_time, 'YYYY-MM-DD HH24:MI:SS') as
completed_date,
@@ -41,5 +43,7 @@ sql:
and rhnserveraction.action_id = rhnaction.id
and rhnaction.action_type = rhnactiontype.id
and rhnserveraction.status = rhnactionstatus.id
- order by rhnserveraction.server_id, rhnaction.created, rhnserveraction.action_id
+ ) X
+ -- where placeholder
+ order by server_id, created_raw_date, event_id
diff --git a/reporting/reports/data/system-history-kickstart
b/reporting/reports/data/system-history-kickstart
index 36d0f66..df3460d 100755
--- a/reporting/reports/data/system-history-kickstart
+++ b/reporting/reports/data/system-history-kickstart
@@ -26,9 +26,11 @@ multival_columns:
sql:
+ select server_id, event_id, created_date, earliest_action, pickup_date, completed_date,
status, event, event_data from (
select rhnserveraction.server_id,
rhnserveraction.action_id as event_id,
to_char(rhnaction.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
+ rhnaction.created as created_raw_date,
to_char(rhnaction.earliest_action, 'YYYY-MM-DD HH24:MI:SS') as
earliest_action,
to_char(rhnserveraction.pickup_time, 'YYYY-MM-DD HH24:MI:SS') as pickup_date,
to_char(rhnserveraction.completion_time, 'YYYY-MM-DD HH24:MI:SS') as
completed_date,
@@ -46,5 +48,7 @@ sql:
and rhnaction.action_type = rhnactiontype.id
and rhnserveraction.status = rhnactionstatus.id
and rhnactiontype.label like 'kickstart.%'
- order by rhnserveraction.server_id, rhnaction.created, rhnserveraction.action_id
+ ) X
+ -- where placeholder
+ order by server_id, created_raw_date, event_id
diff --git a/reporting/reports/data/system-history-packages
b/reporting/reports/data/system-history-packages
index d13f4cc..81e83a9 100755
--- a/reporting/reports/data/system-history-packages
+++ b/reporting/reports/data/system-history-packages
@@ -26,9 +26,11 @@ multival_columns:
sql:
+ select server_id, event_id, created_date, earliest_action, pickup_date, completed_date,
status, event, event_data from (
select rhnserveraction.server_id,
rhnserveraction.action_id as event_id,
to_char(rhnaction.created, 'YYYY-MM-DD HH24:MI:SS') as created_date,
+ rhnaction.created as created_raw_date,
to_char(rhnaction.earliest_action, 'YYYY-MM-DD HH24:MI:SS') as
earliest_action,
to_char(rhnserveraction.pickup_time, 'YYYY-MM-DD HH24:MI:SS') as pickup_date,
to_char(rhnserveraction.completion_time, 'YYYY-MM-DD HH24:MI:SS') as
completed_date,
@@ -50,5 +52,7 @@ sql:
and rhnserveraction.action_id = rhnaction.id
and rhnaction.action_type = rhnactiontype.id
and rhnserveraction.status = rhnactionstatus.id
- order by rhnserveraction.server_id, rhnaction.created, rhnserveraction.action_id
+ ) X
+ -- where placeholder
+ order by server_id, created_raw_date, event_id
diff --git a/reporting/reports/data/users b/reporting/reports/data/users
index efec511..af84cdc 100755
--- a/reporting/reports/data/users
+++ b/reporting/reports/data/users
@@ -31,6 +31,7 @@ multival_columns:
sql:
+ select * from (
select web_contact.org_id as organization_id,
web_customer.name as organization,
web_contact.id as user_id,
@@ -63,5 +64,7 @@ sql:
where web_contact.org_id = web_customer.id
and web_contact.id = web_user_personal_info.web_user_id
and web_contact.id = rhnUserInfo.user_id
- order by web_customer.id, web_contact.id
+ ) X
+ -- where placeholder
+ order by organization_id, user_id
diff --git a/reporting/reports/data/users-systems b/reporting/reports/data/users-systems
index b805004..faf5295 100755
--- a/reporting/reports/data/users-systems
+++ b/reporting/reports/data/users-systems
@@ -26,6 +26,7 @@ multival_columns:
# adapted query available_to_uid
sql:
+ select * from (
select organization_id, web_contact_adm.user_id, username, server_id, group_name as
"GROUP", admin_access
from (
select web_contact.org_id as organization_id,
@@ -54,5 +55,7 @@ sql:
on ( case when web_contact_adm.admin_access is null then 0 else
web_contact_adm.admin_access end ) = rhn_contact_server_group.is_admin
and web_contact_adm.user_id = rhn_contact_server_group.user_id
where rhn_contact_server_group.server_id is not null
+ ) X
+ -- where placeholder
order by organization_id, user_id, server_id
commit eb00b042179a6539ed54c17fe771b0ff141f2da6
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Mon Jun 20 15:29:44 2011 +0200
Process --where-column-id=value parameter and filter based on that.
diff --git a/reporting/spacewalk-report b/reporting/spacewalk-report
index 495d224..cd5b7e3 100755
--- a/reporting/spacewalk-report
+++ b/reporting/spacewalk-report
@@ -67,14 +67,43 @@ def processCommandline():
optionParser = OptionParser( \
usage="usage: %s [options] [report_name]" % sys.argv[0], \
option_list=optionsTable)
+
+ where = {}
+ i = 1
+ while i < len(sys.argv):
+ if sys.argv[i].startswith('--where-'):
+ o = sys.argv[i][len('--where-'):]
+ try:
+ (k, v) = o.split('=', 1)
+ del sys.argv[i]
+ i -= 1
+ except ValueError:
+ # we couldn't split, which means there is no
+ # equal sign -- need to grab the next parameter
+ if i == len(sys.argv) - 1:
+ optionParser.error('option %s has to have a parameter' % sys.argv[i] )
+ k = o
+ del sys.argv[i]
+ v = sys.argv[i]
+ del sys.argv[i]
+ i -= 2
+
+ k = k.replace('-', '_')
+ if where.has_key(k):
+ where[k].append(v)
+ else:
+ where[k] = [ v ]
+
+ i += 1
+
options, args = optionParser.parse_args()
sys.argv[1:] = args
- return options
+ return options, where
if __name__ == '__main__':
- options = processCommandline()
+ (options, where) = processCommandline()
try:
if len(sys.argv) > 2:
@@ -116,13 +145,34 @@ if __name__ == '__main__':
if need_exit:
sys.exit(0)
+ the_sql_where = []
+ the_dict_where = {}
+ pi = 1
+ for k in where.keys():
+ if k not in report.columns:
+ systemExit(-6, 'Unknown column [%s] in report [%s].' % (k, report_name))
+ val = ''
+ for x in where[k]:
+ if val != '':
+ val = val + ', '
+ val = val + ":p%d" % pi
+ the_dict_where["p%d" % pi] = x
+ pi += 1
+
+ the_sql_where.append("%s in ( %s )" % (k, val))
+
initCFG('server')
rhnSQL.initDB(options.db)
writer = csv.writer(sys.stdout, lineterminator = "\n")
- h = rhnSQL.prepare(report.sql)
- h.execute()
+ the_sql = report.sql
+
+ 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)
db_columns = map(lambda x: x[0].lower(), h.description)
if db_columns != report.columns: