aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Moravec <pmoravec@redhat.com>2020-07-10 13:01:53 +0200
committerJake Hunsaker <jhunsake@redhat.com>2020-07-16 11:32:25 -0400
commit91917210e69977005bb254e0f08d4d38bfe49718 (patch)
tree1024dde5899e70d18a71becaebe418dbe222398b
parent0d04bc94d5f29895356a47e95d12fc2e2bc4a39c (diff)
downloadsos-91917210e69977005bb254e0f08d4d38bfe49718.tar.gz
[foreman] collect tasks in CSV format
Collect foreman_tasks_tasks table in CSV format. Further, add escaping of commas inside CSV fields by using COPY (..) WITH (FORMAT 'csv', DELIMITER ',', HEADER) command rather than "psql -A -F , -X". Resolves: #2148 Signed-off-by: Pavel Moravec <pmoravec@redhat.com> Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/report/plugins/foreman.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/sos/report/plugins/foreman.py b/sos/report/plugins/foreman.py
index 0ebef8c1..034e86d3 100644
--- a/sos/report/plugins/foreman.py
+++ b/sos/report/plugins/foreman.py
@@ -222,7 +222,6 @@ class Foreman(Plugin):
'foreman_settings_table': scmd,
'foreman_auth_table': authcmd,
'dynflow_schema_info': 'select * from dynflow_schema_info',
- 'foreman_tasks_tasks': 'select * from foreman_tasks_tasks',
'audits_table_count': 'select count(*) from audits',
'logs_table_count': 'select count(*) from logs',
'fact_names_prefixes': factnamescmd,
@@ -232,9 +231,10 @@ class Foreman(Plugin):
'left join nics as n on n.host_id=h.id'
}
- # Same as above, but for CSV output
+ # Same as above, but tasks should be in CSV output
foremancsv = {
+ 'foreman_tasks_tasks': 'select * from foreman_tasks_tasks',
'dynflow_execution_plans': dyncmd,
'dynflow_actions': dactioncmd,
'dynflow_steps': dstepscmd,
@@ -261,9 +261,11 @@ class Foreman(Plugin):
shell and postgres parsing requirements. Note that this will generate
a large amount of quoting in sos logs referencing the command being run
"""
- csvformat = "-A -F , -X" if csv else ""
- _dbcmd = "psql -h %s -p 5432 -U foreman -d foreman %s -c %s"
- return _dbcmd % (self.dbhost, csvformat, quote(query))
+ if csv:
+ query = "COPY (%s) TO STDOUT " \
+ "WITH (FORMAT 'csv', DELIMITER ',', HEADER)" % query
+ _dbcmd = "psql -h %s -p 5432 -U foreman -d foreman -c %s"
+ return _dbcmd % (self.dbhost, quote(query))
def postproc(self):
satreg = r"((foreman.*)?(\"::(foreman(.*?)|katello).*)?((::(.*)::.*" \