backend/Makefile.defs | 14 ++++++++++++-- backend/satellite_tools/Makefile | 8 ++++++++ backend/satellite_tools/reports.py | 11 +++++++++++ backend/satellite_tools/reports/data/inventory | 19 +++++++++++++++++++ backend/satellite_tools/spacewalk-report | 23 ++++++----------------- backend/spacewalk-backend.spec | 2 ++ 6 files changed, 58 insertions(+), 19 deletions(-)
New commits: commit 3541da9e12b8d29227b3540f337f478ee0bfcf21 Author: Jan Pazdziora jpazdziora@redhat.com Date: Thu Jul 23 14:30:11 2009 +0200
reporting: move the SQL to definition file, to allow for multiple reports.
diff --git a/backend/Makefile.defs b/backend/Makefile.defs index 4ae90b6..ee3fe86 100644 --- a/backend/Makefile.defs +++ b/backend/Makefile.defs @@ -9,6 +9,9 @@ TOP ?= . ROOT ?= /usr/share/rhn export ROOT
+SPACEWALK_ROOT ?= /usr/share/spacewalk +export SPACEWALK_ROOT + PREFIX ?= export PREFIX
@@ -29,18 +32,25 @@ PYFILES = $(addsuffix .py,$(FILES)) PYCFILES = $(addsuffix .pyc,$(FILES)) PYOFILES = $(addsuffix .pyo,$(FILES))
+SPACEWALK_PYFILES = $(addsuffix .py,$(SPACEWALK_FILES)) +SPACEWALK_PYCFILES = $(addsuffix .pyc,$(SPACEWALK_FILES)) + # what do we need to install and where INSTALL_FILES += $(PYFILES) $(PYCFILES) INSTALL_DEST ?= $(ROOT)/$(SUBDIR)
+SPACEWALK_INSTALL_FILES += $(SPACEWALK_PYFILES) $(SPACEWALK_PYCFILES) + DIRS += $(addprefix $(PREFIX), \ - $(sort $(EXTRA_DIRS)) $(INSTALL_DEST)) + $(sort $(EXTRA_DIRS)) $(INSTALL_DEST) $(SPACEWALK_ROOT))
all :: $(INSTALL_FILES)
-install :: all $(DIRS) $(INSTALL_FILES) +install :: all $(DIRS) $(INSTALL_FILES) $(SPACEWALK_INSTALL_FILES) @$(foreach f,$(INSTALL_FILES), \ $(INSTALL_DATA) $(f) $(PREFIX)$(INSTALL_DEST)/$(f) ; ) + @$(foreach f,$(SPACEWALK_INSTALL_FILES), \ + $(INSTALL_DATA) $(f) $(PREFIX)$(SPACEWALK_ROOT)/$(f) ; )
$(DIRS): $(INSTALL_DIR) $@ diff --git a/backend/satellite_tools/Makefile b/backend/satellite_tools/Makefile index b783b27..c2c08c0 100644 --- a/backend/satellite_tools/Makefile +++ b/backend/satellite_tools/Makefile @@ -19,6 +19,12 @@ SCRIPTS = satellite-sync spacewalk-debug\ rhn-ssl-dbstore update-packages rhn-db-stats \ spacewalk-report
+SPACEWALK_SUBDIRS = reports reports/data + +SPACEWALK_FILES = reports + +SPACEWALK_REPORT_FILES = reports/data + # check if we can build man pages DOCBOOK = $(wildcard /usr/bin/docbook2man)
@@ -40,6 +46,8 @@ include $(TOP)/Makefile.defs all :: $(SCRIPTS) install :: $(SCRIPTS) $(PREFIX)/$(BINDIR) $(INSTALL_BIN) $(SCRIPTS) $(PREFIX)/$(BINDIR) + $(INSTALL_DIR) $(addprefix $(PREFIX)$(SPACEWALK_ROOT)/, $(SPACEWALK_SUBDIRS)) + $(INSTALL_DATA) $(SPACEWALK_REPORT_FILES)/* $(PREFIX)$(SPACEWALK_ROOT)/reports/data
ifneq ($(DOCBOOK),) # install man pages diff --git a/backend/satellite_tools/reports.py b/backend/satellite_tools/reports.py new file mode 100644 index 0000000..d0e7ae6 --- /dev/null +++ b/backend/satellite_tools/reports.py @@ -0,0 +1,11 @@ + +import os + +REPORT_DEFINITIONS = "/usr/share/spacewalk/reports/data" + +class report: + def __init__(self, name): + full_path = os.path.join(REPORT_DEFINITIONS, name) + fd = open(full_path, 'r') + self.sql = fd.read() + diff --git a/backend/satellite_tools/reports/data/inventory b/backend/satellite_tools/reports/data/inventory new file mode 100755 index 0000000..3d33ad5 --- /dev/null +++ b/backend/satellite_tools/reports/data/inventory @@ -0,0 +1,19 @@ + + 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, + to_char(rhnserver.created, 'YYYY-MM-DD HH24:MI:SS') as registration_time, + ( select to_char(checkin, 'YYYY-MM-DD HH24:MI:SS') from rhnserverinfo where rhnserver.id = server_id ) as last_checkin_time + from rhnserver, + ( + select server_id, hostname, ipaddr + from rhnservernetwork + where id in ( + select min(id) + from rhnservernetwork + group by server_id + ) + ) rhnservernetwork + where rhnserver.id = rhnservernetwork.server_id (+) + order by server_id + diff --git a/backend/satellite_tools/spacewalk-report b/backend/satellite_tools/spacewalk-report index 2f7c30d..216d52a 100755 --- a/backend/satellite_tools/spacewalk-report +++ b/backend/satellite_tools/spacewalk-report @@ -35,6 +35,9 @@ _LIBPATH = "/usr/share/rhn" if _LIBPATH not in sys.path: sys.path.append(_LIBPATH)
+sys.path.append('/usr/share/spacewalk') +import reports + try: from server import rhnSQL from common import initCFG @@ -67,27 +70,11 @@ if __name__ == '__main__': try: initCFG('server') rhnSQL.initDB(options.db) + + report = reports.report(sys.argv[1]) writer = csv.writer(sys.stdout)
- h = rhnSQL.prepare(""" - 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, - to_char(rhnserver.created, 'YYYY-MM-DD HH24:MI:SS') as registration_time, - ( select to_char(checkin, 'YYYY-MM-DD HH24:MI:SS') from rhnserverinfo where rhnserver.id = server_id ) as last_checkin_time - from rhnserver, - ( - select server_id, hostname, ipaddr - from rhnservernetwork - where id in ( - select min(id) - from rhnservernetwork - group by server_id - ) - ) rhnservernetwork - where rhnserver.id = rhnservernetwork.server_id (+) - order by server_id - """) + h = rhnSQL.prepare(report.sql) h.execute() writer.writerow(map(lambda x: x[0].lower(), h.description)) row = h.fetchone() diff --git a/backend/spacewalk-backend.spec b/backend/spacewalk-backend.spec index 20a389d..bdaeca6 100644 --- a/backend/spacewalk-backend.spec +++ b/backend/spacewalk-backend.spec @@ -535,6 +535,8 @@ rm -f %{rhnconf}/rhnSecret.py* %{rhnroot}/satellite_tools/disk_dumper/iss_actions.py* %{rhnroot}/satellite_tools/disk_dumper/dumper.py* %{rhnroot}/satellite_tools/disk_dumper/string_buffer.py* +%{_prefix}/share/spacewalk/reports.py* +%{_prefix}/share/spacewalk/reports/data/* %config %attr(644,root,apache) %{rhnconf}/default/rhn_server_iss.conf %{_mandir}/man8/rhn-satellite-exporter.8* %{_mandir}/man8/rhn-charsets.8*
commit 69ad5bbfb82751750c1dcc7ad290d9036a7523ab Author: Jan Pazdziora jpazdziora@redhat.com Date: Thu Jul 23 11:58:07 2009 +0200
reporting: add registration time and last check-in time.
diff --git a/backend/satellite_tools/spacewalk-report b/backend/satellite_tools/spacewalk-report index d59002f..2f7c30d 100755 --- a/backend/satellite_tools/spacewalk-report +++ b/backend/satellite_tools/spacewalk-report @@ -72,7 +72,9 @@ if __name__ == '__main__': h = rhnSQL.prepare(""" 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 + ( select login from web_contact where rhnserver.creator_id = web_contact.id ) as registered_by, + to_char(rhnserver.created, 'YYYY-MM-DD HH24:MI:SS') as registration_time, + ( select to_char(checkin, 'YYYY-MM-DD HH24:MI:SS') from rhnserverinfo where rhnserver.id = server_id ) as last_checkin_time from rhnserver, ( select server_id, hostname, ipaddr
spacewalk-commits@lists.fedorahosted.org